wip: improved insurance selection

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 16c239716b
commit 4489169553
6 changed files with 91 additions and 17 deletions
+5 -1
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Service;
use App\BusProNet\Model\Insurance;
use App\BusProNet\Traits\SortByPriceTrait;
use App\Form\Model\BookingCreateDto;
use App\Form\Model\ParticipantDto;
use App\Model\InsuranceEligibilityCriteria;
@@ -19,6 +20,7 @@ use Carbon\Carbon;
*/
class InsuranceMatchingService
{
use SortByPriceTrait;
public function __construct(
private readonly BookingPriceCalculatorService $priceCalculatorService,
) {
@@ -41,10 +43,12 @@ class InsuranceMatchingService
return []; // Cannot match insurances without travel dates
}
return array_filter(
$eligibleInsurances = array_filter(
$insurances,
fn (Insurance $insurance) => $this->isInsuranceEligible($insurance, $criteria)
);
return $this->sortByPrice($eligibleInsurances);
}
/**
@@ -81,7 +81,7 @@ class ParticipantEligibilityService
$travelStartDate = CarbonImmutable::instance($bookingDto->travel->dateFrom);
$birthDate = CarbonImmutable::instance($participant->dateOfBirth);
$ageAtTravelStart = $travelStartDate->diffInYears($birthDate);
$ageAtTravelStart = $birthDate->diffInYears($travelStartDate);
$birthYear = (int) $birthDate->format('Y');
$constraintType = $service->ageConstraintType ?? 'absolute_age';