feat: bulk insurance booking by applicant
This commit is contained in:
@@ -63,8 +63,8 @@ class InsuranceMatchingService
|
||||
*/
|
||||
public function reassignInsuranceForPriceChange(array $availableInsurances, Insurance $currentInsurance, ParticipantDto $participant, BookingCreateDto $booking): ?Insurance
|
||||
{
|
||||
// Group insurances of the same type (subType + familyInsurance)
|
||||
$sameTypeInsurances = $this->filterInsurancesByType($availableInsurances, $currentInsurance->subType, $currentInsurance->familyInsurance);
|
||||
// Group insurances of the same type
|
||||
$sameTypeInsurances = $this->filterInsurancesByType($availableInsurances, $currentInsurance);
|
||||
|
||||
// Get eligible insurances for this participant
|
||||
$eligibleInsurances = $this->getEligibleInsurances($sameTypeInsurances, $participant, $booking);
|
||||
@@ -96,8 +96,8 @@ class InsuranceMatchingService
|
||||
{
|
||||
$assignments = [];
|
||||
|
||||
// Group insurances of the same type (subType + familyInsurance)
|
||||
$sameTypeInsurances = $this->filterInsurancesByType($availableInsurances, $selectedInsurance->subType, $selectedInsurance->familyInsurance);
|
||||
// Group insurances of the same type
|
||||
$sameTypeInsurances = $this->filterInsurancesByType($availableInsurances, $selectedInsurance);
|
||||
|
||||
// Assign appropriate insurance to each participant
|
||||
foreach ($booking->getParticipants() as $index => $participant) {
|
||||
@@ -329,22 +329,39 @@ class InsuranceMatchingService
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters insurances by type (subType and familyInsurance combination).
|
||||
* Filters insurances by type based on label (for packages) or subType (for individual insurances).
|
||||
*
|
||||
* This method groups insurances of the same type together for reassignment or batch assignment.
|
||||
* Insurance type is defined as the combination of subType (RRV, PAK, OHN) and familyInsurance flag.
|
||||
* Insurance type matching strategy:
|
||||
* - **Packages**: Match by label + familyInsurance (packages with same label are different price tiers)
|
||||
* - **Individual insurances**: Match by subType + familyInsurance
|
||||
*
|
||||
* @param array<Insurance> $insurances All available insurances to filter
|
||||
* @param string|null $subType The insurance subType to match (e.g., 'RRV', 'PAK')
|
||||
* @param bool $familyInsurance Whether to match family or individual insurances
|
||||
* 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 Insurance $referenceInsurance The insurance to match against
|
||||
*
|
||||
* @return array<Insurance> Filtered insurances of the same type
|
||||
*/
|
||||
private function filterInsurancesByType(array $insurances, ?string $subType, bool $familyInsurance): array
|
||||
private function filterInsurancesByType(array $insurances, Insurance $referenceInsurance): array
|
||||
{
|
||||
// For packages, match by label (packages with same label are different price tiers of same type)
|
||||
if (true === $referenceInsurance->package) {
|
||||
return array_filter(
|
||||
$insurances,
|
||||
fn (Insurance $insurance) => true === $insurance->package
|
||||
&& $insurance->label === $referenceInsurance->label
|
||||
&& $insurance->familyInsurance === $referenceInsurance->familyInsurance
|
||||
);
|
||||
}
|
||||
|
||||
// For individual insurances, match by subType
|
||||
return array_filter(
|
||||
$insurances,
|
||||
fn (Insurance $insurance) => $insurance->subType === $subType && $insurance->familyInsurance === $familyInsurance
|
||||
fn (Insurance $insurance) => false === $insurance->package
|
||||
&& $insurance->subType === $referenceInsurance->subType
|
||||
&& $insurance->familyInsurance === $referenceInsurance->familyInsurance
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user