From 1899e4d1e8174bf41b73f0838fb8d533da79a411 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Thu, 15 Sep 2022 13:18:42 -0700 Subject: [PATCH 1/3] try/catch wrap notifications on checkin/checkout --- app/Listeners/CheckoutableListener.php | 52 +++++++++++++++----------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 71b131f40..9d6cd942b 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -20,6 +20,8 @@ use App\Notifications\CheckoutConsumableNotification; use App\Notifications\CheckoutLicenseNotification; use App\Notifications\CheckoutLicenseSeatNotification; use Illuminate\Support\Facades\Notification; +use Exception; +use Log; class CheckoutableListener { @@ -43,16 +45,20 @@ class CheckoutableListener */ $acceptance = $this->getCheckoutAcceptance($event); - if (! $event->checkedOutTo->locale) { - Notification::locale(Setting::getSettings()->locale)->send( - $this->getNotifiables($event), - $this->getCheckoutNotification($event, $acceptance) - ); - } else { - Notification::send( - $this->getNotifiables($event), - $this->getCheckoutNotification($event, $acceptance) - ); + try { + if (! $event->checkedOutTo->locale) { + Notification::locale(Setting::getSettings()->locale)->send( + $this->getNotifiables($event), + $this->getCheckoutNotification($event, $acceptance) + ); + } else { + Notification::send( + $this->getNotifiables($event), + $this->getCheckoutNotification($event, $acceptance) + ); + } + } catch (Exception $e) { + Log::error("Exception caught during checkout notification: ".$e->getMessage()); } } @@ -83,17 +89,21 @@ class CheckoutableListener } } - // Use default locale - if (! $event->checkedOutTo->locale) { - Notification::locale(Setting::getSettings()->locale)->send( - $this->getNotifiables($event), - $this->getCheckinNotification($event) - ); - } else { - Notification::send( - $this->getNotifiables($event), - $this->getCheckinNotification($event) - ); + try { + // Use default locale + if (! $event->checkedOutTo->locale) { + Notification::locale(Setting::getSettings()->locale)->send( + $this->getNotifiables($event), + $this->getCheckinNotification($event) + ); + } else { + Notification::send( + $this->getNotifiables($event), + $this->getCheckinNotification($event) + ); + } + } catch (Exception $e) { + Log::error("Exception caught during checkin notification: ".$e->getMessage()); } } From 28059c878a87d07202308f21e4b22d642db7d38f Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 17 Oct 2022 11:16:29 -0700 Subject: [PATCH 2/3] gets the proper amount of months and fixes typo of the word depreciation --- app/Models/Depreciable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index e22fb65a7..11bd745de 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -69,14 +69,14 @@ class Depreciable extends SnipeModel public function getLinearDepreciatedValue() // TODO - for testing it might be nice to have an optional $relative_to param here, defaulted to 'now' { if ($this->purchase_date) { - $months_passed = $this->purchase_date->diff(now())->m; + $months_passed = ($this->purchase_date->diff(now())->m)+($this->purchase_date->diff(now())->y*12); } else { return null; } if ($months_passed >= $this->get_depreciation()->months){ //if there is a floor use it - if($this->get_depreciation()->deprecation_min->isNotEmpty()) { + if(!$this->get_depreciation()->depreciation_min== null) { $current_value = $this->get_depreciation()->depreciation_min; From d359bcb88d9768c3a6c8816e6ac9d9810c09cfc4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 17 Oct 2022 13:15:10 -0700 Subject: [PATCH 3/3] adds proper spacing --- app/Models/Depreciable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 11bd745de..250894820 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -76,7 +76,7 @@ class Depreciable extends SnipeModel if ($months_passed >= $this->get_depreciation()->months){ //if there is a floor use it - if(!$this->get_depreciation()->depreciation_min== null) { + if(!$this->get_depreciation()->depreciation_min == null) { $current_value = $this->get_depreciation()->depreciation_min;