2017-01-24 18:57:33 -08:00
|
|
|
<?php
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-01-24 18:57:33 -08:00
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-01-24 18:57:33 -08:00
|
|
|
use App\Models\License;
|
2017-02-08 18:24:55 -08:00
|
|
|
use Gate;
|
2017-01-24 18:57:33 -08:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class LicensesTransformer
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformLicenses(Collection $licenses, $total)
|
2017-01-24 18:57:33 -08:00
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$array = [];
|
2017-01-24 18:57:33 -08:00
|
|
|
foreach ($licenses as $license) {
|
|
|
|
$array[] = self::transformLicense($license);
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-01-24 18:57:33 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformLicense(License $license)
|
2017-01-24 18:57:33 -08:00
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $license->id,
|
2017-01-24 19:24:47 -08:00
|
|
|
'name' => e($license->name),
|
2021-06-10 13:15:52 -07:00
|
|
|
'company' => ($license->company) ? ['id' => (int) $license->company->id, 'name'=> e($license->company->name)] : null,
|
|
|
|
'manufacturer' => ($license->manufacturer) ? ['id' => (int) $license->manufacturer->id, 'name'=> e($license->manufacturer->name)] : null,
|
2017-12-05 16:26:23 -08:00
|
|
|
'product_key' => (Gate::allows('viewKeys', License::class)) ? e($license->serial) : '------------',
|
2017-02-10 18:43:30 -08:00
|
|
|
'order_number' => e($license->order_number),
|
|
|
|
'purchase_order' => e($license->purchase_order),
|
2017-03-03 17:53:42 -08:00
|
|
|
'purchase_date' => Helper::getFormattedDateObject($license->purchase_date, 'date'),
|
2021-01-27 01:34:32 -08:00
|
|
|
'termination_date' => Helper::getFormattedDateObject($license->termination_date, 'date'),
|
|
|
|
'depreciation' => ($license->depreciation) ? ['id' => (int) $license->depreciation->id,'name'=> e($license->depreciation->name)] : null,
|
2021-09-28 19:10:25 -07:00
|
|
|
'purchase_cost' => Helper::formatCurrencyOutput($license->purchase_cost),
|
|
|
|
'purchase_cost_numeric' => $license->purchase_cost,
|
2017-01-24 19:24:47 -08:00
|
|
|
'notes' => e($license->notes),
|
2017-03-03 17:53:42 -08:00
|
|
|
'expiration_date' => Helper::getFormattedDateObject($license->expiration_date, 'date'),
|
2017-11-02 19:37:30 -07:00
|
|
|
'seats' => (int) $license->seats,
|
2017-11-02 20:23:04 -07:00
|
|
|
'free_seats_count' => (int) $license->free_seats_count,
|
2017-03-11 02:52:50 -08:00
|
|
|
'license_name' => e($license->license_name),
|
2017-01-24 19:24:47 -08:00
|
|
|
'license_email' => e($license->license_email),
|
2020-09-04 10:02:04 -07:00
|
|
|
'reassignable' => ($license->reassignable == 1) ? true : false,
|
2017-01-24 19:24:47 -08:00
|
|
|
'maintained' => ($license->maintained == 1) ? true : false,
|
2021-06-10 13:15:52 -07:00
|
|
|
'supplier' => ($license->supplier) ? ['id' => (int) $license->supplier->id, 'name'=> e($license->supplier->name)] : null,
|
|
|
|
'category' => ($license->category) ? ['id' => (int) $license->category->id, 'name'=> e($license->category->name)] : null,
|
2017-03-03 17:53:42 -08:00
|
|
|
'created_at' => Helper::getFormattedDateObject($license->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($license->updated_at, 'datetime'),
|
2022-02-16 09:33:28 -08:00
|
|
|
'deleted_at' => Helper::getFormattedDateObject($license->deleted_at, 'datetime'),
|
2017-11-02 19:16:09 -07:00
|
|
|
'user_can_checkout' => (bool) ($license->free_seats_count > 0),
|
2022-02-16 09:33:28 -08:00
|
|
|
|
2017-01-24 18:57:33 -08:00
|
|
|
];
|
|
|
|
|
2017-02-08 18:24:55 -08:00
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'checkout' => Gate::allows('checkout', License::class),
|
|
|
|
'checkin' => Gate::allows('checkin', License::class),
|
|
|
|
'clone' => Gate::allows('create', License::class),
|
|
|
|
'update' => Gate::allows('update', License::class),
|
|
|
|
'delete' => Gate::allows('delete', License::class),
|
2017-02-08 18:24:55 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
2017-01-24 18:57:33 -08:00
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
public function transformAssetsDatatable($licenses)
|
|
|
|
{
|
2017-01-24 18:57:33 -08:00
|
|
|
return (new DatatablesTransformer)->transformDatatables($licenses);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|