1616use App \Models \Component ;
1717use App \Models \Consumable ;
1818use App \Models \LicenseSeat ;
19+ use App \Models \Location ;
1920use App \Models \Setting ;
2021use App \Models \User ;
2122use App \Notifications \CheckinAccessoryNotification ;
@@ -60,14 +61,14 @@ public function onCheckedOut($event)
6061 $ adminCcEmailsArray = array_map ('trim ' , explode (', ' , $ adminCcEmail ));
6162 }
6263 $ ccEmails = array_filter ($ adminCcEmailsArray );
63- $ notifiable = $ event ->checkedOutTo ;
6464 $ mailable = $ this ->getCheckoutMailType ($ event , $ acceptance );
65+ $ notifiable = $ this ->getNotifiables ($ event );
66+
67+ if (!$ event ->checkedOutTo ->locale ){
68+ $ mailable ->locale ($ event ->checkedOutTo ->locale );
69+ }
6570 // Send email notifications
6671 try {
67- if (!$ event ->checkedOutTo ->locale ){
68- $ mailable ->locale ($ event ->checkedOutTo ->locale );
69- }
70-
7172 /**
7273 * Send an email if any of the following conditions are met:
7374 * 1. The asset requires acceptance
@@ -77,15 +78,20 @@ public function onCheckedOut($event)
7778
7879 if ($ event ->checkoutable ->requireAcceptance () || $ event ->checkoutable ->getEula () ||
7980 (method_exists ($ event ->checkoutable , 'checkin_email ' ) && $ event ->checkoutable ->checkin_email ())) {
80- if (!empty ($ notifiable-> email )) {
81+ if (!empty ($ notifiable )) {
8182 Mail::to ($ notifiable )->cc ($ ccEmails )->send ($ mailable );
82- } else {
83+ } elseif (! empty ( $ ccEmails )) {
8384 Mail::cc ($ ccEmails )->send ($ mailable );
8485 }
85- Log::info ('Sending email, Locale: ' . ($ event ->checkedOutTo ->locale ?? 'default ' ));
86- }
87-
86+ Log::info ('Sending email, Locale: ' . ($ event ->checkedOutTo ->locale ?? 'default ' ));
87+ }
88+ } catch (ClientException $ e ) {
89+ Log::debug ("Exception caught during checkout email: " . $ e ->getMessage ());
90+ } catch (Exception $ e ) {
91+ Log::debug ("Exception caught during checkout email: " . $ e ->getMessage ());
92+ }
8893// Send Webhook notification
94+ try {
8995 if ($ this ->shouldSendWebhookNotification ()) {
9096 if (Setting::getSettings ()->webhook_selected === 'microsoft ' ) {
9197 $ message = $ this ->getCheckoutNotification ($ event )->toMicrosoftTeams ();
@@ -137,38 +143,43 @@ public function onCheckedIn($event)
137143 $ adminCcEmailsArray = array_map ('trim ' , explode (', ' , $ adminCcEmail ));
138144 }
139145 $ ccEmails = array_filter ($ adminCcEmailsArray );
140- $ notifiable = $ event ->checkedOutTo ;
141146 $ mailable = $ this ->getCheckinMailType ($ event );
147+ $ notifiable = $ this ->getNotifiables ($ event );
142148
149+ if (!$ event ->checkedOutTo ->locale ){
150+ $ mailable ->locale ($ event ->checkedOutTo ->locale );
151+ }
143152 // Send email notifications
144153 try {
145- if (!$ event ->checkedOutTo ->locale ){
146- $ mailable ->locale ($ event ->checkedOutTo ->locale );
147- }
148154 /**
149155 * Send an email if any of the following conditions are met:
150156 * 1. The asset requires acceptance
151157 * 2. The item has a EULA
152158 * 3. The item should send an email at check-in/check-out
153159 */
154-
155160 if ($ event ->checkoutable ->requireAcceptance () || $ event ->checkoutable ->getEula () ||
156161 (method_exists ($ event ->checkoutable , 'checkin_email ' ) && $ event ->checkoutable ->checkin_email ())) {
157- if (!empty ($ notifiable-> email )) {
162+ if (!empty ($ notifiable )) {
158163 Mail::to ($ notifiable )->cc ($ ccEmails )->send ($ mailable );
159- } else {
164+ } elseif (! empty ( $ ccEmails )) {
160165 Mail::cc ($ ccEmails )->send ($ mailable );
161166 }
162167 Log::info ('Sending email, Locale: ' . $ event ->checkedOutTo ->locale );
163168 }
169+ } catch (ClientException $ e ) {
170+ Log::debug ("Exception caught during checkin email: " . $ e ->getMessage ());
171+ } catch (Exception $ e ) {
172+ Log::debug ("Exception caught during checkin email: " . $ e ->getMessage ());
173+ }
164174
165- // Send Webhook notification
175+ // Send Webhook notification
176+ try {
166177 if ($ this ->shouldSendWebhookNotification ()) {
167178 Notification::route (Setting::getSettings ()->webhook_selected , Setting::getSettings ()->webhook_endpoint )
168179 ->notify ($ this ->getCheckinNotification ($ event ));
169180 }
170181 } catch (ClientException $ e ) {
171- Log::warning ("Exception caught during checkout notification: " . $ e ->getMessage ());
182+ Log::warning ("Exception caught during checkin notification: " . $ e ->getMessage ());
172183 } catch (Exception $ e ) {
173184 Log::warning ("Exception caught during checkin notification: " . $ e ->getMessage ());
174185 }
@@ -278,6 +289,19 @@ private function getCheckinMailType($event){
278289 return new $ mailable ($ event ->checkoutable , $ event ->checkedOutTo , $ event ->checkedInBy , $ event ->note );
279290
280291 }
292+ private function getNotifiables ($ event ){
293+
294+ if ($ event ->checkedOutTo instanceof Asset){
295+ $ event ->checkedOutTo ->load ('assignedTo ' );
296+ return $ event ->checkedOutTo ->assignedto ?->email ?? '' ;
297+ }
298+ else if ($ event ->checkedOutTo instanceof Location) {
299+ return $ event ->checkedOutTo ->manager ?->email ?? '' ;
300+ }
301+ else {
302+ return $ event ->checkedOutTo ->email ;
303+ }
304+ }
281305
282306 /**
283307 * Register the listeners for the subscriber.
0 commit comments