mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TransportResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$currentSchedule = $this->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first();
|
|
return [
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
'courier' => $this->courier,
|
|
'tracking_number' => $this->tracking_number,
|
|
'dispatch_date' => $this->dispatch_date ? $this->dispatch_date->format('d-m-Y') : $this->dispatch_date,
|
|
'drop_date' => $this->drop_date ? $this->drop_date->format('d-m-Y') : $this->drop_date,
|
|
'status' => $this->status,
|
|
'current_schedule' => new ScheduleResource($currentSchedule),
|
|
'schedule_history' => ScheduleResource::collection($this->schedules()->where('status', '=', ApprovalStatus::EXPIRED)->get()),
|
|
'dropped_days' => Carbon::now()->diffInDays($this->drop_date, false),
|
|
'schedule_complete' => $currentSchedule ? $currentSchedule->eta <= Carbon::now() : false
|
|
];
|
|
}
|
|
}
|