Skip to content

A free open source IT asset/license management system

Reverse expires diff direction

snipe4934dc85accc
diff --git a/app/Models/License.php b/app/Models/License.php
index 73d7c22c3d..897107dee9 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -168,7 +168,7 @@ class License extends Depreciable
protected function terminatesDiffInDays(): Attribute
{
return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::parse($attributes['termination_date'])->diffInDays() : null,
+ get: fn(mixed $value, array $attributes) => $attributes['termination_date'] ? Carbon::now()->diffInDays($attributes['termination_date']) : null,
);
}
@@ -746,6 +746,23 @@ class License extends Depreciable
});
}
+ /**
+ * Expiried/terminated licenses scope
+ *
+ * @author A. Gianotto <[email protected]>
+ * @since [v1.0]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ * @see \App\Console\Commands\SendExpiringLicenseNotifications
+ */
+ public function scopeExpiredLicenses($query)
+ {
+ return $query->whereDate('termination_date', '<=', Carbon::now())// The termination date is null or within range
+ ->orWhere(function ($query) {
+ $query->whereDate('expiration_date', '<=', Carbon::now());
+ })
+ ->whereNull('deleted_at');
+ }
+
/**
* Expiring/terminating licenses scope
*
@@ -761,7 +778,7 @@ class License extends Depreciable
* @return \Illuminate\Database\Eloquent\Relations\Relation
* @see \App\Console\Commands\SendExpiringLicenseNotifications
*/
- public function scopeExpiredLicenses($query, $days = 60)
+ public function scopeExpiringLicenses($query, $days = 60)
{
return $query// The termination date is null or within range
->where(function ($query) use ($days) {
@@ -770,19 +787,17 @@ class License extends Depreciable
})
->where(function ($query) use ($days) {
$query->whereNotNull('expiration_date')
- // Handle expired licenses without termination dates
+ // Handle expiring licenses without termination dates
->where(function ($query) use ($days) {
$query->whereNull('termination_date')
->whereBetween('expiration_date', [Carbon::now(), Carbon::now()->addDays($days)]);
})
- // Handle expired licenses with termination dates in the future
+ // Handle expiring licenses with termination dates in the future
->orWhere(function ($query) use ($days) {
$query->whereBetween('termination_date', [Carbon::now(), Carbon::now()->addDays($days)]);
});
- })
- ->orderBy('expiration_date', 'ASC')
- ->orderBy('termination_date', 'ASC');
+ });
}
/**
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php
index 37f513bf9d..c4a72d35d7 100644
--- a/app/Models/SnipeModel.php
+++ b/app/Models/SnipeModel.php
@@ -32,7 +32,7 @@ class SnipeModel extends Model
protected function expiresDiffInDays(): Attribute
{
return Attribute:: make(
- get: fn(mixed $value, array $attributes) => $attributes['expiration_date'] ? Carbon::parse($attributes['expiration_date'])->diffInDays() : null,
+ get: fn(mixed $value, array $attributes) => $attributes['expiration_date'] ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
);
}