@@ -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
0 commit comments