From c93229179b6b3e67e81a995c645563cd05bcf8f7 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 19 Sep 2024 16:45:39 +0100 Subject: [PATCH] Added order by created_by to accessories Signed-off-by: snipe --- .../Controllers/Api/AccessoriesController.php | 5 ++++- app/Models/Accessory.php | 10 ++++++++++ app/Presenters/AccessoryPresenter.php | 16 ++++++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index 1297858bdf..19951b6589 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -111,7 +111,10 @@ class AccessoriesController extends Controller break; case 'supplier': $accessories = $accessories->OrderSupplier($order); - break; + break; + case 'created_by': + $accessories = $accessories->OrderByCreatedByName($order); + break; default: $accessories = $accessories->orderBy($column_sort, $order); break; diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index dfcba6dbe8..3fc4c5c9c6 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -422,6 +422,16 @@ class Accessory extends SnipeModel * ----------------------------------------------- **/ + + /** + * Query builder scope to order on created_by name + * + */ + public function scopeOrderByCreatedByName($query, $order) + { + return $query->leftJoin('users as admin_sort', 'accessories.created_by', '=', 'admin_sort.id')->select('accessories.*')->orderBy('admin_sort.first_name', $order)->orderBy('admin_sort.last_name', $order); + } + /** * Query builder scope to order on company * diff --git a/app/Presenters/AccessoryPresenter.php b/app/Presenters/AccessoryPresenter.php index 210dbfc0f7..04f55cf364 100644 --- a/app/Presenters/AccessoryPresenter.php +++ b/app/Presenters/AccessoryPresenter.php @@ -127,13 +127,6 @@ class AccessoryPresenter extends Presenter 'visible' => false, 'title' => trans('general.notes'), 'formatter' => 'notesFormatter' - ], [ - 'field' => 'change', - 'searchable' => false, - 'sortable' => false, - 'visible' => true, - 'title' => trans('general.change'), - 'formatter' => 'accessoriesInOutFormatter', ], [ 'field' => 'created_by', 'searchable' => false, @@ -157,7 +150,14 @@ class AccessoryPresenter extends Presenter 'title' => trans('general.updated_at'), 'visible' => false, 'formatter' => 'dateDisplayFormatter', - ],[ + ], [ + 'field' => 'change', + 'searchable' => false, + 'sortable' => false, + 'visible' => true, + 'title' => trans('general.change'), + 'formatter' => 'accessoriesInOutFormatter', + ], [ 'field' => 'actions', 'searchable' => false, 'sortable' => false,