feat: split nights off an accommodation booking as separate periods
addresses #869f6z36v
This commit is contained in:
1 parent
972839286c
commit
7001bc0cf2
35 files changed
+2221
-25
No files matched your search
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin\AccommodationBooking;
|
||||
|
||||
use App\Entity\Groups\AccommodationBookingPeriod;
|
||||
use App\Exception\ImplausibleBookingPriceException;
|
||||
use App\Form\Admin\Groups\AccommodationBookingPeriodType;
|
||||
use App\Form\Model\AccommodationBookingPeriodDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
/** Changes the length and the lines of a split-off period; the main period absorbs the difference. */
|
||||
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||
class EditPeriodController extends AbstractController
|
||||
{
|
||||
use HxTrait;
|
||||
use RedirectsToEditFormTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly AccommodationBookingService $bookingService,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/accommodation-booking-period/{id}/edit', name: 'app_admin_accommodationbooking_period_edit')]
|
||||
public function index(AccommodationBookingPeriod $period, Request $request): Response
|
||||
{
|
||||
$booking = $period->getBooking() ?? throw $this->createNotFoundException();
|
||||
|
||||
$dto = AccommodationBookingPeriodDto::fromPeriod($period);
|
||||
$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->updatePeriod($booking, $period, $dto);
|
||||
|
||||
foreach ($violations as $violation) {
|
||||
$form->addError(new FormError((string) $violation->getMessage()));
|
||||
}
|
||||
|
||||
if (0 === count($violations)) {
|
||||
$this->addFlash('success', 'Der Zeitraum wurde aktualisiert.');
|
||||
|
||||
$this->logger->info('Updated a period of accommodation booking', [
|
||||
'id' => $booking->getId(),
|
||||
'periodId' => $period->getId(),
|
||||
'nights' => $dto->nights,
|
||||
]);
|
||||
|
||||
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||
}
|
||||
} catch (ImplausibleBookingPriceException $e) {
|
||||
$this->logger->error('Refused to update a period over an implausible accommodation booking total', [
|
||||
'exception' => $e,
|
||||
'id' => $booking->getId(),
|
||||
'periodId' => $period->getId(),
|
||||
]);
|
||||
$form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/accommodation_booking/modal_period.html.twig', [
|
||||
'booking' => $booking,
|
||||
'form' => $form,
|
||||
'title' => 'Zeitraum bearbeiten',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user