diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index a149bc05a3..8816e39cc8 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -8,6 +8,7 @@ use App\Mail\CheckinLicenseMail; use App\Mail\CheckoutAccessoryMail; use App\Mail\CheckoutAssetMail; use App\Mail\CheckinAssetMail; +use App\Mail\CheckoutComponentMail; use App\Mail\CheckoutConsumableMail; use App\Mail\CheckoutLicenseMail; use App\Models\Accessory; @@ -152,7 +153,8 @@ class CheckoutableListener return; } - if ($shouldSendEmailToUser || $shouldSendEmailToAlertAddress) { + if (($shouldSendEmailToUser || $shouldSendEmailToAlertAddress) && + !($event->checkoutable instanceof Component)) { /** * Send the appropriate notification */ @@ -318,6 +320,7 @@ class CheckoutableListener Asset::class => CheckoutAssetMail::class, LicenseSeat::class => CheckoutLicenseMail::class, Consumable::class => CheckoutConsumableMail::class, + Component::class => CheckoutComponentMail::class, ]; $mailable= $lookup[get_class($event->checkoutable)]; diff --git a/app/Mail/CheckoutComponentMail.php b/app/Mail/CheckoutComponentMail.php new file mode 100644 index 0000000000..44f0d33a0d --- /dev/null +++ b/app/Mail/CheckoutComponentMail.php @@ -0,0 +1,88 @@ +item = $component; + $this->admin = $checkedOutBy; + $this->note = $note; + $this->target = $checkedOutTo; + $this->acceptance = $acceptance; + $this->qty = optional($component->assets->first())->pivot->assigned_qty; + + + $this->settings = Setting::getSettings(); + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + $from = new Address(config('mail.from.address'), config('mail.from.name')); + + return new Envelope( + from: $from, + subject: trans('mail.Confirm_component_delivery'), + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + + $eula = $this->item->getEula(); + $req_accept = $this->item->requireAcceptance(); + + $accept_url = is_null($this->acceptance) ? null : route('account.accept.item', $this->acceptance); + + return new Content( + markdown: 'mail.markdown.checkout-component', + with: [ + 'item' => $this->item, + 'admin' => $this->admin, + 'note' => $this->note, + 'target' => $this->target, + 'eula' => $eula, + 'req_accept' => $req_accept, + 'accept_url' => $accept_url, + 'qty' => $this->qty, + ] + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } + public function build() + { + return $this + ->markdown('mail.markdown.checkout-component', $this->viewData); + } +} diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 7c82eec29d..b45f38fdd9 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -11,6 +11,7 @@ return [ 'Confirm_accessory_delivery' => 'Accessory delivery confirmation', 'Confirm_asset_delivery' => 'Asset delivery confirmation', 'Confirm_consumable_delivery' => 'Consumable delivery confirmation', + 'Confirm_component_delivery' => 'Component delivery confirmation', 'Confirm_license_delivery' => 'License delivery confirmation', 'Consumable_checkout_notification' => 'Consumable checked out', 'Component_checkout_notification' => 'Component checked out', diff --git a/resources/views/mail/markdown/checkout-component.blade.php b/resources/views/mail/markdown/checkout-component.blade.php new file mode 100644 index 0000000000..c3359638aa --- /dev/null +++ b/resources/views/mail/markdown/checkout-component.blade.php @@ -0,0 +1,51 @@ +@component('mail::message') +# {{ trans('mail.hello') }} {{ $target->assignedto->present()->fullName() }}, + +{{ trans('mail.new_item_checked') }} + + +@component('mail::table') +| | | +| ------------- | ------------- | +@if (isset($checkout_date)) +| **{{ trans('mail.checkout_date') }}** | {{ $checkout_date }} | +@endif +| **{{ trans('general.component') }}** | {{ $item->name }} | +@if (isset($qty)) +| **{{ trans('general.qty') }}** | {{ $qty }} | +@endif +@if (isset($item->manufacturer)) +| **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} | +@endif +@if ($note) +| **{{ trans('mail.additional_notes') }}** | {{ $note }} | +@endif +@if ($admin) +| **{{ trans('general.administrator') }}** | {{ $admin->present()->fullName() }} | +@endif +@endcomponent + +@if (($req_accept == 1) && ($eula!='')) +{{ trans('mail.read_the_terms_and_click') }} +@elseif (($req_accept == 1) && ($eula=='')) +{{ trans('mail.click_on_the_link_asset') }} +@elseif (($req_accept == 0) && ($eula!='')) +{{ trans('mail.read_the_terms') }} +@endif + +@if ($eula) +@component('mail::panel') +{!! $eula !!} +@endcomponent +@endif + +@if ($req_accept == 1) +**[✔ {{ trans('mail.i_have_read') }}]({{ $accept_url }})** +@endif + + +{{ trans('mail.best_regards') }} + +{{ $snipeSettings->site_name }} + +@endcomponent diff --git a/routes/web.php b/routes/web.php index 9ce977309d..40a1d163ec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -52,7 +52,12 @@ Route::group(['middleware' => 'auth'], function () { [LabelsController::class, 'show'] )->where('labelName', '.*')->name('labels.show'); + Route::get('/test-email', function () { + $mailable = new \App\Mail\CheckoutComponentMail( + ); + return $mailable->render(); // dumps HTML + }); /* * Manufacturers */