mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-21 21:44:01 +00:00
48 lines
1.9 KiB
PHP
48 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Order;
|
|
use App\Models\PackingList;
|
|
use App\Classes\ValueObjects\Constants\RoleTypes;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class PackageReceivedResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$userType = Auth() && Auth()->user() ? Auth()->user()->type : RoleTypes::USER;
|
|
$exceptionUsers = in_array($userType, [RoleTypes::SHADOW_ADMIN, RoleTypes::SUPER_ADMIN]);
|
|
$originalPackingList = $this->packingList->owner instanceof PackingList ? $this->packingList->owner : $this->packingList;
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
'description' => $this->description,
|
|
'width' => floatval($this->width),
|
|
'height' => floatval($this->height),
|
|
'length' => floatval($this->length),
|
|
'weight' => $this->weight,
|
|
'quantity' => $this->quantity,
|
|
'cbm' => (($this->width / 100) * ($this->height / 100) * ($this->length / 100)) * $this->quantity,
|
|
'status' => $this->status,
|
|
$this->mergeWhen($originalPackingList->owner instanceof Order, [
|
|
'order' => New OrderResource($originalPackingList->owner)
|
|
]),
|
|
'container' => new ContainerResource($originalPackingList->containers()->first()),
|
|
'transport' => new TransportResource($originalPackingList->transports()->first()),
|
|
|
|
'reference' => $exceptionUsers ? $this->packingList->reference : '',
|
|
'reference_hash' => hash('sha256', $this->packingList->reference),
|
|
'reference_encrypted' => Crypt::encryptString($this->packingList->reference),
|
|
];
|
|
}
|
|
}
|