wip: additional services with constraints
This commit is contained in:
@@ -358,7 +358,7 @@ class BookingDataProcessor
|
||||
$payload['zusatzleistungen']['zusatzleistung'][] = [
|
||||
'@idleistung' => $service->id,
|
||||
'@anzahl' => count($service->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn($index) => $index + 1, $service->mapping)),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $service->mapping)),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ class BookingDataProcessor
|
||||
$payload['beförderungen']['beförderung'][] = [
|
||||
'@idleistung' => $service->id,
|
||||
'@anzahl' => count($service->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn($index) => $index + 1, $service->mapping)),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $service->mapping)),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ class BookingDataProcessor
|
||||
'@anreise' => $room->dateFrom ? $room->dateFrom->format('d.m.Y') : null,
|
||||
'@abreise' => $room->dateTo ? $room->dateTo->format('d.m.Y') : null,
|
||||
'@anzahl' => $room->totalCount,
|
||||
'@zuordnung' => implode(',', array_map(fn($index) => $index + 1, $room->mapping)),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $room->mapping)),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,7 @@ class BookingDataProcessor
|
||||
$payload['zustiege']['zustieg'][] = [
|
||||
'@idzustieg' => $pickup->id,
|
||||
'@anzahl' => count($pickup->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn($index) => $index + 1, $pickup->mapping)),
|
||||
'@zuordnung' => implode(',', array_map(fn ($index) => $index + 1, $pickup->mapping)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ class Booking
|
||||
|
||||
// Sum up all services
|
||||
foreach ([...$this->transportationServices, ...$this->additionalServices] as $service) {
|
||||
if ((in_array($participantIndex, $service->mapping) || true === $service->mandatory)
|
||||
if ((in_array($participantIndex, $service->mapping) || true === $service->mandatory)
|
||||
&& isset($service->individualPrice[$participantIndex])) {
|
||||
$price += $service->individualPrice[$participantIndex];
|
||||
}
|
||||
@@ -195,7 +195,7 @@ class Booking
|
||||
|
||||
// Sum up all surcharges
|
||||
foreach ($this->surcharges as $surcharge) {
|
||||
if (in_array($participantIndex, $surcharge->mapping)
|
||||
if (in_array($participantIndex, $surcharge->mapping)
|
||||
&& isset($surcharge->individualPrice[$participantIndex])) {
|
||||
$price += $surcharge->individualPrice[$participantIndex];
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ class Room
|
||||
if (1 === preg_match('/bett/i', $this->label)) {
|
||||
return self::SELECTION_TYPE_BY_PAX;
|
||||
}
|
||||
|
||||
return self::SELECTION_TYPE_BY_ROOM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,23 +87,46 @@ class Travel
|
||||
public ?Guide $guide = null;
|
||||
|
||||
/**
|
||||
* Retrieves additional services filtered by group and availability.
|
||||
* Retrieves additional services filtered by subtype, availability, and optionally by travel date range.
|
||||
*
|
||||
* Filters additional services based on the provided group(s) and optionally
|
||||
* by availability. Services are sorted alphabetically by label.
|
||||
* Filters additional services based on the provided subtype(s), availability,
|
||||
* and optionally whether their date range overlaps with the travel dates.
|
||||
* Services with null dates are considered always available when date filtering is enabled.
|
||||
* Services are sorted alphabetically by label.
|
||||
*
|
||||
* @param mixed $group The service group(s) to filter by
|
||||
* @param bool $availableOnly Whether to include only available services
|
||||
* @param mixed $subTypes The service subtype(s) to filter by
|
||||
* @param bool $filterAvailable Whether to include only available services
|
||||
* @param bool $filterByTravelDateRange Whether to filter by travel date range overlap
|
||||
*
|
||||
* @return array<int, Service> The filtered and sorted services array
|
||||
*/
|
||||
public function getAdditionalServicesByGroup(mixed $group, bool $availableOnly = true): array
|
||||
public function getAdditionalServicesBySubTypes(mixed $subTypes, bool $filterAvailable = true, bool $filterByTravelDateRange = false): array
|
||||
{
|
||||
$group = (array) $group;
|
||||
$subTypes = (array) $subTypes;
|
||||
|
||||
$services = array_filter($this->additionalServices, function (Service $service) use ($group, $availableOnly) {
|
||||
return true === in_array($service->subType, $group)
|
||||
&& (false === $availableOnly || 0 < $service->available || null === $service->available);
|
||||
$services = array_filter($this->additionalServices, function (Service $service) use ($subTypes, $filterAvailable, $filterByTravelDateRange) {
|
||||
// Check subtype
|
||||
if (false === in_array($service->subType, $subTypes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check availability
|
||||
if (true === $filterAvailable && null !== $service->available && 0 >= $service->available) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check date range overlap if filtering by travel dates is enabled
|
||||
if (true === $filterByTravelDateRange) {
|
||||
if (null !== $service->dateFrom && null !== $service->dateTo
|
||||
&& null !== $this->dateFrom && null !== $this->dateTo) {
|
||||
// Service is available if its date range overlaps with travel dates:
|
||||
// service.dateFrom <= travel.dateTo AND service.dateTo >= travel.dateFrom
|
||||
return $service->dateFrom <= $this->dateTo && $service->dateTo >= $this->dateFrom;
|
||||
}
|
||||
// Service is available if it has no date constraints or travel has no dates
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
usort($services, function (Service $a, Service $b) {
|
||||
@@ -119,17 +142,17 @@ class Travel
|
||||
* Filters transportation services based on travel direction and optionally
|
||||
* by availability. Services are sorted by subtype.
|
||||
*
|
||||
* @param string $direction The travel direction to filter by
|
||||
* @param bool $availableOnly Whether to include only available services
|
||||
* @param string $direction The travel direction to filter by
|
||||
* @param bool $filterAvailable Whether to include only available services
|
||||
*
|
||||
* @return array<int, Service> The filtered and sorted transportation services
|
||||
*/
|
||||
public function getTransportationServicesByDirection(string $direction, bool $availableOnly = true): array
|
||||
public function getTransportationServicesByDirection(string $direction, bool $filterAvailable = true): array
|
||||
{
|
||||
$services = array_filter($this->transportationServices, function (Service $service) use ($direction, $availableOnly) {
|
||||
$services = array_filter($this->transportationServices, function (Service $service) use ($direction, $filterAvailable) {
|
||||
return $direction === $service->direction
|
||||
&& $service->price >= 0
|
||||
&& (false === $availableOnly || $service->available > 0 || null === $service->available);
|
||||
&& (false === $filterAvailable || $service->available > 0 || null === $service->available);
|
||||
});
|
||||
|
||||
usort($services, function (Service $a, Service $b) {
|
||||
|
||||
Reference in New Issue
Block a user