A free open source IT asset/license management system
Fixed nesting in orWhere
snipe4339e4552ea6
diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.phpindex 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.phpindex 02b865ea80..3caed663cb 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();