- Migration: add current_load_kg (nullable unsigned int) to trips table
- Trip model: add current_load_kg to fillable + integer cast
- New TruckLoadBroadcast event (ShouldBroadcastNow)
- Channel: private admin.live
- Event name: truck.load
- Payload: trip_id, team_id, truck_id, current_load_kg, capacity_kg, is_full
- DriverTripController::updateLoad()
- PATCH /api/v1/driver/trips/{trip}/update-load
- Validates status is in_progress, saves current_load_kg, fires broadcast
- Route: PATCH driver/trips/{trip}/update-load registered
- CollectionTeamResource: truck_is_full uses current_load_kg (live estimate)
with fallback to total_load_kg (authoritative dumpsite weight)
- TripResource: expose current_load_kg field
- Admin Teams card:
- data-team-id attribute added to each card for Echo targeting
- Load bar uses current_load_kg when available
- Echo listener for truck.load event patches load bar + badge in real-time
- truck-status-badge class added to Collecting/Truck Full spans
47 lines
1.9 KiB
PHP
47 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;
|
|
$capacity = $this->truck?->capacity_kg;
|
|
// Prefer driver's live estimate; fall back to dumpsite-scale total
|
|
$effectiveLoad = $trip->current_load_kg ?? $trip->total_load_kg ?? 0;
|
|
return ($capacity && $effectiveLoad >= $capacity)
|
|
|| $trip->status === 'at_dumpsite';
|
|
}, false),
|
|
'performance_stats' => $this->getPerformanceStats(),
|
|
'current_trip' => TripResource::make($this->whenLoaded('currentTrip')),
|
|
'notes' => $this->notes,
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|