From d1207444dbcb31750a045277f612bc68a96e00f1 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 16 Sep 2025 11:20:49 +0100 Subject: [PATCH] Fixed nesting in orWhere --- app/Console/Commands/SendExpirationAlerts.php | 2 +- app/Models/Asset.php | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index 3479e7953e..27f2683b41 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -53,7 +53,7 @@ class SendExpirationAlerts extends Command ->filter(fn($item) => !empty($item)) ->all(); // Expiring Assets - $assets = Asset::getExpiringWarrantee($alert_interval); + $assets = Asset::getExpiringWarranteeOrEol($alert_interval); if ($assets->count() > 0) { $this->info(trans_choice('mail.assets_warrantee_alert', $assets->count(), ['count' => $assets->count(), 'threshold' => $alert_interval])); diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 37c8f34f33..e4d441c856 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -823,24 +823,25 @@ class Asset extends Depreciable * @since [v2.0] * @return mixed */ - public static function getExpiringWarrantee($days = 30) + public static function getExpiringWarranteeOrEol($days = 30) { return self::where('archived', '=', '0') ->NotArchived() ->whereNull('deleted_at') - - // Check for manual asset EOL first ->where(function ($query) use ($days) { - $query->whereNotNull('asset_eol_date') - ->whereBetween('asset_eol_date', [Carbon::now(), Carbon::now()->addDays($days)]); - }) - // Otherwise use the warranty months + purchase date + threshold - ->orWhere(function ($query) use ($days) { - $query->whereNotNull('purchase_date') - ->whereNotNull('warranty_months') - ->whereDate('purchase_date', '<=', Carbon::now()->addMonths('assets.warranty_months')->addDays($days)); + // Check for manual asset EOL first + $query->where(function ($query) use ($days) { + $query->whereNotNull('asset_eol_date') + ->whereBetween('asset_eol_date', [Carbon::now(), Carbon::now()->addDays($days)]); + // Otherwise use the warranty months + purchase date + threshold + })->orWhere(function ($query) use ($days) { + $query->whereNotNull('purchase_date') + ->whereNotNull('warranty_months') + ->whereDate('purchase_date', '<=', Carbon::now()->addMonths('assets.warranty_months')->addDays($days)); + }); }) + ->orderBy('asset_eol_date', 'ASC') ->orderBy('purchase_date', 'ASC') ->get();