wip: improved refresh logic

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 36fe4c9e9a
commit 3063a7c05f
5 changed files with 95 additions and 3 deletions
@@ -286,6 +286,12 @@ class BookingPriceCalculatorService
}
$subType = $serviceData['subType'] ?? 'other';
// Normalize rental subtypes to avoid duplicate sections
if (true === in_array($subType, Constants::TOKEN_RENTALS, true)) {
$subType = 'rentals'; // Normalize all rental subtypes to a single key
}
$isDiscount = $serviceData['totalPrice'] < 0;
// Create separate buckets for positive costs and discounts
@@ -332,9 +338,10 @@ class BookingPriceCalculatorService
Constants::TOKEN_ADDITIONAL => 'Zusatzleistungen',
Constants::TOKEN_BOARD => 'Verpflegung',
'transportation' => 'Beförderung',
'rentals' => 'Leihmaterial', // Normalized rental subtype
];
// Handle rentals array
// Handle rentals array (keep for backward compatibility with non-normalized subtypes)
if (true === in_array($subType, Constants::TOKEN_RENTALS, true)) {
return 'Leihmaterial';
}
+54
View File
@@ -266,4 +266,58 @@ class BookingService
return $oldSnapshot !== $newSnapshot;
}
/**
* Pre-selects mandatory services for all participants in the booking DTO.
*
* This method ensures that mandatory services are selected before form rendering
* and pricing calculations, resolving timing issues where mandatory services
* were only selected during form rendering via choice_attr callbacks.
*
* @param BookingCreateDto $bookingDto The booking DTO to update with mandatory services
*/
public function preselectMandatoryServices(BookingCreateDto $bookingDto): void
{
$additionalServices = $bookingDto->travel->getAdditionalServicesBySubTypes(\App\BusProNet\Constants::TOKEN_ADDITIONAL);
$mandatoryServices = array_filter($additionalServices, fn ($service) => true === $service->mandatory);
// Pre-select mandatory services for each participant
foreach ($bookingDto->participants as $participant) {
if (null === $participant->dateOfBirth) {
continue; // Skip participants without age information
}
// Get age-appropriate mandatory services for this participant
$ageAppropriateServices = array_filter($mandatoryServices, function ($service) use ($bookingDto, $participant) {
// Use the age evaluator service to check if service is appropriate for participant age
if (null === $service->ageFrom && null === $service->ageTo) {
return true; // No age restrictions
}
$age = $participant->dateOfBirth->diff($bookingDto->travel->dateFrom)->y;
if (null !== $service->ageFrom && $age < $service->ageFrom) {
return false;
}
if (null !== $service->ageTo && $age > $service->ageTo) {
return false;
}
return true;
});
// Add mandatory services to current selections
$currentSelections = $participant->additionalServices ?? [];
$currentServiceIds = array_map(fn ($service) => $service->id, $currentSelections);
foreach ($ageAppropriateServices as $mandatoryService) {
if (false === in_array($mandatoryService->id, $currentServiceIds, true)) {
$currentSelections[] = $mandatoryService;
}
}
$participant->additionalServices = $currentSelections;
}
}
}