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..22a97b709f --- /dev/null +++ b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php @@ -0,0 +1,79 @@ +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->company_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..797c527535 100644 --- a/resources/views/account/accept/create.blade.php +++ b/resources/views/account/accept/create.blade.php @@ -43,7 +43,7 @@
-
+
@if ($acceptance->checkoutable->getEula())
{!! $acceptance->checkoutable->getEula() !!} @@ -87,6 +87,15 @@
+ + @if (auth()->user()->email!='') + + @endif @endif
@@ -104,6 +113,9 @@ @stop diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 4e2293f59b..0062a7210e 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -639,11 +639,9 @@ $(document).ready(function() { @if (!config('app.lock_passwords')) if (this.value.length > 5){ - console.log('email field is ' + this.value.length + ' - enable the checkbox'); $('#email_user_checkbox').prop("disabled", false); $("#email_user_checkbox").parent().removeClass("form-control--disabled"); } else { - console.log('email field is ' + this.value.length + ' - DISABLE the checkbox'); $('#email_user_checkbox').prop("disabled", true); $('#email_user_checkbox').prop("checked", false); $("#email_user_checkbox").parent().addClass("form-control--disabled");