wip: modernized edit flow, fix insurance tier calculation
This commit is contained in:
@@ -6,7 +6,6 @@ namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Traits\SortByPriceTrait;
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Model\InsuranceEligibilityCriteria;
|
||||
@@ -31,9 +30,9 @@ class InsuranceMatchingService
|
||||
/**
|
||||
* Filters insurances based on participant and booking criteria.
|
||||
*
|
||||
* @param array<Insurance> $insurances Available insurances to filter
|
||||
* @param ParticipantDto $participant The participant to match insurances for
|
||||
* @param BookingDto $booking The booking context for additional criteria
|
||||
* @param array<Insurance> $insurances Available insurances to filter
|
||||
* @param ParticipantDto $participant The participant to match insurances for
|
||||
* @param BookingDto $booking The booking context for additional criteria
|
||||
*
|
||||
* @return array<Insurance> Filtered array of eligible insurances
|
||||
*/
|
||||
@@ -60,10 +59,10 @@ class InsuranceMatchingService
|
||||
* current insurance is no longer eligible. It finds the same insurance type
|
||||
* (subType + familyInsurance) with the correct price tier.
|
||||
*
|
||||
* @param array<Insurance> $availableInsurances All available insurances
|
||||
* @param Insurance $currentInsurance The currently selected insurance
|
||||
* @param ParticipantDto $participant The participant to reassign for
|
||||
* @param BookingDto $booking The booking context
|
||||
* @param array<Insurance> $availableInsurances All available insurances
|
||||
* @param Insurance $currentInsurance The currently selected insurance
|
||||
* @param ParticipantDto $participant The participant to reassign for
|
||||
* @param BookingDto $booking The booking context
|
||||
*
|
||||
* @return Insurance|null The reassigned insurance or null if no suitable match found
|
||||
*/
|
||||
@@ -90,9 +89,9 @@ class InsuranceMatchingService
|
||||
* (subType + familyInsurance) to all participants, but selects the appropriate price tier
|
||||
* based on each participant's individual travel price.
|
||||
*
|
||||
* @param array<Insurance> $availableInsurances All available insurances
|
||||
* @param Insurance $selectedInsurance The insurance selected by the applicant
|
||||
* @param BookingDto $booking The booking with all participants
|
||||
* @param array<Insurance> $availableInsurances All available insurances
|
||||
* @param Insurance $selectedInsurance The insurance selected by the applicant
|
||||
* @param BookingDto $booking The booking with all participants
|
||||
*
|
||||
* @return array<int, Insurance|null> Array indexed by participant index with assigned insurances
|
||||
*
|
||||
@@ -187,8 +186,8 @@ class InsuranceMatchingService
|
||||
*/
|
||||
private function checkFamilyInsuranceConstraints(Insurance $insurance, BookingDto $booking): bool
|
||||
{
|
||||
// Family booking detection only available in BookingCreateDto
|
||||
if (!$booking instanceof BookingCreateDto) {
|
||||
// Family booking detection only available in create mode
|
||||
if (BookingDto::MODE_EDIT === $booking->getMode()) {
|
||||
return true; // Skip family constraints for edit mode
|
||||
}
|
||||
|
||||
@@ -316,14 +315,34 @@ class InsuranceMatchingService
|
||||
* affects travel price which then affects insurance eligibility.
|
||||
*
|
||||
* @param BookingDto $booking The booking to calculate price for
|
||||
* @param int $participantIndex The participant index to calculate for
|
||||
* @param int $participantIndex The participant index to calculate for
|
||||
*
|
||||
* @return float The total travel price for the participant excluding insurance
|
||||
*/
|
||||
private function calculateTravelPrice(BookingDto $booking, int $participantIndex): float
|
||||
{
|
||||
$participant = $booking->getParticipant($participantIndex);
|
||||
|
||||
// Debug logging to understand price calculation
|
||||
if (null !== $participant && null !== $participant->insurance) {
|
||||
error_log(sprintf(
|
||||
'[InsuranceMatching] Participant %d: calculating travel price WITH insurance=%d (€%.2f) currently selected',
|
||||
$participantIndex,
|
||||
$participant->insurance->id,
|
||||
$participant->insurance->price ?? 0.0
|
||||
));
|
||||
}
|
||||
|
||||
// Use the price calculator to get the participant's individual price excluding insurance
|
||||
return $this->priceCalculatorService->calculateIndividualParticipantPriceExcludingInsurance($booking, $participantIndex);
|
||||
$travelPrice = $this->priceCalculatorService->calculateIndividualParticipantPriceExcludingInsurance($booking, $participantIndex);
|
||||
|
||||
error_log(sprintf(
|
||||
'[InsuranceMatching] Participant %d: calculated travel price (excluding insurance) = €%.2f',
|
||||
$participantIndex,
|
||||
$travelPrice
|
||||
));
|
||||
|
||||
return $travelPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user