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;
|
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'),
|
2021-08-10 18:26:43 -07:00
|
|
|
'depreciation_min' => $depreciation->depreciation_min,
|
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
|
|
|
}
|