Add Booking module: model, create/read/cancel API, Filament resource (T4.1-T4.7)

- 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)
This commit is contained in:
Nyan Lin Paing
2026-08-08 21:43:15 +07:00
parent 4da9ecfe7d
commit 5b68f4fa38
51 changed files with 2698 additions and 42 deletions
@@ -0,0 +1,63 @@
<?php
namespace Modules\Booking\Filament\Resources\Bookings\Actions;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Support\Icons\Heroicon;
use Modules\Booking\Actions\AssignDriverAction;
use Modules\Booking\Data\AssignDriverData;
use Modules\Booking\Enums\BookingStatus;
use Modules\Booking\Exceptions\DriverAssignmentNotAllowedException;
use Modules\Booking\Models\Booking;
/**
* Shared between BookingsTable (row action) and ViewBooking (header action)
* so both surfaces stay in sync one definition, not two.
*/
class AssignDriverTableAction
{
public static function make(): Action
{
return Action::make('assignDriver')
->label('Assign Driver')
->icon(Heroicon::OutlinedTruck)
->color('primary')
->visible(fn (Booking $record): bool => $record->status === BookingStatus::Confirmed
&& (auth()->user()?->can('manage_bookings') ?? false))
->schema([
TextInput::make('driver_name')->required(),
TextInput::make('driver_phone')->required(),
TextInput::make('car_plate_number')->required(),
TextInput::make('car_model'),
])
->fillForm(fn (Booking $record): array => [
'driver_name' => $record->driver_name,
'driver_phone' => $record->driver_phone,
'car_plate_number' => $record->car_plate_number,
'car_model' => $record->car_model,
])
->action(function (array $data, Booking $record, AssignDriverAction $assignDriverAction) {
try {
$assignDriverAction->handle($record, new AssignDriverData(
driverName: $data['driver_name'],
driverPhone: $data['driver_phone'],
carPlateNumber: $data['car_plate_number'],
carModel: $data['car_model'] ?: null,
));
Notification::make()
->title('Driver assigned')
->success()
->send();
} catch (DriverAssignmentNotAllowedException $exception) {
Notification::make()
->title('Cannot assign driver')
->body($exception->getMessage())
->danger()
->send();
}
});
}
}