From f510b9c2a936c2d7a899cae735c3f928f4f5d35b Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 14:21:31 -0600 Subject: [PATCH] Add query to filter non-deprecable assets when the Depreciation Report is called --- app/Http/Controllers/Api/AssetsController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 3b37a2875c..b594cb1c95 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -55,7 +55,7 @@ class AssetsController extends Controller { \Log::debug(Route::currentRouteName()); - + $filter_non_deprecable_assets = false; /** * This looks MAD janky (and it is), but the AssetsController@index does a LOT of heavy lifting throughout the @@ -69,6 +69,7 @@ class AssetsController extends Controller * which would have been far worse of a mess. *sad face* - snipe (Sept 1, 2021) */ if (Route::currentRouteName()=='api.depreciation-report.index') { + $filter_non_deprecable_assets = true; $transformer = 'App\Http\Transformers\DepreciationReportTransformer'; $this->authorize('reports.view'); } else { @@ -119,6 +120,12 @@ class AssetsController extends Controller 'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users. + if($filter_non_deprecable_assets) { + $non_deprecable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get(); + + $assets->InModelList($non_deprecable_models->toArray()); + } + // These are used by the API to query against specific ID numbers. // They are also used by the individual searches on detail pages like // locations, etc.