diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php
index 32271fcdd8..6e0100065a 100644
--- a/app/Http/Controllers/AssetMaintenancesController.php
+++ b/app/Http/Controllers/AssetMaintenancesController.php
@@ -162,6 +162,10 @@ class AssetMaintenancesController extends Controller
// 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.');
+
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
return static::getInsufficientPermissionsRedirect();
}
diff --git a/app/Http/Transformers/AssetMaintenancesTransformer.php b/app/Http/Transformers/AssetMaintenancesTransformer.php
index f3c4d35453..fc11d7a534 100644
--- a/app/Http/Transformers/AssetMaintenancesTransformer.php
+++ b/app/Http/Transformers/AssetMaintenancesTransformer.php
@@ -28,10 +28,15 @@ class AssetMaintenancesTransformer
'asset_tag'=> e($assetmaintenance->asset->asset_tag)
] : null,
- 'model' => ($assetmaintenance->asset->model) ? [
+ '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,
+ 'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [
+ 'id' => (int) $assetmaintenance->asset->company->id,
+ 'name'=> ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null,
+
+ ] : null,
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
'id' => (int) $assetmaintenance->asset->location->id,
diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php
index 9956140fe8..20345aeb47 100644
--- a/resources/views/partials/bootstrap-table.blade.php
+++ b/resources/views/partials/bootstrap-table.blade.php
@@ -423,7 +423,10 @@
}
function assetTagLinkFormatter(value, row) {
- return ' ' + row.asset.asset_tag + '';
+ if ((row.asset) && (row.asset.id)) {
+ return ' ' + row.asset.asset_tag + '';
+ }
+ return '';
}
function assetNameLinkFormatter(value, row) {