wip: booking process, refactor participant room assignment logic
This commit is contained in:
@@ -336,7 +336,7 @@ class BookingDataProcessor
|
||||
{
|
||||
foreach ($bookingData->participants as $index => $participant) {
|
||||
$payload['teilnehmerliste']['teilnehmer'][] = [
|
||||
'@id' => $index,
|
||||
'@id' => $index + 1,
|
||||
'status' => $bookingData->participantsStatus[$index],
|
||||
...$participant->toPayload(),
|
||||
];
|
||||
@@ -358,7 +358,7 @@ class BookingDataProcessor
|
||||
$payload['zusatzleistungen']['zusatzleistung'][] = [
|
||||
'@idleistung' => $service->id,
|
||||
'@anzahl' => count($service->mapping),
|
||||
'@zuordnung' => implode(',', $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(',', $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(',', $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(',', $pickup->mapping),
|
||||
'@zuordnung' => implode(',', array_map(fn($index) => $index + 1, $pickup->mapping)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,20 +187,24 @@ 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];
|
||||
}
|
||||
}
|
||||
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
|
||||
$room = $this->getRoomForParticipant($participantIndex);
|
||||
$price += $room->individualPrice[$participantIndex];
|
||||
if (null !== $room && isset($room->individualPrice[$participantIndex])) {
|
||||
$price += $room->individualPrice[$participantIndex];
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class BookingParser extends AbstractParser
|
||||
$booking->applicant = $this->parsePersonalData($node->filterXPath('//anmelder'));
|
||||
|
||||
$participantsStatus = $this->getArrayValue($node->filterXPath('//status_teilnehmer'), '/');
|
||||
$booking->participantsStatus = array_combine(range(1, count($participantsStatus)), $participantsStatus);
|
||||
$booking->participantsStatus = array_combine(range(0, count($participantsStatus) - 1), $participantsStatus);
|
||||
|
||||
$booking->participants = $this->parseParticipants($node->filterXPath('//teilnehmerliste/teilnehmer'));
|
||||
|
||||
@@ -110,7 +110,7 @@ class BookingParser extends AbstractParser
|
||||
|
||||
$node->each(function (Crawler $node) use (&$participants) {
|
||||
$id = (int) $node->attr('id');
|
||||
$participants[$id] = $this->parsePersonalData($node);
|
||||
$participants[$id - 1] = $this->parsePersonalData($node);
|
||||
});
|
||||
|
||||
return $participants;
|
||||
|
||||
@@ -26,7 +26,7 @@ class PickupsParser extends AbstractParser
|
||||
$pickup->time = $this->stringToDateTime($pickupDate.' '.$pickupTime);
|
||||
$pickup->price = $price;
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$pickup->mapping = array_map('intval', $mapping);
|
||||
$pickup->mapping = array_map(function ($index) { return (int) $index - 1; }, $mapping);
|
||||
|
||||
$pickups[$pickupId] = $pickup;
|
||||
});
|
||||
|
||||
@@ -24,14 +24,14 @@ class RoomsParser extends AbstractParser
|
||||
$room->maxPax = (int) $node->attr('maxpax');
|
||||
$room->board = $node->attr('verpflegung');
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$room->mapping = array_map('intval', $mapping);
|
||||
$room->mapping = array_map(function ($index) { return (int) $index - 1; }, $mapping);
|
||||
$room->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$room->individualPrice = array_combine($mapping, $individualPrices);
|
||||
$room->individualPrice = array_combine($room->mapping, $individualPrices);
|
||||
|
||||
$rooms[$room->id] = $room;
|
||||
});
|
||||
|
||||
@@ -23,14 +23,14 @@ class ServicesParser extends AbstractParser
|
||||
$service->subType = $node->attr('unterart');
|
||||
$service->totalCount = $node->attr('anzahl') ? (int) $node->attr('anzahl') : null;
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$service->mapping = array_map('intval', $mapping);
|
||||
$service->mapping = array_map(function ($index) { return (int) $index - 1; }, $mapping);
|
||||
$service->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$service->individualPrice = array_combine($mapping, $individualPrices);
|
||||
$service->individualPrice = array_combine($service->mapping, $individualPrices);
|
||||
if (Constants::CATEGORY_TRANSPORTATION === $category) {
|
||||
$service->direction = $node->attr('richtung');
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ class SurchargesParser extends AbstractParser
|
||||
$surcharge->label = empty($surchargeLabel) ? 'unbekannt' : $surchargeLabel;
|
||||
$surcharge->totalPrice = $this->stringToFloat($node->attr('gesamtpreis'));
|
||||
$mapping = $this->stringToArray($node->attr('zuordnung'));
|
||||
$surcharge->mapping = array_map('intval', $mapping);
|
||||
$surcharge->mapping = array_map(function ($index) { return (int) $index - 1; }, $mapping);
|
||||
$individualPrices = array_map(
|
||||
function ($price) {
|
||||
return $this->stringToFloat($price);
|
||||
}, $this->stringToArray($node->attr('einzelpreis', ''), '/')
|
||||
);
|
||||
$surcharge->individualPrice = array_combine($mapping, $individualPrices);
|
||||
$surcharge->individualPrice = array_combine($surcharge->mapping, $individualPrices);
|
||||
|
||||
$surcharges[] = $surcharge;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user