Skip to content

A free open source IT asset/license management system

Check for array key for license report/formatters

snipe57b49fc31c3f
diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php
index ae9bff48df..7a97d39375 100644
--- a/app/Console/Commands/SendExpirationAlerts.php
+++ b/app/Console/Commands/SendExpirationAlerts.php
@@ -107,7 +107,7 @@ class SendExpirationAlerts extends Command
trans('general.name') => $item->name,
trans('general.purchase_date') => $item->purchase_date_formatted,
trans('admin/licenses/form.expiration') => $item->expires_formatted_date,
- trans('mail.expires') => $item->expires_diff_for_humans,
+ trans('mail.expires') => $item->expires_formatted_date ? $item->expires_diff_for_humans : '',
trans('admin/licenses/form.termination_date') => $item->terminates_formatted_date,
trans('mail.terminates') => $item->terminates_diff_for_humans
])
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.php
index 68bfc57824..cb93f1753a 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) => in_array('expiration_date', $attributes) ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
+ get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::now()->diffInDays($attributes['expiration_date']) : null,
);
}
@@ -40,14 +40,14 @@ class SnipeModel extends Model
protected function expiresDiffForHumans(): Attribute
{
return Attribute:: make(
- get: fn(mixed $value, array $attributes) => in_array('expiration_date', $attributes) ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
+ get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Carbon::parse($attributes['expiration_date'])->diffForHumans() : null,
);
}
protected function expiresFormattedDate(): Attribute
{
return Attribute:: make(
- get: fn(mixed $value, array $attributes) => in_array('expiration_date', $attributes) ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
+ get: fn(mixed $value, array $attributes) => array_key_exists('expiration_date', $attributes) ? Helper::getFormattedDateObject($attributes['expiration_date'], 'date', false) : null,
);
}
diff --git a/resources/views/notifications/markdown/report-expiring-licenses.blade.php b/resources/views/notifications/markdown/report-expiring-licenses.blade.php
index 6391b16ba0..c2a0394ebe 100644
--- a/resources/views/notifications/markdown/report-expiring-licenses.blade.php
+++ b/resources/views/notifications/markdown/report-expiring-licenses.blade.php
@@ -6,7 +6,7 @@
| | {{ trans('mail.name') }} | {{ trans('general.category') }} | {{ trans('mail.expires') }} | {{ trans('mail.terminates') }} |
| :------------- | :------------- | :------------- | :------------- | :------------- |
@foreach ($licenses as $license)
-| {{ (($license->isExpired()) || ($license->isTerminated()) || ($license->terminates_diff_in_days <= ($threshold / 2)) || ($license->expires_diff_in_days <= ($threshold / 2))) ? '🚨' : (($license->expires_diff_in_days <= $threshold) ? '⚠️' : 'ℹ️ ') }} | <a href="{{ route('licenses.show', $license->id) }}">{{ $license->name }}</a> {{ $license->manufacturer ? '('.$license->manufacturer->name.')' : '' }} | {{ $license->category ? $license->category->name : '' }} | {{ $license->expires_formatted_date }} {!! $license->expires_diff_for_humans ? ' ('.$license->expires_diff_for_humans .')' : '' !!} | {{ $license->terminates_formatted_date }} {{ $license->terminates_diff_for_humans ? ' ('.$license->terminates_diff_for_humans .')' : '' }}|
+| {{ (($license->isExpired()) || ($license->isTerminated()) || ($license->terminates_diff_in_days <= ($threshold / 2)) || ($license->expires_diff_in_days <= ($threshold / 2))) ? '🚨' : (($license->expires_diff_in_days <= $threshold) ? '⚠️' : 'ℹ️ ') }} | <a href="{{ route('licenses.show', $license->id) }}">{{ $license->name }}</a> {{ $license->manufacturer ? '('.$license->manufacturer->name.')' : '' }} | {{ $license->category ? $license->category->name : '' }} | {{ $license->expires_formatted_date }} {{ $license->expires_formatted_date ? ' ('.$license->expires_diff_for_humans .')' : '' }} | {{ $license->terminates_formatted_date }} {{ $license->terminates_diff_for_humans ? ' ('.$license->terminates_diff_for_humans .')' : '' }}|
| <hr> | <hr> | <hr> | <hr> | <hr> |
@endforeach
</x-mail::table>