Added order by admin to assets

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-09-19 16:34:10 +01:00
parent 4363e8b34c
commit a77a7065d7
3 changed files with 21 additions and 0 deletions

View file

@ -371,6 +371,9 @@ class AssetsController extends Controller
case 'assigned_to': case 'assigned_to':
$assets->OrderAssigned($order); $assets->OrderAssigned($order);
break; break;
case 'created_by':
$assets->OrderByCreatedByName($order);
break;
default: default:
$assets->orderBy($column_sort, $order); $assets->orderBy($column_sort, $order);
break; break;

View file

@ -80,6 +80,10 @@ class AssetsTransformer
'assigned_to' => $this->transformAssignedTo($asset), 'assigned_to' => $this->transformAssignedTo($asset),
'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null, 'warranty_months' => ($asset->warranty_months > 0) ? e($asset->warranty_months.' '.trans('admin/hardware/form.months')) : null,
'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null, 'warranty_expires' => ($asset->warranty_months > 0) ? Helper::getFormattedDateObject($asset->warranty_expires, 'date') : null,
'created_by' => ($asset->adminuser) ? [
'id' => (int) $asset->adminuser->id,
'name'=> e($asset->adminuser->present()->fullName()),
] : null,
'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'), 'created_at' => Helper::getFormattedDateObject($asset->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($asset->updated_at, 'datetime'),
'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'), 'last_audit_date' => Helper::getFormattedDateObject($asset->last_audit_date, 'datetime'),

View file

@ -1760,6 +1760,20 @@ class Asset extends Depreciable
} }
/**
* Query builder scope to order on created_by name
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByCreatedByName($query, $order)
{
return $query->leftJoin('users as admin_sort', 'assets.created_by', '=', 'admin_sort.id')->select('assets.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order);
}
/** /**
* Query builder scope to order on assigned user * Query builder scope to order on assigned user
* *