fix: stop offering unbookable services in the booking edit flow

This commit is contained in:
fromme committed 2026-09-16 15:28:07 +02:00
1 parent 672fc30d7e
commit 160ebef39e
18 files changed
+1094 -104

No files matched your search

+25
View File
@@ -143,6 +143,31 @@ class Booking
});
}
/**
* Checks whether a participant already holds a service in this booking.
*
* This is the BusPro-side baseline, not the working edit selection: it answers
* "did the participant have this service when the booking was last read back".
* Services already held may be kept regardless of their current status or
* contingent - withdrawing one produces "Anzahl Leistung stimmt nicht mit
* Teilnehmerzuordnung überein" on the next update.
*
* @param int $participantIndex The participant index to search for
* @param int $serviceId The service ID to look for
*
* @return bool True if the participant already holds the service
*/
public function hasServiceForParticipant(int $participantIndex, int $serviceId): bool
{
foreach ([...$this->additionalServices, ...$this->transportationServices] as $service) {
if ($service->id === $serviceId && in_array($participantIndex, $service->mapping)) {
return true;
}
}
return false;
}
/**
* Retrieves transportation service for a specific participant and direction.
*
+16 -5
View File
@@ -281,9 +281,9 @@ class TravelLoader extends AbstractLoader
/**
* Apply availability data to travel services.
*
* Updates the availability status of additional and transportation
* services, and the allowed booking status, based on the provided
* availability data.
* Updates the remaining contingent and the live status of additional and
* transportation services, and the allowed booking status, based on the
* provided availability data.
*
* @param Travel $travel The travel object to update
* @param ServiceAvailabilityResponse $availabilities The availability data for services
@@ -293,8 +293,19 @@ class TravelLoader extends AbstractLoader
$serviceAvailabilities = $availabilities->getServices();
foreach ([...$travel->additionalServices, ...$travel->transportationServices] as $service) {
if (array_key_exists($service->id, $serviceAvailabilities)) {
$service->available = $serviceAvailabilities[$service->id]->available;
if (false === array_key_exists($service->id, $serviceAvailabilities)) {
continue;
}
$availability = $serviceAvailabilities[$service->id];
$service->available = $availability->available;
// The live status is the only signal that a contingent has run out: BusPro moves a
// Leistung to 'Anfrage' without necessarily reporting frei="0". Only overwrite when the
// response actually carries one, so a response that omits the attribute does not wipe
// the value parsed from the XML export. Mirrors TravelSnapshotManager::applyExtendedToService().
if (null !== $availability->status && '' !== trim($availability->status)) {
$service->status = $availability->status;
}
}