@@ -784,21 +784,24 @@ public function scopeExpiredLicenses($query)
784784 * @return \Illuminate\Database\Eloquent\Relations\Relation
785785 * @see \App\Console\Commands\SendExpiringLicenseNotifications
786786 */
787- public function scopeExpiringLicenses ($ query , $ days = 60 )
787+ public function scopeExpiringLicenses ($ query , $ days = 60 , $ includeExpired = false )
788788 {
789789 return $ query// The termination date is null or within range
790790 ->where (function ($ query ) use ($ days ) {
791791 $ query ->whereNull ('termination_date ' )
792792 ->orWhereBetween ('termination_date ' , [Carbon::now (), Carbon::now ()->addDays ($ days )]);
793793 })
794- ->where (function ($ query ) use ($ days ) {
794+ ->where (function ($ query ) use ($ days, $ includeExpired ) {
795795 $ query ->whereNotNull ('expiration_date ' )
796796 // Handle expiring licenses without termination dates
797- ->where (function ($ query ) use ($ days ) {
797+ ->where (function ($ query ) use ($ days, $ includeExpired ) {
798798 $ query ->whereNull ('termination_date ' )
799- ->whereBetween ('expiration_date ' , [Carbon::now (), Carbon::now ()->addDays ($ days )]);
799+ ->whereBetween ('expiration_date ' , [Carbon::now (), Carbon::now ()->addDays ($ days )])
800+ //include expired licenses if requested
801+ ->when ($ includeExpired , function ($ query ) use ($ days ) {
802+ $ query ->orwhereDate ('expiration_date ' , '<= ' , Carbon::now ());
803+ });
800804 })
801-
802805 // Handle expiring licenses with termination dates in the future
803806 ->orWhere (function ($ query ) use ($ days ) {
804807 $ query ->whereBetween ('termination_date ' , [Carbon::now (), Carbon::now ()->addDays ($ days )]);
0 commit comments