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),
|
2018-03-05 16:26:40 -08:00
|
|
|
|
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,
|
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,
|
2023-03-21 13:52:21 -07:00
|
|
|
'rtd_location' => ($assetmaintenance->asset->defaultLoc) ? [
|
|
|
|
'id' => (int) $assetmaintenance->asset->defaultLoc->id,
|
|
|
|
'name'=> e($assetmaintenance->asset->defaultLoc->name),
|
|
|
|
] : null,
|
2017-08-22 13:52:06 -07:00
|
|
|
'notes' => ($assetmaintenance->notes) ? e($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'),
|
2021-06-10 13:15:52 -07:00
|
|
|
'user_id' => ($assetmaintenance->admin) ? ['id' => $assetmaintenance->admin->id, 'name'=> e($assetmaintenance->admin->getFullNameAttribute())] : 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-12 11:03:32 -07:00
|
|
|
'is_warranty'=> ($assetmaintenance->is_warranty) ? trans('general.yes') : trans('general.no'),
|
2017-08-22 13:52:06 -07:00
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'update' => Gate::allows('update', Asset::class),
|
|
|
|
'delete' => Gate::allows('delete', Asset::class),
|
2017-08-22 13:52:06 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|