From d5f6f6cafe6d74341cde93331ac250beb53d463d Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 03:46:28 -0600 Subject: [PATCH 1/6] Fixes duplicate API endpoint that returns fieldsets instead of customfields --- routes/api.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/routes/api.php b/routes/api.php index 175d17587c..508358f3d1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -368,18 +368,18 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () { }); - Route::resource('fields', + Route::resource('fieldsets', Api\CustomFieldsetsController::class, ['names' => [ - 'index' => 'api.customfields.index', - 'show' => 'api.customfields.show', - 'update' => 'api.customfields.update', - 'store' => 'api.customfields.store', - 'destroy' => 'api.customfields.destroy', + 'index' => 'api.fieldsets.index', + 'show' => 'api.fieldsets.show', + 'update' => 'api.fieldsets.update', + 'store' => 'api.fieldsets.store', + 'destroy' => 'api.fieldsets.destroy', ], 'except' => ['create', 'edit'], - 'parameters' => ['field' => 'field_id'], + 'parameters' => ['fieldset' => 'fieldset_id'], ] ); // end custom fieldsets API routes From 8bd280b416716248cce6add6ff4426b49e55745e Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 04:12:30 -0600 Subject: [PATCH 2/6] Add to Importer the capacity to search Models only with Model Name since Model Number is not required --- app/Importer/ItemImporter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 1584539ee2..0c3a188352 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -178,6 +178,7 @@ class ItemImporter extends Importer */ public function createOrFetchAssetModel(array $row) { + $condition = array(); $asset_model_name = $this->findCsvMatch($row, 'asset_model'); $asset_modelNumber = $this->findCsvMatch($row, 'model_number'); // TODO: At the moment, this means we can't update the model number if the model name stays the same. @@ -189,8 +190,16 @@ class ItemImporter extends Importer } elseif ((empty($asset_model_name)) && (empty($asset_modelNumber))) { $asset_model_name = 'Unknown'; } + + if ((!empty($asset_model_name)) && (empty($asset_modelNumber))) { + $condition[] = ['name', '=', $asset_model_name]; + } elseif ((!empty($asset_model_name)) && (!empty($asset_modelNumber))) { + $condition[] = ['name', '=', $asset_model_name]; + $condition[] = ['model_number', '=', $asset_modelNumber]; + } + $editingModel = $this->updating; - $asset_model = AssetModel::where(['name' => $asset_model_name, 'model_number' => $asset_modelNumber])->first(); + $asset_model = AssetModel::where($condition)->first(); if ($asset_model) { if (! $this->updating) { @@ -201,7 +210,6 @@ class ItemImporter extends Importer $this->log('Matching Model found, updating it.'); $item = $this->sanitizeItemForStoring($asset_model, $editingModel); $item['name'] = $asset_model_name; - $item['model_number'] = $asset_modelNumber; $asset_model->update($item); $asset_model->save(); $this->log('Asset Model Updated'); From 58b1db29e24fb5447450bce42327fdc1720ad7f2 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 04:15:38 -0600 Subject: [PATCH 3/6] Adds condition to only update the Asset's Model Number if is provided by import file --- app/Importer/ItemImporter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 0c3a188352..5dbfccb238 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -210,6 +210,11 @@ class ItemImporter extends Importer $this->log('Matching Model found, updating it.'); $item = $this->sanitizeItemForStoring($asset_model, $editingModel); $item['name'] = $asset_model_name; + + if(!empty($asset_modelNumber)){ + $item['model_number'] = $asset_modelNumber; + } + $asset_model->update($item); $asset_model->save(); $this->log('Asset Model Updated'); From 92b3576395523566687dcef61f5a87e99de50134 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 12:02:43 -0600 Subject: [PATCH 4/6] Fixes a route definition to correctly populate the deprecation report --- routes/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.php b/routes/api.php index 508358f3d1..52900baada 100644 --- a/routes/api.php +++ b/routes/api.php @@ -296,7 +296,7 @@ Route::group(['prefix' => 'v1', 'middleware' => 'api'], function () { ); // end depreciations API routes - Route::post('reports/depreciation', + Route::get('reports/depreciation', [ Api\AssetsController::class, 'index' From 9ae03f21dcbcc07d1846425fa8c6a5921aec426a Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 12:05:15 -0600 Subject: [PATCH 5/6] Adds condition to only charge custom field's livewire when the model is updated --- resources/views/models/edit.blade.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/views/models/edit.blade.php b/resources/views/models/edit.blade.php index 436e425179..ee299cdde4 100755 --- a/resources/views/models/edit.blade.php +++ b/resources/views/models/edit.blade.php @@ -34,7 +34,9 @@ -@livewire('custom-field-set-default-values-for-model',["model_id" => $item->id]) +@if (isset($item->id)) + @livewire('custom-field-set-default-values-for-model',["model_id" => $item->id]) +@endif @include ('partials.forms.edit.notes') @include ('partials.forms.edit.requestable', ['requestable_text' => trans('admin/models/general.requestable')]) From 8334ed6f7eaa5881c3b31f23d63e35c1ef15f9e2 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Sat, 15 Jan 2022 14:01:19 -0600 Subject: [PATCH 6/6] 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 85373833ae..cc04207b88 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -54,7 +54,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 @@ -68,6 +68,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 { @@ -118,6 +119,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.