From 897a1ac7f9b9f9dab9875f297f02e779c5247615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 9 Nov 2026 18:00:47 +0100 Subject: [PATCH] fix: show booked room count in edit summary --- src/Service/RoomPricingCalculator.php | 13 ++---- tests/Service/RoomPricingCalculatorTest.php | 45 +++++++++++++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/Service/RoomPricingCalculator.php b/src/Service/RoomPricingCalculator.php index 79bb4dfd..c1177c51 100644 --- a/src/Service/RoomPricingCalculator.php +++ b/src/Service/RoomPricingCalculator.php @@ -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 - foreach ($roomGroups as $roomId => $data) { + foreach ($roomGroups as $data) { $room = $data['room']; $participantCount = $data['participantCount']; $totalPrice = $data['totalPrice']; @@ -160,14 +156,11 @@ class RoomPricingCalculator // Calculate average unit price (price per person) $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[] = [ 'roomId' => $room->id, 'label' => $room->label, - 'quantity' => $quantity, + // Rooms, not occupants: room assignments cannot change in edit mode + 'quantity' => $room->totalCount, 'participantCount' => $participantCount, 'unitPrice' => $unitPrice, 'totalPrice' => $totalPrice, diff --git a/tests/Service/RoomPricingCalculatorTest.php b/tests/Service/RoomPricingCalculatorTest.php index 866b47cf..ff868d36 100644 --- a/tests/Service/RoomPricingCalculatorTest.php +++ b/tests/Service/RoomPricingCalculatorTest.php @@ -300,6 +300,51 @@ class RoomPricingCalculatorTest extends TestCase $this->assertEquals(2, $result[0]['participantCount']); $this->assertEquals(210.0, $result[0]['unitPrice']); $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