fix: incorrect rules around family insurances
addresses #869dr80qj
This commit is contained in:
1 parent
736128476b
commit
8a46908856
15 files changed
+859
-50
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\Form\Model\BookingDto;
|
||||
|
||||
/**
|
||||
@@ -76,6 +77,22 @@ class BookingPriceCalculator
|
||||
return $this->participantPricingCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates total booking price across all participants, excluding insurance.
|
||||
*
|
||||
* Used for family insurance price-tier determination, where the tier is based on
|
||||
* the combined trip cost rather than any single participant's price.
|
||||
*/
|
||||
public function calculateTotalBookingPriceExcludingInsurance(BookingDto $bookingDto): float
|
||||
{
|
||||
$total = 0.0;
|
||||
foreach ($bookingDto->getParticipants() as $index => $participant) {
|
||||
$total += $this->calculateIndividualParticipantPriceExcludingInsurance($bookingDto, $index);
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total price for an individual participant excluding insurance.
|
||||
*
|
||||
@@ -95,4 +112,22 @@ class BookingPriceCalculator
|
||||
$participantIndex
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the travel price to use for insurance eligibility checks.
|
||||
*
|
||||
* Family insurances are always evaluated against the total booking price (all
|
||||
* participants combined); everything else uses the individual participant's price.
|
||||
* Non-applicant participants can never hold a family insurance (InsuranceManager
|
||||
* restricts family insurances to the applicant), so this does not need to know
|
||||
* whether $participantIndex is the applicant.
|
||||
*/
|
||||
public function resolveInsuranceTravelPrice(BookingDto $bookingDto, int $participantIndex, Insurance $insurance): float
|
||||
{
|
||||
if (true === $insurance->familyInsurance) {
|
||||
return $this->calculateTotalBookingPriceExcludingInsurance($bookingDto);
|
||||
}
|
||||
|
||||
return $this->calculateIndividualParticipantPriceExcludingInsurance($bookingDto, $participantIndex);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user