feat: correct determination of inquiry status and conditional voucher field display
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service\Condition;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Contract\FieldConditionInterface;
|
||||
|
||||
/**
|
||||
* Condition that checks if the booking is a final booking (not an inquiry).
|
||||
*
|
||||
* This condition is used to exclude certain fields (like vouchers) from inquiry
|
||||
* bookings where they are not applicable. When a booking has inquiry status ('A'),
|
||||
* fields with this condition will be excluded from the form.
|
||||
*/
|
||||
class FinalBookingOnlyCondition implements FieldConditionInterface
|
||||
{
|
||||
/**
|
||||
* Evaluates if the booking is a final booking.
|
||||
*
|
||||
* @param BookingDto $bookingDto The current booking data (create or edit)
|
||||
* @param int $participantIndex The index of the participant being evaluated
|
||||
* @param array<string, mixed> $formData Current form data (unused)
|
||||
*
|
||||
* @return bool True if booking status is 'F' (final), false if 'A' (inquiry)
|
||||
*/
|
||||
public function evaluate(BookingDto $bookingDto, int $participantIndex, array $formData): bool
|
||||
{
|
||||
return 'F' === $bookingDto->bookingStatus;
|
||||
}
|
||||
|
||||
public function getDependentFields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Only available for final bookings (not inquiry bookings)';
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ use App\Form\Service\Condition\BulkInsuranceBookingCondition;
|
||||
use App\Form\Service\Condition\CompositeCondition;
|
||||
use App\Form\Service\Condition\DateOfBirthProvidedCondition;
|
||||
use App\Form\Service\Condition\FieldValueCondition;
|
||||
use App\Form\Service\Condition\FinalBookingOnlyCondition;
|
||||
use App\Form\Service\Condition\RentalSelectionCondition;
|
||||
use App\Form\Service\Condition\RoomSelectionCondition;
|
||||
use App\Form\Service\Condition\ServiceSubTypeCondition;
|
||||
@@ -267,9 +268,17 @@ class CreateFieldStateProvider extends AbstractFieldStateProvider
|
||||
'static_text' => new SingleRoomTypeCondition(),
|
||||
];
|
||||
|
||||
// Voucher fields (purchaseVoucherCode, promoVoucherCode) have no state conditions
|
||||
// They are enabled by default for all participants in create mode
|
||||
// No visibility rules - always shown to allow optional voucher entry
|
||||
// Voucher fields - hidden for inquiry bookings (status='A')
|
||||
// Vouchers cannot be redeemed or submitted for inquiry bookings
|
||||
$finalBookingOnlyCondition = new FinalBookingOnlyCondition();
|
||||
|
||||
$this->fieldStateConditions['purchaseVoucherCode'] = [
|
||||
'hidden' => CompositeCondition::not($finalBookingOnlyCondition),
|
||||
];
|
||||
|
||||
$this->fieldStateConditions['promoVoucherCode'] = [
|
||||
'hidden' => CompositeCondition::not($finalBookingOnlyCondition),
|
||||
];
|
||||
|
||||
// Example field state conditions would be registered here
|
||||
// For demonstration purposes, here are some example patterns:
|
||||
|
||||
Reference in New Issue
Block a user