2017-01-26 19:16:06 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Component;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use App\Helpers\Helper;
|
2017-02-08 18:24:55 -08:00
|
|
|
use Gate;
|
2017-01-26 19:16:06 -08:00
|
|
|
|
|
|
|
class ComponentsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformComponents (Collection $components, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($components as $component) {
|
|
|
|
$array[] = self::transformComponent($component);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformComponent (Component $component)
|
|
|
|
{
|
2017-02-08 18:24:55 -08:00
|
|
|
$array = [
|
2017-01-26 19:16:06 -08:00
|
|
|
|
|
|
|
'id' => $component->id,
|
|
|
|
'name' => e($component->name),
|
|
|
|
'serial_number' => e($component->serial),
|
|
|
|
'location' => ($component->location) ?
|
|
|
|
[
|
|
|
|
'id' => $component->location->id,
|
|
|
|
'name' => $component->location->name
|
|
|
|
] : null,
|
|
|
|
'qty' => number_format($component->qty),
|
|
|
|
'min_amt' => e($component->min_amt),
|
|
|
|
'category' => ($component->category) ?
|
|
|
|
[
|
|
|
|
'id' => $component->category->id,
|
|
|
|
'name' => e($component->category->name)
|
|
|
|
] : null,
|
|
|
|
'order_number' => e($component->order_number),
|
|
|
|
'purchase_date' => $component->purchase_date,
|
|
|
|
'purchase_cost' => Helper::formatCurrencyOutput($component->purchase_cost),
|
|
|
|
'remaining' => $component->numRemaining(),
|
|
|
|
'company' => ($component->company) ?
|
|
|
|
[
|
|
|
|
'id' => $component->company->id,
|
|
|
|
'name' => e($component->company->name)
|
|
|
|
] : null,
|
|
|
|
|
|
|
|
];
|
2017-02-08 18:24:55 -08:00
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
|
|
|
'checkout' => Gate::allows('checkout', Component::class) ? true : false,
|
|
|
|
'checkin' => Gate::allows('checkin', Component::class) ? true : false,
|
|
|
|
'update' => Gate::allows('update', Component::class) ? true : false,
|
|
|
|
'delete' => Gate::allows('delete', Component::class) ? true : false,
|
|
|
|
];
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
2017-01-26 19:16:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function transformCheckedoutComponents (Collection $components_users, $total)
|
|
|
|
{
|
|
|
|
|
|
|
|
$array = array();
|
|
|
|
foreach ($components_users as $user) {
|
|
|
|
$array[] = (new UsersTransformer)->transformUser($user);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|