A free open source IT asset/license management system
adds expired-licenses command parameter
Godfrey Mbb7dabc73bd3
diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.phpindex 7a97d39375..29c642ba50 100644--- a/app/Console/Commands/SendExpirationAlerts.php+++ b/app/Console/Commands/SendExpirationAlerts.php@@ -14,11 +14,11 @@ use Illuminate\Support\Facades\Mail;class SendExpirationAlerts extends Command{/**- * The console command name.- *+ * The name and signature of the console command.+ ** @var string*/- protected $name = 'snipeit:expiring-alerts';+ protected $signature = 'snipeit:expiring-alerts {--expired-licenses}';/*** The console command description.@@ -85,7 +85,7 @@ class SendExpirationAlerts extends Command}// Expiring licenses- $licenses = License::query()->ExpiringLicenses($alert_interval)+ $licenses = License::query()->ExpiringLicenses($alert_interval, $this->option('expired-licenses'))->with('manufacturer','category')->orderBy('expiration_date', 'ASC')->orderBy('termination_date', 'ASC')diff --git a/app/Models/License.php b/app/Models/License.phpindex e241d5fd84..3f6bcf1c13 100755--- a/app/Models/License.php+++ b/app/Models/License.php@@ -784,21 +784,24 @@ class License extends Depreciable* @return \Illuminate\Database\Eloquent\Relations\Relation* @see \App\Console\Commands\SendExpiringLicenseNotifications*/- public function scopeExpiringLicenses($query, $days = 60)+ public function scopeExpiringLicenses($query, $days = 60, $includeExpired = false){return $query// The termination date is null or within range->where(function ($query) use ($days) {$query->whereNull('termination_date')->orWhereBetween('termination_date', [Carbon::now(), Carbon::now()->addDays($days)]);})- ->where(function ($query) use ($days) {+ ->where(function ($query) use ($days, $includeExpired) {$query->whereNotNull('expiration_date')// Handle expiring licenses without termination dates- ->where(function ($query) use ($days) {+ ->where(function ($query) use ($days, $includeExpired) {$query->whereNull('termination_date')- ->whereBetween('expiration_date', [Carbon::now(), Carbon::now()->addDays($days)]);+ ->whereBetween('expiration_date', [Carbon::now(), Carbon::now()->addDays($days)])+ //include expired licenses if requested+ ->when($includeExpired, function ($query) use ($days) {+ $query->orwhereDate('expiration_date', '<=', Carbon::now());+ });})-// Handle expiring licenses with termination dates in the future->orWhere(function ($query) use ($days) {$query->whereBetween('termination_date', [Carbon::now(), Carbon::now()->addDays($days)]);