wip: modernized edit flow
This commit is contained in:
@@ -7,6 +7,7 @@ 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;
|
||||
use Carbon\Carbon;
|
||||
@@ -21,6 +22,7 @@ use Carbon\Carbon;
|
||||
class InsuranceMatchingService
|
||||
{
|
||||
use SortByPriceTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly BookingPriceCalculatorService $priceCalculatorService,
|
||||
) {
|
||||
@@ -29,13 +31,13 @@ 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 BookingCreateDto $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
|
||||
*/
|
||||
public function getEligibleInsurances(array $insurances, ParticipantDto $participant, BookingCreateDto $booking): array
|
||||
public function getEligibleInsurances(array $insurances, ParticipantDto $participant, BookingDto $booking): array
|
||||
{
|
||||
$criteria = $this->createEligibilityCriteria($participant, $booking);
|
||||
|
||||
@@ -58,14 +60,14 @@ 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 BookingCreateDto $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
|
||||
*/
|
||||
public function reassignInsuranceForPriceChange(array $availableInsurances, Insurance $currentInsurance, ParticipantDto $participant, BookingCreateDto $booking): ?Insurance
|
||||
public function reassignInsuranceForPriceChange(array $availableInsurances, Insurance $currentInsurance, ParticipantDto $participant, BookingDto $booking): ?Insurance
|
||||
{
|
||||
// Group insurances of the same type
|
||||
$sameTypeInsurances = $this->filterInsurancesByType($availableInsurances, $currentInsurance);
|
||||
@@ -88,15 +90,15 @@ 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 BookingCreateDto $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
|
||||
*
|
||||
* @internal Reserved for future feature implementation
|
||||
*/
|
||||
public function batchAssignInsuranceToParticipants(array $availableInsurances, Insurance $selectedInsurance, BookingCreateDto $booking): array
|
||||
public function batchAssignInsuranceToParticipants(array $availableInsurances, Insurance $selectedInsurance, BookingDto $booking): array
|
||||
{
|
||||
$assignments = [];
|
||||
|
||||
@@ -118,7 +120,7 @@ class InsuranceMatchingService
|
||||
* This method performs early validation before creating the criteria object
|
||||
* to avoid unnecessary object instantiation when criteria cannot be satisfied.
|
||||
*/
|
||||
private function createEligibilityCriteria(ParticipantDto $participant, BookingCreateDto $booking): ?InsuranceEligibilityCriteria
|
||||
private function createEligibilityCriteria(ParticipantDto $participant, BookingDto $booking): ?InsuranceEligibilityCriteria
|
||||
{
|
||||
// Early return if travel dates are missing - cannot evaluate any criteria
|
||||
$travelStartDate = $booking->travel->dateFrom;
|
||||
@@ -183,8 +185,13 @@ class InsuranceMatchingService
|
||||
* Family insurances should only be available for family bookings,
|
||||
* and individual insurances should only be available for non-family bookings.
|
||||
*/
|
||||
private function checkFamilyInsuranceConstraints(Insurance $insurance, BookingCreateDto $booking): bool
|
||||
private function checkFamilyInsuranceConstraints(Insurance $insurance, BookingDto $booking): bool
|
||||
{
|
||||
// Family booking detection only available in BookingCreateDto
|
||||
if (!$booking instanceof BookingCreateDto) {
|
||||
return true; // Skip family constraints for edit mode
|
||||
}
|
||||
|
||||
$isFamilyBooking = $booking->isFamilyBooking();
|
||||
|
||||
// If it's a family insurance, it should only be available for family bookings
|
||||
@@ -308,12 +315,12 @@ class InsuranceMatchingService
|
||||
* It excludes insurance prices to prevent circular dependency where insurance selection
|
||||
* affects travel price which then affects insurance eligibility.
|
||||
*
|
||||
* @param BookingCreateDto $booking The booking to calculate price for
|
||||
* @param int $participantIndex The participant index to calculate for
|
||||
* @param BookingDto $booking The booking to calculate price for
|
||||
* @param int $participantIndex The participant index to calculate for
|
||||
*
|
||||
* @return float The total travel price for the participant excluding insurance
|
||||
*/
|
||||
private function calculateTravelPrice(BookingCreateDto $booking, int $participantIndex): float
|
||||
private function calculateTravelPrice(BookingDto $booking, int $participantIndex): float
|
||||
{
|
||||
// Use the price calculator to get the participant's individual price excluding insurance
|
||||
return $this->priceCalculatorService->calculateIndividualParticipantPriceExcludingInsurance($booking, $participantIndex);
|
||||
@@ -343,7 +350,7 @@ class InsuranceMatchingService
|
||||
* Example: "Reise-Rücktritt + Selbstbehaltübernahme" at €10, €14, €26 are the same type,
|
||||
* but different from "Reiseschutz Platin Auto/Bahn/Bus (Europa) + Selbstbehaltübernahme".
|
||||
*
|
||||
* @param array<Insurance> $insurances All available insurances to filter
|
||||
* @param array<Insurance> $insurances All available insurances to filter
|
||||
* @param Insurance $referenceInsurance The insurance to match against
|
||||
*
|
||||
* @return array<Insurance> Filtered insurances of the same type
|
||||
|
||||
Reference in New Issue
Block a user