Skip to content

A free open source IT asset/license management system

Show warnings on the dates if expired or terminated

snipe7062962cc882
diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
index 5db8bb17d7..db378b8f0f 100644
--- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php
+++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php
@@ -40,7 +40,7 @@ class LicenseCheckoutController extends Controller
}
// Make sure the license is expired or terminated
- if ($license->isInactive()){
+ if ($license->isInactive()) {
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.license_is_inactive'));
}
@@ -130,7 +130,7 @@ class LicenseCheckoutController extends Controller
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.not_enough_seats')));
}
-
+
if (! $licenseSeat->license->is($license)) {
throw new \Illuminate\Http\Exceptions\HttpResponseException(redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.checkout.mismatch')));
}
diff --git a/app/Models/License.php b/app/Models/License.php
index 3edc7a10a9..855995b43c 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -307,7 +307,26 @@ class License extends Depreciable
$terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
- return $expired || $terminated;
+ return $this->isExpired() || $this->isTerminated();
+ }
+
+ public function isExpired(): bool
+ {
+ $day = now()->startOfDay();
+
+ $expired = $this->expiration_date && $this->asDateTime($this->expiration_date)->startofDay()->lessThanOrEqualTo($day);
+
+ return $expired;
+ }
+
+ public function isTerminated(): bool
+ {
+ $day = now()->startOfDay();
+
+ $terminated = $this->termination_date && $this->asDateTime($this->termination_date)->startofDay()->lessThanOrEqualTo($day);
+
+
+ return $terminated;
}
/**
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php
index 591870c544..43d2c697c0 100755
--- a/resources/views/licenses/view.blade.php
+++ b/resources/views/licenses/view.blade.php
@@ -249,6 +249,11 @@
</strong>
</div>
<div class="col-md-9">
+ @if ($license->isExpired())
+ <span class="text-danger">
+ <x-icon type="warning" class="text-warning" />
+ </span>
+ @endif
{{ Helper::getFormattedDateObject($license->expiration_date, 'date', false) }}
</div>
</div>
@@ -262,6 +267,12 @@
</strong>
</div>
<div class="col-md-9">
+ @if ($license->isTerminated())
+ <span class="text-danger">
+ <x-icon type="warning" class="text-warning" />
+ </span>
+ @endif
+
{{ Helper::getFormattedDateObject($license->termination_date, 'date', false) }}
</div>
</div>
@@ -545,7 +556,7 @@
@can('checkout', $license)
- @if ($license->availCount()->count() > 0)
+ @if (($license->availCount()->count() > 0) && (!$license->isInactive()))
<a href="{{ route('licenses.checkout', $license->id) }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print" style="margin-bottom: 5px;">
<x-icon type="checkout" />
@@ -558,17 +569,13 @@
</a>
@else
- <span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') }}">
- <a href="#" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
+ <span data-tooltip="true" title="{{ ($license->availCount()->count() == 0) ? trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') : trans('admin/licenses/message.checkout.license_is_inactive') }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
<x-icon type="checkout" />
{{ trans('general.checkout') }}
- </a>
</span>
- <span data-tooltip="true" title=" {{ trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') }}">
- <a href="#" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
+ <span data-tooltip="true" title="{{ ($license->availCount()->count() == 0) ? trans('admin/licenses/general.bulk.checkout_all.disabled_tooltip') : trans('admin/licenses/message.checkout.license_is_inactive') }}" class="btn bg-maroon btn-sm btn-social btn-block hidden-print disabled" style="margin-bottom: 5px;" data-tooltip="true" title="{{ trans('general.checkout') }}">
<x-icon type="checkout" />
{{ trans('admin/licenses/general.bulk.checkout_all.button') }}
- </a>
</span>
@endif
@endcan