mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
83 lines
2.0 KiB
PHP
83 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\Package;
|
|
use League\Fractal\Resource\Item;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class PackageTransformer extends TransformerAbstract
|
|
{
|
|
/**
|
|
* List of resources to automatically include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $defaultIncludes = [
|
|
'transport',
|
|
'container'
|
|
];
|
|
|
|
/**
|
|
* List of resources possible to include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $availableIncludes = [
|
|
'order'
|
|
];
|
|
|
|
/**
|
|
* A Fractal transformer.
|
|
*
|
|
* @param Package $package
|
|
* @return array
|
|
*/
|
|
public function transform(Package $package): array
|
|
{
|
|
return [
|
|
'id' => $package->id,
|
|
'type' => $package->type,
|
|
'description' => $package->description,
|
|
'width' => floatval($package->width),
|
|
'height' => floatval($package->height),
|
|
'length' => floatval($package->length),
|
|
'weight' => $package->weight,
|
|
'quantity' => $package->quantity,
|
|
'cbm' => (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity,
|
|
'reference' => $package->packingList->reference,
|
|
'status' => $package->status,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Include Transport
|
|
* @param Package $package
|
|
* @return Item
|
|
*/
|
|
public function includeTransport(Package $package): Item
|
|
{
|
|
return $this->item($package->packingList->transports()->first(), new TransportTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include Container
|
|
* @param Package $package
|
|
* @return Item
|
|
*/
|
|
public function includeContainers(Package $package): Item
|
|
{
|
|
return $this->item($package->packingList->containers()->first(), new TransportTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include Order
|
|
* @param Package $package
|
|
* @return Item
|
|
*/
|
|
public function includeOrder(Package $package): Item
|
|
{
|
|
return $this->item($package->packingList->owner, new OrderTransformer());
|
|
}
|
|
}
|