'leading|trailing'], )] public function index(AccommodationBooking $booking, AccommodationBookingPeriodPosition $position, Request $request): Response { // One period per side. The edit page only offers the free sides, so this catches a page // that was open while somebody else split the same side. if (!$booking->canSplitOffPeriod($position)) { $this->addFlash('error', AccommodationBookingPeriodPosition::Leading === $position ? 'Am Anfang wurde bereits ein Zeitraum abgeteilt.' : 'Am Ende wurde bereits ein Zeitraum abgeteilt.'); return $this->htmxRedirect($request, $this->editUrl($booking, $request)); } $dto = new AccommodationBookingPeriodDto(1, [new AccommodationBookingPeriodLineDto()]); $form = $this->createForm(AccommodationBookingPeriodType::class, $dto, [ 'currency' => $booking->getPricingCurrency() ?? $booking->getAccommodation()?->getCurrency() ?? 'EUR', 'hx_post' => $request->getRequestUri(), ]); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { try { $violations = $this->bookingService->splitOffPeriod($booking, $position, $dto); foreach ($violations as $violation) { $form->addError(new FormError((string) $violation->getMessage())); } if (0 === count($violations)) { $this->addFlash('success', 'Der Zeitraum wurde abgeteilt.'); $this->logger->info('Split off a period of accommodation booking', [ 'id' => $booking->getId(), 'position' => $position->value, 'nights' => $dto->nights, ]); return $this->htmxRedirect($request, $this->editUrl($booking, $request)); } } catch (ImplausibleBookingPriceException $e) { $this->logger->error('Refused to split off a period over an implausible accommodation booking total', [ 'exception' => $e, 'id' => $booking->getId(), ]); $form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE)); } } return $this->renderModal($booking, $position, $form); } /** @param FormInterface $form */ private function renderModal(AccommodationBooking $booking, AccommodationBookingPeriodPosition $position, FormInterface $form): Response { return $this->render('admin/accommodation_booking/modal_period.html.twig', [ 'booking' => $booking, 'form' => $form, 'title' => AccommodationBookingPeriodPosition::Leading === $position ? 'Zeitraum am Anfang abteilen' : 'Zeitraum am Ende abteilen', ]); } }