From 02cacf76c678af56ae766c9f8648f4bacf4c32e1 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 16 May 2023 13:58:21 -0700 Subject: [PATCH] Additional multi-select options for custom report Signed-off-by: snipe --- .../Api/StatuslabelsController.php | 42 +++++++++++++++++++ app/Http/Controllers/ReportsController.php | 9 ++-- .../forms/edit/category-select.blade.php | 2 +- .../forms/edit/department-select.blade.php | 2 +- .../forms/edit/manufacturer-select.blade.php | 2 +- .../forms/edit/model-select.blade.php | 2 +- .../forms/edit/status-select.blade.php | 29 +++++++++++++ .../forms/edit/supplier-select.blade.php | 2 +- resources/views/reports/custom.blade.php | 24 +++++------ routes/api.php | 7 ++++ 10 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 resources/views/partials/forms/edit/status-select.blade.php diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index a9e44d91b4..30a0b699e9 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api; use App\Helpers\Helper; use App\Http\Controllers\Controller; use App\Http\Transformers\AssetsTransformer; +use App\Http\Transformers\SelectlistTransformer; use App\Http\Transformers\StatuslabelsTransformer; use App\Models\Asset; use App\Models\Statuslabel; @@ -291,4 +292,45 @@ class StatuslabelsController extends Controller return '0'; } + + /** + * Gets a paginated collection for the select2 menus + * + * @author [A. Gianotto] [] + * @since [v6.1.1] + * @see \App\Http\Transformers\SelectlistTransformer + */ + public function selectlist(Request $request) + { + + $this->authorize('view.selectlists'); + $statuslabels = Statuslabel::orderBy('default_label', 'desc')->orderBy('name', 'asc')->orderBy('deployable', 'desc'); + + if ($request->filled('search')) { + $statuslabels = $statuslabels->where('name', 'LIKE', '%'.$request->get('search').'%'); + } + + if ($request->filled('deployable')) { + $statuslabels = $statuslabels->where('deployable', '=', '1'); + } + + if ($request->filled('pending')) { + $statuslabels = $statuslabels->where('pending', '=', '1'); + } + + if ($request->filled('archived')) { + $statuslabels = $statuslabels->where('archived', '=', '1'); + } + + $statuslabels = $statuslabels->orderBy('name', 'ASC')->paginate(50); + + // Loop through and set some custom properties for the transformer to use. + // This lets us have more flexibility in special cases like assets, where + // they may not have a ->name value but we want to display something anyway + foreach ($statuslabels as $statuslabel) { + $statuslabels->use_text = $statuslabel->name; + } + + return (new SelectlistTransformer)->transformSelectlist($statuslabels); + } } diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 8ffe1faf08..4fa7990a22 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -599,11 +599,11 @@ class ReportsController extends Controller } if ($request->filled('by_rtd_location_id')) { - $assets->where('assets.rtd_location_id', $request->input('by_rtd_location_id')); + $assets->whereIn('assets.rtd_location_id', $request->input('by_rtd_location_id')); } if ($request->filled('by_supplier_id')) { - $assets->where('assets.supplier_id', $request->input('by_supplier_id')); + $assets->whereIn('assets.supplier_id', $request->input('by_supplier_id')); } if ($request->filled('by_company_id')) { @@ -611,7 +611,7 @@ class ReportsController extends Controller } if ($request->filled('by_model_id')) { - $assets->where('assets.model_id', $request->input('by_model_id')); + $assets->whereIn('assets.model_id', $request->input('by_model_id')); } if ($request->filled('by_category_id')) { @@ -631,7 +631,7 @@ class ReportsController extends Controller } if ($request->filled('by_status_id')) { - $assets->where('assets.status_id', $request->input('by_status_id')); + $assets->whereIn('assets.status_id', $request->input('by_status_id')); } if (($request->filled('purchase_start')) && ($request->filled('purchase_end'))) { @@ -666,6 +666,7 @@ class ReportsController extends Controller $assets->onlyTrashed(); } + \Log::debug($assets->toSql()); $assets->orderBy('assets.id', 'ASC')->chunk(20, function ($assets) use ($handle, $customfields, $request) { $executionTime = microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']; diff --git a/resources/views/partials/forms/edit/category-select.blade.php b/resources/views/partials/forms/edit/category-select.blade.php index a5fd9471f3..684b8d76da 100644 --- a/resources/views/partials/forms/edit/category-select.blade.php +++ b/resources/views/partials/forms/edit/category-select.blade.php @@ -4,7 +4,7 @@ {{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
- @if ($category_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))