From fb7bec4be41767d38b45d63d32c715ad2d87bcba Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 11 Feb 2025 10:55:56 -0800 Subject: [PATCH] adds expiring asset and license mail --- app/Console/Commands/SendExpirationAlerts.php | 13 ++-- app/Mail/ExpiringAssetsMail.php | 62 +++++++++++++++++++ app/Mail/ExpiringLicenseMail.php | 62 +++++++++++++++++++ 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 app/Mail/ExpiringAssetsMail.php create mode 100644 app/Mail/ExpiringLicenseMail.php diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 025ba2ce2..20dd6c674 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -2,6 +2,8 @@ namespace App\Console\Commands; +use App\Mail\ExpiringAssetsMail; +use App\Mail\ExpiringLicenseMail; use App\Models\Asset; use App\Models\License; use App\Models\Recipients\AlertRecipient; @@ -9,6 +11,7 @@ use App\Models\Setting; use App\Notifications\ExpiringAssetsNotification; use App\Notifications\ExpiringLicenseNotification; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Mail; class SendExpirationAlerts extends Command { @@ -47,22 +50,22 @@ class SendExpirationAlerts extends Command if (($settings->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 AlertRecipient($item); - }); + $recipients = collect(explode(',', $settings->alert_email)) + ->map(fn($item) => trim($item)) // Trim each email + ->all(); // Expiring Assets $assets = Asset::getExpiringWarrantee($threshold); if ($assets->count() > 0) { $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold])); - \Notification::send($recipients, new ExpiringAssetsNotification($assets, $threshold)); + Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $threshold)); } // Expiring licenses $licenses = License::getExpiringLicenses($threshold); if ($licenses->count() > 0) { $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold])); - \Notification::send($recipients, new ExpiringLicenseNotification($licenses, $threshold)); + Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $threshold)); } } else { if ($settings->alert_email == '') { diff --git a/app/Mail/ExpiringAssetsMail.php b/app/Mail/ExpiringAssetsMail.php new file mode 100644 index 000000000..13d322f06 --- /dev/null +++ b/app/Mail/ExpiringAssetsMail.php @@ -0,0 +1,62 @@ +assets = $params; + $this->threshold = $threshold; + } + + /** + * 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.Expiring_Assets_Report'), + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + markdown: 'notifications.markdown.report-expiring-assets', + with: [ + 'assets' => $this->assets, + 'threshold' => $this->threshold, + ] + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/app/Mail/ExpiringLicenseMail.php b/app/Mail/ExpiringLicenseMail.php new file mode 100644 index 000000000..77d94df63 --- /dev/null +++ b/app/Mail/ExpiringLicenseMail.php @@ -0,0 +1,62 @@ +licenses = $params; + $this->threshold = $threshold; + } + + /** + * 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.Expiring_Licenses_Report'), + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + markdown: 'notifications.markdown.report-expiring-licenses', + with: [ + 'licenses' => $this->licenses, + 'threshold' => $this->threshold, + ] + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +}