wip: insurance booking

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 29bdf794f3
commit e6eebc00a3
4 changed files with 76 additions and 40 deletions
+21 -12
View File
@@ -35,6 +35,10 @@ class ServiceAgeEvaluator
* constraint requirements. Returns false if the participant doesn't
* meet the age requirements or if no birth date is provided.
*
* Age constraints are evaluated at the travel start date to ensure
* that services are appropriately filtered based on the participant's
* age at the time of travel, not their current age.
*
* @param Service $service The service to evaluate
* @param BookingDtoInterface $bookingDto The booking containing participant data
* @param int $participantIndex The index of the participant to evaluate
@@ -49,26 +53,30 @@ class ServiceAgeEvaluator
return false; // Cannot evaluate without birth date
}
// Use travel start date as reference for absolute age calculations
$travelStartDate = $bookingDto->travel->dateFrom;
return match ($service->ageConstraintType) {
'absolute_age' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth),
'absolute_age' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth, $travelStartDate),
'birth_year' => $this->evaluateBirthYear($service, $participant->dateOfBirth),
'mixed' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth)
'mixed' => $this->evaluateAbsoluteAge($service, $participant->dateOfBirth, $travelStartDate)
&& $this->evaluateBirthYear($service, $participant->dateOfBirth),
default => true, // No constraints or unknown type
};
}
/**
* Evaluates absolute age constraints against participant's current age.
* Evaluates absolute age constraints against participant's age at travel date.
*
* @param Service $service The service with age constraints
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
* @param Service $service The service with age constraints
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
* @param \DateTimeImmutable|null $referenceDate The reference date for age calculation (travel start date)
*
* @return bool True if the participant meets the absolute age requirements
*/
private function evaluateAbsoluteAge(Service $service, \DateTimeImmutable $dateOfBirth): bool
private function evaluateAbsoluteAge(Service $service, \DateTimeImmutable $dateOfBirth, ?\DateTimeImmutable $referenceDate = null): bool
{
$age = $this->calculateAge($dateOfBirth);
$age = $this->calculateAge($dateOfBirth, $referenceDate);
if (null !== $service->ageFrom && $age < $service->ageFrom) {
return false;
@@ -105,20 +113,21 @@ class ServiceAgeEvaluator
}
/**
* Calculates age in years from a date of birth.
* Calculates age in years from a date of birth at a reference date.
*
* Uses DateTimeImmutable to ensure accurate age calculations accounting
* for leap years and exact birth date anniversaries.
*
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
* @param \DateTimeImmutable $dateOfBirth The participant's date of birth
* @param \DateTimeImmutable|null $referenceDate The reference date for age calculation (defaults to today)
*
* @return int The calculated age in complete years
*/
private function calculateAge(\DateTimeImmutable $dateOfBirth): int
private function calculateAge(\DateTimeImmutable $dateOfBirth, ?\DateTimeImmutable $referenceDate = null): int
{
$today = new \DateTimeImmutable();
$referenceDate = $referenceDate ?? new \DateTimeImmutable();
return $dateOfBirth->diff($today)->y;
return $dateOfBirth->diff($referenceDate)->y;
}
/**