Files
Verde-Web/app/Http/Resources/CollectionTeamResource.php
Developer f5d520181e feat(admin/teams): add truck operational status badge
- Add truck_is_full computed field to CollectionTeamResource
  - true when current trip load >= truck capacity_kg
  - true when trip status is at_dumpsite (driver rerouted to dumpsite)
  - uses whenLoaded() guard, safe when currentTrip not eager-loaded

- Rework teams card badge layout (Admin UI)
  - H row: remove misleading 'Not Full' for standby teams; show Full/Incomplete for active only
  - Truck Load row: always rendered with 4 context-aware states
    - IDLE (standby teams)
    - READY (active, no current trip)
    - COLLECTING (active trip, under capacity)
    - TRUCK FULL (at capacity or at dumpsite)
2026-07-02 14:23:02 +08:00

49 lines
1.9 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\Trip;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CollectionTeamResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->uuid,
'db_id' => $this->id,
'name' => $this->name,
'status' => $this->status,
'area' => ServiceAreaResource::make($this->whenLoaded('area')),
'driver' => UserResource::make($this->whenLoaded('driver')),
'scanner' => UserResource::make($this->whenLoaded('scanner')),
'truck' => TruckResource::make($this->whenLoaded('truck')),
'helpers' => $this->whenLoaded('helpers', fn () => $this->helpers->map(fn ($m) => [
'id' => $m->user?->uuid,
'db_id' => $m->user?->id,
'name' => $m->user?->full_name,
'assigned_from' => $m->assigned_from?->toDateString(),
'assigned_until' => $m->assigned_until?->toDateString(),
'status' => $m->status,
])),
'is_full' => $this->is_full,
'truck_is_full' => $this->whenLoaded('currentTrip', function () {
$trip = $this->currentTrip;
if (! $trip) {
return false;
}
$atDumpsite = $trip->status === Trip::STATUS_AT_DUMPSITE;
$atCapacity = $this->truck?->capacity_kg > 0
&& $trip->total_load_kg >= $this->truck->capacity_kg;
return $atDumpsite || $atCapacity;
}, false),
'performance_stats' => $this->getPerformanceStats(),
'current_trip' => TripResource::make($this->whenLoaded('currentTrip')),
'notes' => $this->notes,
'created_at' => $this->created_at?->toIso8601String(),
];
}
}