fix: show booked room count in edit summary
This commit is contained in:
1 parent
2705401393
commit
897a1ac7f9
2 files changed
+48
-10
No files matched your search
@@ -147,12 +147,8 @@ class RoomPricingCalculator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count current participant assignments from the DTO (reflects live state
|
|
||||||
// including new assignments not yet in the booking entity)
|
|
||||||
$assignmentCounts = $bookingDto->getRoomAssignmentCounts();
|
|
||||||
|
|
||||||
// Build pricing array
|
// Build pricing array
|
||||||
foreach ($roomGroups as $roomId => $data) {
|
foreach ($roomGroups as $data) {
|
||||||
$room = $data['room'];
|
$room = $data['room'];
|
||||||
$participantCount = $data['participantCount'];
|
$participantCount = $data['participantCount'];
|
||||||
$totalPrice = $data['totalPrice'];
|
$totalPrice = $data['totalPrice'];
|
||||||
@@ -160,14 +156,11 @@ class RoomPricingCalculator
|
|||||||
// Calculate average unit price (price per person)
|
// Calculate average unit price (price per person)
|
||||||
$unitPrice = $participantCount > 0 ? $totalPrice / $participantCount : 0.0;
|
$unitPrice = $participantCount > 0 ? $totalPrice / $participantCount : 0.0;
|
||||||
|
|
||||||
// Use live assignment count for quantity display so the sidebar reflects
|
|
||||||
// new room assignments that haven't been persisted to the booking entity yet
|
|
||||||
$quantity = $assignmentCounts[$roomId] ?? $room->totalCount;
|
|
||||||
|
|
||||||
$roomPricing[] = [
|
$roomPricing[] = [
|
||||||
'roomId' => $room->id,
|
'roomId' => $room->id,
|
||||||
'label' => $room->label,
|
'label' => $room->label,
|
||||||
'quantity' => $quantity,
|
// Rooms, not occupants: room assignments cannot change in edit mode
|
||||||
|
'quantity' => $room->totalCount,
|
||||||
'participantCount' => $participantCount,
|
'participantCount' => $participantCount,
|
||||||
'unitPrice' => $unitPrice,
|
'unitPrice' => $unitPrice,
|
||||||
'totalPrice' => $totalPrice,
|
'totalPrice' => $totalPrice,
|
||||||
|
|||||||
@@ -300,6 +300,51 @@ class RoomPricingCalculatorTest extends TestCase
|
|||||||
$this->assertEquals(2, $result[0]['participantCount']);
|
$this->assertEquals(2, $result[0]['participantCount']);
|
||||||
$this->assertEquals(210.0, $result[0]['unitPrice']);
|
$this->assertEquals(210.0, $result[0]['unitPrice']);
|
||||||
$this->assertEquals(420.0, $result[0]['totalPrice']);
|
$this->assertEquals(420.0, $result[0]['totalPrice']);
|
||||||
|
$this->assertEquals(1, $result[0]['quantity']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCalculateRoomPricingInEditModeShowsBookedRoomCountNotOccupants(): void
|
||||||
|
{
|
||||||
|
// Booking 104407: 16 participants in one 6-bed room, one 4-bed room and three doubles.
|
||||||
|
$bookingDto = new BookingDto(new Travel(), 16);
|
||||||
|
$bookingDto->participants = [];
|
||||||
|
foreach ([0, 1, 2, 3, 4, 5] as $index) {
|
||||||
|
$bookingDto->participants[$index] = $this->participantInRoom(863);
|
||||||
|
}
|
||||||
|
foreach ([6, 7, 8, 9] as $index) {
|
||||||
|
$bookingDto->participants[$index] = $this->participantInRoom(95);
|
||||||
|
}
|
||||||
|
foreach ([10, 11, 12, 13, 14, 15] as $index) {
|
||||||
|
$bookingDto->participants[$index] = $this->participantInRoom(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
$booking = new Booking();
|
||||||
|
$booking->rooms = [
|
||||||
|
863 => $this->bookedRoom(863, 6, 1, [0, 1, 2, 3, 4, 5], 194.0),
|
||||||
|
95 => $this->bookedRoom(95, 4, 1, [6, 7, 8, 9], 204.0),
|
||||||
|
3 => $this->bookedRoom(3, 2, 3, [10, 11, 12, 13, 14, 15], 224.0),
|
||||||
|
];
|
||||||
|
$bookingDto->booking = $booking;
|
||||||
|
|
||||||
|
$result = $this->calculator->calculateRoomPricing($bookingDto);
|
||||||
|
$quantities = array_column($result, 'quantity', 'roomId');
|
||||||
|
|
||||||
|
$this->assertSame([863 => 1, 95 => 1, 3 => 3], $quantities);
|
||||||
|
$this->assertEquals(1344.0, $result[2]['totalPrice']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param int[] $mapping */
|
||||||
|
private function bookedRoom(int $id, int $maxPax, int $totalCount, array $mapping, float $price): Room
|
||||||
|
{
|
||||||
|
$room = new Room();
|
||||||
|
$room->id = $id;
|
||||||
|
$room->label = 'Room '.$id;
|
||||||
|
$room->maxPax = $maxPax;
|
||||||
|
$room->totalCount = $totalCount;
|
||||||
|
$room->mapping = $mapping;
|
||||||
|
$room->individualPrice = array_fill_keys($mapping, $price);
|
||||||
|
|
||||||
|
return $room;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function participantInRoom(int $roomId): ParticipantDto
|
private function participantInRoom(int $roomId): ParticipantDto
|
||||||
|
|||||||
Reference in new issue
Block a user