fix: resolve stale dependent selections after booking family insurance

This commit is contained in:
Björn Fromme committed 2026-08-24 16:58:09 +02:00
1 parent 35826088cb
commit c9c28792e5
11 files changed
+490 -173

No files matched your search

+8 -45
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Service;
use App\BusProNet\Model\Insurance;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
@@ -54,7 +53,7 @@ class ParticipantPricingCalculator
}
// Add service prices for this participant (with booking context for bulk insurance)
$totalPrice += $this->calculateParticipantServiceTotal($participant, true, $bookingDto);
$totalPrice += $this->calculateParticipantServiceTotal($participant, true);
return $totalPrice;
}
@@ -138,62 +137,24 @@ class ParticipantPricingCalculator
// Add service prices for this participant (excluding insurance)
// For insurance eligibility calculation, only include services marked with versicherungsberechnung='J'
$totalPrice += $this->calculateParticipantServiceTotal($participant, false, null, true);
$totalPrice += $this->calculateParticipantServiceTotal($participant, false, true);
return $totalPrice;
})();
}
/**
* Gets the effective insurance for a participant, considering bulk insurance assignment.
*
* When bulk insurance is active and the participant is a dependent (index > 0),
* returns the applicant's insurance. Otherwise returns the participant's own insurance.
*
* This method is used for pricing calculations to show correct prices when bulk
* insurance is enabled, even though the actual assignment happens in the processor.
*
* @param ParticipantDto $participant The participant to get insurance for
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance check
*
* @return Insurance|null The effective insurance for pricing purposes
*/
public function getEffectiveInsurance(ParticipantDto $participant, ?BookingDto $bookingDto): ?Insurance
{
// If no booking context, use participant's own insurance
if (null === $bookingDto) {
return $participant->insurance;
}
// Applicant always uses their own insurance
if (0 === $participant->index) {
return $participant->insurance;
}
// Check if bulk insurance is active
$applicant = $bookingDto->getParticipant(0);
if (null === $applicant || false === $applicant->bulkInsuranceBooking) {
return $participant->insurance;
}
// Bulk insurance is active - use applicant's insurance for dependent participants
return $applicant->insurance;
}
/**
* 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 bool $onlyInsuranceCalculationServices Only include services with includeInInsuranceCalculation=true (default: false)
* @param ParticipantDto $participant The participant to calculate services for
* @param bool $includeInsurance Whether to include insurance pricing (default: true)
* @param bool $onlyInsuranceCalculationServices Only include services with includeInInsuranceCalculation=true (default: false)
*
* @return float The total service cost for this participant
*/
public function calculateParticipantServiceTotal(
ParticipantDto $participant,
bool $includeInsurance = true,
?BookingDto $bookingDto = null,
bool $onlyInsuranceCalculationServices = false,
): float {
$serviceTotal = 0.0;
@@ -212,7 +173,9 @@ class ParticipantPricingCalculator
}
// Get effective insurance (considering bulk insurance for dependent participants)
$effectiveInsurance = $this->getEffectiveInsurance($participant, $bookingDto);
// ApplicantInsuranceCascade materialises bulk and family assignments into the DTO as
// they happen, so the participant's own field is already the effective insurance.
$effectiveInsurance = $participant->insurance;
if ($includeInsurance && null !== $effectiveInsurance && null !== $effectiveInsurance->price) {
$serviceTotal += $effectiveInsurance->price;
}