From 03df4cec45855cd366b6a760132af8d30a75ec31 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:46:43 +0000 Subject: [PATCH 01/13] Fixed typo Signed-off-by: snipe --- app/Models/Asset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index abb2239dc7d5..c2a2a8d9955d 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1560,7 +1560,7 @@ public function scopeByFilter($query, $filter) * * In short, this set of statements tells the query builder to ONLY query against an * actual field that's being passed if it doesn't meet known relational fields. This - * allows us to query custom fields directly in the assetsv table + * allows us to query custom fields directly in the assets table * (regardless of their name) and *skip* any fields that we already know can only be * searched through relational searches that we do earlier in this method. * From 7868a8c1745aa6632b04f3e1b7885163f0e6f36a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:47:13 +0000 Subject: [PATCH 02/13] Added serial for API controller Signed-off-by: snipe --- app/Http/Controllers/Api/AssetMaintenancesController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 931e8e51c08c..b39d9d992698 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -36,7 +36,8 @@ public function index(Request $request) { $this->authorize('view', Asset::class); - $maintenances = AssetMaintenance::select('asset_maintenances.*')->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'admin'); + $maintenances = AssetMaintenance::select('asset_maintenances.*') + ->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'admin'); if ($request->filled('search')) { $maintenances = $maintenances->TextSearch($request->input('search')); @@ -70,6 +71,7 @@ public function index(Request $request) 'notes', 'asset_tag', 'asset_name', + 'serial', 'user_id', 'supplier', 'is_warranty', @@ -90,6 +92,10 @@ public function index(Request $request) case 'asset_name': $maintenances = $maintenances->OrderByAssetName($order); break; + case 'serial': + \Log::debug('sort by serial'); + $maintenances = $maintenances->OrderByAssetSerial($order); + break; default: $maintenances = $maintenances->orderBy($sort, $order); break; From e5ee9760c04b234024cd05ec522fa28ce073f0ed Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:47:33 +0000 Subject: [PATCH 03/13] =?UTF-8?q?I=20don=E2=80=99t=20think=20we=20use=20th?= =?UTF-8?q?ese=20anyore=20because=20of=20the=20modifiers=20on=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/AssetMaintenancesController.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index dc6bc8434711..cb6ecf617746 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -161,17 +161,6 @@ public function edit($assetMaintenanceId = null) return static::getInsufficientPermissionsRedirect(); } - if ($assetMaintenance->completion_date == '0000-00-00') { - $assetMaintenance->completion_date = null; - } - - if ($assetMaintenance->start_date == '0000-00-00') { - $assetMaintenance->start_date = null; - } - - if ($assetMaintenance->cost == '0.00') { - $assetMaintenance->cost = null; - } // Prepare Improvement Type List $assetMaintenanceType = [ From abc9ee22c623d329b0ad3eb9c80ae4b5d67e2478 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:48:02 +0000 Subject: [PATCH 04/13] Added serial and status to transformer Signed-off-by: snipe --- app/Http/Transformers/AssetMaintenancesTransformer.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php index 01ef2adb87fc..114a2cc44d8a 100644 --- a/app/Http/Transformers/AssetMaintenancesTransformer.php +++ b/app/Http/Transformers/AssetMaintenancesTransformer.php @@ -28,12 +28,20 @@ public function transformAssetMaintenance(AssetMaintenance $assetmaintenance) 'id' => (int) $assetmaintenance->asset->id, 'name'=> ($assetmaintenance->asset->name) ? e($assetmaintenance->asset->name) : null, 'asset_tag'=> e($assetmaintenance->asset->asset_tag), - + 'serial'=> e($assetmaintenance->asset->serial), + 'deleted_at'=> e($assetmaintenance->asset->deleted_at), + 'created_at'=> e($assetmaintenance->asset->created_at), ] : null, 'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [ 'id' => (int) $assetmaintenance->asset->model->id, 'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null, ] : null, + 'status_label' => ($assetmaintenance->asset->assetstatus) ? [ + 'id' => (int) $assetmaintenance->asset->assetstatus->id, + 'name'=> e($assetmaintenance->asset->assetstatus->name), + 'status_type'=> e($assetmaintenance->asset->assetstatus->getStatuslabelType()), + 'status_meta' => e($assetmaintenance->asset->present()->statusMeta), + ] : null, 'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [ 'id' => (int) $assetmaintenance->asset->company->id, 'name'=> ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null, From adb8be9345cd0e82e2f9c9e16167f9a54b7e80bc Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:57:57 +0000 Subject: [PATCH 05/13] Added bootstrap formatting to show deleted assets more clearly Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 992162e3dc2e..bff3d6576a6a 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -623,6 +623,9 @@ function groupsAdminLinkFormatter(value, row) { function assetTagLinkFormatter(value, row) { if ((row.asset) && (row.asset.id)) { + if (row.asset.deleted_at!='') { + return 'deleted ' + row.asset.asset_tag + ''; + } return '' + row.asset.asset_tag + ''; } return ''; @@ -640,7 +643,17 @@ function assetNameLinkFormatter(value, row) { if ((row.asset) && (row.asset.name)) { return '' + row.asset.name + ''; } + } + + function assetSerialLinkFormatter(value, row) { + if ((row.asset) && (row.asset.serial)) { + if (row.asset.deleted_at!='') { + return 'deleted ' + row.asset.serial + ''; + } + return '' + row.asset.serial + ''; + } + return ''; } function trueFalseFormatter(value) { From 56ba26eb455ce17fef02cb9a7f22963db0568ede Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:58:07 +0000 Subject: [PATCH 06/13] Disallow editing of deleted assets Signed-off-by: snipe --- resources/views/hardware/view.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index d856427bd372..2c7ddcf535ab 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -872,11 +872,13 @@ @can('update', $asset) + @if ($asset->deleted_at=='') + @endif @endcan @can('create', $asset) From 35a70988cbc0bfa97524f97e2a15f950cea3bb88 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:58:39 +0000 Subject: [PATCH 07/13] Added sorting by status label Signed-off-by: snipe --- app/Http/Controllers/Api/AssetMaintenancesController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index b39d9d992698..a26935cc594d 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -37,7 +37,7 @@ public function index(Request $request) $this->authorize('view', Asset::class); $maintenances = AssetMaintenance::select('asset_maintenances.*') - ->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'admin'); + ->with('asset', 'asset.model', 'asset.location', 'asset.defaultLoc', 'supplier', 'asset.company', 'asset.assetstatus', 'admin'); if ($request->filled('search')) { $maintenances = $maintenances->TextSearch($request->input('search')); @@ -75,7 +75,9 @@ public function index(Request $request) 'user_id', 'supplier', 'is_warranty', + 'status_label', ]; + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; @@ -93,9 +95,11 @@ public function index(Request $request) $maintenances = $maintenances->OrderByAssetName($order); break; case 'serial': - \Log::debug('sort by serial'); $maintenances = $maintenances->OrderByAssetSerial($order); break; + case 'status_label': + $maintenances = $maintenances->OrderStatusName($order); + break; default: $maintenances = $maintenances->orderBy($sort, $order); break; From b86b05c4fc62a4bf409ddb170e2f00a89e7ed503 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:58:55 +0000 Subject: [PATCH 08/13] Added serial and status fields to presenter Signed-off-by: snipe --- app/Presenters/AssetMaintenancesPresenter.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/Presenters/AssetMaintenancesPresenter.php b/app/Presenters/AssetMaintenancesPresenter.php index c4446c0b2aae..5f9694b44ca8 100644 --- a/app/Presenters/AssetMaintenancesPresenter.php +++ b/app/Presenters/AssetMaintenancesPresenter.php @@ -41,6 +41,19 @@ public static function dataTableLayout() 'sortable' => true, 'title' => trans('admin/hardware/table.asset_tag'), 'formatter' => 'assetTagLinkFormatter', + ], [ + 'field' => 'serial', + 'searchable' => true, + 'sortable' => true, + 'title' => trans('admin/hardware/table.serial'), + 'formatter' => 'assetSerialLinkFormatter', + ], [ + 'field' => 'status_label', + 'searchable' => true, + 'sortable' => true, + 'title' => trans('admin/hardware/table.status'), + 'visible' => true, + 'formatter' => 'statuslabelsLinkObjFormatter', ], [ 'field' => 'model', 'searchable' => true, From 71ebade641c2d6a118d0db4929430ff52e465e3d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 09:59:10 +0000 Subject: [PATCH 09/13] Added serial and status to searchable relations Signed-off-by: snipe --- app/Models/AssetMaintenance.php | 43 +++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 760abf1519cf..5f66783cbbe9 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -62,7 +62,15 @@ class AssetMaintenance extends Model implements ICompanyableChild * * @var array */ - protected $searchableAttributes = ['title', 'notes', 'asset_maintenance_type', 'cost', 'start_date', 'completion_date']; + protected $searchableAttributes = + [ + 'title', + 'notes', + 'asset_maintenance_type', + 'cost', + 'start_date', + 'completion_date' + ]; /** * The relations and their attributes that should be included when searching the model. @@ -70,9 +78,10 @@ class AssetMaintenance extends Model implements ICompanyableChild * @var array */ protected $searchableRelations = [ - 'asset' => ['name', 'asset_tag'], + 'asset' => ['name', 'asset_tag', 'serial'], 'asset.model' => ['name', 'model_number'], 'asset.supplier' => ['name'], + 'asset.assetstatus' => ['name'], 'supplier' => ['name'], ]; @@ -197,6 +206,7 @@ public function scopeOrderBySupplier($query, $order) ->orderBy('suppliers_maintenances.name', $order); } + /** * Query builder scope to order on admin user * @@ -239,4 +249,33 @@ public function scopeOrderByAssetName($query, $order) return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id') ->orderBy('assets.name', $order); } + + /** + * Query builder scope to order on serial + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param string $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderByAssetSerial($query, $order) + { + return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id') + ->orderBy('assets.serial', $order); + } + + /** + * Query builder scope to order on status label name + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderStatusName($query, $order) + { + return $query->join('assets as maintained_asset', 'asset_maintenances.asset_id', '=', 'maintained_asset.id') + ->leftjoin('status_labels as maintained_asset_status', 'maintained_asset_status.id', '=', 'maintained_asset.status_id') + ->orderBy('maintained_asset_status.name', $order); + } } From 1dfa1da0ee737db4a5715477c4ca57b7dd6adab9 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 10:14:10 +0000 Subject: [PATCH 10/13] Disable the edit button if permission is not allowed Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index bff3d6576a6a..53fc5df2c8c4 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -296,6 +296,10 @@ function genericActionsFormatter(owner_name, element_name) { if ((row.available_actions) && (row.available_actions.update === true)) { actions += '{{ trans('general.update') }} '; + } else { + if ((row.available_actions) && (row.available_actions.update != true)) { + actions += ' '; + } } if ((row.available_actions) && (row.available_actions.delete === true)) { From 8a4c90ade8ad783233d3700a8655128e81a4063e Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 10:14:25 +0000 Subject: [PATCH 11/13] Check that the asset is not deleted Signed-off-by: snipe --- .../AssetMaintenancesController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index cb6ecf617746..b5a50925ea32 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -148,15 +148,16 @@ public function store(Request $request) */ public function edit($assetMaintenanceId = null) { + $this->authorize('update', Asset::class); + // Check if the asset maintenance exists $this->authorize('update', Asset::class); // Check if the asset maintenance exists if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) { - // Redirect to the improvement management page - return redirect()->route('maintenances.index') - ->with('error', trans('admin/asset_maintenances/message.not_found')); - } elseif (! $assetMaintenance->asset) { - return redirect()->route('maintenances.index') - ->with('error', 'The asset associated with this maintenance does not exist.'); + // Redirect to the asset maintenance management page + return redirect()->route('maintenances.index')->with('error', trans('admin/asset_maintenances/message.not_found')); + } elseif ((!$assetMaintenance->asset) || ($assetMaintenance->asset->deleted_at!='')) { + // Redirect to the asset maintenance management page + return redirect()->route('maintenances.index')->with('error', 'asset does not exist'); } elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) { return static::getInsufficientPermissionsRedirect(); } @@ -192,8 +193,10 @@ public function update(Request $request, $assetMaintenanceId = null) // Check if the asset maintenance exists if (is_null($assetMaintenance = AssetMaintenance::find($assetMaintenanceId))) { // Redirect to the asset maintenance management page - return redirect()->route('maintenances.index') - ->with('error', trans('admin/asset_maintenances/message.not_found')); + return redirect()->route('maintenances.index')->with('error', trans('admin/asset_maintenances/message.not_found')); + } elseif ((!$assetMaintenance->asset) || ($assetMaintenance->asset->deleted_at!='')) { + // Redirect to the asset maintenance management page + return redirect()->route('maintenances.index')->with('error', 'asset does not exist'); } elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) { return static::getInsufficientPermissionsRedirect(); } From 638071dadda76bf481e90037e798a5cee435c13d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 10:14:38 +0000 Subject: [PATCH 12/13] Check the asset is not deleted when creating the permissions array Signed-off-by: snipe --- app/Http/Transformers/AssetMaintenancesTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php index 114a2cc44d8a..88ac447c25bb 100644 --- a/app/Http/Transformers/AssetMaintenancesTransformer.php +++ b/app/Http/Transformers/AssetMaintenancesTransformer.php @@ -72,7 +72,7 @@ public function transformAssetMaintenance(AssetMaintenance $assetmaintenance) ]; $permissions_array['available_actions'] = [ - 'update' => Gate::allows('update', Asset::class), + 'update' => (Gate::allows('update', Asset::class) && ($assetmaintenance->asset->deleted_at=='')) ? true : false, 'delete' => Gate::allows('delete', Asset::class), ]; From 43bb8ae0a8d920cae15a96dbfc40b5121461cbfc Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 14 Feb 2024 10:14:44 +0000 Subject: [PATCH 13/13] Added string Signed-off-by: snipe --- resources/lang/en-US/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 0db52859ff11..fe3ada1a2906 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -459,6 +459,7 @@ 'no_autoassign_licenses_help' => 'Do not include user for bulk-assigning through the license UI or cli tools.', 'modal_confirm_generic' => 'Are you sure?', 'cannot_be_deleted' => 'This item cannot be deleted', + 'cannot_be_edited' => 'This item cannot be edited.', 'undeployable_tooltip' => 'This item cannot be checked out. Check the quantity remaining.', 'serial_number' => 'Serial Number', 'item_notes' => ':item Notes',