feat: additional status
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Controller\Admin\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Admin\Groups\AccommodationBookingType;
|
||||
use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
@@ -75,7 +76,7 @@ class EditController extends AbstractController
|
||||
'current_board_service' => $currentBoardService,
|
||||
'current_additional_services' => $currentAdditionalServices,
|
||||
]);
|
||||
$wasInquiry = $booking->isInquiry();
|
||||
$previousStatus = $booking->getStatus();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
@@ -110,8 +111,11 @@ class EditController extends AbstractController
|
||||
$this->entityManager->persist($booking);
|
||||
$this->entityManager->flush();
|
||||
|
||||
if ($wasInquiry && !$booking->isInquiry()) {
|
||||
$this->bookingService->issueAccessLinkForDirectBooking($booking);
|
||||
// Entering Anfrage or Buchung is what the customer needs to hear about: the offer
|
||||
// becomes viewable, or the booking is confirmed. Entwurf and Absage stay silent.
|
||||
$notifiableStatuses = [AccommodationBookingStatus::Inquiry, AccommodationBookingStatus::Booking];
|
||||
if ($previousStatus !== $booking->getStatus() && in_array($booking->getStatus(), $notifiableStatuses, true)) {
|
||||
$this->bookingService->issueAccessLink($booking);
|
||||
$this->bookingService->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ class OfferController extends AbstractController
|
||||
return $this->render('groups/booking/offer_unavailable.html.twig');
|
||||
}
|
||||
|
||||
if (!$this->isCustomerVisible($booking)) {
|
||||
return $this->render('groups/booking/offer_unavailable.html.twig');
|
||||
}
|
||||
|
||||
$this->linkSigner->authorizeSession($request, $booking);
|
||||
|
||||
return new RedirectResponse($this->generateUrl('app_groups_booking_offer_view', ['uuid' => $uuid]));
|
||||
@@ -58,6 +62,10 @@ class OfferController extends AbstractController
|
||||
return $this->render('groups/booking/offer_unavailable.html.twig');
|
||||
}
|
||||
|
||||
if (!$this->isCustomerVisible($booking)) {
|
||||
return $this->render('groups/booking/offer_unavailable.html.twig');
|
||||
}
|
||||
|
||||
$accommodation = $booking->getAccommodation() ?? throw $this->createNotFoundException('Booking has no accommodation.');
|
||||
$priceBreakdown = $this->breakdownCalculator->compute($booking);
|
||||
|
||||
@@ -105,6 +113,15 @@ class OfferController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A draft is not ready to be shown, and a discarded booking must not be viewable
|
||||
* any more — in both cases the link behaves as if it had expired.
|
||||
*/
|
||||
private function isCustomerVisible(AccommodationBooking $booking): bool
|
||||
{
|
||||
return !$booking->isDraft() && !$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
|
||||
|
||||
@@ -151,7 +151,7 @@ class Step4Controller extends AbstractAccommodationController
|
||||
{
|
||||
$prices = $this->bookingService->loadPrices($dto, $accommodation);
|
||||
$booking = $this->bookingService->finalizeBooking($dto, $accommodation, $prices, $services);
|
||||
$this->addFlash('groups_booking_result', $booking->isInquiry() ? 'inquiry' : 'booking');
|
||||
$this->addFlash('groups_booking_result', $booking->getStatus()->value);
|
||||
$this->sessionManager->clear($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Entity\BlameableEntityInterface;
|
||||
use App\Entity\TimestampableEntity;
|
||||
use App\Entity\TimestampableEntityInterface;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AdditionalServiceType;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -75,8 +76,8 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
#[ORM\Column(type: Types::SMALLINT, nullable: true)]
|
||||
private ?int $pricingVersion = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $isInquiry = false;
|
||||
#[ORM\Column(length: 20, enumType: AccommodationBookingStatus::class)]
|
||||
private AccommodationBookingStatus $status = AccommodationBookingStatus::Draft;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
||||
private ?\DateTimeImmutable $accessLinkIssuedAt = null;
|
||||
@@ -335,18 +336,38 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
return $this->pricingVersion;
|
||||
}
|
||||
|
||||
public function isInquiry(): bool
|
||||
public function getStatus(): AccommodationBookingStatus
|
||||
{
|
||||
return $this->isInquiry;
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setIsInquiry(bool $isInquiry): self
|
||||
public function setStatus(AccommodationBookingStatus $status): self
|
||||
{
|
||||
$this->isInquiry = $isInquiry;
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDraft(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Draft === $this->status;
|
||||
}
|
||||
|
||||
public function isInquiry(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Inquiry === $this->status;
|
||||
}
|
||||
|
||||
public function isBooking(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Booking === $this->status;
|
||||
}
|
||||
|
||||
public function isDiscarded(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Discarded === $this->status;
|
||||
}
|
||||
|
||||
public function getAccessLinkIssuedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->accessLinkIssuedAt;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum\Groups;
|
||||
|
||||
enum AccommodationBookingStatus: string
|
||||
{
|
||||
case Draft = 'draft';
|
||||
case Inquiry = 'inquiry';
|
||||
case Booking = 'booking';
|
||||
case Discarded = 'discarded';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Draft => 'Entwurf',
|
||||
self::Inquiry => 'Anfrage',
|
||||
self::Booking => 'Buchung',
|
||||
self::Discarded => 'Absage',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,11 @@ namespace App\Form\Admin\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
@@ -47,9 +48,15 @@ class AccommodationBookingCreateType extends AbstractType
|
||||
->add('childrenCount', IntegerType::class, [
|
||||
'label' => 'davon Kinder',
|
||||
])
|
||||
->add('isInquiry', CheckboxType::class, [
|
||||
'label' => 'Anfrage (nicht bindend)',
|
||||
'required' => false,
|
||||
->add('status', EnumType::class, [
|
||||
'label' => 'Status',
|
||||
'class' => AccommodationBookingStatus::class,
|
||||
'choices' => [
|
||||
AccommodationBookingStatus::Draft,
|
||||
AccommodationBookingStatus::Inquiry,
|
||||
AccommodationBookingStatus::Booking,
|
||||
],
|
||||
'choice_label' => fn (AccommodationBookingStatus $status) => $status->label(),
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
@@ -7,16 +7,18 @@ namespace App\Form\Admin\Groups;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
|
||||
@@ -25,9 +27,13 @@ class AccommodationBookingType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
// The contact fields carry no HTML5 `required` attribute: a draft must be saveable
|
||||
// while still empty. They are enforced server-side by the `edit` validation group
|
||||
// as soon as the booking leaves Entwurf — see configureOptions().
|
||||
$builder
|
||||
->add('groupName', TextType::class, [
|
||||
'label' => 'Gruppenname',
|
||||
'required' => false,
|
||||
])
|
||||
->add('salutation', ChoiceType::class, [
|
||||
'label' => 'Anrede',
|
||||
@@ -41,12 +47,15 @@ class AccommodationBookingType extends AbstractType
|
||||
])
|
||||
->add('firstName', TextType::class, [
|
||||
'label' => 'Vorname',
|
||||
'required' => false,
|
||||
])
|
||||
->add('lastName', TextType::class, [
|
||||
'label' => 'Nachname',
|
||||
'required' => false,
|
||||
])
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail',
|
||||
'required' => false,
|
||||
])
|
||||
->add('phone', TextType::class, [
|
||||
'label' => 'Telefon',
|
||||
@@ -113,9 +122,10 @@ class AccommodationBookingType extends AbstractType
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('isInquiry', CheckboxType::class, [
|
||||
'label' => 'Anfrage (nicht bindend)',
|
||||
'required' => false,
|
||||
->add('status', EnumType::class, [
|
||||
'label' => 'Status',
|
||||
'class' => AccommodationBookingStatus::class,
|
||||
'choice_label' => fn (AccommodationBookingStatus $status) => $status->label(),
|
||||
])
|
||||
->add('accommodationDiscount', IntegerType::class, [
|
||||
'label' => 'Rabatt Unterkunft (%)',
|
||||
@@ -149,7 +159,18 @@ class AccommodationBookingType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AccommodationBooking::class,
|
||||
'validation_groups' => ['Default', 'edit'],
|
||||
// Entwurf is a scratch record the office fills in over time, and an Absage is
|
||||
// never going anywhere — neither needs complete contact data. The groups are
|
||||
// resolved after binding, so promoting a draft to Anfrage or Buchung enforces
|
||||
// the contact data in the very same save.
|
||||
'validation_groups' => static function (FormInterface $form): array {
|
||||
/** @var AccommodationBooking $booking */
|
||||
$booking = $form->getData();
|
||||
|
||||
return $booking->isDraft() || $booking->isDiscarded()
|
||||
? ['Default']
|
||||
: ['Default', 'edit'];
|
||||
},
|
||||
'max_adolescent_age' => 0,
|
||||
'board_services' => [],
|
||||
'additional_services' => [],
|
||||
|
||||
@@ -88,7 +88,7 @@ final readonly class AccommodationBookingApiResponse
|
||||
public function __construct(AccommodationBooking $booking, ?array $priceBreakdown)
|
||||
{
|
||||
$this->uuid = $booking->getUuid();
|
||||
$this->status = $booking->isInquiry() ? 'inquiry' : 'booking';
|
||||
$this->status = $booking->getStatus()->value;
|
||||
$this->dateFrom = $booking->getDateFrom();
|
||||
$this->dateTo = $booking->getDateTo();
|
||||
$this->nights = $booking->getNights();
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\AccommodationBookingQueryParams;
|
||||
use App\Model\CmsHotelData;
|
||||
@@ -264,7 +265,11 @@ class AccommodationBookingService
|
||||
$booking->setPaxCount($dto->paxCount);
|
||||
$booking->setMinorsCount($dto->minorsCount);
|
||||
$booking->setChildrenCount($dto->childrenCount);
|
||||
$booking->setIsInquiry($dto->forceInquiry || $this->computeInquiryStatus($dto, $prices)->isInquiry);
|
||||
$booking->setStatus(
|
||||
$dto->forceInquiry || $this->computeInquiryStatus($dto, $prices)->isInquiry
|
||||
? AccommodationBookingStatus::Inquiry
|
||||
: AccommodationBookingStatus::Booking
|
||||
);
|
||||
|
||||
// Freeze board service as scalar fields (no FK)
|
||||
if (null !== $dto->selectedBoardServiceId) {
|
||||
@@ -412,13 +417,13 @@ class AccommodationBookingService
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets accessLinkIssuedAt for a direct (non-inquiry) booking if it doesn't have one yet.
|
||||
* Sets accessLinkIssuedAt if the booking doesn't have one yet, whatever its status.
|
||||
* No email side effect — the confirmation email is always sent separately via
|
||||
* sendCustomerConfirmationEmail(), regardless of whether a link exists.
|
||||
*/
|
||||
public function issueAccessLinkForDirectBooking(AccommodationBooking $booking): void
|
||||
public function issueAccessLink(AccommodationBooking $booking): void
|
||||
{
|
||||
if ($booking->isInquiry() || null !== $booking->getAccessLinkIssuedAt()) {
|
||||
if (null !== $booking->getAccessLinkIssuedAt()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -426,18 +431,39 @@ class AccommodationBookingService
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues the access link only for a confirmed booking. Inquiries from the public flow
|
||||
* deliberately get no link — the office prepares the offer first and issues the link
|
||||
* when it switches the booking to Anfrage.
|
||||
*/
|
||||
public function issueAccessLinkForDirectBooking(AccommodationBooking $booking): void
|
||||
{
|
||||
if (!$booking->isBooking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->issueAccessLink($booking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always sends a confirmation email to the customer, whether or not an access link
|
||||
* exists yet — the template renders differently depending on accessLink being present.
|
||||
* exists yet — the template renders differently depending on accessLink being present,
|
||||
* so the subject has to follow the same distinction.
|
||||
*/
|
||||
public function sendCustomerConfirmationEmail(AccommodationBooking $booking): void
|
||||
{
|
||||
if (!$booking->isInquiry()) {
|
||||
$subject = 'Deine Buchung ist bestätigt';
|
||||
} elseif (null !== $booking->getAccessLinkIssuedAt()) {
|
||||
$subject = 'Dein Angebot ist bereit';
|
||||
} else {
|
||||
$subject = 'Deine Anfrage ist bei uns eingegangen';
|
||||
}
|
||||
|
||||
$this->sendBookingEmail(
|
||||
$booking,
|
||||
$booking->getEmail(),
|
||||
$booking->isInquiry()
|
||||
? 'Deine Anfrage ist bei uns eingegangen'
|
||||
: 'Deine Buchung ist bestätigt',
|
||||
$subject,
|
||||
'email/accommodation_booking_customer.html.twig',
|
||||
'Failed to send accommodation booking customer confirmation email',
|
||||
);
|
||||
@@ -464,7 +490,7 @@ class AccommodationBookingService
|
||||
return;
|
||||
}
|
||||
|
||||
$booking->setIsInquiry(false);
|
||||
$booking->setStatus(AccommodationBookingStatus::Booking);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable());
|
||||
$this->entityManager->flush();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user