3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-08 02:05:31 +00:00

attempt to sort chronologically, can not resort still

This commit is contained in:
Godfrey M
2025-09-18 11:01:40 -07:00
parent dcbb09bbd7
commit 51ce570eb3
4 changed files with 32 additions and 17 deletions

View File

@ -1127,7 +1127,8 @@ class ReportsController extends Controller
'assignedTo' => function($query){
$query->withTrashed();
}
]);
])->orderByDesc('checkout_acceptances.created_at');
if ($showDeleted) {
$query->withTrashed();

View File

@ -9,7 +9,6 @@ class Checkoutable
{
public function __construct(
public int $acceptance_id,
public string $created_at,
public string $company,
public string $category,
public string $model,
@ -17,6 +16,7 @@ class Checkoutable
public string $name,
public string $type,
public object $acceptance,
public object $assignee,
){}
// public static function fromCheckoutable(Asset|Accessory|etc..)
@ -29,10 +29,12 @@ class Checkoutable
$unaccepted_row = $unaccepted->checkoutable;
$acceptance = $unaccepted;
$assignee = $acceptance->assignedTo;
$company = optional($unaccepted_row->company)->name ?? '';
$category = $model = $name = $tag = '';
$type = $acceptance->checkoutable_item_type ?? '';
if($unaccepted_row instanceof Asset){
$category = optional($unaccepted_row->model?->category?->present())->nameUrl() ?? '';
$model = optional($unaccepted_row->present())->modelUrl() ?? '';
@ -43,24 +45,22 @@ class Checkoutable
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
$model = $unaccepted_row->model_number ?? '';
$name = optional($unaccepted_row->present())->nameUrl() ?? '';
$tag = '';
}
if($unaccepted_row instanceof LicenseSeat){
$category = '';
$model = '';
$name = $unaccepted_row->license->name ?? '';
$tag = '';
}
if($unaccepted_row instanceof Component){
$category = optional($unaccepted_row->category?->present())->nameUrl() ?? '';
$model = $unaccepted_row->model_number ?? '';
$name = $unaccepted_row->present()->nameUrl() ?? '';
$tag = '';
}
$created = $acceptance->created_at;
return new self(
acceptance_id: $acceptance->id,
created_at: Helper::getFormattedDateObject($acceptance->created_at, 'datetime', false),
company: $company,
category: $category,
model: $model,
@ -68,6 +68,7 @@ class Checkoutable
name: $name,
type: $type,
acceptance: $acceptance,
assignee: $assignee,
);
}
}

View File

@ -870,6 +870,17 @@
return value.formatted;
}
}
function createdAtSorter(a, b, rowA, rowB) {
const CREATED_AT_COL_INDEX = 0;
const ts = row => Number(row?._$el?.find('td').eq(CREATED_AT_COL_INDEX).attr('data-timestamp') || 0);
return ts(rowA) - ts(rowB);
}
function createdAtSorter(a, b, rowA, rowB) {
const ts = row =>
Number(row?._$el?.find('td').eq(CREATED_AT_COL_INDEX).attr('data-timestamp') || 0);
return ts(rowA) - ts(rowB);
}
function iconFormatter(value) {
if (value) {

View File

@ -48,7 +48,13 @@
}'>
<thead>
<tr role="row">
<th class="col-sm-1" data-searchable="false" data-field="created_at" data-sortable="true">{{ trans('general.date') }}</th>
<th class="col-sm-1"
data-field="created_at"
data-searchable="false"
data-sortable="true"
data-sorter="createdAtSorter">
{{ trans('general.date') }}
</th>
<th class="col-sm-1" data-sortable="true" >{{ trans('general.type') }}</th>
<th class="col-sm-1" data-sortable="true" >{{ trans('admin/companies/table.title') }}</th>
<th class="col-sm-1" data-sortable="true" >{{ trans('general.category') }}</th>
@ -63,8 +69,8 @@
@if ($itemsForReport)
@foreach ($itemsForReport as $item)
<tr @if($item->acceptance->trashed()) style="text-decoration: line-through" @endif>
{{-- Created date (already formatted) --}}
<td data-order="{{ $item->acceptance->created_at->getTimestamp() }}">
{{-- Created date --}}
<td>
{{ Helper::getFormattedDateObject($item->acceptance->created_at, 'datetime', false) }}
</td>
{{-- Item Type --}}
@ -85,13 +91,9 @@
<td>{{ $item->asset_tag }}</td>
{{-- Assigned To (with soft-delete strike if needed) --}}
@php
$assignee = $item->acceptance->assignedTo;
$assigneeStruck = !$assignee || (method_exists($assignee, 'trashed') && $assignee->trashed());
@endphp
<td @if($assigneeStruck) style="text-decoration: line-through" @endif>
{!! $assignee
? optional($assignee->present())->nameUrl() ?? e($assignee->name)
<td @if(!$item->assignee || (method_exists($item->assignee, 'trashed') && $item->assignee->trashed())) style="text-decoration: line-through" @endif>
{!! $item->assignee
? optional($item->assignee->present())->nameUrl() ?? e($item->assignee->name)
: trans('admin/reports/general.deleted_user') !!}
</td>
@ -102,7 +104,7 @@
<form method="post" class="white-space: nowrap;" action="{{ route('reports/unaccepted_assets_sent_reminder') }}">
@csrf
<input type="hidden" name="acceptance_id" value="{{ $item->acceptance_id }}">
@if ($assignee && $assignee->email)
@if ($item->assignee && $item->assignee->email)
<button class="btn btn-sm btn-warning" data-tooltip="true" data-title="{{ trans('admin/reports/general.send_reminder') }}">
<i class="fa fa-repeat" aria-hidden="true"></i>
</button>