diff --git a/app/Console/Commands/SendExpectedCheckinAlerts.php b/app/Console/Commands/SendExpectedCheckinAlerts.php index 1a2c6d09dd..cd04aa1193 100644 --- a/app/Console/Commands/SendExpectedCheckinAlerts.php +++ b/app/Console/Commands/SendExpectedCheckinAlerts.php @@ -57,12 +57,12 @@ class SendExpectedCheckinAlerts extends Command } } - - // Send a rollup to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AlertRecipient(); - - if (($assets) && ($assets->count() > 0) && ($settings->alert_email!='')) { - $recipient->notify(new ExpectedCheckinAdminNotification($assets)); + if (($assets) && ($assets->count() > 0) && ($settings->alert_email != '')) { + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new \App\Models\Recipients\AlertRecipient($item); + }); + \Notification::send($recipients, new ExpectedCheckinAdminNotification($assets)); } diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 82a324067c..03ffc0cd41 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -50,26 +50,27 @@ class SendExpirationAlerts extends Command $threshold = $settings->alert_interval; - // Expiring Assets - $assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); - $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count'=>$assets->count(), 'threshold' => $threshold])); + if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) { - // Expiring licenses - $licenses = License::getExpiringLicenses($threshold); - - $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count'=>$licenses->count(), 'threshold' => $threshold])); - - $recipient = new \App\Models\Recipients\AlertRecipient(); - - if ((Setting::getSettings()->alert_email!='') && ($settings->alerts_enabled==1)) { + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new \App\Models\Recipients\AlertRecipient($item); + }); + // Expiring Assets + $assets = Asset::getExpiringWarrantee(Setting::getSettings()->alert_interval); if ($assets->count() > 0) { - // Send a rollup to the admin, if settings dictate - $recipient->notify(new ExpiringAssetsNotification($assets, $threshold)); + $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), + ['count' => $assets->count(), 'threshold' => $threshold])); } + // Expiring licenses + $licenses = License::getExpiringLicenses($threshold); + + if ($licenses->count() > 0) { - $recipient->notify(new ExpiringLicenseNotification($licenses, $threshold)); + $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold])); + \Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold)); } diff --git a/app/Console/Commands/SendInventoryAlerts.php b/app/Console/Commands/SendInventoryAlerts.php index 1f96fca9d1..cd9627e81a 100644 --- a/app/Console/Commands/SendInventoryAlerts.php +++ b/app/Console/Commands/SendInventoryAlerts.php @@ -50,13 +50,14 @@ class SendInventoryAlerts extends Command $items = Helper::checkLowInventory(); // Send a rollup to the admin, if settings dictate - $recipient = new \App\Models\Recipients\AlertRecipient(); - if (($items) && (count($items) > 0) && ($settings->alert_email!='')) { - - $this->info( trans_choice('mail.low_inventory_alert',count($items)) ); - - $recipient->notify(new InventoryAlert($items, $settings->alert_threshold)); + if (($items) && (count($items) > 0)) { + $this->info(trans_choice('mail.low_inventory_alert', count($items))); + // Send a rollup to the admin, if settings dictate + $recipients = collect(explode(',', $settings->alert_email))->map(function ($item, $key) { + return new \App\Models\Recipients\AlertRecipient($item); + }); + \Notification::send($recipients, new InventoryAlert($items, $settings->alert_threshold)); } } else { diff --git a/app/Models/Recipients/AlertRecipient.php b/app/Models/Recipients/AlertRecipient.php index af9e3a012e..548d39d752 100644 --- a/app/Models/Recipients/AlertRecipient.php +++ b/app/Models/Recipients/AlertRecipient.php @@ -5,10 +5,9 @@ use App\Models\Setting; class AlertRecipient extends Recipient{ - public function __construct() + public function __construct(string $email) { - $settings = Setting::getSettings(); - $this->email = $settings->alert_email; + $this->email = trim($email); } }