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:
@@ -37,6 +37,7 @@ class BookingsTable
|
|||||||
->where('is_return_leg', false)
|
->where('is_return_leg', false)
|
||||||
->with([
|
->with([
|
||||||
'route.company', 'route.fromDestination', 'route.toDestination', 'timeSlot', 'vehicleOptions',
|
'route.company', 'route.fromDestination', 'route.toDestination', 'timeSlot', 'vehicleOptions',
|
||||||
|
'linkedBooking',
|
||||||
]))
|
]))
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->columns([
|
->columns([
|
||||||
@@ -76,6 +77,17 @@ class BookingsTable
|
|||||||
->all())
|
->all())
|
||||||
->listWithLineBreaks(),
|
->listWithLineBreaks(),
|
||||||
TextColumn::make('price')
|
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)
|
->numeric(2)
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('passenger_name')
|
TextColumn::make('passenger_name')
|
||||||
|
|||||||
@@ -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]);
|
->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 () {
|
test('the restore action is only visible for a trashed booking', function () {
|
||||||
$active = Booking::factory()->create();
|
$active = Booking::factory()->create();
|
||||||
$deleted = Booking::factory()->create();
|
$deleted = Booking::factory()->create();
|
||||||
|
|||||||
Reference in New Issue
Block a user