wip: improved insurance selection
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user