From 4bac509341c2e3a8187bb00fd98f740afcd4bcc4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 4 Mar 2025 12:58:04 -0800 Subject: [PATCH] fix Expiring alert tests --- app/Console/Commands/SendExpirationAlerts.php | 14 +++++++------- app/Models/Asset.php | 5 ++++- .../Email/ExpiringAlertsNotificationTest.php | 7 +++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 1220e0cd9d..2e0c2a62f5 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -42,7 +42,7 @@ class SendExpirationAlerts extends Command public function handle() { $settings = Setting::getSettings(); - $threshold = $settings->alert_interval; + $alert_interval = $settings->alert_interval; if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) { @@ -51,18 +51,18 @@ class SendExpirationAlerts extends Command ->map(fn($item) => trim($item)) // Trim each email ->all(); // Expiring Assets - $assets = Asset::getExpiringWarrantee($threshold); + $assets = Asset::getExpiringWarrantee($alert_interval); if ($assets->count() > 0) { - $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $threshold])); - Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $threshold)); + $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $alert_interval])); + Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $alert_interval)); } // Expiring licenses - $licenses = License::getExpiringLicenses($threshold); + $licenses = License::getExpiringLicenses($alert_interval); if ($licenses->count() > 0) { - $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $threshold])); - Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $threshold)); + $this->info(trans_choice('mail.license_expiring_alert', $licenses->count(), ['count' => $licenses->count(), 'threshold' => $alert_interval])); + Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $alert_interval)); } } else { if ($settings->alert_email == '') { diff --git a/app/Models/Asset.php b/app/Models/Asset.php index c571578172..cc016583c3 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -785,9 +785,12 @@ class Asset extends Depreciable ->whereNotNull('warranty_months') ->whereNotNull('purchase_date') ->whereNull('deleted_at') - ->whereRaw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL ' + ->whereRaw('DATE_ADD(`purchase_date`, INTERVAL `warranty_months` MONTH) <= DATE_ADD(NOW(), INTERVAL ' . $days . ' DAY) AND DATE_ADD(`purchase_date`, INTERVAL `warranty_months` MONTH) > NOW()') +// ->whereRaw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH) <= DATE(NOW() + INTERVAL ' +// . $days +// . ' DAY) AND DATE_ADD(`purchase_date`, INTERVAL `warranty_months` MONTH) > NOW()') ->orderByRaw('DATE_ADD(`purchase_date`,INTERVAL `warranty_months` MONTH)') ->get(); } diff --git a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php index 5bc034ba5a..09baf26d25 100644 --- a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php +++ b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php @@ -26,20 +26,19 @@ class ExpiringAlertsNotificationTest extends TestCase $alert_email = Setting::first()->alert_email; $expiringAsset = Asset::factory()->create([ - 'purchase_date' => now()->subMonths(11)->format('Y-m-d'), + 'purchase_date' => now()->subDays(350)->format('Y-m-d'), 'warranty_months' => 12, 'archived' => 0, 'deleted_at' => null, ]); - $expiredAsset = Asset::factory()->create([ - 'purchase_date' => now()->subMonths(13)->format('Y-m-d'), + 'purchase_date' => now()->subDays(370)->format('Y-m-d'), 'warranty_months' => 12, 'archived' => 0, 'deleted_at' => null, ]); $notExpiringAsset = Asset::factory()->create([ - 'purchase_date' => now()->subMonths(10)->format('Y-m-d'), + 'purchase_date' => now()->subDays(330)->format('Y-m-d'), 'warranty_months' => 12, 'archived' => 0, 'deleted_at' => null,