feat: clarify booking summary participant count

This commit is contained in:
Björn Fromme
2026-04-13 12:24:09 +02:00
parent e179bbe259
commit 2baa147afa
5 changed files with 276 additions and 30 deletions
+2 -29
View File
@@ -27,6 +27,7 @@ class BookingSummaryDataService
{
public function __construct(
private readonly BookingPriceCalculatorService $priceCalculator,
private readonly BookingSummaryParticipantCountService $participantCountService,
private readonly CmsDataService $cmsDataService,
private readonly HotelLoader $hotelLoader,
private readonly CountryDataProvider $countryDataProvider,
@@ -74,8 +75,7 @@ class BookingSummaryDataService
$cmsData = $this->getCmsDataForProduct($productCode, $hotelCode);
}
// Calculate participant count from room capacity (source of truth)
$participantCount = $this->calculateParticipantCountFromRooms($bookingDto);
$participantCount = $this->participantCountService->calculate($bookingDto);
$acceptedVouchers = $bookingDto->getAcceptedVouchers($participantPrices);
@@ -118,33 +118,6 @@ class BookingSummaryDataService
return max(0.0, $grandTotal - $acceptedVouchers->getTotalDiscount());
}
/**
* Calculates participant count.
*
* In edit mode, counts actual participants. In create mode, calculates
* from room selections by multiplying quantity by maximum capacity (maxPax).
*/
private function calculateParticipantCountFromRooms(BookingDto $bookingDto): int
{
// In edit mode, use actual participant count
if (BookingDto::MODE_EDIT === $bookingDto->getMode()) {
return count($bookingDto->participants);
}
// In create mode, calculate from room selections
$totalCapacity = 0;
$availableRooms = $bookingDto->travel->getAvailableRooms();
foreach ($bookingDto->roomSelections as $selection) {
if ($selection->quantity > 0 && isset($availableRooms[$selection->id])) {
$room = $availableRooms[$selection->id];
$totalCapacity += $selection->quantity * ($room->maxPax ?? 0);
}
}
return $totalCapacity;
}
/**
* Fetches hotel display data combining local base hotel data with CMS images.
*
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Service;
use App\Form\Model\BookingDto;
/**
* Calculates the participant count shown in the summary sidebar.
*
* In create step 1, derive the expected participant count from room selections.
* In later create steps and edit mode, use the actual participant list.
*/
class BookingSummaryParticipantCountService
{
public function calculate(BookingDto $bookingDto): int
{
if (BookingDto::MODE_CREATE === $bookingDto->getMode() && 1 === $bookingDto->currentStep) {
return $this->calculateExpectedParticipantCountFromRooms($bookingDto);
}
return count($bookingDto->participants);
}
private function calculateExpectedParticipantCountFromRooms(BookingDto $bookingDto): int
{
$totalCapacity = 0;
$availableRooms = $bookingDto->travel->getAvailableRooms();
foreach ($bookingDto->roomSelections as $selection) {
if ($selection->quantity > 0 && isset($availableRooms[$selection->id])) {
$room = $availableRooms[$selection->id];
$totalCapacity += $selection->quantity * ($room->maxPax ?? 0);
}
}
return $totalCapacity;
}
}