wip: insurance booking in edit flow
This commit is contained in:
@@ -60,6 +60,10 @@ class BookingEditDto implements BookingDtoInterface
|
||||
$pickup = $booking->getPickupForParticipant($index);
|
||||
$participantData->pickup = $pickup;
|
||||
|
||||
// Insurance - get insurance for participant
|
||||
$insurance = $booking->getInsuranceForParticipant($index);
|
||||
$participantData->insurance = $insurance;
|
||||
|
||||
// Room assignment - extract from booking room mappings
|
||||
$room = $booking->getRoomForParticipant($index);
|
||||
$participantData->assignedRoomId = $room?->id;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\Model\BookingEditDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that determines if insurance fields are editable based on booking and travel dates.
|
||||
*
|
||||
* Implements time-based mutability constraints for insurance booking in the edit flow:
|
||||
* - Standard case: Insurance editable up to 30 days before travel date
|
||||
* - Late booking case: If booking made < 30 days before travel, insurance editable up to 3 days after booking date
|
||||
*/
|
||||
class InsuranceMutabilityCondition implements FieldConditionInterface
|
||||
{
|
||||
private const DAYS_BEFORE_TRAVEL_THRESHOLD = 30;
|
||||
private const DAYS_AFTER_BOOKING_THRESHOLD = 3;
|
||||
|
||||
/**
|
||||
* Evaluates whether the insurance field should be readonly.
|
||||
*
|
||||
* Returns true if the field should be readonly (locked), false if editable.
|
||||
*
|
||||
* Logic:
|
||||
* 1. Always editable in create flow
|
||||
* 2. In edit flow, check standard case: editable if >= 30 days before travel
|
||||
* 3. In edit flow, check late booking case: editable if within 3 days of booking date
|
||||
* 4. Otherwise: readonly
|
||||
*
|
||||
* @param BookingDtoInterface $bookingDto The current booking data
|
||||
* @param int $participantIndex The participant index (unused for insurance mutability)
|
||||
* @param array<string, mixed> $formData Current form data (unused for insurance mutability)
|
||||
*
|
||||
* @return bool True if field should be readonly, false if editable
|
||||
*/
|
||||
public function evaluate(BookingDtoInterface $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
// Only apply mutability constraints to edit flow
|
||||
if (!$bookingDto instanceof BookingEditDto) {
|
||||
return false; // Always editable in create flow
|
||||
}
|
||||
|
||||
$now = \Carbon\Carbon::now()->toDateTimeImmutable();
|
||||
$travelDate = $bookingDto->travel->dateFrom;
|
||||
$bookingDate = $bookingDto->booking->bookingDate;
|
||||
|
||||
// Calculate days until travel
|
||||
$daysUntilTravel = $now->diff($travelDate)->days;
|
||||
$isBeforeTravel = $now < $travelDate;
|
||||
|
||||
// Standard case: Editable if >= 30 days before travel
|
||||
if ($isBeforeTravel && $daysUntilTravel >= self::DAYS_BEFORE_TRAVEL_THRESHOLD) {
|
||||
return false; // Editable
|
||||
}
|
||||
|
||||
// Late booking case: Check if booking was made < 30 days before travel
|
||||
$daysFromBookingToTravel = $bookingDate->diff($travelDate)->days;
|
||||
$wasLateBooking = $daysFromBookingToTravel < self::DAYS_BEFORE_TRAVEL_THRESHOLD;
|
||||
|
||||
if ($wasLateBooking) {
|
||||
// Editable if within 3 days of booking date
|
||||
$daysSinceBooking = $bookingDate->diff($now)->days;
|
||||
|
||||
return $daysSinceBooking > self::DAYS_AFTER_BOOKING_THRESHOLD; // True = readonly (past threshold)
|
||||
}
|
||||
|
||||
// Default: Not editable (readonly)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field names that trigger re-evaluation of this condition.
|
||||
*
|
||||
* Insurance mutability is based on dates, not other form fields,
|
||||
* so no field dependencies are needed.
|
||||
*
|
||||
* @return string[] Empty array - no field dependencies
|
||||
*/
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable description of this condition.
|
||||
*
|
||||
* @return string Description of the insurance mutability logic
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return sprintf(
|
||||
'Insurance is not editable (>= %d days before travel or > %d days after late booking)',
|
||||
self::DAYS_BEFORE_TRAVEL_THRESHOLD,
|
||||
self::DAYS_AFTER_BOOKING_THRESHOLD
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user