2017-03-11 08:03:16 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-03-11 08:03:16 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2022-09-14 17:01:18 -07:00
|
|
|
use App\Models\Depreciable;
|
2017-03-11 08:03:16 -08:00
|
|
|
use App\Models\Depreciation;
|
2023-03-18 11:58:09 -07:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2024-07-16 12:58:23 -07:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2017-03-11 08:03:16 -08:00
|
|
|
|
|
|
|
class DepreciationsTransformer
|
|
|
|
{
|
2022-06-15 19:52:15 -07:00
|
|
|
public function transformDepreciations(Collection $depreciations, $total)
|
2017-03-11 08:03:16 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-03-11 08:03:16 -08:00
|
|
|
foreach ($depreciations as $depreciation) {
|
|
|
|
$array[] = self::transformDepreciation($depreciation);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2022-06-15 19:52:15 -07:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
2017-03-11 08:03:16 -08:00
|
|
|
}
|
|
|
|
|
2022-09-29 17:07:42 -07:00
|
|
|
public function transformDepreciation(Depreciation $depreciation)
|
2017-03-11 08:03:16 -08:00
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $depreciation->id,
|
2017-03-11 08:03:16 -08:00
|
|
|
'name' => e($depreciation->name),
|
2021-06-10 13:15:52 -07:00
|
|
|
'months' => $depreciation->months.' '.trans('general.months'),
|
2024-07-16 12:58:23 -07:00
|
|
|
'depreciation_min' => $depreciation->depreciation_type === 'percent' ? $depreciation->depreciation_min.'%' : $depreciation->depreciation_min,
|
2024-08-28 04:39:43 -07:00
|
|
|
'assets_count' => $depreciation->assets_count,
|
|
|
|
'models_count' => $depreciation->models_count,
|
|
|
|
'licenses_count' => $depreciation->licenses_count,
|
2024-09-19 09:41:05 -07:00
|
|
|
'created_by' => ($depreciation->adminuser) ? [
|
|
|
|
'id' => (int) $depreciation->adminuser->id,
|
|
|
|
'name'=> e($depreciation->adminuser->present()->fullName()),
|
|
|
|
] : null,
|
2017-03-11 08:03:16 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
2022-06-15 19:52:15 -07:00
|
|
|
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
|
2017-03-11 08:03:16 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'update' => Gate::allows('update', Depreciation::class),
|
|
|
|
'delete' => Gate::allows('delete', Depreciation::class),
|
2017-03-11 08:03:16 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
2022-06-15 19:52:15 -07:00
|
|
|
}
|