feat: offer rooms on request by Anf code suffix

This commit is contained in:
fromme committed 2026-11-11 11:35:38 +01:00
1 parent 2936d8947a
commit 0b0286787b
11 files changed
+204 -41

No files matched your search

+3 -2
View File
@@ -270,8 +270,9 @@ them a website shows, and how, is the client's rule, not this endpoint's.
**Which rooms can be booked.** Each room carries `bookable`, the one derived field: `true` exactly when the
booking flow offers the room for a new booking. That is status `Frei` with `available` above 0. A room on request
(`Anfrage`) is not bookable even with rooms left, because booking it would only produce an inquiry; neither is a
room with `available` 0 or `null`. Show a room that is not bookable as sold out and do not count it towards places
(`Anfrage`) is not bookable even with rooms left, because booking it would only produce an inquiry, unless its
`code` ends in `Anf` (case-sensitive, e.g. `6erSDAnf`): the office sells such a room on request on purpose, it is
`bookable`, and booking it makes the whole booking an inquiry. No room with `available` 0 or `null` is bookable. Show a room that is not bookable as sold out and do not count it towards places
or the "ab" price. Read `bookable` rather than deriving it from `status` and `available`, so a change to the rule
reaches you without a client change.
+7 -5
View File
@@ -80,11 +80,13 @@ Trip rules (`App\Chatbot\TripCatalog`):
shown under its TYPO3 title, and under BusPro's name only when TYPO3 has no hotel for its code.
`query` searches both. Trips have no name in BusPro's export, only a code; their names are TYPO3's.
- A room is listed unless its status is `Buchungsstop`. The baby row (room code `Baby`) is not a room.
A listed room is bookable when the booking flow offers it (`Frei` with rooms left, the export's `bookable`);
any other room, including one on request (`Anfrage`), is sold out, as the website shows it. Dates with
only sold-out rooms stay in `search_trips`, marked `ausgebucht`. `available` counts rooms, so the places
of a date at a hotel are `Σ available × maxPax` over its bookable rooms, and the "ab" price is the
cheapest bookable room's. The tools never output room counts, only `frei` or `ausgebucht`.
A listed room is bookable when the booking flow offers it (the export's `bookable`): `Frei` with rooms
left is `frei`; `Anfrage` with rooms left and a room code ending in `Anf` (sold on request on purpose,
booking it produces an inquiry) is `auf Anfrage`. Any other room, including any other one on request, is
sold out, as the website shows it. A date at a hotel is as available as its best room; dates with only
sold-out rooms stay in `search_trips`, marked `ausgebucht`. `available` counts rooms, so the places of a
date at a hotel are `Σ available × maxPax` over its bookable rooms, and the "ab" price is the cheapest
bookable room's. The tools never output room counts, only `frei`, `auf Anfrage` or `ausgebucht`.
- `search_trips` only offers products that TYPO3 lists in its own website search (`searchable`) and does
not mark as unbookable. Closed group trips and staff trainings are `searchable: false`. `get_trip` still
answers when someone names their code.
+26 -7
View File
@@ -22,15 +22,34 @@ class Room
public const SELECTION_TYPE_BY_ROOM = 'by_room';
/**
* Whether a room with this status and availability is offered for new bookings.
*
* Only 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking
* into an inquiry, so it is treated as sold out. Static and taking the raw values so the
* product export and the chatbot, which hold rooms as arrays, apply the same rule.
* Room code suffix by which the office marks a room as deliberately sold on request.
*/
public static function isBookableState(?string $status, ?int $available): bool
public const ON_REQUEST_CODE_SUFFIX = 'Anf';
/**
* Whether a room with this status, availability and code is offered for new bookings.
*
* 'Frei' rooms with rooms left. A room on request ('Anfrage') would turn the booking into
* an inquiry, so it is treated as sold out, unless isOnRequestByCode() says the office
* sells it that way on purpose. Static and taking the raw values so the product export
* and the chatbot, which hold rooms as arrays, apply the same rule.
*/
public static function isBookableState(?string $status, ?int $available, ?string $code): bool
{
return Constants::STATUS_AVAILABLE === $status && ($available ?? 0) > 0;
if (($available ?? 0) <= 0) {
return false;
}
return Constants::STATUS_AVAILABLE === $status
|| (Constants::STATUS_ON_REQUEST === $status && self::isOnRequestByCode($code));
}
/**
* Whether the room code carries the on-request suffix (case-sensitive, e.g. `6erSDAnf`).
*/
public static function isOnRequestByCode(?string $code): bool
{
return null !== $code && str_ends_with($code, self::ON_REQUEST_CODE_SUFFIX);
}
#[Groups(['api:list', 'api:single', 'snapshot'])]
+3 -2
View File
@@ -279,7 +279,8 @@ class Travel
/**
* Retrieves all bookable rooms.
*
* Returns the rooms Room::isBookableState() accepts: status 'Frei' with rooms left.
* Returns the rooms Room::isBookableState() accepts: status 'Frei' with rooms left, or rooms
* the office sells on request on purpose, which turn the booking into an inquiry.
*
* @return array<int, Room> The filtered array of bookable rooms, indexed by room ID
*/
@@ -287,7 +288,7 @@ class Travel
{
$result = [];
foreach ($this->rooms as $room) {
if (Room::isBookableState($room->status, $room->available)) {
if (Room::isBookableState($room->status, $room->available, $room->code)) {
$result[$room->id] = $room;
}
}
@@ -92,7 +92,7 @@ class ProductExportParser extends AbstractParser
'price' => $this->stringToFloat($this->getAttrOrNullValue($room, 'preis')),
'available' => $available,
'status' => $status,
'bookable' => Room::isBookableState($status, $available),
'bookable' => Room::isBookableState($status, $available, $code),
'boardCode' => $this->getAttrOrNullValue($room, 'vpcode'),
'boardBusProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_vp'),
];
+2 -2
View File
@@ -694,7 +694,7 @@ class TripCatalog
'board' => $room['boardCode'] ?? null,
'nights' => $room['nights'] ?? null,
'price' => $room['price'] ?? null,
'availability' => TravelDateFacts::isBookableRoom($room) ? TravelDateFacts::AVAILABILITY_FREE : TravelDateFacts::AVAILABILITY_SOLD_OUT,
'availability' => TravelDateFacts::roomAvailability($room),
], static fn (mixed $value): bool => null !== $value);
}
@@ -710,7 +710,7 @@ class TripCatalog
'hotel' => $this->hotelName($catalog, $hotel, $row),
'hotelCode' => $row['hotel']['code'],
'rooms' => $rooms,
'bookable' => in_array(TravelDateFacts::AVAILABILITY_FREE, array_column($rooms, 'availability'), true),
'bookable' => [] !== array_diff(array_column($rooms, 'availability'), [TravelDateFacts::AVAILABILITY_SOLD_OUT]),
];
}
+28 -7
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Model\Chatbot;
use App\BusProNet\Constants;
use App\BusProNet\Model\Room;
use App\Enum\RoomType;
@@ -12,7 +13,8 @@ use App\Enum\RoomType;
* a product export row the way TYPO3's DateImportService derives it, with two deliberate
* differences: rooms in `Buchungsstop` are not listed, and neither is the baby row. A listed
* room is bookable when Room::isBookableState() says so, as the booking flow offers it;
* the others are sold out, as the website shows them.
* the others are sold out, as the website shows them. A bookable room on request is reported
* as such, because booking it only produces an inquiry.
*
* - places: Σ available × maxPax over the bookable rooms (`available` counts rooms);
* - priceFrom ("ab" price): cheapest bookable room, else cheapest listed room;
@@ -23,8 +25,12 @@ use App\Enum\RoomType;
final readonly class TravelDateFacts
{
public const AVAILABILITY_FREE = 'frei';
public const AVAILABILITY_ON_REQUEST = 'auf Anfrage';
public const AVAILABILITY_SOLD_OUT = 'ausgebucht';
/** Best first: a date is as available as its best room. */
private const AVAILABILITY_RANK = [self::AVAILABILITY_FREE, self::AVAILABILITY_ON_REQUEST, self::AVAILABILITY_SOLD_OUT];
public const STATUS_BOOKING_STOP = 'Buchungsstop';
private const GROUP_SKIPASS = 7;
@@ -73,14 +79,13 @@ final readonly class TravelDateFacts
continue;
}
$bookable = self::isBookableRoom($room);
$roomAvailability = self::roomAvailability($room);
$bookable = self::AVAILABILITY_SOLD_OUT !== $roomAvailability;
if ($bookable) {
$places += (int) $room['available'] * (int) ($room['maxPax'] ?? 0);
}
$roomTypes[$type->value] = $type;
$availability = $bookable || self::AVAILABILITY_FREE === $availability
? self::AVAILABILITY_FREE
: self::AVAILABILITY_SOLD_OUT;
$availability = null === $availability ? $roomAvailability : self::better($availability, $roomAvailability);
if (is_int($room['minPax'] ?? null) && (null === $minPax || $room['minPax'] < $minPax)) {
$minPax = $room['minPax'];
@@ -144,11 +149,27 @@ final readonly class TravelDateFacts
}
/**
* One of the AVAILABILITY_* constants.
*
* @param array<string, mixed> $room a room of a ProductExportBuilder row
*/
public static function isBookableRoom(array $room): bool
public static function roomAvailability(array $room): string
{
return Room::isBookableState($room['status'] ?? null, $room['available'] ?? null);
if (!Room::isBookableState($room['status'] ?? null, $room['available'] ?? null, $room['code'] ?? null)) {
return self::AVAILABILITY_SOLD_OUT;
}
return Constants::STATUS_ON_REQUEST === ($room['status'] ?? null)
? self::AVAILABILITY_ON_REQUEST
: self::AVAILABILITY_FREE;
}
/**
* The better of two AVAILABILITY_* values.
*/
private static function better(string $a, string $b): string
{
return array_search($a, self::AVAILABILITY_RANK, true) <= array_search($b, self::AVAILABILITY_RANK, true) ? $a : $b;
}
/**
+24 -4
View File
@@ -648,16 +648,24 @@ class BookingConfigurator
}
/**
* Resets the booking status after the room selection in Step 1.
* Updates the booking status after the room selection in Step 1.
*
* The status returns to what the travel called for when the booking started, and the
* create-flow rules run again. An 'A' from the Step 3 BusPro fallback is cleared this way;
* Step 3 validates again with the new rooms and re-applies it if needed.
* If any selected room is on request, which Step 1 offers only for rooms the office sells
* that way on purpose (Room::isBookableState()), the whole booking becomes an inquiry.
* Otherwise the status returns to what the travel called for when the booking started,
* and the create-flow rules run again. An 'A' from the Step 3 BusPro fallback is cleared
* this way; Step 3 validates again with the new rooms and re-applies it if needed.
*
* @param BookingDto $bookingDto The booking DTO to update
*/
public function updateBookingStatusFromRoomSelection(BookingDto $bookingDto): void
{
if ($this->hasOnRequestRoomSelected($bookingDto)) {
$bookingDto->bookingStatus = Constants::BOOKING_STATUS_INQUIRY;
return;
}
// Sessions started before the initial status was recorded keep their current status
if (null === $bookingDto->initialBookingStatus) {
return;
@@ -667,6 +675,18 @@ class BookingConfigurator
$this->applyCreateBookingStatusRules($bookingDto);
}
private function hasOnRequestRoomSelected(BookingDto $bookingDto): bool
{
foreach ($bookingDto->getSelectedRooms() as $roomSelection) {
$room = $bookingDto->travel->getRoomById($roomSelection->id);
if (null !== $room && Constants::STATUS_ON_REQUEST === $room->status) {
return true;
}
}
return false;
}
/**
* Applies booking-level status rules in create flow.
*
+16 -10
View File
@@ -12,22 +12,28 @@ use PHPUnit\Framework\TestCase;
class RoomTest extends TestCase
{
#[DataProvider('bookableStateProvider')]
public function testIsBookableState(?string $status, ?int $available, bool $expected): void
public function testIsBookableState(?string $status, ?int $available, ?string $code, bool $expected): void
{
self::assertSame($expected, Room::isBookableState($status, $available));
self::assertSame($expected, Room::isBookableState($status, $available, $code));
}
/**
* @return iterable<string, array{?string, ?int, bool}>
* @return iterable<string, array{?string, ?int, ?string, bool}>
*/
public static function bookableStateProvider(): iterable
{
yield 'free with rooms left' => [Constants::STATUS_AVAILABLE, 3, true];
yield 'free but sold out' => [Constants::STATUS_AVAILABLE, 0, false];
yield 'free without a count' => [Constants::STATUS_AVAILABLE, null, false];
yield 'on request with rooms left' => [Constants::STATUS_ON_REQUEST, 5, false];
yield 'on request and sold out' => [Constants::STATUS_ON_REQUEST, 0, false];
yield 'booking stop' => [Constants::STATUS_BLOCKED, 5, false];
yield 'no status' => [null, 5, false];
yield 'free with rooms left' => [Constants::STATUS_AVAILABLE, 3, '2erDW', true];
yield 'free but sold out' => [Constants::STATUS_AVAILABLE, 0, '2erDW', false];
yield 'free without a count' => [Constants::STATUS_AVAILABLE, null, '2erDW', false];
yield 'free with the on-request suffix' => [Constants::STATUS_AVAILABLE, 3, '6erSDAnf', true];
yield 'on request with rooms left' => [Constants::STATUS_ON_REQUEST, 5, '2erDW', false];
yield 'on request and sold out' => [Constants::STATUS_ON_REQUEST, 0, '2erDW', false];
yield 'on request without a code' => [Constants::STATUS_ON_REQUEST, 5, null, false];
yield 'on request by code with rooms left' => [Constants::STATUS_ON_REQUEST, 1, '6erSDAnf', true];
yield 'on request by code and sold out' => [Constants::STATUS_ON_REQUEST, 0, '6erSDAnf', false];
yield 'on request, marker not a suffix' => [Constants::STATUS_ON_REQUEST, 1, 'Anf6erSD', false];
yield 'on request, marker in another case' => [Constants::STATUS_ON_REQUEST, 1, '6erSDANF', false];
yield 'booking stop with the on-request suffix' => [Constants::STATUS_BLOCKED, 5, '6erSDAnf', false];
yield 'no status' => [null, 5, '2erDW', false];
}
}
+21
View File
@@ -100,6 +100,27 @@ class TripCatalogTest extends TestCase
self::assertFalse($trip['dates'][1]['hotels'][0]['bookable']);
}
public function testRoomsOnRequestByCodeAreListedOnRequest(): void
{
$rows = [
// The office sells the suffixed room on request on purpose; the plain one stays sold out.
$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(2000, available: 1, maxPax: 6, status: 'Anfrage', code: '6erSDAnf'), $this->room(300, status: 'Anfrage')]),
// A free room makes the date free, whatever else is on request.
$this->row('VTH', 3, '2027-01-09', 'HOT1', [$this->room(2000, available: 1, maxPax: 6, status: 'Anfrage', code: '6erSDAnf'), $this->room(500)]),
];
$catalog = $this->catalog($rows);
$results = $catalog->search(new TripCriteria())['results'];
self::assertSame(['auf Anfrage', 'frei'], array_column($results, 'availability'));
self::assertSame([2000.0, 500.0], array_column($results, 'priceFrom'));
self::assertSame(['VTH2', 'VTH3'], array_column($catalog->search(new TripCriteria(persons: 6))['results'], 'dateCode'), 'its places count');
$trip = $catalog->get('VTH');
self::assertNotNull($trip);
self::assertSame(['auf Anfrage', 'ausgebucht'], array_column($trip['dates'][0]['hotels'][0]['rooms'], 'availability'));
self::assertTrue($trip['dates'][0]['hotels'][0]['bookable']);
}
public function testTheTravelPeriodContainsTheTripAndPricesApplyToTheAbPrice(): void
{
$rows = [$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(450), $this->room(700)])];
@@ -137,6 +137,41 @@ class BookingConfiguratorStatusTest extends TestCase
$this->assertSame([1], array_keys($bookingDto->roomSelections));
}
public function testStartFreshBookingOffersRoomsOnRequestByCode(): void
{
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 3],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 0, 'code' => '6erSDAnf'],
]);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$bookingDto = $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
$this->assertSame('F', $bookingDto->bookingStatus);
$this->assertSame([1, 3], array_keys($bookingDto->roomSelections));
}
public function testStartFreshBookingWithOnlyRoomsOnRequestByCodeStaysFinalUntilSelected(): void
{
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
]);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$bookingDto = $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
$this->assertSame('F', $bookingDto->bookingStatus);
$this->assertSame([1], array_keys($bookingDto->roomSelections));
}
public function testStartFreshBookingWithNoBookableRoomsThrowsException(): void
{
// Rooms exist but all have 0 availability
@@ -206,6 +241,28 @@ class BookingConfiguratorStatusTest extends TestCase
$this->assertSame('O', $bookingDto->bookingStatus);
}
public function testRoomSelectionSwitchesToInquiryForRoomOnRequestByCode(): void
{
$bookingDto = $this->startOnRequestByCodeBooking();
$this->selectRoom($bookingDto, 2);
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
$this->assertSame('A', $bookingDto->bookingStatus);
}
public function testRoomSelectionRevertsInquiryWhenRoomOnRequestByCodeIsDeselected(): void
{
$bookingDto = $this->startOnRequestByCodeBooking();
$this->selectRoom($bookingDto, 2);
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
$this->selectRoom($bookingDto, 1);
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
$this->assertSame('F', $bookingDto->bookingStatus);
}
public function testRoomSelectionClearsInquiryFromStep3Fallback(): void
{
$bookingDto = $this->startMixedRoomsBooking();
@@ -305,7 +362,7 @@ class BookingConfiguratorStatusTest extends TestCase
}
/**
* @param array<array{status: string, available: int}> $roomsConfig
* @param array<array{status: string, available: int, code?: string}> $roomsConfig
*/
private function createTravelWithRooms(array $roomsConfig, array $selectionGroups = []): Travel
{
@@ -325,6 +382,7 @@ class BookingConfiguratorStatusTest extends TestCase
$room->price = 100.0;
$room->available = $config['available'];
$room->status = $config['status'];
$room->code = $config['code'] ?? 'DZ';
$room->minPax = 2;
$room->category = 'A';
$room->boardId = 1;
@@ -369,6 +427,20 @@ class BookingConfiguratorStatusTest extends TestCase
return $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
}
/**
* Starts a booking on a travel with a free room (id 1) and a room on request by code (id 2).
*/
private function startOnRequestByCodeBooking(): BookingDto
{
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
]);
$this->travelDataService->method('getTravelData')->willReturn($travel);
return $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
}
private function selectRoom(BookingDto $bookingDto, int $roomId): void
{
foreach ($bookingDto->roomSelections as $roomSelection) {