Skip to content

Commit bb7dabc

Browse files
committed
adds expired-licenses command parameter
1 parent f233408 commit bb7dabc

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/Console/Commands/SendExpirationAlerts.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
class SendExpirationAlerts extends Command
1515
{
1616
/**
17-
* The console command name.
18-
*
17+
* The name and signature of the console command.
18+
*
1919
* @var string
2020
*/
21-
protected $name = 'snipeit:expiring-alerts';
21+
protected $signature = 'snipeit:expiring-alerts {--expired-licenses}';
2222

2323
/**
2424
* The console command description.
@@ -85,7 +85,7 @@ public function handle()
8585
}
8686

8787
// Expiring licenses
88-
$licenses = License::query()->ExpiringLicenses($alert_interval)
88+
$licenses = License::query()->ExpiringLicenses($alert_interval, $this->option('expired-licenses'))
8989
->with('manufacturer','category')
9090
->orderBy('expiration_date', 'ASC')
9191
->orderBy('termination_date', 'ASC')

app/Models/License.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)