feat: refactor to cards

This commit is contained in:
Björn Fromme
2025-10-15 18:31:10 +02:00
parent ead2c092da
commit 49b7a3fe34
40 changed files with 2639 additions and 3097 deletions
+64 -3
View File
@@ -56,6 +56,12 @@ class BookingPriceCalculatorService
{
$roomPricing = [];
// In edit mode, use room data from the booking entity
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $bookingDto->booking) {
return $this->calculateRoomPricingFromBooking($bookingDto);
}
// In create mode, use room selections from the form
$selectedRooms = $bookingDto->getSelectedRooms();
if (true === empty($selectedRooms)) {
return $roomPricing;
@@ -86,6 +92,61 @@ class BookingPriceCalculatorService
return $roomPricing;
}
/**
* Calculates room pricing from booking entity data (edit mode).
*
* In edit mode, room prices come from the booking entity's individualPrice arrays.
* Each participant has their room price stored in the room's individualPrice array.
*
* @param BookingDto $bookingDto The booking data with booking entity
*
* @return array Array of room pricing data with labels, quantities, and totals
*/
private function calculateRoomPricingFromBooking(BookingDto $bookingDto): array
{
$roomPricing = [];
$roomGroups = [];
// Group participants by room and sum their individual prices
foreach ($bookingDto->booking->rooms as $room) {
if (false === isset($roomGroups[$room->id])) {
$roomGroups[$room->id] = [
'room' => $room,
'participantCount' => 0,
'totalPrice' => 0.0,
];
}
// Sum individual prices for all participants in this room
foreach ($room->mapping as $participantIndex) {
$individualPrice = $room->individualPrice[$participantIndex] ?? 0.0;
$roomGroups[$room->id]['totalPrice'] += $individualPrice;
++$roomGroups[$room->id]['participantCount'];
}
}
// Build pricing array
foreach ($roomGroups as $roomId => $data) {
$room = $data['room'];
$participantCount = $data['participantCount'];
$totalPrice = $data['totalPrice'];
// Calculate average unit price (price per person)
$unitPrice = $participantCount > 0 ? $totalPrice / $participantCount : 0.0;
$roomPricing[] = [
'roomId' => $room->id,
'label' => $room->label,
'quantity' => $room->totalCount,
'participantCount' => $participantCount,
'unitPrice' => $unitPrice,
'totalPrice' => $totalPrice,
];
}
return $roomPricing;
}
/**
* Calculates pricing for all selected services across all participants, grouped by subtype.
*
@@ -516,9 +577,9 @@ class BookingPriceCalculatorService
/**
* Calculates the total service cost for a single participant.
*
* @param ParticipantDto $participant The participant to calculate services for
* @param bool $includeInsurance Whether to include insurance pricing (default: true)
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance resolution
* @param ParticipantDto $participant The participant to calculate services for
* @param bool $includeInsurance Whether to include insurance pricing (default: true)
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance resolution
* @param bool $onlyInsuranceCalculationServices Only include services with includeInInsuranceCalculation=true (default: false)
*
* @return float The total service cost for this participant