5b68f4fa38
- Booking model with booking_vehicle_options line items (supports mixing vehicle options like front_seat + back_seat in one booking), price snapshot, status machine, and driver/car assignment fields - BookingService: front-seat max, disabled-option toggles, duplicate-option and whole-vehicle-exclusivity guards - CreateBookingAction, CancelBookingAction, AssignDriverAction - BookingRefGenerator: sequential EVB-AAAAA1-style refs via row lock - POST/GET/cancel booking API endpoints (Sanctum, ownership + admin policy) - BookingPlugin + Filament BookingResource: list, detail view, Cancel and Assign Driver actions (shared between table and detail page) - domain.md updated for multi-vehicle-option bookings (§2) and driver/ vehicle assignment (§5a)
34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Booking\Actions;
|
|
|
|
use Modules\Booking\Data\AssignDriverData;
|
|
use Modules\Booking\Enums\BookingStatus;
|
|
use Modules\Booking\Exceptions\DriverAssignmentNotAllowedException;
|
|
use Modules\Booking\Models\Booking;
|
|
|
|
/**
|
|
* Driver/vehicle details only make sense once a booking is confirmed
|
|
* (paid) — dispatch assigns who's actually doing the trip at that point,
|
|
* not before. Re-running this (e.g. reassigning a different driver) is
|
|
* allowed as long as the booking is still confirmed.
|
|
*/
|
|
class AssignDriverAction
|
|
{
|
|
public function handle(Booking $booking, AssignDriverData $data): Booking
|
|
{
|
|
if ($booking->status !== BookingStatus::Confirmed) {
|
|
throw DriverAssignmentNotAllowedException::notConfirmed($booking);
|
|
}
|
|
|
|
$booking->update([
|
|
'driver_name' => $data->driverName,
|
|
'driver_phone' => $data->driverPhone,
|
|
'car_plate_number' => $data->carPlateNumber,
|
|
'car_model' => $data->carModel,
|
|
]);
|
|
|
|
return $booking;
|
|
}
|
|
}
|