Show combined price for round trip bookings in the list
PHP Tests / php-tests (push) Waiting to run

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.
This commit is contained in:
Nyan Lin Paing
2026-09-03 12:00:36 +07:00
parent 90e5807a17
commit e61a847a02
2 changed files with 32 additions and 0 deletions
@@ -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')