Skip to content

A free open source IT asset/license management system

Switched to newer button model

snipe1d6b21e1c7af
diff --git a/app/Models/License.php b/app/Models/License.php
index 95109f7036..bd6cb102da 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -13,6 +13,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Session;
use Watson\Validating\ValidatingTrait;
@@ -158,6 +159,14 @@ class License extends Depreciable
);
}
+ public function isDeletable()
+ {
+ return Gate::allows('delete', $this)
+ && ($this->free_seats_count == $this->seats)
+ && ($this->deleted_at == '');
+ }
+
+
protected function terminatesFormattedDate(): Attribute
{
@@ -582,6 +591,23 @@ class License extends Depreciable
->whereNull('deleted_at');
}
+ /**
+ * This is really dumb - needs to be refactored, since we have ~3 diff methods that do almost the same thing
+ *
+ * @author A. Gianotto <[email protected]>
+ * @since [v2.0]
+ * @return \Illuminate\Database\Eloquent\Relations\Relation
+ */
+ public function numRemaining()
+ {
+ return $this->licenseSeatsRelation()
+ ->whereNull('asset_id')
+ ->whereNull('assigned_to')
+ ->where('unreassignable_seat', '=', false)
+ ->whereNull('deleted_at')
+ ->count();
+ }
+
/**
* Sets the available seats attribute
*
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php
index 538bdce7b7..3948d2f2ab 100755
--- a/resources/views/licenses/view.blade.php
+++ b/resources/views/licenses/view.blade.php
@@ -126,27 +126,23 @@
<x-box class="side-box expanded">
<x-box.info-panel :infoPanelObj="$license" img_path="{{ app('licenses_upload_url') }}">
+
+ <x-slot:buttons>
+ <x-button.checkout permission="checkout" :item="$license" :route="route('licenses.freecheckout', $license->id)" />
+ <x-button.edit :item="$license" :route="route('licenses.edit', $license->id)" />
+ <x-button.clone :item="$license" :route="route('clone/license', $license->id)" />
+ <x-button.delete :item="$license" />
+ </x-slot:buttons>
+
+
<x-slot:before_list>
- @can('update', $license)
- <a href="{{ route('licenses.edit', $license->id) }}" class="btn btn-warning btn-sm btn-social btn-block hidden-print" style="margin-bottom: 5px;">
- <x-icon type="edit" />
- {{ trans('admin/licenses/general.edit') }}
- </a>
- <a href="{{ route('clone/license', $license->id) }}" class="btn btn-info btn-block btn-sm btn-social hidden-print" style="margin-bottom: 5px;">
- <x-icon type="clone" />
- {{ trans('admin/licenses/general.clone') }}</a>
- @endcan
+
@can('checkout', $license)
@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" />
- {{ trans('general.checkout') }}
- </a>
-
<a href="#" class="btn bg-maroon btn-sm btn-social btn-block hidden-print" style="margin-bottom: 5px;" data-toggle="modal" data-tooltip="true" title="{{ trans('admin/licenses/general.bulk.checkout_all.enabled_tooltip') }}" data-target="#checkoutFromAllModal">
<x-icon type="checkout-all" />
{{ trans('admin/licenses/general.bulk.checkout_all.button') }}
@@ -181,25 +177,6 @@
@endif
@endcan
- @can('delete', $license)
-
- @if ($license->availCount()->count() == $license->seats)
- <a class="btn btn-block btn-danger btn-sm btn-social delete-asset" data-icon="fa fa-trash" data-toggle="modal" data-title="{{ trans('general.delete') }}" data-content="{{ trans('general.delete_confirm', ['item' => $license->name]) }}" data-target="#dataConfirmModal" onClick="return false;">
- <x-icon type="delete" />
- {{ trans('general.delete') }}
- </a>
- @else
- <span data-tooltip="true" title=" {{ trans('admin/licenses/general.delete_disabled') }}">
- <a href="#" class="btn btn-block btn-danger btn-sm btn-social delete-asset disabled" onClick="return false;">
- <x-icon type="delete" />
- {{ trans('general.delete') }}
- </a>
- </span>
- @endif
- @endcan
-
-
-
</x-slot:before_list>
</x-box.info-panel>
@@ -218,6 +195,15 @@
])
@endcan
+@can('checkin', \App\Models\License::class)
+ @include ('modals.confirm-action',
+ [
+ 'modal_name' => 'checkinFromAllModal',
+ 'route' => route('licenses.bulkcheckin', $license->id),
+ 'title' => trans('general.modal_confirm_generic'),
+ 'body' => trans_choice('admin/licenses/general.bulk.checkin_all.modal', 2, ['checkedout_seats_count' => $checkedout_seats_count])
+ ])
+@endcan
@can('update', \App\Models\License::class)
@include ('modals.upload-file', ['item_type' => 'license', 'item_id' => $license->id])