mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
f9e190eb32
Signed-off-by: snipe <snipe@snipe.net>
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Depreciable;
|
|
use App\Models\Depreciation;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class DepreciationsTransformer
|
|
{
|
|
public function transformDepreciations(Collection $depreciations, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($depreciations as $depreciation) {
|
|
$array[] = self::transformDepreciation($depreciation);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformDepreciation(Depreciation $depreciation)
|
|
{
|
|
$array = [
|
|
'id' => (int) $depreciation->id,
|
|
'name' => e($depreciation->name),
|
|
'months' => $depreciation->months.' '.trans('general.months'),
|
|
'depreciation_min' => $depreciation->depreciation_min,
|
|
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime')
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'update' => Gate::allows('update', Depreciation::class),
|
|
'delete' => Gate::allows('delete', Depreciation::class),
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
} |