61 lines
2.9 KiB
PHP
61 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TripResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->uuid,
|
|
'trip_number' => $this->trip_number,
|
|
'status' => $this->status,
|
|
'scheduled_date' => $this->scheduled_date?->toDateString(),
|
|
'scheduled_start_time' => $this->scheduled_start_time,
|
|
'actual_start_time' => $this->actual_start_time?->toIso8601String(),
|
|
'actual_end_time' => $this->actual_end_time?->toIso8601String(),
|
|
'dumpsite_arrival_time' => $this->dumpsite_arrival_time?->toIso8601String(),
|
|
'dumpsite_departure_time' => $this->dumpsite_departure_time?->toIso8601String(),
|
|
'total_load_kg' => $this->total_load_kg,
|
|
'current_load_kg' => $this->current_load_kg,
|
|
'is_detouring' => $this->is_detouring,
|
|
'route' => RouteResource::make($this->whenLoaded('route')),
|
|
'team' => CollectionTeamResource::make($this->whenLoaded('team')),
|
|
'truck' => TruckResource::make($this->whenLoaded('truck')),
|
|
'dumpsite' => DumpsiteResource::make($this->whenLoaded('dumpsite')),
|
|
'stops' => TripStopResource::collection($this->whenLoaded('stops')),
|
|
'timeline' => TripTimelineEventResource::collection($this->whenLoaded('timelineEvents')),
|
|
'notes' => $this->notes,
|
|
'end_reason' => $this->end_reason,
|
|
'parent_trip' => $this->whenLoaded('parentTrip', fn () => $this->parentTrip ? [
|
|
'id' => $this->parentTrip->uuid,
|
|
'trip_number' => $this->parentTrip->trip_number,
|
|
] : null),
|
|
'continuation_trips' => $this->whenLoaded('continuationTrips', fn () => $this->continuationTrips->map(fn ($c) => [
|
|
'id' => $c->uuid,
|
|
'trip_number' => $c->trip_number,
|
|
'status' => $c->status,
|
|
'team_name' => $c->team?->name ?? null,
|
|
])),
|
|
'releases' => $this->whenLoaded('dumpsiteReleases', fn () => $this->dumpsiteReleases->map(fn ($r) => [
|
|
'id' => $r->id,
|
|
'weight_kg' => $r->weight_kg,
|
|
'released_at' => $r->released_at?->toIso8601String(),
|
|
'dumpsite_name' => $r->dumpsite?->name,
|
|
'driver_name' => $r->releasedByDriver?->full_name,
|
|
'gate_pass_number' => $r->gate_pass_number,
|
|
'dumpsite_attendant' => $r->dumpsite_attendant_name,
|
|
'notes' => $r->notes,
|
|
])),
|
|
'tenant' => $this->whenLoaded('tenant', fn () => [
|
|
'id' => $this->tenant->id,
|
|
'name' => $this->tenant->name,
|
|
]),
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|