feat: inquiry bookings
This commit is contained in:
@@ -671,7 +671,7 @@ class BookingDataProcessor
|
||||
|
||||
$payload = [
|
||||
'buchungsart' => $bookingType,
|
||||
'status' => 'F',
|
||||
'status' => $bookingDto->bookingStatus,
|
||||
'idreise' => $bookingDto->travel->id,
|
||||
'idpartner' => $bookingDto->travel->hotelId,
|
||||
'idagentur' => $bookingDto->agencyId,
|
||||
|
||||
@@ -46,6 +46,13 @@ class Travel
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
public ?string $type = null;
|
||||
|
||||
/**
|
||||
* Travel booking status from BusProNet API.
|
||||
* Possible values: 'Frei', 'Anfrage', 'Buchungsstop'
|
||||
*/
|
||||
#[Groups(['api:single'])]
|
||||
public ?string $status = null;
|
||||
|
||||
#[Groups(['api:list', 'api:single'])]
|
||||
public ?float $priceFrom = null;
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ class TravelParser extends AbstractParser
|
||||
$travel->dateTo = $this->stringToDate($node->attr('bis'));
|
||||
$travel->code = $node->attr('code');
|
||||
$travel->type = $node->attr('reiseart');
|
||||
$travel->status = $this->getStringOrNullValue($node->filterXPath('//status_hin'));
|
||||
$travel->priceFrom = $this->stringToFloat($this->getStringOrNullValue($node->filterXPath('//abpreis')));
|
||||
$travel->selectionGroups = $this->getSelectionGroups($node->filterXPath('//selektiongruppe'));
|
||||
$travel->additionalServices = $this
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
use App\Exception\HotelNotFoundException;
|
||||
use App\Exception\HotelNotInTravelException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
@@ -64,6 +65,8 @@ class CreateInitController extends AbstractController
|
||||
throw $this->createNotFoundException(sprintf('Hotel ID %d is not available for travel ID %d', $hotelId, $dateId));
|
||||
} catch (NoRoomsAvailableException $e) {
|
||||
throw $this->createNotFoundException('No rooms available for this travel.');
|
||||
} catch (BookingNotPossibleException $e) {
|
||||
throw $this->createNotFoundException('Booking is not possible for this travel (Buchungsstop).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exception;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
/**
|
||||
* Exception thrown when attempting to create a booking for a travel with Buchungsstop status.
|
||||
*/
|
||||
class BookingNotPossibleException extends HttpException
|
||||
{
|
||||
public function __construct(int $dateId, int $hotelId, ?\Throwable $previous = null)
|
||||
{
|
||||
$message = sprintf(
|
||||
'Für diese Reise ist aktuell keine Buchung möglich (Travel ID: %d, Hotel ID: %d). Status: Buchungsstop',
|
||||
$dateId,
|
||||
$hotelId
|
||||
);
|
||||
|
||||
parent::__construct(400, $message, $previous);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,12 @@ class BookingDto
|
||||
|
||||
public ?int $agencyId = null;
|
||||
|
||||
/**
|
||||
* Booking status code for API submission.
|
||||
* Values: 'F' (Final/Frei), 'A' (Anfrage/Inquiry)
|
||||
*/
|
||||
public string $bookingStatus = 'F';
|
||||
|
||||
/**
|
||||
* Reference to booking entity (only populated in edit mode).
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
use App\Exception\BookingSessionNotFoundException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Form\Model\BookingDto;
|
||||
@@ -166,6 +167,11 @@ class BookingService
|
||||
* This method initializes a new BookingDto with empty room selections
|
||||
* and saves it to the session. It's designed to be called from the clean
|
||||
* booking entry point without requiring UID parameters.
|
||||
*
|
||||
* Handles three booking status types:
|
||||
* - 'Frei': Regular booking with availability checks
|
||||
* - 'Anfrage': Inquiry booking, allows booking even with 0 availability
|
||||
* - 'Buchungsstop': Booking stopped, no bookings allowed
|
||||
*/
|
||||
public function startFreshBooking(Request $request, int $dateId, int $hotelId, ?int $agencyId = null): BookingDto
|
||||
{
|
||||
@@ -174,13 +180,31 @@ class BookingService
|
||||
throw new NotFoundHttpException(sprintf('Travel data not found for date ID %d and hotel ID %d', $dateId, $hotelId));
|
||||
}
|
||||
|
||||
// Handle Buchungsstop - no bookings allowed at all
|
||||
if ('Buchungsstop' === $travelData->status) {
|
||||
throw new BookingNotPossibleException($dateId, $hotelId);
|
||||
}
|
||||
|
||||
// Determine booking status based on travel status
|
||||
$isInquiryBooking = 'Anfrage' === $travelData->status;
|
||||
$bookingStatus = $isInquiryBooking ? 'A' : 'F';
|
||||
|
||||
// Get available rooms
|
||||
$availableRooms = $travelData->getAvailableRooms();
|
||||
|
||||
// Prevent booking flow entry when no rooms are available
|
||||
if (empty($availableRooms)) {
|
||||
// For regular bookings (Frei), prevent entry when no rooms are available
|
||||
// For inquiry bookings (Anfrage), allow even with 0 availability
|
||||
if (false === $isInquiryBooking && empty($availableRooms)) {
|
||||
throw new NoRoomsAvailableException($dateId, $hotelId);
|
||||
}
|
||||
|
||||
// For inquiry bookings with 0 availability, get all rooms ignoring availability count
|
||||
if ($isInquiryBooking && empty($availableRooms)) {
|
||||
$availableRooms = array_filter($travelData->rooms, function (Room $room) {
|
||||
return \App\BusProNet\Constants::STATUS_AVAILABLE === $room->status;
|
||||
});
|
||||
}
|
||||
|
||||
// Create room selections with zero quantities (user will set these in step 1)
|
||||
$roomSelections = array_map(
|
||||
fn (Room $room) => $this->createRoomSelection($room, []),
|
||||
@@ -191,6 +215,7 @@ class BookingService
|
||||
$bookingCreateDto->roomSelections = $roomSelections;
|
||||
$bookingCreateDto->currentStep = 1;
|
||||
$bookingCreateDto->agencyId = $agencyId;
|
||||
$bookingCreateDto->bookingStatus = $bookingStatus;
|
||||
|
||||
$this->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
{% block content %}
|
||||
{% include '_partials/_flashes.html.twig' %}
|
||||
<h1>Neue Buchung</h1>
|
||||
{% if bookingCreateDto.bookingStatus == 'A' %}
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6">
|
||||
<div class="flex items-start">
|
||||
<svg class="w-5 h-5 text-blue-600 mt-0.5 mr-3" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
<div>
|
||||
<h3 class="text-blue-900 font-semibold">Buchung auf Anfrage</h3>
|
||||
<p class="text-blue-800 text-sm mt-1">Diese Reise kann nur auf Anfrage gebucht werden. Deine Buchung wird nach Eingang geprüft und du erhältst eine Bestätigung.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="grid grid-cols-3 gap-8">
|
||||
<div class="col-span-2">
|
||||
<h2 class="pb-4">
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
|
||||
<h1>Neue Buchung</h1>
|
||||
|
||||
{% if bookingCreateDto.bookingStatus == 'A' %}
|
||||
<div class="bg-amber-50 border border-amber-200 rounded-lg p-4 mb-6">
|
||||
<div class="flex items-start">
|
||||
<svg class="w-5 h-5 text-amber-600 mt-0.5 mr-3 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
<div>
|
||||
<h3 class="text-amber-900 font-semibold">Achtung: Buchung auf Anfrage</h3>
|
||||
<p class="text-amber-800 text-sm mt-1">Diese Buchung erfolgt auf Anfrage. Nach der Absendung wird deine Anfrage geprüft. Du erhältst anschließend eine verbindliche Buchungsbestätigung oder eine Absage per E-Mail.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<h2 class="mb-6">Buchung bestätigen</h2>
|
||||
|
||||
|
||||
@@ -184,4 +184,103 @@ class TravelParserTest extends TestCase
|
||||
$this->assertSame('Service with empty description', $service->label);
|
||||
$this->assertNull($service->description); // Empty hinweis should result in null description
|
||||
}
|
||||
|
||||
public function testParseTravelStatusFrei(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<reisen>
|
||||
<reise id="1" idbuspro="2187" code="SSTMR">
|
||||
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
|
||||
<text>Test Travel</text>
|
||||
<abpreis>659,00</abpreis>
|
||||
<status_hin>Frei</status_hin>
|
||||
<hotel id="1" idbuspro="157047">
|
||||
<zimmer>
|
||||
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="8" />
|
||||
</zimmer>
|
||||
</hotel>
|
||||
</termin>
|
||||
</reise>
|
||||
</reisen>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$travelNode = $crawler->filterXPath('//reise/termin')->first();
|
||||
$travel = $this->parser->parse($travelNode);
|
||||
|
||||
$this->assertSame('Frei', $travel->status);
|
||||
}
|
||||
|
||||
public function testParseTravelStatusAnfrage(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<reisen>
|
||||
<reise id="1" idbuspro="2187" code="SSTMR">
|
||||
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
|
||||
<text>Test Travel</text>
|
||||
<abpreis>659,00</abpreis>
|
||||
<status_hin>Anfrage</status_hin>
|
||||
<hotel id="1" idbuspro="157047">
|
||||
<zimmer>
|
||||
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="0" />
|
||||
</zimmer>
|
||||
</hotel>
|
||||
</termin>
|
||||
</reise>
|
||||
</reisen>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$travelNode = $crawler->filterXPath('//reise/termin')->first();
|
||||
$travel = $this->parser->parse($travelNode);
|
||||
|
||||
$this->assertSame('Anfrage', $travel->status);
|
||||
}
|
||||
|
||||
public function testParseTravelStatusBuchungsstop(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<reisen>
|
||||
<reise id="1" idbuspro="2187" code="SSTMR">
|
||||
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
|
||||
<text>Test Travel</text>
|
||||
<abpreis>659,00</abpreis>
|
||||
<status_hin>Buchungsstop</status_hin>
|
||||
<hotel id="1" idbuspro="157047">
|
||||
<zimmer>
|
||||
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="5" />
|
||||
</zimmer>
|
||||
</hotel>
|
||||
</termin>
|
||||
</reise>
|
||||
</reisen>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$travelNode = $crawler->filterXPath('//reise/termin')->first();
|
||||
$travel = $this->parser->parse($travelNode);
|
||||
|
||||
$this->assertSame('Buchungsstop', $travel->status);
|
||||
}
|
||||
|
||||
public function testParseTravelWithoutStatus(): void
|
||||
{
|
||||
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<reisen>
|
||||
<reise id="1" idbuspro="2187" code="SSTMR">
|
||||
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
|
||||
<text>Test Travel</text>
|
||||
<abpreis>659,00</abpreis>
|
||||
<hotel id="1" idbuspro="157047">
|
||||
<zimmer>
|
||||
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="8" />
|
||||
</zimmer>
|
||||
</hotel>
|
||||
</termin>
|
||||
</reise>
|
||||
</reisen>';
|
||||
|
||||
$crawler = new Crawler($xmlContent);
|
||||
$travelNode = $crawler->filterXPath('//reise/termin')->first();
|
||||
$travel = $this->parser->parse($travelNode);
|
||||
|
||||
$this->assertNull($travel->status); // No status_hin node should result in null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\ParticipantEligibilityService;
|
||||
use App\Service\TravelDataService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class BookingServiceStatusTest extends TestCase
|
||||
{
|
||||
private BookingService $bookingService;
|
||||
private TravelDataService $travelDataService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->travelDataService = $this->createMock(TravelDataService::class);
|
||||
$priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
|
||||
$participantEligibility = $this->createMock(ParticipantEligibilityService::class);
|
||||
|
||||
$this->bookingService = new BookingService(
|
||||
$this->travelDataService,
|
||||
$priceCalculator,
|
||||
$participantEligibility
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithFreiStatus(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Frei', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('F', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithFreiStatusAndNoRoomsThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Frei', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(NoRoomsAvailableException::class);
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithAnfrageStatus(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Anfrage', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('A', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithAnfrageStatusAndNoRoomsAllowsBooking(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Anfrage', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('A', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithBuchungsstopThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Buchungsstop', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(BookingNotPossibleException::class);
|
||||
$this->expectExceptionMessage('Für diese Reise ist aktuell keine Buchung möglich');
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithBuchungsstopAndNoRoomsThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Buchungsstop', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(BookingNotPossibleException::class);
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
private function createTravelWithStatus(string $status, int $availability): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->id = 123;
|
||||
$travel->hotelId = 456;
|
||||
$travel->status = $status;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->label = 'Test Room';
|
||||
$room->price = 100.0;
|
||||
$room->available = $availability;
|
||||
$room->status = \App\BusProNet\Constants::STATUS_AVAILABLE;
|
||||
$room->minPax = 2;
|
||||
$room->category = 'A';
|
||||
$room->boardId = 1;
|
||||
|
||||
$travel->rooms = [1 => $room];
|
||||
|
||||
return $travel;
|
||||
}
|
||||
|
||||
private function createRequestWithSession(): Request
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user