Generalize per-vehicle-option booking rules to Front Seat too

Front Seat previously had a hardcoded max-per-booking check with no enable
toggle; now every Vehicle Option (front_seat/back_seat/whole_vehicle) gets
the same config-driven pair — an on/off toggle and a max passenger_count —
surfaced via new BOOKING_*_ENABLED/BOOKING_*_MAX_PER_BOOKING env vars,
editable from ManageAppSettings, and exposed on route pricing as
max_per_booking.
This commit is contained in:
Nyan Lin Paing
2026-08-30 15:45:27 +07:00
parent 914b7f97f3
commit bebcab88fa
11 changed files with 175 additions and 97 deletions
@@ -60,9 +60,12 @@ class ManageAppSettings extends Page
'support_phone' => config('app.support_phone'),
'timezone' => config('app.timezone'),
'currency' => config('app.currency'),
'back_seat_enabled' => (bool) config('booking.back_seat_enabled'),
'whole_vehicle_enabled' => (bool) config('booking.whole_vehicle_enabled'),
'front_seat_enabled' => (bool) config('booking.front_seat_enabled'),
'front_seat_max_per_booking' => config('booking.front_seat_max_per_booking'),
'back_seat_enabled' => (bool) config('booking.back_seat_enabled'),
'back_seat_max_per_booking' => config('booking.back_seat_max_per_booking'),
'whole_vehicle_enabled' => (bool) config('booking.whole_vehicle_enabled'),
'whole_vehicle_max_per_booking' => config('booking.whole_vehicle_max_per_booking'),
'booking_admin_emails' => config('booking.admin_emails'),
'sms_enabled' => (bool) config('services.sms.enabled'),
'sms_server' => config('services.sms.sms_poh.server'),
@@ -106,23 +109,39 @@ class ManageAppSettings extends Page
->columns(2),
Tab::make('Booking')
->schema([
Toggle::make('back_seat_enabled')
->label('Back Seat Enabled')
->helperText('Whether customers can select Back Seat at all right now.'),
Toggle::make('whole_vehicle_enabled')
->label('Whole Vehicle Enabled')
->helperText('Whether customers can select Whole Vehicle at all right now.'),
Toggle::make('front_seat_enabled')
->label('Front Seat Enabled')
->helperText('Whether customers can select Front Seat at all right now.'),
TextInput::make('front_seat_max_per_booking')
->label('Front Seat Max Per Booking')
->numeric()
->minValue(1)
->required()
->helperText('Max Front Seats a single booking may request.'),
Toggle::make('back_seat_enabled')
->label('Back Seat Enabled')
->helperText('Whether customers can select Back Seat at all right now.'),
TextInput::make('back_seat_max_per_booking')
->label('Back Seat Max Per Booking')
->numeric()
->minValue(1)
->required()
->helperText('Max Back Seats a single booking may request.'),
Toggle::make('whole_vehicle_enabled')
->label('Whole Vehicle Enabled')
->helperText('Whether customers can select Whole Vehicle at all right now.'),
TextInput::make('whole_vehicle_max_per_booking')
->label('Whole Vehicle Max Per Booking')
->numeric()
->minValue(1)
->required()
->helperText('Max Whole Vehicle passenger count a single booking may request.'),
TagsInput::make('booking_admin_emails')
->label('Admin Emails')
->required()
->helperText('Notified on booking events. Press enter after each address.'),
]),
])
->columns(2),
Tab::make('SMS')
->schema([
Toggle::make('sms_enabled')
@@ -170,9 +189,12 @@ class ManageAppSettings extends Page
'SUPPORT_PHONE' => $state['support_phone'],
'APP_TIMEZONE' => $state['timezone'],
'APP_CURRENCY' => $state['currency'],
'BOOKING_BACK_SEAT_ENABLED' => (bool) $state['back_seat_enabled'],
'BOOKING_WHOLE_VEHICLE_ENABLED' => (bool) $state['whole_vehicle_enabled'],
'BOOKING_FRONT_SEAT_ENABLED' => (bool) $state['front_seat_enabled'],
'BOOKING_FRONT_SEAT_MAX_PER_BOOKING' => (int) $state['front_seat_max_per_booking'],
'BOOKING_BACK_SEAT_ENABLED' => (bool) $state['back_seat_enabled'],
'BOOKING_BACK_SEAT_MAX_PER_BOOKING' => (int) $state['back_seat_max_per_booking'],
'BOOKING_WHOLE_VEHICLE_ENABLED' => (bool) $state['whole_vehicle_enabled'],
'BOOKING_WHOLE_VEHICLE_MAX_PER_BOOKING' => (int) $state['whole_vehicle_max_per_booking'],
'BOOKING_ADMIN_EMAILS' => implode(',', $state['booking_admin_emails'] ?? []),
'SMS_ENABLED' => (bool) $state['sms_enabled'],
'SMS_SERVER' => $state['sms_server'],
@@ -40,9 +40,12 @@ test('a super_admin can view and save app settings, writing them to .env', funct
'support_phone' => '+95912345678',
'timezone' => 'Asia/Yangon',
'currency' => 'MMK',
'back_seat_enabled' => false,
'whole_vehicle_enabled' => true,
'front_seat_enabled' => false,
'front_seat_max_per_booking' => 2,
'back_seat_enabled' => false,
'back_seat_max_per_booking' => 5,
'whole_vehicle_enabled' => true,
'whole_vehicle_max_per_booking' => 6,
'booking_admin_emails' => ['ops@evbooking.test', 'dispatch@evbooking.test'],
'sms_enabled' => true,
'sms_server' => 'https://sms.example.test/send',
@@ -59,9 +62,12 @@ test('a super_admin can view and save app settings, writing them to .env', funct
->toContain('SUPPORT_EMAIL=help@evbooking.test')
->toContain('APP_TIMEZONE=Asia/Yangon')
->toContain('APP_CURRENCY=MMK')
->toContain('BOOKING_BACK_SEAT_ENABLED=false')
->toContain('BOOKING_WHOLE_VEHICLE_ENABLED=true')
->toContain('BOOKING_FRONT_SEAT_ENABLED=false')
->toContain('BOOKING_FRONT_SEAT_MAX_PER_BOOKING=2')
->toContain('BOOKING_BACK_SEAT_ENABLED=false')
->toContain('BOOKING_BACK_SEAT_MAX_PER_BOOKING=5')
->toContain('BOOKING_WHOLE_VEHICLE_ENABLED=true')
->toContain('BOOKING_WHOLE_VEHICLE_MAX_PER_BOOKING=6')
->toContain('BOOKING_ADMIN_EMAILS=ops@evbooking.test,dispatch@evbooking.test')
->toContain('SMS_ENABLED=true')
->toContain('SMS_SERVER=https://sms.example.test/send')
@@ -80,13 +86,17 @@ test('sms server and token are required once sms is enabled', function () {
->assertHasFormErrors(['sms_server', 'sms_token']);
});
test('front seat max per booking must be at least 1', function () {
test('max per booking fields must be at least 1', function (string $field) {
$superAdmin = User::factory()->create();
$superAdmin->assignRole('super_admin');
$this->actingAs($superAdmin);
Livewire::test(ManageAppSettings::class)
->fillForm(['front_seat_max_per_booking' => 0])
->fillForm([$field => 0])
->call('save')
->assertHasFormErrors(['front_seat_max_per_booking']);
});
->assertHasFormErrors([$field]);
})->with([
'front_seat_max_per_booking',
'back_seat_max_per_booking',
'whole_vehicle_max_per_booking',
]);