Skip to content

A free open source IT asset/license management system

rewrite expired assets collection query

Godfrey Me2019a13abd7
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 422b2dd538..f68e797d5f 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -937,28 +937,37 @@ class Asset extends Depreciable
*/
public static function getExpiringWarrantyOrEol($days = 30)
{
-
- return self::where('archived', '=', '0')
+ $now = now();
+ $end = now()->addDays($days);
+ $expired_assets = self::query()
+ ->where('archived', '=', '0')
->NotArchived()
->whereNull('deleted_at')
- ->where(function ($query) use ($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')
- ->whereRaw(
- 'DATE_ADD(purchase_date, INTERVAL warranty_months MONTH) BETWEEN ? AND ?',
- [now(), now()->addDays($days)]
- );
- });
- })
- ->orderBy('asset_eol_date', 'ASC')
- ->orderBy('purchase_date', 'ASC')
+ ->whereNotNull('asset_eol_date')
+ ->whereBetween('asset_eol_date', [$now, $end])
->get();
+
+// return self::where('archived', '=', '0')
+// ->NotArchived()
+// ->whereNull('deleted_at')
+// ->where(function ($query) use ($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')
+// ->whereRaw(
+// 'DATE_ADD(purchase_date, INTERVAL warranty_months MONTH) BETWEEN ? AND ?',
+// [now(), now()->addDays($days)]
+// );
+// });
+// })
+// ->orderBy('asset_eol_date', 'ASC')
+// ->orderBy('purchase_date', 'ASC')
+// ->get();
}
diff --git a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php
index 89b9716e56..707f5468d4 100644
--- a/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php
+++ b/tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php
@@ -17,7 +17,6 @@ class ExpiringAlertsNotificationTest extends TestCase
public function testExpiringAssetsEmailNotification()
{
Mail::fake();
- $this->markIncompleteIfSqlite();
$this->settings->enableAlertEmail('[email protected]');
$this->settings->setAlertInterval(30);
@@ -71,8 +70,6 @@ class ExpiringAlertsNotificationTest extends TestCase
public function testExpiringLicensesEmailNotification()
{
Mail::fake();
- $this->markIncompleteIfSqlite();
-
$this->settings->enableAlertEmail('[email protected]');
$this->settings->setAlertInterval(60);