From 7d9a0eba04d6607adffa93b0a2117c2c22dd3d2a Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 9 Sep 2024 03:49:58 +0100 Subject: [PATCH 1/2] Added ability to sort on qty and remaining for consumables Signed-off-by: snipe --- app/Http/Controllers/Api/ConsumablesController.php | 3 +++ app/Models/Consumable.php | 14 ++++++++++++++ app/Presenters/ConsumablePresenter.php | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index 1665b7f4f0..7be4c3d2dd 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -86,6 +86,9 @@ class ConsumablesController extends Controller case 'company': $consumables = $consumables->OrderCompany($order); break; + case 'remaining': + $consumables = $consumables->OrderRemaining($order); + break; case 'supplier': $consumables = $consumables->OrderSupplier($order); break; diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 944ac5bfde..3b33035b1e 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -425,6 +425,20 @@ class Consumable extends SnipeModel return $query->leftJoin('companies', 'consumables.company_id', '=', 'companies.id')->orderBy('companies.name', $order); } + /** + * Query builder scope to order on remaining + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param string $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderRemaining($query, $order) + { + $order_by = 'consumables.qty - consumables_users_count ' . $order; + return $query->orderByRaw($order_by); + } + /** * Query builder scope to order on supplier * diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.php index d3e73de1cf..dc22c69e24 100644 --- a/app/Presenters/ConsumablePresenter.php +++ b/app/Presenters/ConsumablePresenter.php @@ -75,13 +75,13 @@ class ConsumablePresenter extends Presenter ], [ 'field' => 'qty', 'searchable' => false, - 'sortable' => false, + 'sortable' => true, 'title' => trans('admin/components/general.total'), 'visible' => true, ], [ 'field' => 'remaining', 'searchable' => false, - 'sortable' => false, + 'sortable' => true, 'title' => trans('admin/components/general.remaining'), 'visible' => true, ], [ From c5dbc5f6b887d866a4dfb9800cb001b26593a89b Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 9 Sep 2024 10:01:07 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Correctly=20save=20user=E2=80=99s=20city=20?= =?UTF-8?q?on=20bulk=20edit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/Users/BulkUsersController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index 12dc14e29f..5d1007e79a 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -118,6 +118,7 @@ class BulkUsersController extends Controller ->conditionallyAddItem('activated') ->conditionallyAddItem('start_date') ->conditionallyAddItem('end_date') + ->conditionallyAddItem('city') ->conditionallyAddItem('autoassign_licenses');