mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
103 lines
2.5 KiB
PHP
103 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Classes\ValueObjects\Constants\AddressType;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Models\Order;
|
|
use League\Fractal\Resource\Item;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class DeliveryOrderTransformer extends TransformerAbstract
|
|
{
|
|
/**
|
|
* List of resources to automatically include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $defaultIncludes = [
|
|
'company_module',
|
|
'sender_address',
|
|
'delivery_address',
|
|
'packingList',
|
|
'remarks'
|
|
];
|
|
|
|
/**
|
|
* List of resources possible to include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $availableIncludes = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* A Fractal transformer.
|
|
*
|
|
* @param Order $order
|
|
* @return array
|
|
*/
|
|
public function transform(Order $order): array
|
|
{
|
|
return [
|
|
'id' => $order->id,
|
|
'reference' => $order->reference,
|
|
'type' => $order->type,
|
|
'status' => $order->status,
|
|
'created_at' => $order->created_at->format('d-m-Y')
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Include CompanyModule
|
|
* @param Order $order
|
|
* @return Item
|
|
*/
|
|
public function includeCompanyModule(Order $order): Item
|
|
{
|
|
return $this->item($order->companyModule, new CompanyModuleTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include SenderAddress
|
|
* @param Order $order
|
|
* @return Item
|
|
*/
|
|
public function includeSenderAddress(Order $order): Item
|
|
{
|
|
return $this->item($order->addresses()->where('status', '=', ApprovalStatus::APPROVED)->where('type', AddressType::PICK_UP)->first(), new AddressTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include DeliveryAddress
|
|
* @param Order $order
|
|
* @return Item
|
|
*/
|
|
|
|
public function includeDeliveryAddress(Order $order): Item
|
|
{
|
|
return $this->item($order->addresses()->where('status', '=', ApprovalStatus::APPROVED)->where('type', AddressType::DELIVERY)->first(), new AddressTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include PackingList
|
|
* @param Order $order
|
|
* @return Item
|
|
*/
|
|
public function includePackingList(Order $order): Item
|
|
{
|
|
return $this->item($order->packingLists()->first(), new DeliveryPackingListTransformer());
|
|
}
|
|
|
|
/**
|
|
* Include Remarks
|
|
* @param Order $order
|
|
* @return Item
|
|
*/
|
|
public function includeRemarks(Order $order): Item
|
|
{
|
|
return $this->item($order->remarks, new RemarkTransformer());
|
|
}
|
|
}
|