A free open source IT asset/license management system
Updated checkout create and cancel actions for assetts
snipee767aed58b76
diff --git a/app/Actions/CheckoutRequests/CancelCheckoutRequestAction.php b/app/Actions/CheckoutRequests/CancelCheckoutRequestAction.phpindex 043817b178..2c484df2c3 100644--- a/app/Actions/CheckoutRequests/CancelCheckoutRequestAction.php+++ b/app/Actions/CheckoutRequests/CancelCheckoutRequestAction.php@@ -28,9 +28,9 @@ class CancelCheckoutRequestAction// decrement is gated on the actual affected row count.// Previously this method unconditionally decremented by 1// regardless of whether the caller had an active request,- // driving the shared requests_counter negative on no-op calls- // and letting a duplicate-request cancel decrement by less- // than the number of rows it actually canceled.+ // driving the shared requests_counter negative on no-op calls.+ // The pending-state filter inside cancelRequest() plus this+ // affected-count gate together keep the counter honest.$affected = DB::transaction(function () use ($asset) {$affected = $asset->cancelRequest();if ($affected > 0) {diff --git a/app/Actions/CheckoutRequests/CreateCheckoutRequestAction.php b/app/Actions/CheckoutRequests/CreateCheckoutRequestAction.phpindex 4cb3a8aeae..c66bdaf33e 100644--- a/app/Actions/CheckoutRequests/CreateCheckoutRequestAction.php+++ b/app/Actions/CheckoutRequests/CreateCheckoutRequestAction.php@@ -30,11 +30,12 @@ class CreateCheckoutRequestActionthrow new AuthorizationException;}- // Enforce single-active-request-per-user-per-asset. Without this- // gate the same POST fires repeatedly, each firing adds an- // active CheckoutRequest row AND bumps requests_counter, but a- // single cancellation only decrements the counter by 1, so the- // counter and admin queue drift apart.+ // Enforce single-active-request-per-user-per-asset. Without+ // this gate the same POST fires repeatedly, adding duplicate+ // pending rows for the same (user, asset) pair. Downstream+ // aggregators (open_requests count, admin queue, requester+ // tab) all reason in terms of "one open row per pair" so+ // duplicates would double-count everywhere.if ($asset->isRequestedBy($user)) {throw new DuplicateCheckoutRequest;}@@ -55,7 +56,10 @@ class CreateCheckoutRequestAction// Row write + counter increment share one transaction so a// partial failure can't leave the counter incremented without a- // matching row (or vice versa).+ // matching row (or vice versa). Counter is the denormalized+ // fast-path for open-request reads on the assets list; state+ // on the row is the source of truth, counter is a materialized+ // view kept in sync at write time.DB::transaction(function () use ($asset) {$asset->request();$asset->increment('requests_counter', 1);diff --git a/resources/views/blade/checkout-request-context.blade.php b/resources/views/blade/checkout-request-context.blade.phpnew file mode 100644index 0000000000..46a87f2db9--- /dev/null+++ b/resources/views/blade/checkout-request-context.blade.php@@ -0,0 +1,89 @@+@props([+ 'request' => null,+ 'others' => null,+])++{{-- Rendered on the four checkout screens (asset / accessory /+ consumable / component / license) when the admin arrived from+ a /requests row (?request_id=N). Two boxes: the current request+ for context, and the waiting list of other open requesters so+ the admin can arbitrate who gets it. Renders nothing when+ $request is null, so callers can drop it in unconditionally. --}}+@if (! empty($request))+ <x-box header="{{ trans('admin/hardware/general.requested') }}">+ <x-page-data>+ <x-data-row :label="trans('admin/hardware/table.requesting_user')">+ <a href="{{ route('users.show', $request->user->id) }}">{{ $request->user->display_name }}</a>+ </x-data-row>++ <x-data-row :label="trans('admin/hardware/table.requested_date')" icon_type="calendar">+ {{ $request->created_at->format($snipeSettings->date_display_format.' '.$snipeSettings->time_display_format) }}+ <span class="text-muted">{{ $request->created_at->diffForHumans(['parts' => 2]) }}</span>+ </x-data-row>++ <x-data-row :label="trans('admin/hardware/general.requested')">+ {{ (int) $request->quantity }}+ </x-data-row>++ @if ($request->start_date)+ <x-data-row :label="trans('general.start_date')" icon_type="start_date">+ {{ $request->start_date->format($snipeSettings->date_display_format) }}+ </x-data-row>+ @endif++ @if ($request->end_date)+ <x-data-row :label="trans('general.end_date')" icon_type="end_date">+ {{ $request->end_date->format($snipeSettings->date_display_format) }}+ </x-data-row>+ @endif++ @if ($request->notes)+ <x-data-row :label="trans('general.notes')">+ {{ $request->notes }}+ </x-data-row>+ @endif+ </x-page-data>+ </x-box>++ @if (! empty($others) && $others->isNotEmpty())+ <x-box header="{{ trans('admin/hardware/table.pending_requesters') }}">+ @foreach ($others as $pending)+ @if (! $loop->first)+ <hr>+ @endif+ <x-page-data>+ <x-data-row :label="trans('admin/hardware/table.requesting_user')">+ <a href="{{ route('users.show', $pending->user->id) }}">{{ $pending->user->display_name }}</a>+ </x-data-row>++ <x-data-row :label="trans('admin/hardware/table.requested_date')" icon_type="calendar">+ {{ $pending->created_at->format($snipeSettings->date_display_format.' '.$snipeSettings->time_display_format) }}+ <span class="text-muted">{{ $pending->created_at->diffForHumans(['parts' => 2]) }}</span>+ </x-data-row>++ <x-data-row :label="trans('admin/hardware/general.requested')">+ {{ (int) $pending->quantity }}+ </x-data-row>++ @if ($pending->start_date)+ <x-data-row :label="trans('general.start_date')" icon_type="start_date">+ {{ $pending->start_date->format($snipeSettings->date_display_format) }}+ </x-data-row>+ @endif++ @if ($pending->end_date)+ <x-data-row :label="trans('general.end_date')" icon_type="end_date">+ {{ $pending->end_date->format($snipeSettings->date_display_format) }}+ </x-data-row>+ @endif++ @if ($pending->notes)+ <x-data-row :label="trans('general.notes')">+ {{ $pending->notes }}+ </x-data-row>+ @endif+ </x-page-data>+ @endforeach+ </x-box>+ @endif+@endifdiff --git a/resources/views/blade/checkout/asset-picker-row.blade.php b/resources/views/blade/checkout/asset-picker-row.blade.phpnew file mode 100644index 0000000000..06aef81f8d--- /dev/null+++ b/resources/views/blade/checkout/asset-picker-row.blade.php@@ -0,0 +1,114 @@+@props([+ 'request',+ 'requester',+ 'availableAssets',+ 'showQty' => true,+ 'maxQty' => null,+ 'defaultChecked' => false,+ 'emptyMessage' => null,+])++{{-- Row variant of the bulk-fulfill form for types where the+ checkout target is an Asset (not a User):+ - Component installs INTO an asset (per-request, admin picks+ from the requester's assigned assets)+ - AssetModel fulfills via picking a specific Asset OF that+ model (from the model's available assets)++ The available-asset set is pre-computed by the controller+ (small, deterministic list) so the picker is a plain <select>+ rather than the ajax select2 - no pagination needed for the+ typical scope, and the "auto-pick next available" default just+ falls out of pre-selecting the first option.++ Field shape matches the user-target recipient-row so the+ controller-side per-row iteration stays uniform:+ enabled_requests[] = list of request ids ticked+ asset_id[<request_id>] = target asset for that row+ qty[<request_id>] = qty for that row (or 1 if showQty=false)+ notes[<request_id>] = admin/checkout note --}}+<fieldset class="form-group has-feedback" style="border: 1px solid #ddd; border-radius: 4px; padding: 15px; margin-bottom: 20px;">+ <legend class="col-sm-3 col-md-3 control-label" style="width: auto; padding: 0 10px; border: 0; margin-bottom: 0;">+ <label class="form-control" style="display: inline-flex; align-items: center; gap: 8px; margin-bottom: 0;">+ <input+ type="checkbox"+ name="enabled_requests[]"+ value="{{ (int) $request->id }}"+ @checked($defaultChecked || in_array((int) $request->id, (array) old('enabled_requests', []), true))+ @if ($availableAssets->isEmpty()) disabled @endif+ aria-label="{{ trans('general.fulfill') }} #{{ $request->id }}"+ >+ <span>#{{ $request->id }}</span>+ @if ($requester)+ <span class="text-muted">+ — {{ $requester->display_name }}+ </span>+ @endif+ </label>+ </legend>++ <div class="form-group {{ $errors->has('asset_id.'.$request->id) ? 'has-error' : '' }}">+ <label for="fulfill-asset-{{ $request->id }}" class="col-md-3 control-label">+ {{ trans('general.asset') }}+ </label>+ <div class="col-md-7">+ @if ($availableAssets->isEmpty())+ <p class="form-control-static text-muted">+ <em>{{ $emptyMessage ?? trans('general.no_results') }}</em>+ </p>+ @else+ <select+ class="form-control select2"+ id="fulfill-asset-{{ $request->id }}"+ name="asset_id[{{ $request->id }}]"+ aria-label="{{ trans('general.asset') }}"+ >+ @foreach ($availableAssets as $asset)+ <option+ value="{{ $asset->id }}"+ @selected(old('asset_id.'.$request->id, $availableAssets->first()->id) == $asset->id)+ >+ {{ $asset->present()->fullName }}+ </option>+ @endforeach+ </select>+ @endif+ <div class="col-md-8" style="padding-left: 0;">+ <x-form.error :name="'asset_id.'.$request->id" />+ </div>+ </div>+ </div>++ @if ($showQty)+ <div class="form-group {{ $errors->has('qty.'.$request->id) ? 'has-error' : '' }}">+ <label for="fulfill-qty-{{ $request->id }}" class="col-md-3 control-label">{{ trans('general.qty') }}</label>+ <div class="col-md-7 col-sm-12">+ <div class="col-md-2" style="padding-left: 0">+ <input+ class="form-control"+ type="number"+ id="fulfill-qty-{{ $request->id }}"+ name="qty[{{ $request->id }}]"+ value="{{ old('qty.'.$request->id, (int) $request->quantity) }}"+ min="1"+ @if ($maxQty !== null) max="{{ $maxQty }}" @endif+ aria-label="{{ trans('general.qty') }}"+ >+ </div>+ </div>+ <div class="col-md-8 col-md-offset-3"><x-form.error :name="'qty.'.$request->id" /></div>+ </div>+ @else+ {{-- AssetModel rows fulfill one asset per request, so qty+ is fixed at 1. Hidden input keeps the POST shape+ uniform with the qty-tracked types. --}}+ <input type="hidden" name="qty[{{ $request->id }}]" value="1">+ @endif++ <x-form.row+ :label="trans('admin/hardware/form.notes')"+ :name="'notes['.$request->id.']'"+ type="textarea"+ :default="old('notes.'.$request->id, $request->notes ?? '')"+ />+</fieldset>diff --git a/resources/views/blade/checkout/recipient-row.blade.php b/resources/views/blade/checkout/recipient-row.blade.phpnew file mode 100644index 0000000000..a7369a0414--- /dev/null+++ b/resources/views/blade/checkout/recipient-row.blade.php@@ -0,0 +1,92 @@+@props([+ 'request',+ 'requester',+ 'companyId' => null,+ 'maxQty' => null,+ 'defaultChecked' => false,+ 'showQty' => true,+])++{{-- One row of the bulk-fulfill form. Renders a checkbox to opt this+ row into the batch, a user-select prefilled with the requester+ (editable, so admin can hand the item to someone else if the+ original requester is out sick), a qty input prefilled from the+ row's requested quantity, and the requester's notes as pre-+ filled context the admin can amend before checkout.++ Field names are keyed by CheckoutRequest id so the server can+ correlate the opt-in list with each row's per-field values+ without index-tracking. See bulk-fulfill controllers for the+ paired shape:+ enabled_requests[] = list of request ids ticked+ user_id[<request_id>] = target user for that row+ qty[<request_id>] = qty for that row+ notes[<request_id>] = admin/checkout note for that row++ Sign-in-place is deliberately absent. That flow assumes the+ requester is standing at the admin's device to sign in person,+ which doesn't match a bulk batch where the admin is processing+ multiple people from their own desk. Single-target checkout+ screens keep their sign-in-place checkbox unchanged. --}}+<fieldset class="form-group has-feedback" style="border: 1px solid #ddd; border-radius: 4px; padding: 15px; margin-bottom: 20px;">+ <legend class="col-sm-3 col-md-3 control-label" style="width: auto; padding: 0 10px; border: 0; margin-bottom: 0;">+ <label class="form-control" style="display: inline-flex; align-items: center; gap: 8px; margin-bottom: 0;">+ <input+ type="checkbox"+ name="enabled_requests[]"+ value="{{ (int) $request->id }}"+ @checked($defaultChecked || in_array((int) $request->id, (array) old('enabled_requests', []), true))+ aria-label="{{ trans('general.fulfill') }} #{{ $request->id }}"+ >+ <span>#{{ $request->id }}</span>+ @if ($requester)+ <span class="text-muted">+ — {{ $requester->display_name }}+ </span>+ @endif+ </label>+ </legend>++ <x-input.user-select+ :label="trans('general.user')"+ name="user_id[{{ $request->id }}]"+ :selected="old('user_id.'.$request->id, $requester?->id)"+ :companyId="$companyId"+ wrapperId="fulfill-user-{{ $request->id }}"+ id="fulfill-user-select-{{ $request->id }}"+ />++ @if ($showQty)+ <div class="form-group {{ $errors->has('qty.'.$request->id) ? 'has-error' : '' }}">+ <label for="fulfill-qty-{{ $request->id }}" class="col-md-3 control-label">{{ trans('general.qty') }}</label>+ <div class="col-md-7 col-sm-12">+ <div class="col-md-2" style="padding-left: 0">+ <input+ class="form-control"+ type="number"+ id="fulfill-qty-{{ $request->id }}"+ name="qty[{{ $request->id }}]"+ value="{{ old('qty.'.$request->id, (int) $request->quantity) }}"+ min="1"+ @if ($maxQty !== null) max="{{ $maxQty }}" @endif+ aria-label="{{ trans('general.qty') }}"+ >+ </div>+ </div>+ <div class="col-md-8 col-md-offset-3"><x-form.error :name="'qty.'.$request->id" /></div>+ </div>+ @else+ {{-- Types where qty is meaningless (license = one seat per+ requester, asset = 1:1) hide the input but keep a+ hidden value=1 so the controller's per-row shape stays+ uniform across every requestable type. --}}+ <input type="hidden" name="qty[{{ $request->id }}]" value="1">+ @endif++ <x-form.row+ :label="trans('admin/hardware/form.notes')"+ :name="'notes['.$request->id.']'"+ type="textarea"+ :default="old('notes.'.$request->id, $request->notes ?? '')"+ />+</fieldset>diff --git a/resources/views/checkouts/fulfill-multiple-to-asset.blade.php b/resources/views/checkouts/fulfill-multiple-to-asset.blade.phpnew file mode 100644index 0000000000..495b4e0dc3--- /dev/null+++ b/resources/views/checkouts/fulfill-multiple-to-asset.blade.php@@ -0,0 +1,70 @@+@extends('layouts/default')++@section('title')+ {{ trans('admin/hardware/general.fulfill_multiple') }}+ @parent+@stop++{{-- Bulk-fulfill for asset-target requestable types (Component,+ AssetModel). Each row picks a specific Asset per request; the+ controller pre-computes the available-asset set per row so the+ picker is a plain <select> (no ajax pagination needed for the+ typical scope). Sibling template checkouts/fulfill-multiple.blade.php+ handles the user-target types (Accessory/Consumable/License). --}}++@section('content')++<x-container class="col-md-12">+ <x-form :route="$formRoute" id="fulfill_multiple_form">++ <x-box header="{{ $item->display_name ?? $item->name }}">++ @if ($remaining !== null)+ <x-form.static :label="trans('admin/components/general.remaining')">+ {{ (int) $remaining }}+ </x-form.static>+ @endif++ @if ($item->company ?? null)+ <x-form.static :label="trans('general.company')">{!! $item->company->present()->formattedNameLink !!}</x-form.static>+ @endif++ @if ($item->category ?? null)+ <x-form.static :label="trans('general.category')">{!! $item->category->present()->formattedNameLink !!}</x-form.static>+ @endif++ {{-- $rowContext[$requestId] = ['availableAssets' => Collection, 'emptyMessage' => ?string]+ Rows whose availableAssets is empty render the+ row disabled (checkbox unavailable) with the+ empty message so the admin sees WHY that row+ can't be fulfilled from this screen. --}}+ @foreach ($pendingRequests as $request)+ @php ($context = $rowContext[$request->id] ?? ['availableAssets' => collect(), 'emptyMessage' => null])+ <x-checkout.asset-picker-row+ :request="$request"+ :requester="$request->user"+ :available-assets="$context['availableAssets']"+ :empty-message="$context['emptyMessage']"+ :show-qty="! ($hideQty ?? false)"+ :max-qty="$remaining"+ />+ @endforeach++ <x-slot:customfooter>+ <div class="col-md-9 col-md-offset-3">+ <a href="{{ route('requests.index') }}" class="btn btn-default">+ {{ trans('button.cancel') }}+ </a>+ <button type="submit" class="btn btn-primary" id="submit_button">+ <x-icon type="checkmark" />+ {{ trans('admin/hardware/general.fulfill_multiple') }}+ </button>+ </div>+ </x-slot:customfooter>++ </x-box>++ </x-form>+</x-container>++@stopdiff --git a/resources/views/checkouts/fulfill-multiple.blade.php b/resources/views/checkouts/fulfill-multiple.blade.phpnew file mode 100644index 0000000000..9a2ba46f72--- /dev/null+++ b/resources/views/checkouts/fulfill-multiple.blade.php@@ -0,0 +1,65 @@+@extends('layouts/default')++@section('title')+ {{ trans('admin/hardware/general.fulfill_multiple') }}+ @parent+@stop++@section('content')++<x-container class="col-md-12">+ <x-form :route="$formRoute" id="fulfill_multiple_form">++ <x-box header="{{ $item->display_name ?? $item->name }} ({{ (int) $item->numRemaining() }} {{ trans('admin/components/general.remaining') }})">++ @if ($remaining !== null)+ <x-form.static :label="trans('admin/components/general.remaining')">+ {{ (int) $remaining }}+ </x-form.static>+ @endif++ @if ($item->company ?? null)+ <x-form.static :label="trans('general.company')">{!! $item->company->present()->formattedNameLink !!}</x-form.static>+ @endif++ @if ($item->category ?? null)+ <x-form.static :label="trans('general.category')">{!! $item->category->present()->formattedNameLink !!}</x-form.static>+ @endif++ {{-- One row per pending CheckoutRequest, ordered+ oldest-first (waiting-list). Admin ticks the+ ones to fulfill; rows left unchecked stay+ pending. Qty defaults to what was requested and+ is capped at the item's numRemaining so the+ server can trust the sum won't over-allocate,+ but the controller re-checks under lock during+ the transaction so a stale page load can't+ over-fulfill on submit. --}}+ @foreach ($pendingRequests as $request)+ <x-checkout.recipient-row+ :request="$request"+ :requester="$request->user"+ :company-id="$item->company_id ?? null"+ :max-qty="$remaining"+ :show-qty="! ($hideQty ?? false)"+ />+ @endforeach++ <x-slot:customfooter>+ <div class="col-md-9 col-md-offset-3">+ <a href="{{ route('requests.index') }}" class="btn btn-default">+ {{ trans('button.cancel') }}+ </a>+ <button type="submit" class="btn btn-primary" id="submit_button">+ <x-icon type="checkmark" />+ {{ trans('admin/hardware/general.fulfill_multiple') }}+ </button>+ </div>+ </x-slot:customfooter>++ </x-box>++ </x-form>+</x-container>++@stop