A free open source IT asset/license management system
add Component Checkin Mail
Godfrey Mf130186b3785
diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.phpindex 8816e39cc8..7e289b19e6 100644--- a/app/Listeners/CheckoutableListener.php+++ b/app/Listeners/CheckoutableListener.php@@ -4,6 +4,7 @@ namespace App\Listeners;use App\Events\CheckoutableCheckedOut;use App\Mail\CheckinAccessoryMail;+use App\Mail\CheckinComponentMail;use App\Mail\CheckinLicenseMail;use App\Mail\CheckoutAccessoryMail;use App\Mail\CheckoutAssetMail;@@ -28,7 +29,6 @@ use App\Notifications\CheckinLicenseSeatNotification;use App\Notifications\CheckoutAccessoryNotification;use App\Notifications\CheckoutAssetNotification;use App\Notifications\CheckoutComponentNotification;-use App\Notifications\CheckoutComponentsNotification;use App\Notifications\CheckoutConsumableNotification;use App\Notifications\CheckoutLicenseSeatNotification;use GuzzleHttp\Exception\ClientException;@@ -153,8 +153,7 @@ class CheckoutableListenerreturn;}- if (($shouldSendEmailToUser || $shouldSendEmailToAlertAddress) &&- !($event->checkoutable instanceof Component)) {+ if ($shouldSendEmailToUser || $shouldSendEmailToAlertAddress) {/*** Send the appropriate notification*/@@ -333,8 +332,8 @@ class CheckoutableListenerAccessory::class => CheckinAccessoryMail::class,Asset::class => CheckinAssetMail::class,LicenseSeat::class => CheckinLicenseMail::class,+ Component::class => CheckinComponentMail::class,];-$mailable= $lookup[get_class($event->checkoutable)];return new $mailable($event->checkoutable, $event->checkedOutTo, $event->checkedInBy, $event->note);@@ -480,7 +479,8 @@ class CheckoutableListenerreturn match (true) {$checkoutable instanceof Asset => $checkoutable->model->category,$checkoutable instanceof Accessory,- $checkoutable instanceof Consumable => $checkoutable->category,+ $checkoutable instanceof Consumable,+ $checkoutable instanceof Component => $checkoutable->category,$checkoutable instanceof LicenseSeat => $checkoutable->license->category,};}diff --git a/app/Mail/CheckinComponentMail.php b/app/Mail/CheckinComponentMail.phpnew file mode 100644index 0000000000..5b62a2c4b8--- /dev/null+++ b/app/Mail/CheckinComponentMail.php@@ -0,0 +1,71 @@+<?php++namespace App\Mail;++use App\Models\Accessory;+use App\Models\Component;+use App\Models\Setting;+use App\Models\User;+use Illuminate\Bus\Queueable;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Mail\Mailable;+use Illuminate\Mail\Mailables\Address;+use Illuminate\Mail\Mailables\Content;+use Illuminate\Mail\Mailables\Envelope;+use Illuminate\Queue\SerializesModels;++class CheckinComponentMail extends Mailable+{+ use Queueable, SerializesModels;++ /**+ * Create a new message instance.+ */+ public function __construct(Component $component, $checkedOutTo, User $checkedInby, $note)+ {+ $this->item = $component;+ $this->target = $checkedOutTo;+ $this->admin = $checkedInby;+ $this->note = $note;+ $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_checkin'),+ );+ }++ /**+ * Get the message content definition.+ */+ public function content(): Content+ {+ return new Content(+ markdown: 'mail.markdown.checkin-component',+ with: [+ 'item' => $this->item,+ 'admin' => $this->admin,+ 'note' => $this->note,+ 'target' => $this->target,+ ]+ );+ }++ /**+ * Get the attachments for the message.+ *+ * @return array<int, \Illuminate\Mail\Mailables\Attachment>+ */+ public function attachments(): array+ {+ return [];+ }+}diff --git a/app/Models/Component.php b/app/Models/Component.phpindex 997579a021..63ed623012 100644--- a/app/Models/Component.php+++ b/app/Models/Component.php@@ -9,6 +9,7 @@ use App\Presenters\Presentable;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\SoftDeletes;use Illuminate\Support\Facades\Gate;+use Illuminate\Support\Facades\Storage;use Watson\Validating\ValidatingTrait;/**@@ -278,6 +279,19 @@ class Component extends SnipeModel}+ /**+ * Determine whether to send a checkin/checkout email based on+ * asset model category+ *+ * @author [A. Gianotto] [<[email protected]>]+ * @since [v4.0]+ * @return bool+ */+ public function checkin_email()+ {+ return $this->category?->checkin_email;+ }+/*** Check how many items within a component are remainingdiff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.phpindex b45f38fdd9..c38932d6fc 100644--- a/resources/lang/en-US/mail.php+++ b/resources/lang/en-US/mail.php@@ -8,6 +8,7 @@ return ['Asset_Checkout_Notification' => 'Asset checked out','Confirm_Accessory_Checkin' => 'Accessory checkin confirmation','Confirm_Asset_Checkin' => 'Asset checkin confirmation',+ 'Confirm_component_checkin' => 'Component checkin confirmation','Confirm_accessory_delivery' => 'Accessory delivery confirmation','Confirm_asset_delivery' => 'Asset delivery confirmation','Confirm_consumable_delivery' => 'Consumable delivery confirmation',diff --git a/resources/views/mail/markdown/checkin-component.blade.php b/resources/views/mail/markdown/checkin-component.blade.phpnew file mode 100644index 0000000000..70442f5e3e--- /dev/null+++ b/resources/views/mail/markdown/checkin-component.blade.php@@ -0,0 +1,25 @@+@component('mail::message')+# {{ trans('mail.hello') }} {{ $target->assignedto->present()->fullName() }},++{{ trans('mail.the_following_item') }}++@component('mail::table')+| | |+| ------------- | ------------- |+| **{{ trans('general.component') }}** | {{ $item->name }} |+@if (isset($item->manufacturer))+| **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} |+@endif+@if ($admin)+| **{{ trans('general.administrator') }}** | {{ $admin->present()->fullName() }} |+@endif+@if ($note)+| **{{ trans('mail.additional_notes') }}** | {{ $note }} |+@endif+@endcomponent++{{ trans('mail.best_regards') }}++{{ $snipeSettings->site_name }}++@endcomponentdiff --git a/resources/views/mail/markdown/checkout-component.blade.php b/resources/views/mail/markdown/checkout-component.blade.phpindex c3359638aa..0a26b57512 100644--- a/resources/views/mail/markdown/checkout-component.blade.php+++ b/resources/views/mail/markdown/checkout-component.blade.php@@ -3,7 +3,6 @@{{ trans('mail.new_item_checked') }}-@component('mail::table')| | || ------------- | ------------- |