mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-14 01:24:06 -08:00
c3d55ee27e
Signed-off-by: snipe <snipe@snipe.net> # Conflicts: # .all-contributorsrc # README.md # app/Exceptions/Handler.php # app/Http/Controllers/Api/AssetsController.php # app/Http/Controllers/Api/SettingsController.php # app/Http/Controllers/CustomFieldsController.php # app/Http/Controllers/SettingsController.php # app/Http/Transformers/AssetsTransformer.php # app/Models/Setting.php # config/version.php # resources/lang/af/button.php # resources/lang/ar/button.php # resources/lang/bg/button.php # resources/lang/cs/button.php # resources/lang/cy/button.php # resources/lang/da/button.php # resources/lang/de/button.php # resources/lang/el/button.php # resources/lang/en-GB/button.php # resources/lang/en-ID/button.php # resources/lang/es-CO/admin/groups/message.php # resources/lang/es-MX/button.php # resources/lang/et/admin/custom_fields/general.php # resources/lang/et/admin/hardware/table.php # resources/lang/et/admin/kits/general.php # resources/lang/et/admin/manufacturers/message.php # resources/lang/et/admin/models/general.php # resources/lang/et/admin/settings/general.php # resources/lang/et/button.php # resources/lang/et/mail.php # resources/lang/fa/button.php # resources/lang/fa/help.php # resources/lang/fi/button.php # resources/lang/fil/button.php # resources/lang/fr/button.php # resources/lang/ga-IE/button.php # resources/lang/he/button.php # resources/lang/hr/button.php # resources/lang/hu/admin/settings/general.php # resources/lang/hu/auth/message.php # resources/lang/hu/button.php # resources/lang/hu/mail.php # resources/lang/id/admin/hardware/table.php # resources/lang/id/button.php # resources/lang/it/button.php # resources/lang/iu/button.php # resources/lang/ja/button.php # resources/lang/ko/button.php # resources/lang/lt/button.php # resources/lang/lv/button.php # resources/lang/mi/button.php # resources/lang/mk/button.php # resources/lang/ml-IN/button.php # resources/lang/mn/button.php # resources/lang/ms/admin/hardware/table.php # resources/lang/ms/admin/kits/general.php # resources/lang/ms/admin/models/general.php # resources/lang/ms/admin/models/message.php # resources/lang/ms/admin/settings/general.php # resources/lang/ms/button.php # resources/lang/nl/button.php # resources/lang/no/admin/hardware/table.php # resources/lang/no/admin/kits/general.php # resources/lang/no/admin/settings/general.php # resources/lang/no/auth/message.php # resources/lang/no/button.php # resources/lang/no/help.php # resources/lang/no/mail.php # resources/lang/pl/button.php # resources/lang/pt-BR/button.php # resources/lang/pt-PT/auth/message.php # resources/lang/pt-PT/button.php # resources/lang/pt-PT/mail.php # resources/lang/ro/button.php # resources/lang/ru/admin/settings/general.php # resources/lang/ru/button.php # resources/lang/ru/help.php # resources/lang/sl/admin/custom_fields/general.php # resources/lang/sl/admin/hardware/table.php # resources/lang/sl/admin/kits/general.php # resources/lang/sl/admin/manufacturers/message.php # resources/lang/sl/admin/models/general.php # resources/lang/sl/admin/settings/general.php # resources/lang/sl/admin/users/general.php # resources/lang/sl/auth/message.php # resources/lang/sl/button.php # resources/lang/sl/help.php # resources/lang/sr-CS/button.php # resources/lang/ta/button.php # resources/lang/th/button.php # resources/lang/th/mail.php # resources/lang/tl/button.php # resources/lang/tr/admin/settings/general.php # resources/lang/tr/auth/message.php # resources/lang/tr/button.php # resources/lang/uk/button.php # resources/lang/ur-PK/button.php # resources/lang/vi/button.php # resources/lang/zh-CN/button.php # resources/lang/zh-HK/button.php # resources/lang/zh-TW/admin/hardware/table.php # resources/lang/zh-TW/button.php # resources/lang/zu/button.php # resources/views/models/custom_fields_form.blade.php # resources/views/reports/custom.blade.php # resources/views/settings/slack.blade.php
92 lines
3.9 KiB
PHP
92 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
use App\Helpers\Helper;
|
|
use App\Models\Accessory;
|
|
use Gate;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class AccessoriesTransformer
|
|
{
|
|
public function transformAccessories(Collection $accessories, $total)
|
|
{
|
|
$array = [];
|
|
foreach ($accessories as $accessory) {
|
|
$array[] = self::transformAccessory($accessory);
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
|
|
public function transformAccessory(Accessory $accessory)
|
|
{
|
|
$array = [
|
|
'id' => $accessory->id,
|
|
'name' => e($accessory->name),
|
|
'image' => ($accessory->image) ? Storage::disk('public')->url('accessories/'.e($accessory->image)) : null,
|
|
'company' => ($accessory->company) ? ['id' => $accessory->company->id, 'name'=> e($accessory->company->name)] : null,
|
|
'manufacturer' => ($accessory->manufacturer) ? ['id' => $accessory->manufacturer->id, 'name'=> e($accessory->manufacturer->name)] : null,
|
|
'supplier' => ($accessory->supplier) ? ['id' => $accessory->supplier->id, 'name'=> e($accessory->supplier->name)] : null,
|
|
'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null,
|
|
'category' => ($accessory->category) ? ['id' => $accessory->category->id, 'name'=> e($accessory->category->name)] : null,
|
|
'location' => ($accessory->location) ? ['id' => $accessory->location->id, 'name'=> e($accessory->location->name)] : null,
|
|
'notes' => ($accessory->notes) ? e($accessory->notes) : null,
|
|
'qty' => ($accessory->qty) ? (int) $accessory->qty : null,
|
|
'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null,
|
|
'purchase_cost' => Helper::formatCurrencyOutput($accessory->purchase_cost),
|
|
'order_number' => ($accessory->order_number) ? e($accessory->order_number) : null,
|
|
'min_qty' => ($accessory->min_amt) ? (int) $accessory->min_amt : null,
|
|
'remaining_qty' => $accessory->numRemaining(),
|
|
|
|
'created_at' => Helper::getFormattedDateObject($accessory->created_at, 'datetime'),
|
|
'updated_at' => Helper::getFormattedDateObject($accessory->updated_at, 'datetime'),
|
|
|
|
];
|
|
|
|
$permissions_array['available_actions'] = [
|
|
'checkout' => Gate::allows('checkout', Accessory::class),
|
|
'checkin' => false,
|
|
'update' => Gate::allows('update', Accessory::class),
|
|
'delete' => Gate::allows('delete', Accessory::class),
|
|
];
|
|
|
|
$permissions_array['user_can_checkout'] = false;
|
|
|
|
if ($accessory->numRemaining() > 0) {
|
|
$permissions_array['user_can_checkout'] = true;
|
|
}
|
|
|
|
$array += $permissions_array;
|
|
|
|
return $array;
|
|
}
|
|
|
|
public function transformCheckedoutAccessory($accessory, $accessory_users, $total)
|
|
{
|
|
$array = [];
|
|
|
|
foreach ($accessory_users as $user) {
|
|
\Log::debug(print_r($user->pivot, true));
|
|
\Log::debug(print_r($user->pivot, true));
|
|
$array[] = [
|
|
|
|
'assigned_pivot_id' => $user->pivot->id,
|
|
'id' => (int) $user->id,
|
|
'username' => e($user->username),
|
|
'name' => e($user->getFullNameAttribute()),
|
|
'first_name'=> e($user->first_name),
|
|
'last_name'=> e($user->last_name),
|
|
'employee_number' => e($user->employee_num),
|
|
'checkout_notes' => e($user->pivot->note),
|
|
'last_checkout' => Helper::getFormattedDateObject($user->pivot->created_at, 'datetime'),
|
|
'type' => 'user',
|
|
'available_actions' => ['checkin' => true],
|
|
];
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
}
|
|
}
|