A free open source IT asset/license management system
Added checkout date to side panel of assigned things on checkout screens
snipe02ecf8274d3f
diff --git a/app/Livewire/CheckoutTargetPanel.php b/app/Livewire/CheckoutTargetPanel.phpindex 6d8bfc6a2e..cb62bc755d 100644--- a/app/Livewire/CheckoutTargetPanel.php+++ b/app/Livewire/CheckoutTargetPanel.php@@ -2,7 +2,6 @@namespace App\Livewire;-use App\Models\Accessory;use App\Models\Asset;use App\Models\Location;use App\Models\User;@@ -117,23 +116,23 @@ class CheckoutTargetPanel extends Component// and means "assets physically at this location". Same story for// accessories: query the checkout pivot rather than the// location_id column.+ // Ordered by most-recent checkout first so the operator sees+ // what the target just received at the top of the panel, not+ // whatever the underlying relation's default order emits.return match ("{$this->type}:{$this->targetType}") {- 'assets:user' => $target->assets,- 'licenses:user' => $target->licenses,- 'accessories:user' => $target->accessories,- 'consumables:user' => $target->consumables,-- 'assets:asset' => $target->assignedAssets,- 'licenses:asset' => $target->licenses,- 'accessories:asset' => $target->accessories,-- 'assets:location' => $target->assignedAssets,- 'accessories:location' => Accessory::whereHas('checkouts', function ($q) {- $q->where('assigned_type', Location::class)- ->where('assigned_to', $this->targetId);- })->get(),-- 'components:asset' => $target->components,+ 'assets:user' => $target->assets()->reorder('last_checkout', 'desc')->get(),+ 'licenses:user' => $target->licenses()->orderByPivot('created_at', 'desc')->get(),+ 'accessories:user' => $target->accessories()->reorder('accessories_checkout.created_at', 'desc')->get(),+ 'consumables:user' => $target->consumables()->orderByPivot('created_at', 'desc')->get(),++ 'assets:asset' => $target->assignedAssets()->reorder('last_checkout', 'desc')->get(),+ 'licenses:asset' => $target->licenses()->orderByPivot('created_at', 'desc')->get(),+ 'accessories:asset' => $target->assignedAccessories()->with('accessory')->orderBy('created_at', 'desc')->get(),++ 'assets:location' => $target->assignedAssets()->reorder('last_checkout', 'desc')->get(),+ 'accessories:location' => $target->assignedAccessories()->with('accessory')->orderBy('created_at', 'desc')->get(),++ 'components:asset' => $target->components()->orderByPivot('created_at', 'desc')->get(),default => collect(),};diff --git a/resources/views/livewire/checkout-target-panel.blade.php b/resources/views/livewire/checkout-target-panel.blade.phpindex 550d93f916..fd947b2fac 100644--- a/resources/views/livewire/checkout-target-panel.blade.php+++ b/resources/views/livewire/checkout-target-panel.blade.php@@ -27,6 +27,7 @@<th scope="col">{{ trans('general.name') }}</th><th scope="col">{{ trans('admin/hardware/form.tag') }}</th><th scope="col">{{ trans('admin/hardware/form.serial') }}</th>+ <th scope="col">{{ trans('admin/hardware/form.checkout_date') }}</th></tr></thead><tbody>@@ -44,9 +45,10 @@</td><td>{{ $asset->asset_tag }}</td><td>{{ $asset->serial }}</td>+ <td>{{ $asset->last_checkout ? \App\Helpers\Helper::getFormattedDateObject($asset->last_checkout, 'date', false) : '' }}</td></tr>@empty- <tr><td colspan="4">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ <tr><td colspan="5">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>@endforelse</tbody>@break@@ -59,6 +61,7 @@@if ($canViewKeys)<th scope="col">{{ trans('admin/licenses/form.license_key') }}</th>@endif+ <th scope="col">{{ trans('admin/hardware/form.checkout_date') }}</th></tr></thead><tbody>@@ -68,26 +71,32 @@@if ($canViewKeys)<td>{{ $license->serial }}</td>@endif+ <td>{{ $license->pivot?->created_at ? \App\Helpers\Helper::getFormattedDateObject($license->pivot->created_at, 'date', false) : '' }}</td></tr>@empty- <tr><td colspan="{{ $canViewKeys ? 2 : 1 }}">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ <tr><td colspan="{{ $canViewKeys ? 3 : 2 }}">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>@endforelse</tbody>@break@case('accessories')+ {{-- Row shape differs by target: User branch returns Accessory-with-pivot (belongsToMany+ accessories()), Asset / Location branches return AccessoryCheckout with ->accessory+ eager loaded (assignedAccessories()). Reconciled inline via null-coalescing. --}}<thead><tr><th scope="col">{{ trans('general.name') }}</th>+ <th scope="col">{{ trans('admin/hardware/form.checkout_date') }}</th></tr></thead><tbody>- @forelse ($items as $accessory)+ @forelse ($items as $item)<tr>- <td><a href="{{ route('accessories.show', $accessory->id) }}">{{ $accessory->name }}</a></td>+ <td><a href="{{ route('accessories.show', $item->accessory?->id ?? $item->id) }}">{{ $item->accessory?->name ?? $item->name }}</a></td>+ <td>{{ ($item->pivot?->created_at ?? $item->created_at) ? \App\Helpers\Helper::getFormattedDateObject($item->pivot?->created_at ?? $item->created_at, 'date', false) : '' }}</td></tr>@empty- <tr><td>{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ <tr><td colspan="2">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>@endforelse</tbody>@break@@ -96,15 +105,17 @@<thead><tr><th scope="col">{{ trans('general.name') }}</th>+ <th scope="col">{{ trans('admin/hardware/form.checkout_date') }}</th></tr></thead><tbody>@forelse ($items as $consumable)<tr><td><a href="{{ route('consumables.show', $consumable->id) }}">{{ $consumable->name }}</a></td>+ <td>{{ $consumable->pivot?->created_at ? \App\Helpers\Helper::getFormattedDateObject($consumable->pivot->created_at, 'date', false) : '' }}</td></tr>@empty- <tr><td>{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ <tr><td colspan="2">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>@endforelse</tbody>@break@@ -114,6 +125,7 @@<tr><th scope="col">{{ trans('general.name') }}</th><th scope="col">{{ trans('general.qty') }}</th>+ <th scope="col">{{ trans('admin/hardware/form.checkout_date') }}</th></tr></thead><tbody>@@ -121,9 +133,10 @@<tr><td><a href="{{ route('components.show', $component->id) }}">{{ $component->name }}</a></td><td>{{ $component->pivot->assigned_qty ?? 1 }}</td>+ <td>{{ $component->pivot?->created_at ? \App\Helpers\Helper::getFormattedDateObject($component->pivot->created_at, 'date', false) : '' }}</td></tr>@empty- <tr><td colspan="2">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>+ <tr><td colspan="3">{{ trans('admin/users/message.nothing_currently_assigned') }}</td></tr>@endforelse</tbody>@break