feat: offer contact validation flow
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups\Offer;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Htmx\HxTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SymfonyAbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
abstract class AbstractController extends SymfonyAbstractController
|
||||
{
|
||||
use HxTrait;
|
||||
|
||||
/**
|
||||
* A draft and an inquiry the office has not worked through yet are not ready to be
|
||||
* shown, and a discarded booking must not be viewable any more — in all three cases
|
||||
* the link behaves as if it had expired.
|
||||
*/
|
||||
protected function isCustomerVisible(AccommodationBooking $booking): bool
|
||||
{
|
||||
return $booking->isCustomerAccessible() && !$booking->isRequested() && !$booking->isDiscarded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the browser to a full reload of the (non-modal) offer page — this is
|
||||
* triggered from an htmx-loaded modal, so a plain render/redirect here would
|
||||
* get appended as an inert HTML fragment instead of actually navigating.
|
||||
*/
|
||||
protected function redirectToOfferPage(Request $request, string $uuid): Response
|
||||
{
|
||||
$url = $this->generateUrl('app_groups_offer_view', ['uuid' => $uuid]);
|
||||
|
||||
return $this->htmxRedirect($request, $url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups\Offer;
|
||||
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use App\Form\OfferAcceptConfirmationType;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationTermsUrlProvider;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ConfirmController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingRepository $bookingRepository,
|
||||
private readonly AccommodationBookingLinkSigner $linkSigner,
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly AccommodationTermsUrlProvider $termsUrlProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/groups/booking/offer/{uuid}/confirm', name: 'app_groups_offer_confirm', methods: ['GET', 'POST'])]
|
||||
public function index(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
if (null === $booking || false === $this->linkSigner->isSessionAuthorized($request, $booking)) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
// Offen is the one status that means an offer is out and awaiting acceptance, so it
|
||||
// is the whole guard — mirroring acceptBooking(), which no-ops on anything else.
|
||||
if (!$booking->isOpen()) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
// Checked for POST as well, so the modal cannot be submitted around the contact page.
|
||||
if (!$this->bookingService->hasCompleteContactData($booking)) {
|
||||
return $this->htmxRedirect($request, $this->generateUrl('app_groups_offer_contact', ['uuid' => $uuid]));
|
||||
}
|
||||
|
||||
$dto = new OfferAcceptDto(remarks: $booking->getRemarks());
|
||||
$confirmationForm = $this->createForm(OfferAcceptConfirmationType::class, $dto, [
|
||||
'terms_url' => $this->termsUrlProvider->forAccommodation($booking->getAccommodation()),
|
||||
]);
|
||||
$confirmationForm->handleRequest($request);
|
||||
|
||||
if ($confirmationForm->isSubmitted() && $confirmationForm->isValid()) {
|
||||
// The textarea is prefilled, so the submitted value is the complete remark —
|
||||
// an emptied field arrives as null and must clear the stored one, not keep it.
|
||||
$this->bookingService->acceptBooking($booking, $dto->remarks ?? '');
|
||||
$this->addFlash('success', 'Deine Buchung ist bei uns eingegangen. Sobald sie geprüft ist, erhältst du eine Bestätigung per E-Mail.');
|
||||
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
return $this->render('groups/offer/modal_accept_confirmation.html.twig', [
|
||||
'booking' => $booking,
|
||||
'confirmationForm' => $confirmationForm,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups\Offer;
|
||||
|
||||
use App\Form\AccommodationContactType;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ContactController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingRepository $bookingRepository,
|
||||
private readonly AccommodationBookingLinkSigner $linkSigner,
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full page rather than modal: the form is as large as step 3 of a self-service booking,
|
||||
* whose fields and constraints it shares. Once saved, the customer is back on the offer
|
||||
* and accepts it from there as usual.
|
||||
*/
|
||||
#[Route(path: '/groups/booking/offer/{uuid}/contact', name: 'app_groups_offer_contact', methods: ['GET', 'POST'])]
|
||||
public function index(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
if (null === $booking || false === $this->linkSigner->isSessionAuthorized($request, $booking)) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
if (!$booking->isOpen()) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
$dto = $this->bookingService->contactDataFromBooking($booking);
|
||||
$form = $this->createForm(AccommodationContactType::class, $dto, [
|
||||
'email_readonly' => true,
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->bookingService->applyContactData($booking, $dto);
|
||||
$this->addFlash('success', 'Deine Kontaktdaten wurden gespeichert. Du kannst die Buchung jetzt abschließen.');
|
||||
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
$accommodation = $booking->getAccommodation() ?? throw $this->createNotFoundException('Booking has no accommodation.');
|
||||
$ctx = $this->bookingService->createOfferContext($booking, $accommodation);
|
||||
|
||||
return $this->render('groups/offer/contact.html.twig', [
|
||||
'booking' => $booking,
|
||||
'priceBreakdown' => $ctx->priceBreakdown,
|
||||
'ctx' => $ctx,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups\Offer;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Form\Model\OfferAcceptDto;
|
||||
use App\Form\OfferAcceptConfirmationType;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Model\AccommodationBookingContext;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationTermsUrlProvider;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -22,14 +13,9 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
use HxTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingRepository $bookingRepository,
|
||||
private readonly AccommodationBookingLinkSigner $linkSigner,
|
||||
private readonly AccommodationBookingBreakdownCalculator $breakdownCalculator,
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly AccommodationTermsUrlProvider $termsUrlProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -39,7 +25,7 @@ class IndexController extends AbstractController
|
||||
* (session-gated) offer page — nothing downstream needs the signature again.
|
||||
*/
|
||||
#[Route(path: '/groups/booking/offer/{uuid}', name: 'app_groups_offer', methods: ['GET'])]
|
||||
public function access(string $uuid, Request $request): Response
|
||||
public function index(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
@@ -55,91 +41,4 @@ class IndexController extends AbstractController
|
||||
|
||||
return new RedirectResponse($this->generateUrl('app_groups_offer_view', ['uuid' => $uuid]));
|
||||
}
|
||||
|
||||
#[Route(path: '/groups/booking/offer/{uuid}/view', name: 'app_groups_offer_view', methods: ['GET'])]
|
||||
public function view(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
if (null === $booking || false === $this->linkSigner->isSessionAuthorized($request, $booking)) {
|
||||
return $this->render('groups/offer/unavailable.html.twig');
|
||||
}
|
||||
|
||||
if (!$this->isCustomerVisible($booking)) {
|
||||
return $this->render('groups/offer/unavailable.html.twig');
|
||||
}
|
||||
|
||||
$accommodation = $booking->getAccommodation() ?? throw $this->createNotFoundException('Booking has no accommodation.');
|
||||
$priceBreakdown = $this->breakdownCalculator->compute($booking);
|
||||
|
||||
$ctx = new AccommodationBookingContext(
|
||||
accommodation: $accommodation,
|
||||
hotelCmsData: $this->bookingService->loadHotelCmsData($accommodation),
|
||||
priceBreakdown: $priceBreakdown,
|
||||
);
|
||||
|
||||
return $this->render('groups/offer/view.html.twig', [
|
||||
'booking' => $booking,
|
||||
'priceBreakdown' => $priceBreakdown,
|
||||
'ctx' => $ctx,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/groups/booking/offer/{uuid}/confirm', name: 'app_groups_offer_confirm', methods: ['GET', 'POST'])]
|
||||
public function confirm(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
if (null === $booking || false === $this->linkSigner->isSessionAuthorized($request, $booking)) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
// Offen is the one status that means an offer is out and awaiting acceptance, so it
|
||||
// is the whole guard — mirroring acceptBooking(), which no-ops on anything else.
|
||||
if (!$booking->isOpen()) {
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
$dto = new OfferAcceptDto(remarks: $booking->getRemarks());
|
||||
$confirmationForm = $this->createForm(OfferAcceptConfirmationType::class, $dto, [
|
||||
'terms_url' => $this->termsUrlProvider->forAccommodation($booking->getAccommodation()),
|
||||
]);
|
||||
$confirmationForm->handleRequest($request);
|
||||
|
||||
if ($confirmationForm->isSubmitted() && $confirmationForm->isValid()) {
|
||||
// The textarea is prefilled, so the submitted value is the complete remark —
|
||||
// an emptied field arrives as null and must clear the stored one, not keep it.
|
||||
$this->bookingService->acceptBooking($booking, $dto->remarks ?? '');
|
||||
$this->addFlash('success', 'Deine Buchung ist bei uns eingegangen. Sobald sie geprüft ist, erhältst du eine Bestätigung per E-Mail.');
|
||||
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
return $this->render('groups/offer/modal_accept_confirmation.html.twig', [
|
||||
'booking' => $booking,
|
||||
'confirmationForm' => $confirmationForm,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A draft and an inquiry the office has not worked through yet are not ready to be
|
||||
* shown, and a discarded booking must not be viewable any more — in all three cases
|
||||
* the link behaves as if it had expired.
|
||||
*/
|
||||
private function isCustomerVisible(AccommodationBooking $booking): bool
|
||||
{
|
||||
return $booking->isCustomerAccessible() && !$booking->isRequested() && !$booking->isDiscarded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the browser to a full reload of the (non-modal) offer page — this is
|
||||
* triggered from an htmx-loaded modal, so a plain render/redirect here would
|
||||
* get appended as an inert HTML fragment instead of actually navigating.
|
||||
*/
|
||||
private function redirectToOfferPage(Request $request, string $uuid): Response
|
||||
{
|
||||
$url = $this->generateUrl('app_groups_offer_view', ['uuid' => $uuid]);
|
||||
|
||||
return $this->htmxRedirect($request, $url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Groups\Offer;
|
||||
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingLinkSigner;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class ViewController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingRepository $bookingRepository,
|
||||
private readonly AccommodationBookingLinkSigner $linkSigner,
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(path: '/groups/booking/offer/{uuid}/view', name: 'app_groups_offer_view', methods: ['GET'])]
|
||||
public function index(string $uuid, Request $request): Response
|
||||
{
|
||||
$booking = $this->bookingRepository->findOneBy(['uuid' => $uuid]);
|
||||
|
||||
if (null === $booking || false === $this->linkSigner->isSessionAuthorized($request, $booking)) {
|
||||
return $this->render('groups/offer/unavailable.html.twig');
|
||||
}
|
||||
|
||||
if (!$this->isCustomerVisible($booking)) {
|
||||
return $this->render('groups/offer/unavailable.html.twig');
|
||||
}
|
||||
|
||||
$accommodation = $booking->getAccommodation() ?? throw $this->createNotFoundException('Booking has no accommodation.');
|
||||
$ctx = $this->bookingService->createOfferContext($booking, $accommodation);
|
||||
|
||||
return $this->render('groups/offer/view.html.twig', [
|
||||
'booking' => $booking,
|
||||
'priceBreakdown' => $ctx->priceBreakdown,
|
||||
'ctx' => $ctx,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* The contact data of a group booking — shared by step 3 of the self-service flow and by
|
||||
* the page that completes an office-made offer before it can be accepted, so both ask
|
||||
* for the same fields under the same constraints.
|
||||
*
|
||||
* @extends AbstractType<AccommodationBookingDto>
|
||||
*/
|
||||
class AccommodationContactType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('groupName', TextType::class, [
|
||||
'label' => 'Name der Gruppe',
|
||||
])
|
||||
->add('salutation', ChoiceType::class, [
|
||||
'label' => 'Anrede',
|
||||
'choices' => [
|
||||
'Herr' => 'Herr',
|
||||
'Frau' => 'Frau',
|
||||
'divers' => 'divers',
|
||||
],
|
||||
'expanded' => false,
|
||||
'multiple' => false,
|
||||
'placeholder' => 'Bitte wählen',
|
||||
])
|
||||
->add('firstName', TextType::class, [
|
||||
'label' => 'Vorname',
|
||||
])
|
||||
->add('lastName', TextType::class, [
|
||||
'label' => 'Nachname',
|
||||
])
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail-Adresse',
|
||||
// An offer's access link and every notification already go to this address.
|
||||
'disabled' => $options['email_readonly'],
|
||||
])
|
||||
->add('phone', TextType::class, [
|
||||
'label' => 'Telefon',
|
||||
])
|
||||
->add('street', TextType::class, [
|
||||
'label' => 'Straße und Hausnummer',
|
||||
])
|
||||
->add('zip', TextType::class, [
|
||||
'label' => 'Postleitzahl',
|
||||
])
|
||||
->add('city', TextType::class, [
|
||||
'label' => 'Ort',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AccommodationBookingDto::class,
|
||||
'validation_groups' => ['contact'],
|
||||
'email_readonly' => false,
|
||||
]);
|
||||
$resolver->setAllowedTypes('email_readonly', 'bool');
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ namespace App\Form;
|
||||
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@@ -21,41 +18,6 @@ class AccommodationStep3Type extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('groupName', TextType::class, [
|
||||
'label' => 'Name der Gruppe',
|
||||
])
|
||||
->add('salutation', ChoiceType::class, [
|
||||
'label' => 'Anrede',
|
||||
'choices' => [
|
||||
'Herr' => 'Herr',
|
||||
'Frau' => 'Frau',
|
||||
'divers' => 'divers',
|
||||
],
|
||||
'expanded' => false,
|
||||
'multiple' => false,
|
||||
'placeholder' => 'Bitte wählen',
|
||||
])
|
||||
->add('firstName', TextType::class, [
|
||||
'label' => 'Vorname',
|
||||
])
|
||||
->add('lastName', TextType::class, [
|
||||
'label' => 'Nachname',
|
||||
])
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail-Adresse',
|
||||
])
|
||||
->add('phone', TextType::class, [
|
||||
'label' => 'Telefon',
|
||||
])
|
||||
->add('street', TextType::class, [
|
||||
'label' => 'Straße und Hausnummer',
|
||||
])
|
||||
->add('zip', TextType::class, [
|
||||
'label' => 'Postleitzahl',
|
||||
])
|
||||
->add('city', TextType::class, [
|
||||
'label' => 'Ort',
|
||||
])
|
||||
->add('remarks', TextareaType::class, [
|
||||
'label' => false,
|
||||
'required' => false,
|
||||
@@ -71,4 +33,9 @@ class AccommodationStep3Type extends AbstractType
|
||||
'validation_groups' => ['step_3'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function getParent(): string
|
||||
{
|
||||
return AccommodationContactType::class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,33 +43,35 @@ class AccommodationBookingDto
|
||||
/** @var array<string, mixed> */
|
||||
public array $priceBreakdown = [];
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
// `contact` is the subset an office-made offer is checked against before the customer
|
||||
// may accept it — the same constraints the customer meets in step 3 of a self-service booking.
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $groupName = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\Choice(choices: ['Herr', 'Frau', 'divers'], groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
#[Assert\Choice(choices: ['Herr', 'Frau', 'divers'], groups: ['step_3', 'contact'])]
|
||||
public ?string $salutation = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $firstName = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $lastName = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\Email(message: 'invalid', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
#[Assert\Email(message: 'invalid', groups: ['step_3', 'contact'])]
|
||||
public ?string $email = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $phone = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $street = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $zip = null;
|
||||
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3'])]
|
||||
#[Assert\NotBlank(message: 'required', groups: ['step_3', 'contact'])]
|
||||
public ?string $city = null;
|
||||
|
||||
public ?string $remarks = null;
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Entity\Groups\BoardService;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\AccommodationBookingContext;
|
||||
use App\Model\AccommodationBookingQueryParams;
|
||||
use App\Model\CmsHotelData;
|
||||
use App\Model\InquiryStatus;
|
||||
@@ -23,6 +24,7 @@ use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class AccommodationBookingService
|
||||
{
|
||||
@@ -41,6 +43,7 @@ class AccommodationBookingService
|
||||
private readonly AccommodationBookingLinkSigner $linkSigner,
|
||||
private readonly AccommodationBookingBreakdownCalculator $breakdownCalculator,
|
||||
private readonly AccommodationBookingPdfGenerator $pdfGenerator,
|
||||
private readonly ValidatorInterface $validator,
|
||||
private readonly string $accommodationEmail,
|
||||
) {
|
||||
}
|
||||
@@ -115,6 +118,19 @@ class AccommodationBookingService
|
||||
return $this->cmsDataProvider->getHotelDetails($accommodation->getEffectiveCmsCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* What the customer-facing offer pages show around a stored booking: the hotel's CMS
|
||||
* content and the price breakdown computed from the booking's frozen snapshot.
|
||||
*/
|
||||
public function createOfferContext(AccommodationBooking $booking, Accommodation $accommodation): AccommodationBookingContext
|
||||
{
|
||||
return new AccommodationBookingContext(
|
||||
accommodation: $accommodation,
|
||||
hotelCmsData: $this->loadHotelCmsData($accommodation),
|
||||
priceBreakdown: $this->breakdownCalculator->compute($booking),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccommodationPrice[]
|
||||
*/
|
||||
@@ -262,7 +278,6 @@ class AccommodationBookingService
|
||||
): AccommodationBooking {
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setAccommodation($accommodation);
|
||||
$booking->setGroupName($dto->groupName);
|
||||
$booking->setDateFrom($dto->dateFrom);
|
||||
$booking->setDateTo($dto->dateTo);
|
||||
$booking->setPaxCount($dto->paxCount);
|
||||
@@ -305,15 +320,7 @@ class AccommodationBookingService
|
||||
);
|
||||
}
|
||||
|
||||
// Personal data
|
||||
$booking->setSalutation($dto->salutation);
|
||||
$booking->setFirstName($dto->firstName);
|
||||
$booking->setLastName($dto->lastName);
|
||||
$booking->setEmail($dto->email);
|
||||
$booking->setPhone($dto->phone);
|
||||
$booking->setStreet($dto->street);
|
||||
$booking->setZip($dto->zip);
|
||||
$booking->setCity($dto->city);
|
||||
$this->copyContactData($dto, $booking);
|
||||
$booking->setRemarks($dto->remarks);
|
||||
|
||||
$this->refreshPriceSnapshot($booking);
|
||||
@@ -627,6 +634,51 @@ class AccommodationBookingService
|
||||
$this->sendOfferAcceptedNotificationEmail($booking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Offers are put together by the office, which only has to supply name and email, so
|
||||
* the rest of the contact data is often missing. A customer may accept an offer once it
|
||||
* meets the constraints a self-service booking meets in step 3.
|
||||
*/
|
||||
public function hasCompleteContactData(AccommodationBooking $booking): bool
|
||||
{
|
||||
return 0 === $this->validator->validate($this->contactDataFromBooking($booking), null, ['contact'])->count();
|
||||
}
|
||||
|
||||
public function contactDataFromBooking(AccommodationBooking $booking): AccommodationBookingDto
|
||||
{
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->groupName = $booking->getGroupName();
|
||||
$dto->salutation = $booking->getSalutation();
|
||||
$dto->firstName = $booking->getFirstName();
|
||||
$dto->lastName = $booking->getLastName();
|
||||
$dto->email = $booking->getEmail();
|
||||
$dto->phone = $booking->getPhone();
|
||||
$dto->street = $booking->getStreet();
|
||||
$dto->zip = $booking->getZip();
|
||||
$dto->city = $booking->getCity();
|
||||
|
||||
return $dto;
|
||||
}
|
||||
|
||||
public function applyContactData(AccommodationBooking $booking, AccommodationBookingDto $dto): void
|
||||
{
|
||||
$this->copyContactData($dto, $booking);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
private function copyContactData(AccommodationBookingDto $dto, AccommodationBooking $booking): void
|
||||
{
|
||||
$booking->setGroupName($dto->groupName);
|
||||
$booking->setSalutation($dto->salutation);
|
||||
$booking->setFirstName($dto->firstName);
|
||||
$booking->setLastName($dto->lastName);
|
||||
$booking->setEmail($dto->email);
|
||||
$booking->setPhone($dto->phone);
|
||||
$booking->setStreet($dto->street);
|
||||
$booking->setZip($dto->zip);
|
||||
$booking->setCity($dto->city);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicit office action after the requested services and capacities have been validated:
|
||||
* this is the moment the booking becomes binding for the customer, and the only place the
|
||||
|
||||
Reference in New Issue
Block a user