Skip to content

A free open source IT asset/license management system

Fixes #14295 - allow user to receive an email PDF upon signing

snipe8e38b3898ecb
diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php
index c041cfa6b2..75ccd5004f 100644
--- a/app/Http/Controllers/Account/AcceptanceController.php
+++ b/app/Http/Controllers/Account/AcceptanceController.php
@@ -21,6 +21,7 @@ use App\Models\License;
use App\Models\Component;
use App\Models\Consumable;
use App\Notifications\AcceptanceAssetAcceptedNotification;
+use App\Notifications\AcceptanceAssetAcceptedToUserNotification;
use App\Notifications\AcceptanceAssetDeclinedNotification;
use Exception;
use Illuminate\Http\Request;
@@ -151,6 +152,8 @@ class AcceptanceController extends Controller
}
}
+
+ $assigned_user = User::find($acceptance->assigned_to_id);
// this is horrible
switch($acceptance->checkoutable_type){
case 'App\Models\Asset':
@@ -160,35 +163,30 @@ class AcceptanceController extends Controller
return redirect()->back()->with('error', trans('admin/models/message.does_not_exist'));
}
$display_model = $asset_model->name;
- $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
break;
case 'App\Models\Accessory':
$pdf_view_route ='account.accept.accept-accessory-eula';
$accessory = Accessory::find($item->id);
$display_model = $accessory->name;
- $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
break;
case 'App\Models\LicenseSeat':
$pdf_view_route ='account.accept.accept-license-eula';
$license = License::find($item->license_id);
$display_model = $license->name;
- $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
break;
case 'App\Models\Component':
$pdf_view_route ='account.accept.accept-component-eula';
$component = Component::find($item->id);
$display_model = $component->name;
- $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
break;
case 'App\Models\Consumable':
$pdf_view_route ='account.accept.accept-consumable-eula';
$consumable = Consumable::find($item->id);
$display_model = $consumable->name;
- $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
break;
}
// if ($acceptance->checkoutable_type == 'App\Models\Asset') {
@@ -229,7 +227,7 @@ class AcceptanceController extends Controller
'note' => $request->input('note'),
'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'),
'accepted_date' => Carbon::parse($acceptance->accepted_at)->format('Y-m-d'),
- 'assigned_to' => $assigned_to,
+ 'assigned_to' => $assigned_user->present()->fullName,
'company_name' => $branding_settings->site_name,
'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null,
'logo' => $path_logo,
@@ -243,6 +241,19 @@ class AcceptanceController extends Controller
}
$acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note'));
+
+ // Send the PDF to the signing user
+ if (($request->input('send_copy') == '1') && ($assigned_user->email !='')) {
+
+ // Add the attachment for the signing user into the $data array
+ $data['file'] = $pdf_filename;
+
+ try {
+ $assigned_user->notify(new AcceptanceAssetAcceptedToUserNotification($data));
+ } catch (\Exception $e) {
+ Log::warning($e);
+ }
+ }
try {
$acceptance->notify(new AcceptanceAssetAcceptedNotification($data));
} catch (\Exception $e) {
diff --git a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php
new file mode 100644
index 0000000000..238b48f708
--- /dev/null
+++ b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Notifications;
+
+use App\Helpers\Helper;
+use App\Models\Setting;
+use Illuminate\Bus\Queueable;
+use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Notifications\Notification;
+
+class AcceptanceAssetAcceptedToUserNotification extends Notification
+{
+ use Queueable;
+
+ /**
+ * Create a new notification instance.
+ *
+ * @return void
+ */
+ public function __construct($params)
+ {
+ $this->item_tag = $params['item_tag'];
+ $this->item_model = $params['item_model'];
+ $this->item_serial = $params['item_serial'];
+ $this->item_status = $params['item_status'];
+ $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false);
+ $this->assigned_to = $params['assigned_to'];
+ $this->note = $params['note'];
+ $this->company_name = $params['company_name'];
+ $this->settings = Setting::getSettings();
+ $this->file = $params['file'] ?? null;
+
+ }
+
+ /**
+ * Get the notification's delivery channels.
+ *
+ * @param mixed $notifiable
+ * @return array
+ */
+ public function via()
+ {
+
+ $notifyBy = ['mail'];
+
+ return $notifyBy;
+
+ }
+
+ /**
+ * Get the mail representation of the notification.
+ *
+ * @param mixed $notifiable
+ * @return \Illuminate\Notifications\Messages\MailMessage
+ */
+ public function toMail()
+ {
+ $pdf_path = storage_path('private_uploads/eula-pdfs/'.$this->file);
+ $message = (new MailMessage)->markdown('notifications.markdown.asset-acceptance',
+ [
+ 'item_tag' => $this->item_tag,
+ 'item_model' => $this->item_model,
+ 'item_serial' => $this->item_serial,
+ 'item_status' => $this->item_status,
+ 'note' => $this->note,
+ 'accepted_date' => $this->accepted_date,
+ 'assigned_to' => $this->assigned_to,
+ 'company_name' => $this->company_name,
+ 'intro_text' => trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name]),
+ ])
+ ->attach($pdf_path)
+ ->subject(trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->settings->site_name]));
+
+ return $message;
+ }
+
+
+
+}
diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php
index 65b544b343..6878de1561 100644
--- a/resources/lang/en-US/mail.php
+++ b/resources/lang/en-US/mail.php
@@ -27,8 +27,10 @@ return [
'Low_Inventory_Report' => 'Low Inventory Report',
'a_user_canceled' => 'A user has canceled an item request on the website',
'a_user_requested' => 'A user has requested an item on the website',
+ 'acceptance_asset_accepted_to_user' => 'You have accepted an item assigned to you by :site_name',
'acceptance_asset_accepted' => 'A user has accepted an item',
'acceptance_asset_declined' => 'A user has declined an item',
+ 'send_pdf_copy' => 'Send a copy of this acceptance to my email address',
'accessory_name' => 'Accessory Name',
'additional_notes' => 'Additional Notes',
'admin_has_created' => 'An administrator has created an account for you on the :web website.',
diff --git a/resources/views/account/accept/create.blade.php b/resources/views/account/accept/create.blade.php
index e811d48105..bf078969fd 100644
--- a/resources/views/account/accept/create.blade.php
+++ b/resources/views/account/accept/create.blade.php
@@ -43,7 +43,7 @@
<div class="col-sm-12 col-sm-offset-1 col-md-10 col-md-offset-1">
<div class="panel box box-default">
<div class="box-body">
- <div class="col-md-12">
+ <div class="col-md-12" style="padding-top: 20px;">
@if ($acceptance->checkoutable->getEula())
<div id="eula_div" style="padding-bottom: 20px">
{!! $acceptance->checkoutable->getEula() !!}
@@ -87,6 +87,13 @@
</div>
</div>
</div>
+
+ <div class="col-md-12" style="padding-top: 20px">
+ <label class="form-control">
+ <input type="checkbox" value="1" name="send_copy" checked="checked" aria-label="send_copy">
+ {{ trans('mail.send_pdf_copy') }} ({{ auth()->user()->email }})
+ </label>
+ </div>
@endif
</div> <!-- / box-body -->