wip: first working version

This commit is contained in:
Björn Fromme
2024-11-21 18:38:41 +01:00
parent d4c4e69d09
commit bd13ae6537
24 changed files with 590 additions and 319 deletions
+84 -9
View File
@@ -7,6 +7,7 @@ use App\Form\Model\BookingData;
class Booking
{
public ?int $id = null;
public ?int $agencyId = null;
public ?int $bookingNumber = null;
public ?Travel $travelData = null;
public ?string $status = null;
@@ -22,11 +23,15 @@ class Booking
public ?string $hotelName = null;
public ?bool $document = null;
public ?float $payment = null;
public ?string $paymentId = null;
public ?string $paymentType = null;
public ?string $paymentLabel = null;
public array $participantsStatus = [];
public array $participants = [];
public array $transportationServices = [];
public array $additionalServices = [];
public array $rooms = [];
public array $pickups = [];
public ?int $invoiceNumber = null;
public ?float $totalPrice = null;
@@ -111,11 +116,11 @@ class Booking
public function toPayload(?BookingData $formData): array
{
// Reset services to participants mappings
foreach ([...$this->additionalServices, ...$this->transportationServices] as $service) {
// Reset mappings
foreach ([...$this->additionalServices, ...$this->transportationServices, ...$this->pickups] as $service) {
$service->mapping = [];
}
// Update mappings and add previously unselected services
// Update mappings, add services and pickups
foreach ($formData->participants as $participant) {
$servicesToMap = [
...$participant->courses,
@@ -140,6 +145,12 @@ class Booking
}
$this->transportationServices[$service->id]->mapping[] = $participant->index;
}
if ('BUS' === $participant->transportationServiceTo->subType && null !== $selectedPickup = $participant->pickup) {
if (false === isset($this->pickups[$selectedPickup->id])) {
$this->pickups[$selectedPickup->id] = $selectedPickup;
}
$this->pickups[$selectedPickup->id]->mapping[] = $participant->index;
}
}
// Remove services with empty mappings
foreach ($this->additionalServices as $service) {
@@ -166,15 +177,79 @@ class Booking
$this->participants[$participant->index]->communication->mobile = $participant->mobile;
}
return [
$payload = [
'idbuchung' => $this->id,
'status' => $this->status,
'idagentur' => $this->agencyId,
'idreise' => $this->travelId,
'idpartner' => $this->hotelId,
'anmelder' => $this->applicant->toPayload(),
'teilnehmerliste' => [],
'beförderungen' => [],
'unterbringungen' => [],
'zusatzleistungen' => [],
'zustiege' => [],
'zahlung' => [
'@idzahlungsart' => $this->paymentId,
'@bezeichnung' => $this->paymentLabel,
'@art' => $this->paymentType,
],
'teilnehmerliste' => [
'teilnehmer' => [],
],
'zusatzleistungen' => [
'zusatzleistung' => [],
],
'beförderungen' => [
'beförderung' => [],
],
'ferienzielunterbringungen' => [
'ferienzielunterbringung' => [],
],
];
foreach ($this->participants as $index => $participant) {
$payload['teilnehmerliste']['teilnehmer'][] = [
'@id' => $index,
'status' => $this->participantsStatus[$index],
...$participant->toPayload(),
];
}
foreach ($this->additionalServices as $service) {
$payload['zusatzleistungen']['zusatzleistung'][] = [
'@idleistung' => $service->id,
'@anzahl' => count($service->mapping),
'@zuordnung' => implode(',', $service->mapping),
];
}
foreach ($this->transportationServices as $service) {
$payload['beförderungen']['beförderung'][] = [
'@idleistung' => $service->id,
'@anzahl' => count($service->mapping),
'@zuordnung' => implode(',', $service->mapping),
];
}
foreach ($this->rooms as $room) {
$payload['ferienzielunterbringungen']['ferienzielunterbringung'][] = [
'@idzimmer' => $room->id,
'@kategorie' => $room->category,
'@idverpflegung' => $room->boardId,
'@anreise' => $room->dateFrom ? $room->dateFrom->format('d.m.Y') : null,
'@abreise' => $room->dateTo ? $room->dateTo->format('d.m.Y') : null,
'@anzahl' => count($room->mapping),
'@zuordnung' => implode(',', $room->mapping),
];
}
if (0 < count($this->pickups)) {
$payload['zustiege']['zustieg'] = [];
foreach ($this->pickups as $pickup) {
$payload['zustiege']['zustieg'][] = [
'@idzustieg' => $pickup->id,
'@anzahl' => count($pickup->mapping),
'@zuordnung' => implode(',', $pickup->mapping),
];
}
}
return $payload;
}
}