Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/Console/Commands/SendExpirationAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
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.
Expand Down Expand Up @@ -85,7 +85,7 @@ public function handle()
}

// 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')
Expand Down
13 changes: 8 additions & 5 deletions app/Models/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,21 +784,24 @@ public function scopeExpiredLicenses($query)
* @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)]);
Expand Down
Loading