Skip to content

Commit e2019a1

Browse files
committed
rewrite expired assets collection query
1 parent c5252ea commit e2019a1

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

app/Models/Asset.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -937,28 +937,37 @@ public function model()
937937
*/
938938
public static function getExpiringWarrantyOrEol($days = 30)
939939
{
940-
941-
return self::where('archived', '=', '0')
940+
$now = now();
941+
$end = now()->addDays($days);
942+
$expired_assets = self::query()
943+
->where('archived', '=', '0')
942944
->NotArchived()
943945
->whereNull('deleted_at')
944-
->where(function ($query) use ($days) {
945-
// Check for manual asset EOL first
946-
$query->where(function ($query) use ($days) {
947-
$query->whereNotNull('asset_eol_date')
948-
->whereBetween('asset_eol_date', [Carbon::now(), Carbon::now()->addDays($days)]);
949-
// Otherwise use the warranty months + purchase date + threshold
950-
})->orWhere(function ($query) use ($days) {
951-
$query->whereNotNull('purchase_date')
952-
->whereNotNull('warranty_months')
953-
->whereRaw(
954-
'DATE_ADD(purchase_date, INTERVAL warranty_months MONTH) BETWEEN ? AND ?',
955-
[now(), now()->addDays($days)]
956-
);
957-
});
958-
})
959-
->orderBy('asset_eol_date', 'ASC')
960-
->orderBy('purchase_date', 'ASC')
946+
->whereNotNull('asset_eol_date')
947+
->whereBetween('asset_eol_date', [$now, $end])
961948
->get();
949+
950+
// return self::where('archived', '=', '0')
951+
// ->NotArchived()
952+
// ->whereNull('deleted_at')
953+
// ->where(function ($query) use ($days) {
954+
// // Check for manual asset EOL first
955+
// $query->where(function ($query) use ($days) {
956+
// $query->whereNotNull('asset_eol_date')
957+
// ->whereBetween('asset_eol_date', [Carbon::now(), Carbon::now()->addDays($days)]);
958+
// // Otherwise use the warranty months + purchase date + threshold
959+
// })->orWhere(function ($query) use ($days) {
960+
// $query->whereNotNull('purchase_date')
961+
// ->whereNotNull('warranty_months')
962+
// ->whereRaw(
963+
// 'DATE_ADD(purchase_date, INTERVAL warranty_months MONTH) BETWEEN ? AND ?',
964+
// [now(), now()->addDays($days)]
965+
// );
966+
// });
967+
// })
968+
// ->orderBy('asset_eol_date', 'ASC')
969+
// ->orderBy('purchase_date', 'ASC')
970+
// ->get();
962971
}
963972

964973

tests/Feature/Notifications/Email/ExpiringAlertsNotificationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ExpiringAlertsNotificationTest extends TestCase
1717
public function testExpiringAssetsEmailNotification()
1818
{
1919
Mail::fake();
20-
$this->markIncompleteIfSqlite();
2120

2221
$this->settings->enableAlertEmail('[email protected]');
2322
$this->settings->setAlertInterval(30);
@@ -71,8 +70,6 @@ public function testExpiringAssetsEmailNotification()
7170
public function testExpiringLicensesEmailNotification()
7271
{
7372
Mail::fake();
74-
$this->markIncompleteIfSqlite();
75-
7673
$this->settings->enableAlertEmail('[email protected]');
7774
$this->settings->setAlertInterval(60);
7875

0 commit comments

Comments
 (0)