From e61a847a02ab9b27d9fb88612648ffb8847cfe7f Mon Sep 17 00:00:00 2001 From: Nyan Lin Paing <117423022+LinPaing21@users.noreply.github.com> Date: Thu, 3 Sep 2026 12:00:36 +0700 Subject: [PATCH] Show combined price for round trip bookings in the list Now that only the outbound leg gets a row, its Price column showed just that leg's price, silently missing the return leg's half. It now sums both legs (bcadd, 2dp) for a round trip, with a breakdown shown underneath; unchanged for one-way bookings. --- .../Bookings/Tables/BookingsTable.php | 12 +++++++++++ .../tests/Feature/BookingResourceTest.php | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app-modules/booking/src/Filament/Resources/Bookings/Tables/BookingsTable.php b/app-modules/booking/src/Filament/Resources/Bookings/Tables/BookingsTable.php index 92036bc..1c60b7d 100644 --- a/app-modules/booking/src/Filament/Resources/Bookings/Tables/BookingsTable.php +++ b/app-modules/booking/src/Filament/Resources/Bookings/Tables/BookingsTable.php @@ -37,6 +37,7 @@ class BookingsTable ->where('is_return_leg', false) ->with([ 'route.company', 'route.fromDestination', 'route.toDestination', 'timeSlot', 'vehicleOptions', + 'linkedBooking', ])) ->defaultSort('created_at', 'desc') ->columns([ @@ -76,6 +77,17 @@ class BookingsTable ->all()) ->listWithLineBreaks(), TextColumn::make('price') + ->label('Price') + // Since the return leg no longer has its own row (it's + // now hidden — see the query above), the price shown + // here for a round trip needs to be both legs combined, + // or it silently reads as just the outbound half. + ->state(fn (Booking $record) => $record->is_round_trip + ? bcadd((string) $record->price, (string) ($record->linkedBooking?->price ?? '0'), 2) + : $record->price) + ->description(fn (Booking $record) => $record->is_round_trip + ? number_format((float) $record->price, 2).' + '.number_format((float) ($record->linkedBooking?->price ?? 0), 2) + : null) ->numeric(2) ->sortable(), TextColumn::make('passenger_name') diff --git a/app-modules/booking/tests/Feature/BookingResourceTest.php b/app-modules/booking/tests/Feature/BookingResourceTest.php index 199f1e3..f04b0ff 100644 --- a/app-modules/booking/tests/Feature/BookingResourceTest.php +++ b/app-modules/booking/tests/Feature/BookingResourceTest.php @@ -360,6 +360,26 @@ test('a round trip\'s return leg has no row of its own in the list, only its out ->assertCanNotSeeTableRecords([$return]); }); +test('a round trip\'s price column shows both legs combined', function () { + $outbound = Booking::factory()->create(['is_return_leg' => false, 'price' => 15000]); + $return = Booking::factory()->create([ + 'is_return_leg' => true, + 'linked_booking_id' => $outbound->id, + 'price' => 20000, + ]); + $outbound->update(['linked_booking_id' => $return->id]); + + Livewire::test(ListBookings::class) + ->assertTableColumnStateSet('price', '35000.00', record: $outbound); +}); + +test('a one-way booking\'s price column shows just its own price', function () { + $booking = Booking::factory()->create(['is_return_leg' => false, 'linked_booking_id' => null, 'price' => 15000]); + + Livewire::test(ListBookings::class) + ->assertTableColumnStateSet('price', '15000.00', record: $booking); +}); + test('the restore action is only visible for a trashed booking', function () { $active = Booking::factory()->create(); $deleted = Booking::factory()->create();