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;
|
2017-03-11 08:03:16 -08:00
|
|
|
use App\Models\Depreciation;
|
|
|
|
use Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-03-11 08:03:16 -08:00
|
|
|
|
|
|
|
class DepreciationsTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformDepreciations(Collection $depreciations)
|
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
|
|
|
|
2017-03-11 08:03:16 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -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'),
|
2017-03-11 08:03:16 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|