feat: refactored accommodation booking status model
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260819120000 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Split the ambiguous Offen status into Angefragt and Offen, and turn the booking type into an immutable origin';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// Offen used to mean both "inquiry just arrived" and "offer is out with the customer",
|
||||
// told apart only by the access link. An Offen row without a link is exactly the
|
||||
// former case and becomes Angefragt; rows with a link are genuinely awaiting the
|
||||
// customer's acceptance and keep their status.
|
||||
$this->addSql("UPDATE accommodation_booking SET status = 'requested' WHERE status = 'open' AND access_link_issued_at IS NULL");
|
||||
|
||||
// The type described the lifecycle a second time and contradicted the status once an
|
||||
// offer had been accepted. It now records only where the booking came from, which is
|
||||
// true at every point of its life: an old `inquiry` went through an offer however far
|
||||
// it got, an old `booking` was placed directly.
|
||||
$this->addSql('ALTER TABLE accommodation_booking CHANGE type origin VARCHAR(20) NOT NULL');
|
||||
$this->addSql("UPDATE accommodation_booking SET origin = 'offer' WHERE origin = 'inquiry'");
|
||||
$this->addSql("UPDATE accommodation_booking SET origin = 'direct' WHERE origin = 'booking'");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql("UPDATE accommodation_booking SET origin = 'inquiry' WHERE origin = 'offer'");
|
||||
$this->addSql("UPDATE accommodation_booking SET origin = 'booking' WHERE origin = 'direct'");
|
||||
$this->addSql('ALTER TABLE accommodation_booking CHANGE origin type VARCHAR(20) NOT NULL');
|
||||
$this->addSql("UPDATE accommodation_booking SET status = 'open' WHERE status = 'requested'");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||
class DiscardController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/accommodation-booking/{id}/discard', name: 'app_admin_accommodationbooking_discard')]
|
||||
public function index(AccommodationBooking $booking, Request $request): Response
|
||||
{
|
||||
// A confirmation that has gone out is binding, so a confirmed booking is not something
|
||||
// the office can walk back here; an already discarded one has nothing left to do.
|
||||
if ($booking->isConfirmed() || $booking->isDiscarded()) {
|
||||
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
|
||||
}
|
||||
|
||||
if ($request->isMethod(Request::METHOD_POST)) {
|
||||
if (!$this->isCsrfTokenValid('discard_accommodation_booking_'.$booking->getId(), $request->request->getString('_token'))) {
|
||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||
}
|
||||
|
||||
$this->bookingService->discardBooking($booking);
|
||||
|
||||
$this->addFlash('success', 'Die Buchung wurde abgesagt.');
|
||||
|
||||
$this->logger->info('Discarded accommodation booking', [
|
||||
'id' => $booking->getId(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_show', ['id' => $booking->getId()]));
|
||||
}
|
||||
|
||||
return $this->render('admin/accommodation_booking/modal_discard.html.twig', [
|
||||
'booking' => $booking,
|
||||
'csrf_token_id' => 'discard_accommodation_booking_'.$booking->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ 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;
|
||||
@@ -93,8 +92,6 @@ class EditController extends AbstractController
|
||||
'current_additional_services' => $currentAdditionalServices,
|
||||
'assignable_managers' => $assignableManagers,
|
||||
]);
|
||||
$previousStatus = $booking->getStatus();
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
@@ -125,19 +122,12 @@ class EditController extends AbstractController
|
||||
|
||||
$this->bookingService->refreshPriceSnapshot($booking);
|
||||
|
||||
// Editing never moves the booking on and never mails the customer: every status
|
||||
// change is its own named action (Angebot senden, bestätigen, absagen), so the
|
||||
// status, its timestamp and its email can no longer drift apart.
|
||||
$this->entityManager->persist($booking);
|
||||
$this->entityManager->flush();
|
||||
|
||||
// Entering Offen is what the customer needs to hear about: the offer becomes
|
||||
// viewable. Every other status stays silent here — in particular Bestätigt, which
|
||||
// is only ever reached through the explicit confirm action so that the binding
|
||||
// confirmation is never sent as a side effect of editing.
|
||||
$notifiableStatuses = [AccommodationBookingStatus::Open];
|
||||
if ($previousStatus !== $booking->getStatus() && in_array($booking->getStatus(), $notifiableStatuses, true)) {
|
||||
$this->bookingService->issueAccessLink($booking);
|
||||
$this->bookingService->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'Die Buchung wurde aktualisiert');
|
||||
|
||||
$this->logger->info('Updated accommodation booking', [
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||
class SendOfferController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/accommodation-booking/{id}/send-offer', name: 'app_admin_accommodationbooking_send_offer')]
|
||||
public function index(AccommodationBooking $booking, Request $request): Response
|
||||
{
|
||||
// Only a booking still waiting for its offer can have one sent — anything further
|
||||
// along has already been put in front of the customer or been dealt with.
|
||||
if (!$booking->isDraft() && !$booking->isRequested()) {
|
||||
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
|
||||
}
|
||||
|
||||
if ($request->isMethod(Request::METHOD_POST)) {
|
||||
if (!$this->isCsrfTokenValid('send_offer_accommodation_booking_'.$booking->getId(), $request->request->getString('_token'))) {
|
||||
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||
}
|
||||
|
||||
// The offer only exists for the customer as the email carrying its link, so
|
||||
// publishing it without a deliverable address would strand the booking in Offen.
|
||||
if (null === $booking->getEmail() || '' === trim($booking->getEmail())) {
|
||||
$this->addFlash('error', 'Für diese Buchung ist keine E-Mail-Adresse hinterlegt. Bitte ergänze sie, um das Angebot zu versenden.');
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_edit', ['id' => $booking->getId()]));
|
||||
}
|
||||
|
||||
$this->bookingService->sendOffer($booking);
|
||||
|
||||
$this->addFlash('success', 'Das Angebot wurde dem Kunden per E-Mail zugestellt.');
|
||||
|
||||
$this->logger->info('Sent accommodation booking offer', [
|
||||
'id' => $booking->getId(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_admin_accommodationbooking_show', ['id' => $booking->getId()]));
|
||||
}
|
||||
|
||||
return $this->render('admin/accommodation_booking/modal_send_offer.html.twig', [
|
||||
'booking' => $booking,
|
||||
'csrf_token_id' => 'send_offer_accommodation_booking_'.$booking->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,9 @@ class OfferController extends AbstractController
|
||||
return $this->redirectToOfferPage($request, $uuid);
|
||||
}
|
||||
|
||||
if (!$booking->isInquiry() || !$booking->isOpen()) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -120,12 +122,13 @@ 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.
|
||||
* 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->isDraft() && !$booking->isDiscarded();
|
||||
return !$booking->isDraft() && !$booking->isRequested() && !$booking->isDiscarded();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -153,7 +153,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->getType()->value);
|
||||
$this->addFlash('groups_booking_result', $booking->getOrigin()->value);
|
||||
$this->sessionManager->clear($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use App\Entity\BlameableEntityInterface;
|
||||
use App\Entity\TimestampableEntity;
|
||||
use App\Entity\TimestampableEntityInterface;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Enum\Groups\AdditionalServiceType;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -81,12 +81,12 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
private AccommodationBookingStatus $status = AccommodationBookingStatus::Draft;
|
||||
|
||||
/**
|
||||
* What kind of record this is — an offer the customer still has to accept, or a
|
||||
* directly placed, binding booking. Independent of the status: an accepted offer
|
||||
* keeps its Inquiry type, which is how offer-originated bookings stay recognisable.
|
||||
* How this record came about — through an offer the customer had to accept, or as a
|
||||
* booking the customer placed directly. Orthogonal to the status and never changed
|
||||
* after creation, so it stays truthful at every point of the lifecycle.
|
||||
*/
|
||||
#[ORM\Column(length: 20, enumType: AccommodationBookingType::class)]
|
||||
private AccommodationBookingType $type = AccommodationBookingType::Inquiry;
|
||||
#[ORM\Column(length: 20, enumType: AccommodationBookingOrigin::class)]
|
||||
private AccommodationBookingOrigin $origin = AccommodationBookingOrigin::Offer;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
||||
private ?\DateTimeImmutable $accessLinkIssuedAt = null;
|
||||
@@ -118,14 +118,15 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
private ?string $lastName = null;
|
||||
|
||||
/**
|
||||
* The `offer` group covers the one field a customer-facing booking cannot do without:
|
||||
* the access link and every notification are addressed to it. It is enforced on
|
||||
* creation as soon as the booking is not a draft, while `edit` additionally demands
|
||||
* the rest of the contact data.
|
||||
* The one field a customer-facing booking cannot do without — the access link and every
|
||||
* notification are addressed to it. A record on its way to the customer is validated with
|
||||
* `edit`, which additionally demands the rest of the contact data; the actions that
|
||||
* actually reach out (SendOfferController, ConfirmController) check the address again on
|
||||
* their own, since a draft may legitimately be saved without one.
|
||||
*/
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Assert\NotBlank(groups: ['edit', 'offer'])]
|
||||
#[Assert\Email(groups: ['edit', 'offer'])]
|
||||
#[Assert\NotBlank(groups: ['edit'])]
|
||||
#[Assert\Email(groups: ['edit'])]
|
||||
private ?string $email = null;
|
||||
|
||||
#[ORM\Column(length: 50, nullable: true)]
|
||||
@@ -376,6 +377,11 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
return AccommodationBookingStatus::Draft === $this->status;
|
||||
}
|
||||
|
||||
public function isRequested(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Requested === $this->status;
|
||||
}
|
||||
|
||||
public function isOpen(): bool
|
||||
{
|
||||
return AccommodationBookingStatus::Open === $this->status;
|
||||
@@ -396,26 +402,37 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
||||
return AccommodationBookingStatus::Discarded === $this->status;
|
||||
}
|
||||
|
||||
public function getType(): AccommodationBookingType
|
||||
public function getOrigin(): AccommodationBookingOrigin
|
||||
{
|
||||
return $this->type;
|
||||
return $this->origin;
|
||||
}
|
||||
|
||||
public function setType(AccommodationBookingType $type): self
|
||||
public function setOrigin(AccommodationBookingOrigin $origin): self
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->origin = $origin;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isInquiry(): bool
|
||||
public function isFromOffer(): bool
|
||||
{
|
||||
return AccommodationBookingType::Inquiry === $this->type;
|
||||
return AccommodationBookingOrigin::Offer === $this->origin;
|
||||
}
|
||||
|
||||
public function isBooking(): bool
|
||||
public function isDirectBooking(): bool
|
||||
{
|
||||
return AccommodationBookingType::Booking === $this->type;
|
||||
return AccommodationBookingOrigin::Direct === $this->origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to call this record wherever it is named next to its status. An offer becomes a
|
||||
* booking the moment the customer commits, which is exactly what acceptedAt records — so
|
||||
* this can never contradict the status the way a stored type could. The origin is a
|
||||
* separate question ("where did this come from") and keeps its own label.
|
||||
*/
|
||||
public function recordLabel(): string
|
||||
{
|
||||
return null !== $this->acceptedAt ? 'Buchung' : 'Angebot';
|
||||
}
|
||||
|
||||
public function getAccessLinkIssuedAt(): ?\DateTimeImmutable
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum\Groups;
|
||||
|
||||
/**
|
||||
* How a booking record came about — deliberately orthogonal to the status, which
|
||||
* carries the lifecycle. The origin is set once when the record is created and
|
||||
* never changes afterwards, so an accepted offer stays recognisable as one without
|
||||
* the origin ever contradicting the status it has reached.
|
||||
*/
|
||||
enum AccommodationBookingOrigin: string
|
||||
{
|
||||
case Offer = 'offer';
|
||||
case Direct = 'direct';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Offer => 'Angebot',
|
||||
self::Direct => 'Direktbuchung',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,17 @@
|
||||
|
||||
namespace App\Enum\Groups;
|
||||
|
||||
/**
|
||||
* The single lifecycle of a booking record. Every case names exactly one state and
|
||||
* exactly one party it is waiting on: Angefragt and Entwurf wait on the office to
|
||||
* prepare an offer, Offen waits on the customer to accept it, Eingegangen waits on
|
||||
* the office to confirm. Where the record came from is not encoded here — that is
|
||||
* what AccommodationBookingOrigin is for.
|
||||
*/
|
||||
enum AccommodationBookingStatus: string
|
||||
{
|
||||
case Draft = 'draft';
|
||||
case Requested = 'requested';
|
||||
case Open = 'open';
|
||||
case Received = 'received';
|
||||
case Confirmed = 'confirmed';
|
||||
@@ -14,6 +22,7 @@ enum AccommodationBookingStatus: string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Draft => 'Entwurf',
|
||||
self::Requested => 'Angefragt',
|
||||
self::Open => 'Offen',
|
||||
self::Received => 'Eingegangen',
|
||||
self::Confirmed => 'Bestätigt',
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum\Groups;
|
||||
|
||||
enum AccommodationBookingType: string
|
||||
{
|
||||
case Inquiry = 'inquiry';
|
||||
case Booking = 'booking';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Inquiry => 'Anfrage',
|
||||
self::Booking => 'Buchung',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ namespace App\Form\Admin\Filter;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Form\Model\Filter\AccommodationBookingFilterDto;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@@ -30,10 +30,10 @@ class AccommodationBookingFilterType extends AbstractListFilterType
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
]],
|
||||
'type' => [EnumType::class, [
|
||||
'label' => 'Art',
|
||||
'class' => AccommodationBookingType::class,
|
||||
'choice_label' => static fn (AccommodationBookingType $type) => $type->label(),
|
||||
'origin' => [EnumType::class, [
|
||||
'label' => 'Herkunft',
|
||||
'class' => AccommodationBookingOrigin::class,
|
||||
'choice_label' => static fn (AccommodationBookingOrigin $origin) => $origin->label(),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
|
||||
@@ -6,15 +6,12 @@ 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\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\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
@@ -50,17 +47,9 @@ class AccommodationBookingCreateType extends AbstractType
|
||||
->add('childrenCount', IntegerType::class, [
|
||||
'label' => 'davon Kinder',
|
||||
])
|
||||
->add('status', EnumType::class, [
|
||||
'label' => 'Status',
|
||||
'class' => AccommodationBookingStatus::class,
|
||||
'choices' => [
|
||||
AccommodationBookingStatus::Draft,
|
||||
AccommodationBookingStatus::Open,
|
||||
],
|
||||
'choice_label' => fn (AccommodationBookingStatus $status) => $status->label(),
|
||||
])
|
||||
// Not marked required in HTML: a draft may be saved without it, and the
|
||||
// validation group below enforces it for everything else.
|
||||
// Not marked required in HTML: a new record is always an Entwurf, which is a
|
||||
// scratch record nobody is pointed at yet. The address is enforced when the
|
||||
// offer is actually sent — see SendOfferController.
|
||||
->add('email', EmailType::class, [
|
||||
'label' => 'E-Mail',
|
||||
'required' => false,
|
||||
@@ -73,15 +62,10 @@ class AccommodationBookingCreateType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AccommodationBooking::class,
|
||||
// A draft is a scratch record, but anything the customer can be pointed at
|
||||
// needs a reachable address — see the `offer` group on the entity. The rest of
|
||||
// the contact data is collected on the edit page, which validates `edit`.
|
||||
'validation_groups' => static function (FormInterface $form): array {
|
||||
/** @var AccommodationBooking $booking */
|
||||
$booking = $form->getData();
|
||||
|
||||
return $booking->isDraft() ? ['Default'] : ['Default', 'offer'];
|
||||
},
|
||||
// Creation always yields an Entwurf, a scratch record the office fills in over
|
||||
// time, so nothing beyond the basics is required here. The contact data is
|
||||
// collected on the edit page, which validates `edit`.
|
||||
'validation_groups' => ['Default'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,11 @@ use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
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;
|
||||
@@ -137,11 +135,8 @@ class AccommodationBookingType extends AbstractType
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('status', EnumType::class, [
|
||||
'label' => 'Status',
|
||||
'class' => AccommodationBookingStatus::class,
|
||||
'choice_label' => fn (AccommodationBookingStatus $status) => $status->label(),
|
||||
])
|
||||
// No status field: the status is only ever moved by a named action, so that it
|
||||
// can never end up set without the timestamp and email that belong to it.
|
||||
->add('accommodationDiscount', IntegerType::class, [
|
||||
'label' => 'Rabatt Unterkunft (%)',
|
||||
'required' => false,
|
||||
@@ -175,9 +170,9 @@ class AccommodationBookingType extends AbstractType
|
||||
$resolver->setDefaults([
|
||||
'data_class' => AccommodationBooking::class,
|
||||
// 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.
|
||||
// never going anywhere — neither needs complete contact data. Everything else,
|
||||
// Angefragt included, has already been in contact with the customer and is
|
||||
// expected to carry the full set.
|
||||
'validation_groups' => static function (FormInterface $form): array {
|
||||
/** @var AccommodationBooking $booking */
|
||||
$booking = $form->getData();
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace App\Form\Model\Filter;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Model\ListFilterChip;
|
||||
|
||||
class AccommodationBookingFilterDto extends AbstractListFilterDto
|
||||
@@ -15,8 +15,8 @@ class AccommodationBookingFilterDto extends AbstractListFilterDto
|
||||
/** @var AccommodationBookingStatus[] */
|
||||
public array $status = [];
|
||||
|
||||
/** @var AccommodationBookingType[] */
|
||||
public array $type = [];
|
||||
/** @var AccommodationBookingOrigin[] */
|
||||
public array $origin = [];
|
||||
|
||||
public ?User $managedBy = null;
|
||||
|
||||
@@ -38,15 +38,17 @@ class AccommodationBookingFilterDto extends AbstractListFilterDto
|
||||
/**
|
||||
* The list as it presents itself to someone who has not filtered yet.
|
||||
*
|
||||
* The still-live statuses — drafts, open bookings and bookings awaiting validation, i.e.
|
||||
* everything that may still need work — nothing whose stay is already over, and, for
|
||||
* staff who are not group admins, only the bookings they are responsible for.
|
||||
* The still-live statuses — drafts, inquiries awaiting an offer, offers out with the
|
||||
* customer and bookings awaiting validation, i.e. everything that may still need work —
|
||||
* nothing whose stay is already over, and, for staff who are not group admins, only the
|
||||
* bookings they are responsible for.
|
||||
*/
|
||||
public static function defaults(bool $seesAllBookings, ?User $currentUser): self
|
||||
{
|
||||
$filter = new self();
|
||||
$filter->status = [
|
||||
AccommodationBookingStatus::Draft,
|
||||
AccommodationBookingStatus::Requested,
|
||||
AccommodationBookingStatus::Open,
|
||||
AccommodationBookingStatus::Received,
|
||||
];
|
||||
@@ -72,11 +74,11 @@ class AccommodationBookingFilterDto extends AbstractListFilterDto
|
||||
);
|
||||
}
|
||||
|
||||
if ([] !== $this->type) {
|
||||
if ([] !== $this->origin) {
|
||||
$chips[] = new ListFilterChip(
|
||||
'Art',
|
||||
implode(', ', array_map(static fn (AccommodationBookingType $t) => $t->label(), $this->type)),
|
||||
['type'],
|
||||
'Herkunft',
|
||||
implode(', ', array_map(static fn (AccommodationBookingOrigin $o) => $o->label(), $this->origin)),
|
||||
['origin'],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ final readonly class AccommodationBookingApiResponse
|
||||
{
|
||||
$this->uuid = $booking->getUuid();
|
||||
$this->status = $booking->getStatus()->value;
|
||||
$this->type = $booking->getType()->value;
|
||||
$this->type = $booking->getOrigin()->value;
|
||||
$this->dateFrom = $booking->getDateFrom();
|
||||
$this->dateTo = $booking->getDateTo();
|
||||
$this->nights = $booking->getNights();
|
||||
|
||||
@@ -84,8 +84,8 @@ class AccommodationBookingRepository extends ServiceEntityRepository
|
||||
$qb->andWhere('booking.status IN (:status)')->setParameter('status', $filter->status);
|
||||
}
|
||||
|
||||
if ([] !== $filter->type) {
|
||||
$qb->andWhere('booking.type IN (:type)')->setParameter('type', $filter->type);
|
||||
if ([] !== $filter->origin) {
|
||||
$qb->andWhere('booking.origin IN (:origin)')->setParameter('origin', $filter->origin);
|
||||
}
|
||||
|
||||
if ($filter->unassigned) {
|
||||
|
||||
@@ -98,7 +98,8 @@ class AccommodationBookingPdfGenerator
|
||||
$groupName = (new AsciiSlugger('de'))->slug((string) $booking->getGroupName())->lower()->toString();
|
||||
|
||||
return sprintf(
|
||||
'buchung-%s%s.pdf',
|
||||
'%s-%s%s.pdf',
|
||||
mb_strtolower($booking->recordLabel()),
|
||||
$booking->getDateFrom()?->format('Y-m-d') ?? 'ohne-datum',
|
||||
'' !== $groupName ? '-'.$groupName : ''
|
||||
);
|
||||
|
||||
@@ -11,8 +11,8 @@ use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\AccommodationBookingQueryParams;
|
||||
use App\Model\CmsHotelData;
|
||||
@@ -268,12 +268,12 @@ class AccommodationBookingService
|
||||
$booking->setPaxCount($dto->paxCount);
|
||||
$booking->setMinorsCount($dto->minorsCount);
|
||||
$booking->setChildrenCount($dto->childrenCount);
|
||||
// An inquiry arrives live — the office has nothing to prepare first, so it goes
|
||||
// straight to Offen. A direct booking has been committed to by the customer but
|
||||
// still awaits the office's validation, hence Eingegangen rather than Bestätigt.
|
||||
// An inquiry still needs an offer the office has to prepare, so it waits at Angefragt
|
||||
// until that offer goes out. A direct booking has been committed to by the customer
|
||||
// but still awaits the office's validation, hence Eingegangen rather than Bestätigt.
|
||||
$isInquiry = $dto->forceInquiry || $this->computeInquiryStatus($dto, $prices)->isInquiry;
|
||||
$booking->setType($isInquiry ? AccommodationBookingType::Inquiry : AccommodationBookingType::Booking);
|
||||
$booking->setStatus($isInquiry ? AccommodationBookingStatus::Open : AccommodationBookingStatus::Received);
|
||||
$booking->setOrigin($isInquiry ? AccommodationBookingOrigin::Offer : AccommodationBookingOrigin::Direct);
|
||||
$booking->setStatus($isInquiry ? AccommodationBookingStatus::Requested : AccommodationBookingStatus::Received);
|
||||
if (!$isInquiry) {
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable());
|
||||
}
|
||||
@@ -342,7 +342,7 @@ class AccommodationBookingService
|
||||
// A direct booking gets no customer mail here: it only reaches the customer once the
|
||||
// office has validated it and confirmed via confirmBooking(). Acknowledging an
|
||||
// inquiry is a different matter — it promises nothing, so it still goes out.
|
||||
if ($booking->isInquiry()) {
|
||||
if ($booking->isFromOffer()) {
|
||||
$this->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ class AccommodationBookingService
|
||||
$this->accommodationEmail,
|
||||
sprintf(
|
||||
'Neue Unterkunfts%s: %s',
|
||||
$booking->isInquiry() ? 'anfrage' : 'buchung',
|
||||
$booking->isDirectBooking() ? 'buchung' : 'anfrage',
|
||||
$booking->getAccommodation()?->getName(),
|
||||
),
|
||||
'email/accommodation_booking.html.twig',
|
||||
@@ -457,7 +457,7 @@ class AccommodationBookingService
|
||||
*/
|
||||
public function issueAccessLinkForDirectBooking(AccommodationBooking $booking): void
|
||||
{
|
||||
if (!$booking->isBooking()) {
|
||||
if (!$booking->isDirectBooking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -465,13 +465,14 @@ class AccommodationBookingService
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
* so the subject has to follow the same distinction.
|
||||
* Serves both customer-facing messages of the pre-booking phase: the acknowledgement
|
||||
* that an inquiry arrived, and the offer itself. Offen is the status that means the
|
||||
* offer is out, so it is what decides the subject — the template makes the same
|
||||
* distinction via accessLink, which is always issued as the offer goes out.
|
||||
*/
|
||||
public function sendCustomerConfirmationEmail(AccommodationBooking $booking): void
|
||||
{
|
||||
$subject = null !== $booking->getAccessLinkIssuedAt()
|
||||
$subject = $booking->isOpen()
|
||||
? 'Dein Angebot ist bereit'
|
||||
: 'Deine Anfrage ist bei uns eingegangen';
|
||||
|
||||
@@ -496,9 +497,45 @@ class AccommodationBookingService
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an open offer and notifies the office. The type stays Anfrage —
|
||||
* only the status moves to Eingegangen, so an offer-originated booking remains
|
||||
* distinguishable from a direct one.
|
||||
* Publishes the prepared offer: the single action that puts an offer in front of the
|
||||
* customer, and the only transition into Offen. Issues the access link the email links
|
||||
* to, so the two can never drift apart the way they could when sending was a side
|
||||
* effect of editing.
|
||||
* Idempotent — a no-op (including no email) for anything that is not awaiting an offer.
|
||||
*/
|
||||
public function sendOffer(AccommodationBooking $booking): void
|
||||
{
|
||||
if (!$booking->isDraft() && !$booking->isRequested()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->issueAccessLink($booking);
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes a booking that is not going to happen. Deliberately silent: the office tells
|
||||
* the customer itself, so this only records the outcome.
|
||||
* Idempotent — a no-op for a booking that is already confirmed or discarded, since a
|
||||
* released confirmation is binding and must not be withdrawn behind the customer's back.
|
||||
*/
|
||||
public function discardBooking(AccommodationBooking $booking): void
|
||||
{
|
||||
if ($booking->isConfirmed() || $booking->isDiscarded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$booking->setStatus(AccommodationBookingStatus::Discarded);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an offer that is out with the customer and notifies the office. The origin
|
||||
* stays untouched, so the booking remains recognisable as offer-originated for the
|
||||
* rest of its life; only the status moves on to Eingegangen.
|
||||
* Idempotent — a no-op (including no emails) if the offer is not open any more.
|
||||
*
|
||||
* The customer deliberately gets no mail here: nothing is confirmed until the office
|
||||
@@ -509,7 +546,9 @@ class AccommodationBookingService
|
||||
*/
|
||||
public function acceptBooking(AccommodationBooking $booking, ?string $remarks = null): void
|
||||
{
|
||||
if (!$booking->isInquiry() || !$booking->isOpen()) {
|
||||
// Offen means exactly one thing — an offer is out and awaiting this acceptance —
|
||||
// so the status alone is the whole guard.
|
||||
if (!$booking->isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
{#- Offen covers two situations that need different office action, told apart by the access
|
||||
link: no link yet means the offer still has to be prepared, a link means the customer is
|
||||
the one who has to act. Display only — both are the same status. -#}
|
||||
{{- booking.status.label -}}
|
||||
{%- if booking.open %} · {{ booking.accessLinkIssuedAt is not null ? 'Angebot versendet' : 'Angebot ausstehend' }}{% endif -%}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends 'layout_admin.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
<twig:page:heading>Buchung {{ booking.groupName }}</twig:page:heading>
|
||||
<twig:page:heading>{{ booking.recordLabel }} {{ booking.groupName }}</twig:page:heading>
|
||||
<p class="text-sm text-gray-500 mb-6">{{ booking.accommodation.name }}</p>
|
||||
|
||||
{% form_theme form 'forms_admin.html.twig' %}
|
||||
@@ -39,9 +39,13 @@
|
||||
{% endif %}
|
||||
|
||||
<h2 class="lg:col-span-2 text-base font-bold pt-2">Status & Rabatt</h2>
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.status) }}
|
||||
</div>
|
||||
{# Read-only: the status only ever moves through a named action on the detail page,
|
||||
so that it cannot be set without the email and timestamp that belong to it. #}
|
||||
<p class="lg:col-span-2 text-sm">
|
||||
<span class="font-medium">Status:</span>
|
||||
{% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||
<span class="text-gray-500">· Herkunft: {{ booking.origin.label }}</span>
|
||||
</p>
|
||||
{% if booking.acceptedAt is not null %}
|
||||
<p class="lg:col-span-2 text-xs text-gray-500">
|
||||
Angenommen am {{ booking.acceptedAt | date('d.m.Y, H:i') }}
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ booking.type.label }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||
{{ booking.recordLabel }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||
</td>
|
||||
<td>
|
||||
{% set discounts = [] %}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="text-xl font-bold pb-4">
|
||||
Neue Buchung
|
||||
Neues Angebot
|
||||
</div>
|
||||
{{ form_start(form) }}
|
||||
<div class="grid lg:grid-cols-2 gap-y-4 lg:gap-x-8">
|
||||
@@ -15,9 +15,6 @@
|
||||
{{ form_row(form.paxCount) }}
|
||||
{{ form_row(form.minorsCount) }}
|
||||
{{ form_row(form.childrenCount) }}
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.status) }}
|
||||
</div>
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.email) }}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{% extends 'htmx_confirmation_modal.html.twig' %}
|
||||
|
||||
{% block title %}{{ booking.recordLabel }} absagen{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
Möchtest du {{ booking.acceptedAt is not null ? 'die Buchung' : 'das Angebot' }} für
|
||||
<em>{{ booking.groupName }}</em> absagen?
|
||||
{% if booking.open %}
|
||||
Das versendete Angebot kann danach nicht mehr angenommen werden.
|
||||
{% endif %}
|
||||
Der Kunde wird nicht automatisch benachrichtigt.
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block button_confirm %}Absagen{% endblock %}
|
||||
@@ -7,7 +7,7 @@
|
||||
{{ form_row(form.dateFrom) }}
|
||||
{{ form_row(form.dateTo) }}
|
||||
{{ form_row(form.status) }}
|
||||
{{ form_row(form.type) }}
|
||||
{{ form_row(form.origin) }}
|
||||
<div class="lg:col-span-2">
|
||||
{{ form_row(form.accommodation) }}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{% extends 'htmx_confirmation_modal.html.twig' %}
|
||||
|
||||
{% block title %}Angebot senden{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
Möchtest du das Angebot für <em>{{ booking.groupName }}</em> an <em>{{ booking.email }}</em> senden?
|
||||
Der Kunde kann es anschließend über den Zugangslink annehmen.
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block button_confirm %}Angebot senden{% endblock %}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{% block content %}
|
||||
<twig:page:heading>
|
||||
{{ booking.type.label }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||
{{ booking.recordLabel }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||
{{ booking.groupName }}
|
||||
</twig:page:heading>
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
<dt class="font-medium">davon Kinder (4–{{ booking.accommodation.maxAdolescentAge }} Jahre)</dt>
|
||||
<dd>{{ booking.childrenCount }}</dd>
|
||||
{% endif %}
|
||||
<dt class="font-medium">Art</dt>
|
||||
<dd>{{ booking.type.label }}</dd>
|
||||
<dt class="font-medium">Herkunft</dt>
|
||||
<dd>{{ booking.origin.label }}</dd>
|
||||
<dt class="font-medium">Status</dt>
|
||||
<dd>{% include 'admin/accommodation_booking/_status_label.html.twig' %}</dd>
|
||||
{% if booking.acceptedAt is not null %}
|
||||
@@ -177,6 +177,23 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if booking.draft or booking.requested %}
|
||||
<div class="mt-6 border-t border-gray-200 pt-6">
|
||||
<h2 class="text-lg font-bold mb-2">Angebot</h2>
|
||||
<p class="text-sm text-gray-500 mb-2">
|
||||
Das Angebot wurde dem Kunden noch nicht zugestellt. Beim Versand wird der Zugangslink
|
||||
erzeugt und die Buchung wartet anschließend auf die Annahme durch den Kunden.
|
||||
</p>
|
||||
<button type="button"
|
||||
class="button button--primary button--small"
|
||||
hx-get="{{ path('app_admin_accommodationbooking_send_offer', { id: booking.id }) }}"
|
||||
hx-target="body"
|
||||
hx-swap="beforeend">
|
||||
Angebot per E-Mail senden
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if booking.received %}
|
||||
<div class="mt-6 border-t border-gray-200 pt-6">
|
||||
<h2 class="text-lg font-bold mb-2">Bestätigung</h2>
|
||||
@@ -238,6 +255,15 @@
|
||||
zurück
|
||||
</a>
|
||||
<div class="flex items-center gap-2">
|
||||
{% if not booking.confirmed and not booking.discarded %}
|
||||
<button type="button"
|
||||
class="button button--warning button--small"
|
||||
hx-get="{{ path('app_admin_accommodationbooking_discard', { id: booking.id }) }}"
|
||||
hx-target="body"
|
||||
hx-swap="beforeend">
|
||||
Absagen
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if booking.confirmed %}
|
||||
<a href="{{ path('app_admin_accommodationbooking_pdf', { 'id': booking.id }) }}" class="button button--secondary button--small">
|
||||
PDF herunterladen
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
{% block body %}
|
||||
<h1>
|
||||
Neue Unterkunfts{% if booking.inquiry %}anfrage{% else %}buchung{% endif %}
|
||||
Neue Unterkunfts{% if booking.directBooking %}buchung{% else %}anfrage{% endif %}
|
||||
</h1>
|
||||
|
||||
{% if accessLink %}
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
{% if booking.boardServiceLabel or booking.additionalServices | length > 0 %}
|
||||
<div>
|
||||
<h2 class="text-xl font-bold mb-2">
|
||||
{{ booking.acceptedAt is not null ? 'Gebuchte' : 'Angefragte' }} Leistungen
|
||||
{{ booking.acceptedAt is not null ? 'Gebuchte' : 'Angebotene' }} Leistungen
|
||||
</h2>
|
||||
<ul class="list-disc pl-4">
|
||||
{% if booking.boardServiceLabel %}
|
||||
@@ -74,7 +74,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if booking.inquiry and booking.open %}
|
||||
{% if booking.open %}
|
||||
<div>
|
||||
<button type="button"
|
||||
class="button button--primary w-full"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{% block title %}{{ resultType == 'booking' ? 'Buchung erfolgreich' : 'Anfrage erfolgreich' }}{% endblock %}
|
||||
{% block title %}{{ resultType == 'direct' ? 'Buchung erfolgreich' : 'Anfrage erfolgreich' }}{% endblock %}
|
||||
|
||||
{% block background %}bg-outer bg-outer--summer{% endblock %}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
level: 'success',
|
||||
title: 'Vielen Dank!',
|
||||
messages: [
|
||||
resultType == 'booking'
|
||||
resultType == 'direct'
|
||||
? 'Deine Buchung ist bei uns eingegangen. Sobald sie geprüft ist, erhälst du eine Bestätigung per E-Mail.'
|
||||
: 'Deine Anfrage ist bei uns eingegangen. Wir melden uns so schnell wie möglich bei dir.'
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Buchung {{ booking.id }} – {{ booking.groupName }}</title>
|
||||
<title>{{ booking.recordLabel }} {{ booking.id }} – {{ booking.groupName }}</title>
|
||||
<style>
|
||||
@page { size: A4 portrait; margin: 16mm 15mm; }
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>{{ booking.type.label }} · {{ booking.groupName }}</h1>
|
||||
<h1>{{ booking.recordLabel }} · {{ booking.groupName }}</h1>
|
||||
|
||||
<table class="columns">
|
||||
<tr>
|
||||
@@ -90,7 +90,6 @@
|
||||
{% if booking.childrenCount > 0 %}
|
||||
<tr><th>davon Kinder (4–{{ booking.accommodation.maxAdolescentAge }} J.)</th><td>{{ booking.childrenCount }}</td></tr>
|
||||
{% endif %}
|
||||
<tr><th>Art</th><td>{{ booking.type.label }}</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -83,6 +83,7 @@ class ConfirmControllerTest extends TestCase
|
||||
public static function nonReceivedStatuses(): iterable
|
||||
{
|
||||
yield 'draft' => [AccommodationBookingStatus::Draft];
|
||||
yield 'requested' => [AccommodationBookingStatus::Requested];
|
||||
yield 'open' => [AccommodationBookingStatus::Open];
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Controller\Admin\AccommodationBooking\DiscardController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* Covers the guards around discarding — the transition itself is tested in
|
||||
* AccommodationBookingServiceTest.
|
||||
*/
|
||||
class DiscardControllerTest extends TestCase
|
||||
{
|
||||
public function testGetRendersTheConfirmationModal(): void
|
||||
{
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('discardBooking');
|
||||
|
||||
$controller = new TestableDiscardController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($this->openBooking(), Request::create('/admin/accommodation-booking/1/discard'));
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('admin/accommodation_booking/modal_discard.html.twig', $controller->renderedView);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider discardableStatuses
|
||||
*/
|
||||
public function testPostDiscardsTheBookingAndRedirectsTheBrowser(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = $this->openBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('discardBooking')->with($booking);
|
||||
|
||||
$controller = new TestableDiscardController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/discard', 'POST'));
|
||||
|
||||
self::assertTrue($response->headers->has('HX-Redirect'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function discardableStatuses(): iterable
|
||||
{
|
||||
yield 'draft' => [AccommodationBookingStatus::Draft];
|
||||
yield 'requested' => [AccommodationBookingStatus::Requested];
|
||||
yield 'open' => [AccommodationBookingStatus::Open];
|
||||
yield 'received' => [AccommodationBookingStatus::Received];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider closedStatuses
|
||||
*/
|
||||
public function testAClosedBookingCannotBeDiscarded(AccommodationBookingStatus $status): void
|
||||
{
|
||||
// A released confirmation is binding, and an Absage is already the end of the line.
|
||||
$booking = $this->openBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('discardBooking');
|
||||
|
||||
$controller = new TestableDiscardController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/discard', 'POST'));
|
||||
|
||||
self::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function closedStatuses(): iterable
|
||||
{
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
}
|
||||
|
||||
public function testPostWithAnInvalidTokenIsDenied(): void
|
||||
{
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('discardBooking');
|
||||
|
||||
$controller = new TestableDiscardController($bookingService, $this->createMock(LoggerInterface::class), tokenValid: false);
|
||||
|
||||
$this->expectException(AccessDeniedException::class);
|
||||
|
||||
$controller->index($this->openBooking(), Request::create('/admin/accommodation-booking/1/discard', 'POST'));
|
||||
}
|
||||
|
||||
private function openBooking(): AccommodationBooking
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setGroupName('Schulklasse 7b');
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
return $booking;
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableDiscardController extends DiscardController
|
||||
{
|
||||
public ?string $renderedView = null;
|
||||
|
||||
/** @var list<array{type: string, message: mixed}> */
|
||||
public array $flashes = [];
|
||||
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
LoggerInterface $logger,
|
||||
private readonly bool $tokenValid = true,
|
||||
) {
|
||||
parent::__construct($bookingService, $logger);
|
||||
}
|
||||
|
||||
protected function isCsrfTokenValid(string $id, #[\SensitiveParameter] ?string $token): bool
|
||||
{
|
||||
return $this->tokenValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
|
||||
return new Response();
|
||||
}
|
||||
|
||||
protected function addFlash(string $type, mixed $message): void
|
||||
{
|
||||
$this->flashes[] = ['type' => $type, 'message' => $message];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string
|
||||
{
|
||||
return '/'.$route.'?'.http_build_query($parameters);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,8 @@ namespace App\Tests\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Controller\Admin\AccommodationBooking\EditController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Repository\Groups\AdditionalServiceRepository;
|
||||
use App\Repository\Groups\BoardServiceRepository;
|
||||
use App\Repository\UserRepository;
|
||||
@@ -20,79 +20,47 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Covers the status transition side effects only — the service and form behaviour
|
||||
* they build on is tested in AccommodationBookingServiceTest.
|
||||
* Covers what editing must NOT do — it never moves the booking on and never mails the
|
||||
* customer — plus the Betreuer choices. The transitions themselves belong to the named
|
||||
* actions and are tested in AccommodationBookingServiceTest and the action controllers.
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
public function testTransitionToOpenIssuesAccessLinkAndSendsCustomerEmail(): void
|
||||
{
|
||||
$bookingService = $this->assertNotified(AccommodationBookingStatus::Open);
|
||||
|
||||
$this->submitStatusChange(AccommodationBookingStatus::Draft, AccommodationBookingStatus::Open, $bookingService);
|
||||
}
|
||||
|
||||
public function testTransitionToConfirmedSendsNothing(): void
|
||||
{
|
||||
// The binding confirmation only ever goes out through the explicit confirm action,
|
||||
// never as a side effect of editing the status.
|
||||
$bookingService = $this->assertNotNotified();
|
||||
|
||||
$this->submitStatusChange(AccommodationBookingStatus::Received, AccommodationBookingStatus::Confirmed, $bookingService);
|
||||
}
|
||||
|
||||
public function testTransitionToDiscardedSendsNothing(): void
|
||||
{
|
||||
$bookingService = $this->assertNotNotified();
|
||||
|
||||
$this->submitStatusChange(AccommodationBookingStatus::Open, AccommodationBookingStatus::Discarded, $bookingService);
|
||||
}
|
||||
|
||||
public function testSavingWithoutStatusChangeSendsNothing(): void
|
||||
{
|
||||
$bookingService = $this->assertNotNotified();
|
||||
|
||||
$this->submitStatusChange(AccommodationBookingStatus::Confirmed, AccommodationBookingStatus::Confirmed, $bookingService);
|
||||
}
|
||||
|
||||
private function assertNotified(AccommodationBookingStatus $expected): AccommodationBookingService
|
||||
{
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('refreshPriceSnapshot');
|
||||
$bookingService
|
||||
->expects(self::once())
|
||||
->method('issueAccessLink')
|
||||
->with(self::callback(static fn (AccommodationBooking $booking) => $expected === $booking->getStatus()));
|
||||
$bookingService->expects(self::once())->method('sendCustomerConfirmationEmail');
|
||||
|
||||
return $bookingService;
|
||||
}
|
||||
|
||||
private function assertNotNotified(): AccommodationBookingService
|
||||
/**
|
||||
* @dataProvider everyStatus
|
||||
*/
|
||||
public function testSavingNeverNotifiesTheCustomer(AccommodationBookingStatus $status): void
|
||||
{
|
||||
// Sending used to be a side effect of saving a status change, which is how an inquiry
|
||||
// that arrived already Offen could never be offered at all. Editing is now inert.
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('refreshPriceSnapshot');
|
||||
$bookingService->expects(self::never())->method('issueAccessLink');
|
||||
$bookingService->expects(self::never())->method('sendCustomerConfirmationEmail');
|
||||
$bookingService->expects(self::never())->method('sendOffer');
|
||||
|
||||
return $bookingService;
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$this->submitEdit($booking, $bookingService);
|
||||
|
||||
self::assertSame($status, $booking->getStatus(), 'editing leaves the status where it was');
|
||||
}
|
||||
|
||||
private function submitStatusChange(
|
||||
AccommodationBookingStatus $from,
|
||||
AccommodationBookingStatus $to,
|
||||
AccommodationBookingService $bookingService,
|
||||
): void {
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($from);
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function everyStatus(): iterable
|
||||
{
|
||||
foreach (AccommodationBookingStatus::cases() as $status) {
|
||||
yield $status->value => [$status];
|
||||
}
|
||||
}
|
||||
|
||||
// The form is what moves the entity to its new status during handleRequest().
|
||||
private function submitEdit(AccommodationBooking $booking, AccommodationBookingService $bookingService): void
|
||||
{
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('handleRequest')->willReturnCallback(static function () use ($booking, $to, $form) {
|
||||
$booking->setStatus($to);
|
||||
|
||||
return $form;
|
||||
});
|
||||
$form->method('handleRequest')->willReturn($form);
|
||||
$form->method('isSubmitted')->willReturn(true);
|
||||
$form->method('isValid')->willReturn(true);
|
||||
$form->method('has')->willReturn(false);
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Controller\Admin\AccommodationBooking\SendOfferController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* Covers the guards around sending an offer — the sending itself is tested in
|
||||
* AccommodationBookingServiceTest.
|
||||
*/
|
||||
class SendOfferControllerTest extends TestCase
|
||||
{
|
||||
public function testGetRendersTheConfirmationModal(): void
|
||||
{
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('sendOffer');
|
||||
|
||||
$controller = new TestableSendOfferController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($this->requestedBooking(), Request::create('/admin/accommodation-booking/1/send-offer'));
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('admin/accommodation_booking/modal_send_offer.html.twig', $controller->renderedView);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider statusesAwaitingAnOffer
|
||||
*/
|
||||
public function testPostSendsTheOfferAndRedirectsTheBrowser(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = $this->requestedBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('sendOffer')->with($booking);
|
||||
|
||||
$controller = new TestableSendOfferController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/send-offer', 'POST'));
|
||||
|
||||
self::assertTrue($response->headers->has('HX-Redirect'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesAwaitingAnOffer(): iterable
|
||||
{
|
||||
// The admin-authored offer and the customer's inquiry converge on the same action.
|
||||
yield 'draft' => [AccommodationBookingStatus::Draft];
|
||||
yield 'requested' => [AccommodationBookingStatus::Requested];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider statusesPastTheOffer
|
||||
*/
|
||||
public function testABookingThatIsNotAwaitingAnOfferGetsNone(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = $this->requestedBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('sendOffer');
|
||||
|
||||
$controller = new TestableSendOfferController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/send-offer', 'POST'));
|
||||
|
||||
self::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesPastTheOffer(): iterable
|
||||
{
|
||||
yield 'open' => [AccommodationBookingStatus::Open];
|
||||
yield 'received' => [AccommodationBookingStatus::Received];
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
}
|
||||
|
||||
public function testPostWithAnInvalidTokenIsDenied(): void
|
||||
{
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('sendOffer');
|
||||
|
||||
$controller = new TestableSendOfferController($bookingService, $this->createMock(LoggerInterface::class), tokenValid: false);
|
||||
|
||||
$this->expectException(AccessDeniedException::class);
|
||||
|
||||
$controller->index($this->requestedBooking(), Request::create('/admin/accommodation-booking/1/send-offer', 'POST'));
|
||||
}
|
||||
|
||||
public function testABookingWithoutAnEmailAddressGetsNoOffer(): void
|
||||
{
|
||||
// The offer only exists for the customer as the mail carrying its link, so sending
|
||||
// it nowhere would leave the booking waiting in Offen for an acceptance that cannot
|
||||
// come — the dead end this whole flow is meant to remove.
|
||||
$booking = $this->requestedBooking();
|
||||
$booking->setEmail(null);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('sendOffer');
|
||||
|
||||
$controller = new TestableSendOfferController($bookingService, $this->createMock(LoggerInterface::class));
|
||||
|
||||
$response = $controller->index($booking, Request::create('/admin/accommodation-booking/1/send-offer', 'POST'));
|
||||
|
||||
self::assertSame(['error'], array_column($controller->flashes, 'type'));
|
||||
self::assertStringContainsString('app_admin_accommodationbooking_edit', (string) $response->headers->get('HX-Redirect'));
|
||||
}
|
||||
|
||||
private function requestedBooking(): AccommodationBooking
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Requested);
|
||||
$booking->setGroupName('Schulklasse 7b');
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
return $booking;
|
||||
}
|
||||
}
|
||||
|
||||
final class TestableSendOfferController extends SendOfferController
|
||||
{
|
||||
public ?string $renderedView = null;
|
||||
|
||||
/** @var list<array{type: string, message: mixed}> */
|
||||
public array $flashes = [];
|
||||
|
||||
public function __construct(
|
||||
AccommodationBookingService $bookingService,
|
||||
LoggerInterface $logger,
|
||||
private readonly bool $tokenValid = true,
|
||||
) {
|
||||
parent::__construct($bookingService, $logger);
|
||||
}
|
||||
|
||||
protected function isCsrfTokenValid(string $id, #[\SensitiveParameter] ?string $token): bool
|
||||
{
|
||||
return $this->tokenValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
|
||||
return new Response();
|
||||
}
|
||||
|
||||
protected function addFlash(string $type, mixed $message): void
|
||||
{
|
||||
$this->flashes[] = ['type' => $type, 'message' => $message];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $parameters
|
||||
*/
|
||||
protected function generateUrl(string $route, array $parameters = [], int $referenceType = 1): string
|
||||
{
|
||||
return '/'.$route.'?'.http_build_query($parameters);
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ namespace App\Tests\Controller\Api;
|
||||
use App\Controller\Api\AccommodationBookingController;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Repository\Groups\AccommodationBookingRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\AccommodationBookingService;
|
||||
@@ -57,7 +57,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
$booking->setBoardServiceDiscount(20);
|
||||
$booking->setAdditionalServicesDiscount(30);
|
||||
$booking->setStatus(AccommodationBookingStatus::Confirmed);
|
||||
$booking->setType(AccommodationBookingType::Booking);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Direct);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable('2026-07-15T10:00:00+00:00'));
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
@@ -88,7 +88,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
self::assertSame([
|
||||
'uuid' => $booking->getUuid(),
|
||||
'status' => 'confirmed',
|
||||
'type' => 'booking',
|
||||
'type' => 'direct',
|
||||
'dateFrom' => '2026-07-20',
|
||||
'dateTo' => '2026-07-25',
|
||||
'nights' => 5,
|
||||
@@ -139,7 +139,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
self::assertArrayNotHasKey('currency', $payload['accommodation']);
|
||||
}
|
||||
|
||||
public function testSingleReturnsOpenStatusAndInquiryTypeForAnOffer(): void
|
||||
public function testSingleReturnsOpenStatusAndOfferOriginForAnOffer(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-08-01'));
|
||||
@@ -149,7 +149,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
$booking->setLastName('Beispiel');
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setType(AccommodationBookingType::Inquiry);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository
|
||||
@@ -166,7 +166,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
$payload = json_decode((string) $response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
self::assertSame('open', $payload['status']);
|
||||
self::assertSame('inquiry', $payload['type']);
|
||||
self::assertSame('offer', $payload['type']);
|
||||
self::assertNull($payload['priceBreakdown']);
|
||||
self::assertNull($payload['acceptedAt']);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
self::assertSame('received', $payload['status']);
|
||||
self::assertSame('inquiry', $payload['type']);
|
||||
self::assertSame('offer', $payload['type']);
|
||||
self::assertSame(AccommodationBookingStatus::Received, $booking->getStatus());
|
||||
self::assertNotNull($booking->getAcceptedAt());
|
||||
self::assertSame($booking->getAcceptedAt()->format(\DATE_ATOM), $payload['acceptedAt']);
|
||||
|
||||
@@ -94,10 +94,13 @@ class OfferControllerTest extends TestCase
|
||||
self::assertSame('groups/booking/offer_unavailable.html.twig', $controller->renderedView);
|
||||
}
|
||||
|
||||
public function testAccessRendersUnavailableForDraft(): void
|
||||
/**
|
||||
* @dataProvider statusesTheCustomerMustNotSee
|
||||
*/
|
||||
public function testAccessRendersUnavailableForABookingThatIsNotOfferedYet(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Draft);
|
||||
$booking->setStatus($status);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
@@ -119,6 +122,18 @@ class OfferControllerTest extends TestCase
|
||||
self::assertSame('groups/booking/offer_unavailable.html.twig', $controller->renderedView);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesTheCustomerMustNotSee(): iterable
|
||||
{
|
||||
// A scratch record and an inquiry the office has not worked through yet are both
|
||||
// unfinished; a discarded one is over. All three behave like an expired link.
|
||||
yield 'draft' => [AccommodationBookingStatus::Draft];
|
||||
yield 'requested' => [AccommodationBookingStatus::Requested];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
}
|
||||
|
||||
public function testViewRendersUnavailableForDiscardedBooking(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace App\Tests\Controller\Groups;
|
||||
use App\Controller\Groups\Step4Controller;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use App\Service\AccommodationSessionManager;
|
||||
@@ -102,7 +102,7 @@ class Step4ControllerTest extends TestCase
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$booking = (new AccommodationBooking())->setType(AccommodationBookingType::Inquiry);
|
||||
$booking = (new AccommodationBooking())->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
@@ -275,7 +275,7 @@ class Step4ControllerTest extends TestCase
|
||||
->setCalendarCode('HOTEL')
|
||||
->setMaxAdolescentAge(17);
|
||||
|
||||
$booking = (new AccommodationBooking())->setType(AccommodationBookingType::Booking);
|
||||
$booking = (new AccommodationBooking())->setOrigin(AccommodationBookingOrigin::Direct);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->method('loadAccommodation')->with(1)->willReturn($accommodation);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Entity\Groups;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AccommodationBookingTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* The label is what the backoffice prints next to the status, so it must never
|
||||
* contradict it — "Angebot · Bestätigt" is the shape of mistake this replaces.
|
||||
*
|
||||
* @dataProvider statusesBeforeTheCustomerCommits
|
||||
*/
|
||||
public function testARecordIsCalledAnOfferUntilTheCustomerCommits(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
self::assertNull($booking->getAcceptedAt());
|
||||
self::assertSame('Angebot', $booking->recordLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesBeforeTheCustomerCommits(): iterable
|
||||
{
|
||||
yield 'draft' => [AccommodationBookingStatus::Draft];
|
||||
yield 'requested' => [AccommodationBookingStatus::Requested];
|
||||
yield 'open' => [AccommodationBookingStatus::Open];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider statusesAfterTheCustomerCommits
|
||||
*/
|
||||
public function testARecordIsCalledABookingOnceTheCustomerHasCommitted(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable());
|
||||
|
||||
self::assertSame('Buchung', $booking->recordLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesAfterTheCustomerCommits(): iterable
|
||||
{
|
||||
yield 'received' => [AccommodationBookingStatus::Received];
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
}
|
||||
|
||||
public function testADiscardedRecordKeepsWhicheverItHadBecome(): void
|
||||
{
|
||||
// An Absage can close either an offer nobody accepted or a booking that fell
|
||||
// through, so the label follows the commitment rather than the status.
|
||||
$unaccepted = new AccommodationBooking();
|
||||
$unaccepted->setStatus(AccommodationBookingStatus::Discarded);
|
||||
|
||||
$accepted = new AccommodationBooking();
|
||||
$accepted->setStatus(AccommodationBookingStatus::Discarded);
|
||||
$accepted->setAcceptedAt(new \DateTimeImmutable());
|
||||
|
||||
self::assertSame('Angebot', $unaccepted->recordLabel());
|
||||
self::assertSame('Buchung', $accepted->recordLabel());
|
||||
}
|
||||
|
||||
public function testTheLabelIsIndependentOfWhereTheBookingCameFrom(): void
|
||||
{
|
||||
// Origin answers "how did this come about" and is deliberately not the same
|
||||
// question — a confirmed booking that started as an offer is still a Buchung.
|
||||
foreach (AccommodationBookingOrigin::cases() as $origin) {
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setOrigin($origin);
|
||||
$booking->setStatus(AccommodationBookingStatus::Confirmed);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable());
|
||||
|
||||
self::assertSame('Buchung', $booking->recordLabel(), $origin->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Form\Admin\Groups\AccommodationBookingCreateType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Symfony\Component\Validator\Constraints\EmailValidator;
|
||||
@@ -17,76 +17,74 @@ use Symfony\Component\Validator\Validation;
|
||||
|
||||
class AccommodationBookingCreateTypeTest extends TestCase
|
||||
{
|
||||
public function testDraftsAreValidatedWithoutTheOfferGroup(): void
|
||||
public function testCreationIsAlwaysValidatedAsAScratchRecord(): void
|
||||
{
|
||||
self::assertSame(['Default'], $this->resolveValidationGroups(AccommodationBookingStatus::Draft));
|
||||
self::assertSame(['Default'], $this->resolveValidationGroups());
|
||||
}
|
||||
|
||||
public function testOffersAddTheOfferGroup(): void
|
||||
public function testTheStatusCannotBeChosenOnCreation(): void
|
||||
{
|
||||
self::assertSame(['Default', 'offer'], $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
// A new record is always an Entwurf and only leaves that status through a named
|
||||
// action, so offering the choice here would let it start out somewhere it cannot
|
||||
// have arrived at legitimately.
|
||||
self::assertNotContains('status', $this->builtFieldNames());
|
||||
}
|
||||
|
||||
public function testDraftCanBeCreatedWithoutAnEmail(): void
|
||||
public function testANewBookingStartsAsADraft(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Draft);
|
||||
self::assertTrue((new AccommodationBooking())->isDraft());
|
||||
}
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Draft));
|
||||
public function testABookingCanBeCreatedWithoutAnEmail(): void
|
||||
{
|
||||
// The address is enforced when the booking is actually sent somewhere — see
|
||||
// SendOfferController and ConfirmController — not while it is still a scratch record.
|
||||
$violations = $this->validate(new AccommodationBooking(), $this->resolveValidationGroups());
|
||||
|
||||
self::assertCount(0, $violations);
|
||||
}
|
||||
|
||||
public function testOfferCannotBeCreatedWithoutAnEmail(): void
|
||||
public function testAMalformedEmailIsStillRejectedOnceTheBookingIsEdited(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setStatus(AccommodationBookingStatus::Requested);
|
||||
$booking->setEmail('not-an-address');
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
$violations = $this->validate($booking, ['edit']);
|
||||
|
||||
$properties = array_map(static fn ($violation) => $violation->getPropertyPath(), iterator_to_array($violations));
|
||||
|
||||
self::assertSame(['email'], $properties, 'only the address is enforced here — the rest of the contact data belongs to the edit form');
|
||||
}
|
||||
|
||||
public function testOfferRejectsAMalformedEmail(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('not-an-address');
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
|
||||
self::assertCount(1, $violations);
|
||||
self::assertSame('email', $violations[0]->getPropertyPath());
|
||||
}
|
||||
|
||||
public function testOfferWithAnEmailIsValid(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$violations = $this->validate($booking, $this->resolveValidationGroups(AccommodationBookingStatus::Open));
|
||||
|
||||
self::assertCount(0, $violations);
|
||||
self::assertContains('email', $properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function resolveValidationGroups(AccommodationBookingStatus $status): array
|
||||
private function resolveValidationGroups(): array
|
||||
{
|
||||
$resolver = new OptionsResolver();
|
||||
(new AccommodationBookingCreateType())->configureOptions($resolver);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
return $resolver->resolve()['validation_groups'];
|
||||
}
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('getData')->willReturn($booking);
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private function builtFieldNames(): array
|
||||
{
|
||||
$names = [];
|
||||
|
||||
return ($resolver->resolve()['validation_groups'])($form);
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnCallback(static function (string $name) use (&$names, $builder) {
|
||||
$names[] = $name;
|
||||
|
||||
return $builder;
|
||||
});
|
||||
|
||||
(new AccommodationBookingCreateType())->buildForm($builder, ['data' => new AccommodationBooking()]);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Form\Model\Filter;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Form\Model\Filter\AccommodationBookingFilterDto;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -17,9 +17,14 @@ class AccommodationBookingFilterDtoTest extends TestCase
|
||||
$filter = AccommodationBookingFilterDto::defaults(true, new User('[email protected]'));
|
||||
|
||||
self::assertSame(
|
||||
[AccommodationBookingStatus::Draft, AccommodationBookingStatus::Open, AccommodationBookingStatus::Received],
|
||||
[
|
||||
AccommodationBookingStatus::Draft,
|
||||
AccommodationBookingStatus::Requested,
|
||||
AccommodationBookingStatus::Open,
|
||||
AccommodationBookingStatus::Received,
|
||||
],
|
||||
$filter->status,
|
||||
'accepted and discarded bookings need no further work, so they stay out of the way',
|
||||
'confirmed and discarded bookings need no further work, so they stay out of the way',
|
||||
);
|
||||
self::assertSame((new \DateTimeImmutable('today'))->format('Y-m-d'), $filter->dateFrom?->format('Y-m-d'));
|
||||
self::assertNull($filter->managedBy, 'a group admin sees everybody’s bookings');
|
||||
@@ -83,11 +88,11 @@ class AccommodationBookingFilterDtoTest extends TestCase
|
||||
$filter->q = 'meier';
|
||||
$filter->dateFrom = new \DateTimeImmutable('2026-08-01');
|
||||
$filter->status = [AccommodationBookingStatus::Open, AccommodationBookingStatus::Confirmed];
|
||||
$filter->type = [AccommodationBookingType::Booking];
|
||||
$filter->origin = [AccommodationBookingOrigin::Direct];
|
||||
|
||||
self::assertSame(4, $filter->activeCount());
|
||||
self::assertSame('Offen, Bestätigt', $this->chipFor($filter, 'Status')?->value);
|
||||
self::assertSame('Buchung', $this->chipFor($filter, 'Art')?->value);
|
||||
self::assertSame('Direktbuchung', $this->chipFor($filter, 'Herkunft')?->value);
|
||||
self::assertSame('01.08.2026', $this->chipFor($filter, 'Aufenthalt ab')?->value);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,19 @@ class AccommodationBookingPdfGeneratorTest extends TestCase
|
||||
self::assertStringContainsString('buchung-2026-07-06-schulklasse-7b.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testADocumentForAnUnacceptedOfferIsNamedAsOne(): void
|
||||
{
|
||||
// The document describes whatever the record is at the time it is produced, so it
|
||||
// must not call an offer nobody has accepted a booking.
|
||||
$booking = $this->booking();
|
||||
$booking->setAcceptedAt(null);
|
||||
$booking->setConfirmedAt(null);
|
||||
|
||||
$response = $this->createGenerator($this->breakdown())->createDownloadResponse($booking);
|
||||
|
||||
self::assertStringContainsString('angebot-2026-07-06-schulklasse-7b.pdf', (string) $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
|
||||
public function testABookingWithoutPricesCannotBeRendered(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
@@ -81,6 +94,9 @@ class AccommodationBookingPdfGeneratorTest extends TestCase
|
||||
$booking->setBoardServiceLabel('Vollpension');
|
||||
$booking->addAdditionalServiceSnapshot('Bettwäsche', 900, 'per_person', 5);
|
||||
$booking->setRemarks('Zwei Vegetarier.');
|
||||
// A confirmation is only ever released for a booking the customer committed to,
|
||||
// so acceptedAt is always set by the time confirmedAt is.
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable('2026-08-17'));
|
||||
$booking->setConfirmedAt(new \DateTimeImmutable('2026-08-18'));
|
||||
|
||||
return $booking;
|
||||
|
||||
@@ -9,8 +9,9 @@ use App\Email\PdfAttachment;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Enum\Groups\AccommodationBookingType;
|
||||
use App\Form\Model\AccommodationBookingDto;
|
||||
use App\Model\AccommodationBookingQueryParams;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Repository\Groups\AccommodationRepository;
|
||||
@@ -69,14 +70,14 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setType(AccommodationBookingType::Booking);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Direct);
|
||||
|
||||
$service->issueAccessLinkForDirectBooking($booking);
|
||||
|
||||
self::assertNotNull($booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testIssueAccessLinkForDirectBookingNoOpsForInquiry(): void
|
||||
public function testIssueAccessLinkForDirectBookingNoOpsForAnOffer(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
@@ -84,7 +85,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setType(AccommodationBookingType::Inquiry);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
|
||||
$service->issueAccessLinkForDirectBooking($booking);
|
||||
|
||||
@@ -99,7 +100,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setType(AccommodationBookingType::Booking);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Direct);
|
||||
$issuedAt = new \DateTimeImmutable('2026-01-01');
|
||||
$booking->setAccessLinkIssuedAt($issuedAt);
|
||||
|
||||
@@ -267,7 +268,236 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
self::assertNotSame($previousIssuedAt, $booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
public function testAcceptBookingMovesOpenInquiryToReceivedAndNotifiesTheOfficeOnly(): void
|
||||
public function testAnInquiryIsPersistedAsRequestedSoTheOfficeStillOwesAnOffer(): void
|
||||
{
|
||||
// Angefragt, not Offen: the customer has asked, nobody has offered anything yet.
|
||||
$booking = $this->persistDto(forceInquiry: true);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Requested, $booking->getStatus());
|
||||
self::assertSame(AccommodationBookingOrigin::Offer, $booking->getOrigin());
|
||||
self::assertNull($booking->getAcceptedAt(), 'asking is not committing');
|
||||
}
|
||||
|
||||
public function testADirectBookingIsPersistedAsReceivedAwaitingTheOffice(): void
|
||||
{
|
||||
$booking = $this->persistDto(forceInquiry: false);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Received, $booking->getStatus());
|
||||
self::assertSame(AccommodationBookingOrigin::Direct, $booking->getOrigin());
|
||||
self::assertNotNull($booking->getAcceptedAt(), 'booking directly is the commitment');
|
||||
}
|
||||
|
||||
private function persistDto(bool $forceInquiry): AccommodationBooking
|
||||
{
|
||||
// A price covering the whole window with no minimum the booking misses, so
|
||||
// computeInquiryStatus() has no reason of its own to force an inquiry.
|
||||
$price = (new AccommodationPrice())
|
||||
->setDateFrom(new \DateTimeImmutable('2026-07-01'))
|
||||
->setDateTo(new \DateTimeImmutable('2026-09-30'))
|
||||
->setIncludedPax(10)
|
||||
->setMinNights(2);
|
||||
|
||||
$dto = new AccommodationBookingDto();
|
||||
$dto->dateFrom = new \DateTimeImmutable('2026-08-01');
|
||||
$dto->dateTo = new \DateTimeImmutable('2026-08-05');
|
||||
$dto->paxCount = 40;
|
||||
$dto->groupName = 'Schulklasse 7b';
|
||||
$dto->email = '[email protected]';
|
||||
$dto->forceInquiry = $forceInquiry;
|
||||
|
||||
$accommodation = (new Accommodation())->setName('Hotel')->setCalendarCode('HOTEL')->setMaxAdolescentAge(17);
|
||||
|
||||
return $this->createServiceWithAccommodation()->persist(
|
||||
$dto,
|
||||
$accommodation,
|
||||
[$price],
|
||||
['additionalServices' => [], 'boardServices' => []],
|
||||
);
|
||||
}
|
||||
|
||||
public function testSendOfferIssuesTheLinkMovesToOpenAndMailsTheCustomer(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::atLeastOnce())->method('flush');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Requested);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer
|
||||
->expects(self::once())
|
||||
->method('createAndSendEmail')
|
||||
->with(
|
||||
self::anything(),
|
||||
self::callback(static fn (array $options) => '[email protected]' === $options['to']
|
||||
&& 'Dein Angebot ist bereit' === $options['subject']
|
||||
&& 'email/accommodation_booking_customer.html.twig' === $options['template']),
|
||||
);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager, mailer: $mailer);
|
||||
|
||||
$service->sendOffer($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Open, $booking->getStatus());
|
||||
self::assertNotNull($booking->getAccessLinkIssuedAt(), 'the mail links to the offer, so the link has to exist by the time it goes out');
|
||||
}
|
||||
|
||||
public function testSendOfferPublishesAnAdminAuthoredDraftTheSameWay(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Draft);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$service->sendOffer($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Open, $booking->getStatus());
|
||||
}
|
||||
|
||||
public function testSendOfferKeepsAnAlreadyIssuedLinkSoEarlierLinksStayValid(): void
|
||||
{
|
||||
$issuedAt = new \DateTimeImmutable('2026-01-01');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Requested);
|
||||
$booking->setEmail('[email protected]');
|
||||
$booking->setAccessLinkIssuedAt($issuedAt);
|
||||
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$service->sendOffer($booking);
|
||||
|
||||
self::assertSame($issuedAt, $booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider statusesThatAreNotAwaitingAnOffer
|
||||
*/
|
||||
public function testSendOfferNoOpsOnceTheOfferIsOut(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer->expects(self::never())->method('createAndSendEmail');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager, mailer: $mailer);
|
||||
|
||||
$service->sendOffer($booking);
|
||||
|
||||
self::assertSame($status, $booking->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function statusesThatAreNotAwaitingAnOffer(): iterable
|
||||
{
|
||||
yield 'open' => [AccommodationBookingStatus::Open];
|
||||
yield 'received' => [AccommodationBookingStatus::Received];
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
}
|
||||
|
||||
public function testDiscardBookingClosesTheBookingSilently(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer->expects(self::never())->method('createAndSendEmail');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager, mailer: $mailer);
|
||||
|
||||
$service->discardBooking($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Discarded, $booking->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider closedStatuses
|
||||
*/
|
||||
public function testDiscardBookingNoOpsForAClosedBooking(AccommodationBookingStatus $status): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus($status);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$service->discardBooking($booking);
|
||||
|
||||
self::assertSame($status, $booking->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{AccommodationBookingStatus}>
|
||||
*/
|
||||
public static function closedStatuses(): iterable
|
||||
{
|
||||
yield 'confirmed' => [AccommodationBookingStatus::Confirmed];
|
||||
yield 'discarded' => [AccommodationBookingStatus::Discarded];
|
||||
}
|
||||
|
||||
/**
|
||||
* The dead end this flow was rebuilt to remove: Offen used to mean both "inquiry not yet
|
||||
* offered" and "offer out with the customer", and acceptBooking() additionally demanded
|
||||
* the Anfrage type. A direct booking nudged into Offen therefore rendered an offer page
|
||||
* whose accept button silently did nothing, forever. Offen is now reachable only through
|
||||
* sendOffer(), and acceptance turns on the status alone.
|
||||
*/
|
||||
public function testAnOpenBookingCanAlwaysBeAcceptedWhateverItsOrigin(): void
|
||||
{
|
||||
foreach (AccommodationBookingOrigin::cases() as $origin) {
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Open);
|
||||
$booking->setOrigin($origin);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$this->createServiceWithAccommodation()->acceptBooking($booking);
|
||||
|
||||
self::assertSame(
|
||||
AccommodationBookingStatus::Received,
|
||||
$booking->getStatus(),
|
||||
sprintf('an offer that is out must be acceptable, %s origin included', $origin->value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testTheOriginSurvivesTheWholeLifecycleUntouched(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setStatus(AccommodationBookingStatus::Requested);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
$booking->setEmail('[email protected]');
|
||||
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$service->sendOffer($booking);
|
||||
$service->acceptBooking($booking);
|
||||
$service->confirmBooking($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Confirmed, $booking->getStatus());
|
||||
self::assertSame(
|
||||
AccommodationBookingOrigin::Offer,
|
||||
$booking->getOrigin(),
|
||||
'where a booking came from stays true at every point of its life',
|
||||
);
|
||||
}
|
||||
|
||||
public function testAcceptBookingMovesOpenOfferToReceivedAndNotifiesTheOfficeOnly(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
@@ -293,7 +523,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
self::assertSame(AccommodationBookingStatus::Received, $booking->getStatus());
|
||||
self::assertSame(AccommodationBookingType::Inquiry, $booking->getType(), 'an accepted offer stays an Anfrage');
|
||||
self::assertSame(AccommodationBookingOrigin::Offer, $booking->getOrigin(), 'accepting does not rewrite where the booking came from');
|
||||
self::assertNotNull($booking->getAcceptedAt());
|
||||
}
|
||||
|
||||
@@ -482,7 +712,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager, mailer: $mailer);
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setType(AccommodationBookingType::Inquiry);
|
||||
$booking->setOrigin(AccommodationBookingOrigin::Offer);
|
||||
$booking->setStatus(AccommodationBookingStatus::Draft);
|
||||
|
||||
$service->acceptBooking($booking);
|
||||
|
||||
Reference in New Issue
Block a user