2017-08-22 13:52:06 -07:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-08-22 13:52:06 -07:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2021-06-10 13:15:52 -07:00
|
|
|
use App\Models\Asset;
|
2017-08-22 13:52:06 -07:00
|
|
|
use App\Models\AssetMaintenance;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2017-08-22 13:52:06 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class AssetMaintenancesTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformAssetMaintenances(Collection $assetmaintenances, $total)
|
2017-08-22 13:52:06 -07:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-08-22 13:52:06 -07:00
|
|
|
foreach ($assetmaintenances as $assetmaintenance) {
|
|
|
|
$array[] = self::transformAssetMaintenance($assetmaintenance);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-08-22 13:52:06 -07:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformAssetMaintenance(AssetMaintenance $assetmaintenance)
|
2017-08-22 13:52:06 -07:00
|
|
|
{
|
|
|
|
$array = [
|
|
|
|
'id' => (int) $assetmaintenance->id,
|
2018-03-05 16:26:40 -08:00
|
|
|
'asset' => ($assetmaintenance->asset) ? [
|
|
|
|
'id' => (int) $assetmaintenance->asset->id,
|
|
|
|
'name'=> ($assetmaintenance->asset->name) ? e($assetmaintenance->asset->name) : null,
|
2021-06-10 13:15:52 -07:00
|
|
|
'asset_tag'=> e($assetmaintenance->asset->asset_tag),
|
2024-02-14 01:48:02 -08:00
|
|
|
'serial'=> e($assetmaintenance->asset->serial),
|
|
|
|
'deleted_at'=> e($assetmaintenance->asset->deleted_at),
|
|
|
|
'created_at'=> e($assetmaintenance->asset->created_at),
|
2021-06-10 13:15:52 -07:00
|
|
|
] : null,
|
2019-01-16 02:26:42 -08:00
|
|
|
'model' => (($assetmaintenance->asset) && ($assetmaintenance->asset->model)) ? [
|
2018-08-01 18:24:52 -07:00
|
|
|
'id' => (int) $assetmaintenance->asset->model->id,
|
2021-06-10 13:15:52 -07:00
|
|
|
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null,
|
|
|
|
] : null,
|
2024-02-14 01:48:02 -08:00
|
|
|
'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,
|
2019-01-16 01:45:51 -08:00
|
|
|
'company' => (($assetmaintenance->asset) && ($assetmaintenance->asset->company)) ? [
|
2018-10-30 00:20:16 -07:00
|
|
|
'id' => (int) $assetmaintenance->asset->company->id,
|
|
|
|
'name'=> ($assetmaintenance->asset->company->name) ? e($assetmaintenance->asset->company->name) : null,
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
] : null,
|
2017-08-22 13:52:06 -07:00
|
|
|
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
|
2018-03-07 22:22:36 -08:00
|
|
|
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
|
2018-03-05 16:26:40 -08:00
|
|
|
'id' => (int) $assetmaintenance->asset->location->id,
|
|
|
|
'name'=> e($assetmaintenance->asset->location->name),
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
] : null,
|
2024-01-08 04:42:05 -08:00
|
|
|
'rtd_location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->defaultLoc)) ? [
|
2023-03-21 13:52:21 -07:00
|
|
|
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
|
|
|
|
'name'=> e($assetmaintenance->asset->defaultLoc->name),
|
|
|
|
] : null,
|
2023-07-11 03:41:58 -07:00
|
|
|
'notes' => ($assetmaintenance->notes) ? Helper::parseEscapedMarkedownInline($assetmaintenance->notes) : null,
|
2021-06-10 13:15:52 -07:00
|
|
|
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id, 'name'=> e($assetmaintenance->supplier->name)] : null,
|
2017-08-22 13:52:06 -07:00
|
|
|
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),
|
|
|
|
'asset_maintenance_type' => e($assetmaintenance->asset_maintenance_type),
|
2018-07-18 02:24:53 -07:00
|
|
|
'start_date' => Helper::getFormattedDateObject($assetmaintenance->start_date, 'date'),
|
2017-08-22 13:52:06 -07:00
|
|
|
'asset_maintenance_time' => $assetmaintenance->asset_maintenance_time,
|
2018-07-18 02:24:53 -07:00
|
|
|
'completion_date' => Helper::getFormattedDateObject($assetmaintenance->completion_date, 'date'),
|
2024-09-19 09:31:46 -07:00
|
|
|
'user_id' => ($assetmaintenance->adminuser) ? [
|
|
|
|
'id' => $assetmaintenance->adminuser->id,
|
2024-10-11 03:16:24 -07:00
|
|
|
'name'=> e($assetmaintenance->adminuser->present()->fullName())
|
2024-09-19 09:31:46 -07:00
|
|
|
] : null, // legacy to not change the shape of the API
|
2024-09-19 09:01:48 -07:00
|
|
|
'created_by' => ($assetmaintenance->adminuser) ? [
|
|
|
|
'id' => (int) $assetmaintenance->adminuser->id,
|
|
|
|
'name'=> e($assetmaintenance->adminuser->present()->fullName()),
|
|
|
|
] : null,
|
2017-08-22 13:52:06 -07:00
|
|
|
'created_at' => Helper::getFormattedDateObject($assetmaintenance->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($assetmaintenance->updated_at, 'datetime'),
|
2023-06-13 09:10:42 -07:00
|
|
|
'is_warranty'=> $assetmaintenance->is_warranty,
|
2017-08-22 13:52:06 -07:00
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2024-02-14 02:14:38 -08:00
|
|
|
'update' => (Gate::allows('update', Asset::class) && ($assetmaintenance->asset->deleted_at=='')) ? true : false,
|
2020-05-23 10:36:02 -07:00
|
|
|
'delete' => Gate::allows('delete', Asset::class),
|
2017-08-22 13:52:06 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|