@@ -299,16 +299,36 @@ public function setTerminationDateAttribute($value)
299299 }
300300
301301 public function isInactive (): bool
302- {
303- $ day = now ()->startOfDay ();
302+ {
303+ $ day = now ()->startOfDay ();
304304
305- $ expired = $ this ->expiration_date && $ this ->asDateTime ($ this ->expiration_date )->startofDay ()->lessThanOrEqualTo ($ day );
305+ $ expired = $ this ->expiration_date && $ this ->asDateTime ($ this ->expiration_date )->startofDay ()->lessThanOrEqualTo ($ day );
306306
307- $ terminated = $ this ->termination_date && $ this ->asDateTime ($ this ->termination_date )->startofDay ()->lessThanOrEqualTo ($ day );
307+ $ terminated = $ this ->termination_date && $ this ->asDateTime ($ this ->termination_date )->startofDay ()->lessThanOrEqualTo ($ day );
308308
309309
310- return $ expired || $ terminated ;
311- }
310+ return $ this ->isExpired () || $ this ->isTerminated ();
311+ }
312+
313+ public function isExpired (): bool
314+ {
315+ $ day = now ()->startOfDay ();
316+
317+ $ expired = $ this ->expiration_date && $ this ->asDateTime ($ this ->expiration_date )->startofDay ()->lessThanOrEqualTo ($ day );
318+
319+ return $ expired ;
320+ }
321+
322+ public function isTerminated (): bool
323+ {
324+ $ day = now ()->startOfDay ();
325+
326+ $ terminated = $ this ->termination_date && $ this ->asDateTime ($ this ->termination_date )->startofDay ()->lessThanOrEqualTo ($ day );
327+
328+
329+ return $ terminated ;
330+ }
331+
312332 /**
313333 * Sets free_seat_count attribute
314334 *
@@ -750,6 +770,38 @@ public static function getExpiringLicenses($days = 60)
750770 ->get ();
751771 }
752772
773+ public function scopeActiveLicenses ($ query )
774+ {
775+
776+ return $ query ->whereNull ('deleted_at ' )
777+
778+ // The termination date is null or within range
779+ ->where (function ($ query ) {
780+ $ query ->whereNull ('termination_date ' )
781+ ->orWhereDate ('termination_date ' , '> ' , [Carbon::now ()]);
782+ })
783+ ->where (function ($ query ) {
784+ $ query ->whereNull ('expiration_date ' )
785+ ->orWhereDate ('expiration_date ' , '> ' , [Carbon::now ()]);
786+ });
787+ }
788+
789+ public function scopeExpiredLicenses ($ query )
790+ {
791+
792+ return $ query ->whereNull ('deleted_at ' )
793+
794+ // The termination date is null or within range
795+ ->where (function ($ query ) {
796+ $ query ->whereNull ('termination_date ' )
797+ ->orWhereDate ('termination_date ' , '<= ' , [Carbon::now ()]);
798+ })
799+ ->orWhere (function ($ query ) {
800+ $ query ->whereNull ('expiration_date ' )
801+ ->orWhereDate ('expiration_date ' , '<= ' , [Carbon::now ()]);
802+ });
803+ }
804+
753805 /**
754806 * Query builder scope to order on manufacturer
755807 *
0 commit comments