Skip to content

A free open source IT asset/license management system

API endpoints for user licenses, consumables

snipe038c09444d55
diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php
index 1a599029e6..c71de6f583 100644
--- a/app/Http/Controllers/Api/UsersController.php
+++ b/app/Http/Controllers/Api/UsersController.php
@@ -9,10 +9,8 @@ use App\Http\Controllers\Controller;
use App\Http\Requests\DeleteUserRequest;
use App\Http\Requests\FilterRequest;
use App\Http\Requests\SaveUserRequest;
-use App\Http\Transformers\AccessoriesTransformer;
use App\Http\Transformers\ActionlogsTransformer;
use App\Http\Transformers\AssetsTransformer;
-use App\Http\Transformers\LicensesTransformer;
use App\Http\Transformers\SelectlistTransformer;
use App\Http\Transformers\UsersTransformer;
use App\Models\Accessory;
@@ -29,6 +27,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
@@ -896,6 +895,13 @@ class UsersController extends Controller
$query = $user->consumables();
+ if ($search = $request->input('search')) {
+ $query->where(function ($q) use ($search) {
+ $q->where('consumables.name', 'like', "%{$search}%")
+ ->orWhere('consumables_users.note', 'like', "%{$search}%");
+ });
+ }
+
$total = $query->count();
$offset = ($request->input('offset') > $total) ? $total : app('api_offset_value');
$limit = app('api_limit_value');
@@ -918,13 +924,12 @@ class UsersController extends Controller
}
/**
- * Return JSON containing a list of accessories assigned to a user.
+ * Return JSON containing a paginated list of accessory checkouts
+ * assigned to a user. One row per accessories_checkout pivot entry.
*
* @author [A. Gianotto] [<[email protected]>]
*
* @since [v4.6.14]
- *
- * @param $userId
*/
public function accessories(Request $request, $id): array
{
@@ -933,25 +938,43 @@ class UsersController extends Controller
$this->authorize('view', $user);
$this->authorize('view', Accessory::class);
- $accessories = $user->accessories();
+ $query = $user->accessories();
- $total = $accessories->count();
+ if ($search = $request->input('search')) {
+ $query->where(function ($q) use ($search) {
+ $q->where('accessories.name', 'like', "%{$search}%")
+ ->orWhere('accessories_checkout.note', 'like', "%{$search}%");
+ });
+ }
+
+ $total = $query->count();
$offset = ($request->input('offset') > $total) ? $total : app('api_offset_value');
$limit = app('api_limit_value');
- $accessories = $accessories->skip($offset)->take($limit)->get();
+ $sortColumn = $request->input('sort') === 'name'
+ ? 'accessories.name'
+ : 'accessories_checkout.created_at';
+ $order = $request->input('order') === 'asc' ? 'asc' : 'desc';
+
+ $accessories = $query
+ ->reorder($sortColumn, $order)
+ ->skip($offset)
+ ->take($limit)
+ ->get();
+
+ $unitCostsById = Accessory::lastUnitCostsFor($accessories);
- return (new AccessoriesTransformer)->transformAccessories($accessories, $total);
+ return (new UsersTransformer)
+ ->transformUserAccessories($accessories, $unitCostsById, $total);
}
/**
- * Return JSON containing a list of licenses assigned to a user.
+ * Return JSON containing a paginated list of license seat
+ * assignments for a user. One row per license_seats pivot entry.
*
* @author [N. Mathar] [<[email protected]>]
*
* @since [v5.0]
- *
- * @param $userId
*/
public function licenses(Request $request, $id): JsonResponse|array
{
@@ -960,15 +983,37 @@ class UsersController extends Controller
if ($user = User::where('id', $id)->withTrashed()->first()) {
$this->authorize('view', $user);
- $licenses = $user->licenses();
- $total = $licenses->count();
+ $query = $user->licenses();
+
+ if ($search = $request->input('search')) {
+ $canViewKeys = Gate::allows('viewKeys', License::class);
+ $query->where(function ($q) use ($search, $canViewKeys) {
+ $q->where('licenses.name', 'like', "%{$search}%")
+ ->orWhere('licenses.purchase_order', 'like', "%{$search}%")
+ ->orWhere('licenses.order_number', 'like', "%{$search}%");
+ if ($canViewKeys) {
+ $q->orWhere('licenses.serial', 'like', "%{$search}%");
+ }
+ });
+ }
+
+ $total = $query->count();
$offset = ($request->input('offset') > $total) ? $total : app('api_offset_value');
$limit = app('api_limit_value');
- $licenses = $licenses->skip($offset)->take($limit)->get();
+ $sortColumn = $request->input('sort') === 'created_at'
+ ? 'license_seats.created_at'
+ : 'licenses.name';
+ $order = $request->input('order') === 'desc' ? 'desc' : 'asc';
+
+ $licenses = $query
+ ->orderBy($sortColumn, $order)
+ ->skip($offset)
+ ->take($limit)
+ ->get();
- return (new LicensesTransformer)->transformLicenses($licenses, $total);
+ return (new UsersTransformer)->transformUserLicenses($licenses, $total);
}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))));
diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php
index 15386adf35..63a3681531 100755
--- a/app/Http/Controllers/Users/UsersController.php
+++ b/app/Http/Controllers/Users/UsersController.php
@@ -221,7 +221,7 @@ class UsersController extends Controller
if ($safeReferer = Helper::sameOriginUrl(url()->previous())) {
session()->put('url.intended', $safeReferer);
}
- $user = User::with(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed()->find($user->id);
+ $user = User::withTrashed()->find($user->id);
if ($user) {
@@ -272,8 +272,6 @@ class UsersController extends Controller
$permissions = $request->input('permissions', []);
app('request')->request->set('permissions', $permissions);
- $user->load(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed();
-
$this->authorize('update', $user);
$orig_permissions_array = NormalizePermissionsPayloadAction::run($user->decodePermissions());
@@ -458,14 +456,9 @@ class UsersController extends Controller
$this->authorize('view', $user);
$user = User::with([
- 'consumables',
- 'accessories',
- 'licenses',
'userloc',
'groups',
- ])
- ->withTrashed()
- ->find($user->id);
+ ])->withTrashed()->find($user->id);
// Make sure they can view this particular user
$this->authorize('view', $user);
diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php
index 222d68ef0b..7ec8eecbf2 100644
--- a/app/Http/Transformers/UsersTransformer.php
+++ b/app/Http/Transformers/UsersTransformer.php
@@ -3,7 +3,9 @@
namespace App\Http\Transformers;
use App\Helpers\Helper;
+use App\Models\Accessory;
use App\Models\Consumable;
+use App\Models\License;
use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Gate;
@@ -272,4 +274,107 @@ class UsersTransformer
'note' => $pivot->note ? e($pivot->note) : null,
];
}
+
+ /**
+ * @param Collection<int, Accessory> $accessories
+ * @param array<int, string|null> $unitCostsById
+ * @return array<string, mixed>
+ */
+ public function transformUserAccessories(Collection $accessories, array $unitCostsById, int $total): array
+ {
+ $rows = [];
+ foreach ($accessories as $accessory) {
+ $rows[] = $this->transformUserAccessoryRow($accessory, $unitCostsById);
+ }
+
+ return (new DatatablesTransformer)->transformDatatables($rows, $total);
+ }
+
+ /**
+ * @param array<int, string|null> $unitCostsById
+ * @return array<string, mixed>
+ */
+ private function transformUserAccessoryRow(Accessory $accessory, array $unitCostsById): array
+ {
+ $unitCost = $unitCostsById[$accessory->id] ?? null;
+ /** @var \Illuminate\Database\Eloquent\Relations\Pivot $pivot */
+ $pivot = $accessory->pivot;
+
+ return [
+ // row.id is the pivot id, which
+ // genericCheckinCheckoutFormatter uses to build the
+ // checkin URL when assigned_to is populated.
+ 'id' => (int) $pivot->id,
+ 'accessory' => [
+ 'id' => (int) $accessory->id,
+ 'name' => e($accessory->name),
+ ],
+ 'name' => e($accessory->name),
+ 'image' => $accessory->getImageUrl() ?: null,
+ 'purchase_cost' => Helper::formatCurrencyOutput($unitCost),
+ 'created_at' => Helper::getFormattedDateObject($pivot->created_at, 'datetime'),
+ 'note' => $pivot->note ? e($pivot->note) : null,
+ // Truthy assigned_to flags this row as "checked out" so
+ // genericCheckinCheckoutFormatter's checkin branch fires.
+ 'assigned_to' => (int) ($pivot->assigned_to ?? 0),
+ 'checkin_backto' => 'user',
+ 'available_actions' => [
+ 'checkin' => Gate::allows('checkin', $accessory),
+ ],
+ ];
+ }
+
+ /**
+ * @param Collection<int, License> $licenses
+ * @return array<string, mixed>
+ */
+ public function transformUserLicenses(Collection $licenses, int $total): array
+ {
+ $rows = [];
+ foreach ($licenses as $license) {
+ $rows[] = $this->transformUserLicenseRow($license);
+ }
+
+ return (new DatatablesTransformer)->transformDatatables($rows, $total);
+ }
+
+ /**
+ * @return array<string, mixed>
+ */
+ private function transformUserLicenseRow(License $license): array
+ {
+ /** @var \Illuminate\Database\Eloquent\Relations\Pivot $pivot */
+ $pivot = $license->pivot;
+ $canViewKeys = Gate::allows('viewKeys', $license);
+
+ return [
+ // row.id is the LicenseSeat id, which
+ // licenseSeatInOutFormatter uses to build the checkin
+ // URL. Note that row.license.id is the parent License
+ // id, used for checkout URLs by the same formatter.
+ 'id' => (int) $pivot->id,
+ 'license' => [
+ 'id' => (int) $license->id,
+ 'name' => e($license->name),
+ ],
+ 'license_id' => (int) $license->id,
+ 'name' => e($license->name),
+ 'serial' => $canViewKeys ? e($license->serial) : null,
+ 'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
+ 'purchase_order' => e($license->purchase_order),
+ 'order_number' => e($license->order_number),
+ // Truthy assigned_user tells licenseSeatInOutFormatter
+ // this seat is checked out to a user, so the checkin
+ // branch fires. asset_id / assigned_asset stay unset
+ // because a seat cannot be assigned to both at once.
+ 'assigned_user' => (int) ($pivot->assigned_to ?? 0) ?: null,
+ 'checkin_backto' => 'user',
+ 'available_actions' => [
+ 'checkin' => Gate::allows('update', $license),
+ 'bulk_selectable' => [
+ 'checkin' => Gate::allows('checkin', $license),
+ ],
+ ],
+ ];
+ }
}
diff --git a/app/Presenters/UserPresenter.php b/app/Presenters/UserPresenter.php
index 2d4288300c..fa22671c3e 100644
--- a/app/Presenters/UserPresenter.php
+++ b/app/Presenters/UserPresenter.php
@@ -687,4 +687,139 @@ class UserPresenter extends Presenter
return json_encode($layout);
}
+
+ public static function accessoriesDataTableLayout(): string
+ {
+ $layout = [
+ [
+ 'field' => 'accessory',
+ 'scope' => 'col',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => false,
+ 'title' => trans('general.name'),
+ 'visible' => true,
+ 'formatter' => 'accessoriesLinkObjFormatter',
+ ],
+ [
+ 'field' => 'created_at',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => true,
+ 'switchable' => true,
+ 'title' => trans('general.date'),
+ 'visible' => true,
+ 'formatter' => 'dateDisplayFormatter',
+ ],
+ [
+ 'field' => 'note',
+ 'scope' => 'col',
+ 'searchable' => true,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.notes'),
+ 'visible' => true,
+ ],
+ [
+ 'field' => 'purchase_cost',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.unit_cost'),
+ 'visible' => true,
+ 'footerFormatter' => 'sumFormatter',
+ 'class' => 'text-right',
+ ],
+ [
+ 'field' => 'actions',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => false,
+ 'title' => trans('table.actions'),
+ 'visible' => true,
+ 'formatter' => 'accessoriesInOutFormatter',
+ 'class' => 'hidden-print',
+ ],
+ ];
+
+ return json_encode($layout);
+ }
+
+ public static function licensesDataTableLayout(): string
+ {
+ $layout = [
+ [
+ 'field' => 'checkbox',
+ 'scope' => 'col',
+ 'checkbox' => true,
+ 'titleTooltip' => trans('general.select_all_none'),
+ 'printIgnore' => true,
+ 'class' => 'hidden-print',
+ ],
+ [
+ 'field' => 'license',
+ 'scope' => 'col',
+ 'searchable' => true,
+ 'sortable' => true,
+ 'switchable' => false,
+ 'title' => trans('general.name'),
+ 'visible' => true,
+ 'formatter' => 'licensesLinkObjFormatter',
+ ],
+ [
+ 'field' => 'serial',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('admin/licenses/form.license_key'),
+ 'visible' => true,
+ 'formatter' => 'licenseKeyFormatter',
+ ],
+ [
+ 'field' => 'purchase_cost',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.purchase_cost'),
+ 'visible' => true,
+ 'footerFormatter' => 'sumFormatter',
+ 'class' => 'text-right',
+ ],
+ [
+ 'field' => 'purchase_order',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('admin/licenses/form.purchase_order'),
+ 'visible' => true,
+ ],
+ [
+ 'field' => 'order_number',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => true,
+ 'title' => trans('general.order_number'),
+ 'visible' => true,
+ ],
+ [
+ 'field' => 'actions',
+ 'scope' => 'col',
+ 'searchable' => false,
+ 'sortable' => false,
+ 'switchable' => false,
+ 'title' => trans('table.actions'),
+ 'visible' => true,
+ 'formatter' => 'licenseSeatInOutFormatter',
+ 'class' => 'hidden-print',
+ ],
+ ];
+
+ return json_encode($layout);
+ }
}
diff --git a/resources/views/licenses/checkin.blade.php b/resources/views/licenses/checkin.blade.php
index 5118c9b0ab..6e7566c5b5 100755
--- a/resources/views/licenses/checkin.blade.php
+++ b/resources/views/licenses/checkin.blade.php
@@ -56,20 +56,15 @@
@endif
<!-- Serial -->
- @can('viewKeys', $licenseSeat->license)
- <div class="form-group">
- <label class="col-sm-3 control-label">{{ trans('admin/licenses/form.license_key') }}
- <i class="fa-regular fa-clipboard js-copy-link hidden-print" data-clipboard-target=".js-copy-key" aria-hidden="true" data-tooltip="true" data-placement="top" title="{{ trans('general.copy_to_clipboard') }}">
- <span class="sr-only">{{ trans('general.copy_to_clipboard') }}</span>
- </i>
- </label>
- <div class="col-md-8">
- <p class="form-control-static">
- <code style="white-space: pre-wrap"><span class="js-copy-key">{{ $licenseSeat->license->serial }}</span></code>
- </p>
- </div>
- </div>
- @endcan
+ @if ($licenseSeat->license->serial)
+ @can('viewKeys', $licenseSeat->license)
+ <x-form.static :label="trans('admin/licenses/form.license_key')">
+ <x-copy-to-clipboard copy_what="license_key">
+ <code>{!! nl2br(e($licenseSeat->license->serial)) !!}</code>
+ </x-copy-to-clipboard>
+ </x-form.static>
+ @endcan
+ @endif
<!-- Note -->
<div class="form-group {{ $errors->has('notes') ? 'error' : '' }}">
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index c7e06a1ca4..9b71e2074d 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -3089,11 +3089,13 @@
// Checkouts need the license ID, checkins need the specific seat ID
function licenseSeatInOutFormatter(value, row) {
+
+ var backto = row.checkin_backto ? '/' + row.checkin_backto : '';
if (row.disabled && (row.assigned_user || row.assigned_asset)) {
- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin' + backto + '" class="btn btn-sm bg-purple" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
}
if (row.disabled) {
- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-maroon btn-checkout disabled" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkout') }}</a>';
+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin' + backto + '" class="btn btn-sm bg-maroon btn-checkout disabled" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkout') }}</a>';
}
// The user is allowed to check the license seat out and it's available
if ((row.available_actions.checkout === true) && (row.user_can_checkout === true) && ((!row.assigned_asset) && (!row.assigned_user))) {
@@ -3102,7 +3104,7 @@
// The user is allowed to check the license seat in and it's available
if ((row.available_actions.checkin === true) && ((row.assigned_asset) || (row.assigned_user))) {
- return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
+ return '<a href="{{ config('app.url') }}/licenses/' + row.id + '/checkin' + backto + '" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
}
}
@@ -3117,6 +3119,12 @@
}
return function (value, row) {
+ // Optional row.checkin_backto lets the caller redirect
+ // back to a context page (e.g. a user detail view) after
+ // a checkin action. Segment appended to the URL to match
+ // the /{destination}/{id}/checkin/{backto?} route.
+ var backto = row.checkin_backto ? '/' + row.checkin_backto : '';
+
// The user is allowed to check items out, AND the item is deployable
if ((row.available_actions.checkout == true) && (row.user_can_checkout == true) && ((!row.asset_id) && (!row.assigned_to))) {
@@ -3136,9 +3144,9 @@
// The user is allowed to check items in
} else if (row.available_actions.checkin == true) {
if (row.assigned_to) {
- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkin" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
+ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.id + '/checkin' + backto + '" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
} else if (row.assigned_pivot_id) {
- return '<a href="{{ config('app.url') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
+ return '<a href="{{ config('app.url') }}/' + destination + '/' + row.assigned_pivot_id + '/checkin' + backto + '" class="btn btn-sm bg-purple btn-checkin" data-tooltip="true" title="{{ trans('general.checkin_tooltip') }}">{{ trans('general.checkin') }}</a>';
}
}
diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php
index 37a8e8c570..536e0bf23e 100755
--- a/resources/views/users/view.blade.php
+++ b/resources/views/users/view.blade.php
@@ -327,87 +327,31 @@
<x-tabs.pane name="licenses" :count="$user->licenses()->count()">
- @can('checkin', \App\Models\License::class)
<x-slot:table_header>{{ trans('general.licenses') }}</x-slot:table_header>
+
+ @can('checkin', \App\Models\License::class)
<x-slot:bulkactions>
- <div class="hidden-print" style="padding-top:10px; min-width:400px;">
- <form method="POST" action="{{ route('licenses.bulkcheckin.selected') }}" id="userLicenseBulkCheckinForm" class="form-inline">
- @csrf
- <label for="userLicenseBulkActions"><span class="sr-only">{{ trans('button.bulk_actions') }}</span></label>
- <select name="bulk_actions" id="userLicenseBulkActions" class="form-control select2" style="min-width:350px;">
- <option value="checkin">{{ trans('general.checkin') }}</option>
- </select>
- <button type="submit" id="userLicenseBulkCheckinButton" class="btn btn-theme" disabled>{{ trans('button.go') }}</button>
- <span id="userLicenseBulkCheckinCount" style="display:none; margin-left:8px; line-height:34px;">&mdash; <span class="badge">0</span> {{ trans('general.selected') }}</span>
- </form>
- </div>
+ <x-table.bulk-actions
+ name="userLicenseTable"
+ :action_route="route('licenses.bulkcheckin.selected')"
+ model_name="license_seats"
+ :actions="[
+ 'checkin' => ['label' => trans('general.checkin')],
+ ]"
+ />
</x-slot:bulkactions>
@endcan
@can('view', \App\Models\License::class)
- <table
- data-cookie-id-table="userLicenseTable"
- data-id-table="userLicenseTable"
- id="userLicenseTable"
- data-buttons="licenseButtons"
- data-side-pagination="client"
- data-show-footer="true"
- data-sort-name="name"
- class="table table-striped snipe-table table-hover"
- data-export-options='{
- "fileName": "export-license-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}",
- "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","delete","download","icon"]
- }'>
-
- <thead>
- <tr>
- @can('checkin', \App\Models\License::class)
- <th scope="col" class="hidden-print">{{ trans('general.id') }}</th>
- @endcan
- <th scope="col">{{ trans('general.name') }}</th>
- <th scope="col">{{ trans('admin/licenses/form.license_key') }}</th>
- <th scope="col" data-footer-formatter="sumFormatter" data-fieldname="purchase_cost">{{ trans('general.purchase_cost') }}</th>
- <th scope="col">{{ trans('admin/licenses/form.purchase_order') }}</th>
- <th scope="col">{{ trans('general.order_number') }}</th>
- <th scope="col" class="col-md-1 hidden-print">{{ trans('general.action') }}</th>
- </tr>
- </thead>
- <tbody>
- @foreach ($user->licenses as $license)
- <tr>
- @can('checkin', \App\Models\License::class)
- <td class="hidden-print">
- <input type="checkbox" class="user-license-seat-checkbox hidden-print" form="userLicenseBulkCheckinForm" name="ids[]" value="{{ $license->pivot->id }}">
- </td>
- @endcan
- <td class="col-md-4">
- {!! $license->present()->nameUrl() !!}
- </td>
- <td class="col-md-4">
- @can('viewKeys', $license)
- <code class="single-line"><span class="js-copy-link" data-clipboard-target=".js-copy-key-{{ $license->id }}" aria-hidden="true" data-tooltip="true" data-placement="top" title="{{ trans('general.copy_to_clipboard') }}"><span class="js-copy-key-{{ $license->id }}">{{ $license->serial }}</span></span></code>
- @else
- ------------
- @endcan
- </td>
- <td class="col-md-2">
- {{ Helper::formatCurrencyOutput($license->purchase_cost) }}
- </td>
- <td>
- {{ $license->purchase_order }}
- </td>
- <td>
- {{ $license->order_number }}
- </td>
- <td class="hidden-print col-md-2">
- @can('update', $license)
- <a href="{{ route('licenses.checkin', $license->pivot->id, ['backto'=>'user']) }}" class="btn bg-purple btn-sm hidden-print">{{ trans('general.checkin') }}</a>
- @endcan
- </td>
- </tr>
- @endforeach
- </tbody>
- </table>
+ <x-table
+ name="userLicenseTable"
+ show_column_search="false"
+ show_footer="true"
+ buttons="licenseButtons"
+ api_url="{{ route('api.users.licenselist', ['user' => $user->id]) }}"
+ :presenter="\App\Presenters\UserPresenter::licensesDataTableLayout()"
+ export_filename="export-license-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}"
+ />
@endcan
</x-tabs.pane>
@@ -422,47 +366,15 @@
</x-slot:table_header>
@can('view', \App\Models\Accessory::class)
- <table
- data-cookie-id-table="userAccessoryTable"
- data-id-table="userAccessoryTable"
- id="userAccessoryTable"
- data-buttons="accessoryButtons"
- data-side-pagination="client"
- data-sort-name="name"
- class="table table-striped snipe-table table-hover"
- data-export-options='{
- "fileName": "export-accessory-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}",
- "ignoreColumn": ["actions","image","change","checkbox","checkincheckout","delete","download","icon"]
- }'>
- <thead>
- <tr>
- <th scope="col">{{ trans('general.id') }}</th>
- <th scope="col">{{ trans('general.name') }}</th>
- <th scope="col">{{ trans('general.date') }}</th>
- <th scope="col" data-fieldname="note">{{ trans('general.notes') }}</th>
- <th scope="col" data-footer-formatter="sumFormatter" data-fieldname="purchase_cost">{{ trans('general.unit_cost') }}</th>
- <th scope="col" class="hidden-print">{{ trans('general.action') }}</th>
- </tr>
- </thead>
- <tbody>
- @foreach ($user->accessories as $accessory)
- <tr>
- <td>{{ $accessory->pivot->id }}</td>
- <td>{!! $accessory->present()->nameUrl() !!}</td>
- <td>{{ Helper::getFormattedDateObject($accessory->pivot->created_at, 'datetime', false) }}</td>
- <td>{{ $accessory->pivot->note }}</td>
- <td>
- {!! Helper::formatCurrencyOutput($accessory->lastOrderDefaults()['unit_cost'] ?? null) !!}
- </td>
- <td class="hidden-print">
- @can('checkin', $accessory)
- <a href="{{ route('accessories.checkin.show', array('accessoryID'=> $accessory->pivot->id, 'backto'=>'user')) }}" class="btn bg-purple btn-sm hidden-print">{{ trans('general.checkin') }}</a>
- @endcan
- </td>
- </tr>
- @endforeach
- </tbody>
- </table>
+ <x-table
+ name="userAccessoryTable"
+ show_column_search="false"
+ show_footer="true"
+ buttons="accessoryButtons"
+ api_url="{{ route('api.users.accessorieslist', ['user' => $user->id]) }}"
+ :presenter="\App\Presenters\UserPresenter::accessoriesDataTableLayout()"
+ export_filename="export-accessory-{{ str_slug($user->username) }}-{{ date('Y-m-d') }}"
+ />
@endcan
</x-tabs.pane>
@@ -679,23 +591,6 @@ $(function () {
document.cookie = "optional_info_open="+optional_info_open+'; path=/';
});
- $(document).on('change', '.user-license-seat-checkbox', function () {
- var count = $('.user-license-seat-checkbox:checked').length;
- $('#userLicenseBulkCheckinButton').prop('disabled', count === 0);
- $('#userLicenseBulkCheckinCount .badge').text(count);
- if (count > 0) {
- $('#userLicenseBulkCheckinCount').show();
- } else {
- $('#userLicenseBulkCheckinCount').hide();
- }
- var total = $('.user-license-seat-checkbox').length;
- $('#userLicenseSelectAll').prop('indeterminate', count > 0 && count < total);
- $('#userLicenseSelectAll').prop('checked', count === total);
- });
-
- $(document).on('change', '#userLicenseSelectAll', function () {
- $('.user-license-seat-checkbox').prop('checked', $(this).is(':checked')).trigger('change');
- });
});
</script>