wip: continue implemntation
This commit is contained in:
@@ -11,4 +11,9 @@ class BaseData
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
public function getItemByKey(string $key): mixed
|
||||
{
|
||||
return $this->items[$key] ?? null;
|
||||
}
|
||||
}
|
||||
+25
-153
@@ -2,14 +2,11 @@
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
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;
|
||||
public ?PersonalData $applicant = null;
|
||||
public ?int $participantCount = null;
|
||||
@@ -32,6 +29,7 @@ class Booking
|
||||
public array $additionalServices = [];
|
||||
public array $rooms = [];
|
||||
public array $pickups = [];
|
||||
public array $surcharges = [];
|
||||
public ?int $invoiceNumber = null;
|
||||
public ?float $totalPrice = null;
|
||||
|
||||
@@ -47,6 +45,7 @@ class Booking
|
||||
public function getAdditionalServicesByGroup(mixed $group): array
|
||||
{
|
||||
$group = (array) $group;
|
||||
|
||||
return array_filter($this->additionalServices, function (Service $service) use ($group) {
|
||||
return in_array($service->subType, $group);
|
||||
});
|
||||
@@ -54,9 +53,9 @@ class Booking
|
||||
|
||||
public function getAdditionalServicesForParticipantByGroup(int $participantIndex, mixed $group): array
|
||||
{
|
||||
$services = $this->getAdditionalServicesByGroup($group);
|
||||
$selectedServices = $this->getAdditionalServicesByGroup($group);
|
||||
|
||||
return array_filter($services, function (Service $service) use ($participantIndex) {
|
||||
return array_filter($selectedServices, function (Service $service) use ($participantIndex) {
|
||||
return in_array($participantIndex, $service->mapping);
|
||||
});
|
||||
}
|
||||
@@ -75,6 +74,17 @@ class Booking
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPickupForParticipant(int $participantIndex): ?Pickup
|
||||
{
|
||||
foreach ($this->pickups as $pickup) {
|
||||
if (in_array($participantIndex, $pickup->mapping)) {
|
||||
return $pickup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRoomForParticipant(int $participantIndex): ?Room
|
||||
{
|
||||
foreach ($this->rooms as $room) {
|
||||
@@ -90,21 +100,22 @@ class Booking
|
||||
{
|
||||
$price = 0.0;
|
||||
|
||||
// Sum up all services
|
||||
foreach ([...$this->transportationServices, ...$this->additionalServices] as $service) {
|
||||
if (in_array($participantIndex, $service->mapping) && isset($service->individualPrice[$participantIndex])) {
|
||||
if (in_array($participantIndex, $service->mapping) || true === $service->mandatory) {
|
||||
$price += $service->individualPrice[$participantIndex];
|
||||
} elseif ($service->price) {
|
||||
$price += $service->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Sum up all surcharges
|
||||
foreach ($this->surcharges as $surcharge) {
|
||||
if (in_array($participantIndex, $surcharge->mapping)) {
|
||||
$price += $surcharge->individualPrice[$participantIndex];
|
||||
}
|
||||
}
|
||||
|
||||
$room = $this->getRoomForParticipant($participantIndex);
|
||||
|
||||
if (isset($room->individualPrice[$participantIndex])) {
|
||||
$price += $room->individualPrice[$participantIndex];
|
||||
} elseif ($room->price) {
|
||||
$price += $room->price;
|
||||
}
|
||||
$price += $room->individualPrice[$participantIndex];
|
||||
|
||||
return $price;
|
||||
}
|
||||
@@ -113,143 +124,4 @@ class Booking
|
||||
{
|
||||
return $this->travelDate > new \DateTimeImmutable() && false === in_array($this->status, ['S', 'U']);
|
||||
}
|
||||
|
||||
public function toPayload(?BookingData $formData): array
|
||||
{
|
||||
// Reset mappings
|
||||
foreach ([...$this->additionalServices, ...$this->transportationServices, ...$this->pickups] as $service) {
|
||||
$service->mapping = [];
|
||||
}
|
||||
// Update mappings, add services and pickups
|
||||
foreach ($formData->participants as $participant) {
|
||||
$servicesToMap = [
|
||||
...$participant->courses,
|
||||
...$participant->additionalServices,
|
||||
...$participant->skiPass,
|
||||
...$participant->board,
|
||||
...$participant->rentals,
|
||||
];
|
||||
foreach ($servicesToMap as $service) {
|
||||
if (false === isset($this->additionalServices[$service->id])) {
|
||||
$serviceToAdd = $this->travelData->additionalServices[$service->id];
|
||||
$this->additionalServices[$service->id] = $serviceToAdd;
|
||||
$this->additionalServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
}
|
||||
$this->additionalServices[$service->id]->mapping[] = $participant->index;
|
||||
}
|
||||
foreach ([$participant->transportationServiceTo, $participant->transportationServiceFro] as $service) {
|
||||
if (false === isset($this->transportationServices[$service->id])) {
|
||||
$serviceToAdd = $this->travelData->transportationServices[$service->id];
|
||||
$this->transportationServices[$service->id] = $serviceToAdd;
|
||||
$this->transportationServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
}
|
||||
$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) {
|
||||
if (0 === count($service->mapping)) {
|
||||
unset($this->additionalServices[$service->id]);
|
||||
}
|
||||
}
|
||||
foreach ($this->transportationServices as $service) {
|
||||
if (0 === count($service->mapping)) {
|
||||
unset($this->transportationServices[$service->id]);
|
||||
}
|
||||
}
|
||||
// Update participants' personal data
|
||||
foreach ($formData->participants as $participant) {
|
||||
$this->participants[$participant->index]->firstName = $participant->firstName;
|
||||
$this->participants[$participant->index]->lastName = $participant->lastName;
|
||||
$this->participants[$participant->index]->dateOfBirth = $participant->dateOfBirth;
|
||||
$this->participants[$participant->index]->gender = $participant->gender;
|
||||
$this->participants[$participant->index]->nationality = $participant->nationality;
|
||||
$this->participants[$participant->index]->height = $participant->height;
|
||||
$this->participants[$participant->index]->weight = $participant->weight;
|
||||
$this->participants[$participant->index]->shoeSize = $participant->shoeSize;
|
||||
$this->participants[$participant->index]->communication->email = $participant->email;
|
||||
$this->participants[$participant->index]->communication->mobile = $participant->mobile;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'idbuchung' => $this->id,
|
||||
'status' => $this->status,
|
||||
'idagentur' => $this->agencyId,
|
||||
'idreise' => $this->travelId,
|
||||
'idpartner' => $this->hotelId,
|
||||
'anmelder' => $this->applicant->toPayload(),
|
||||
'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;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class CrmAttributeGroup
|
||||
{
|
||||
public ?int $id = null;
|
||||
public ?string $label = null;
|
||||
public ?array $attributes = null;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\BusProNet\Model;
|
||||
|
||||
class CrmAttributes
|
||||
{
|
||||
public ?array $attributeGroups = null;
|
||||
public ?array $selectionGroups = null;
|
||||
public bool $admin = false;
|
||||
public bool $manager = false;
|
||||
public bool $houseManager = false;
|
||||
@@ -15,13 +15,13 @@ class CrmAttributes
|
||||
{
|
||||
$crmSelections = [];
|
||||
|
||||
foreach ($this->attributeGroups as $group) {
|
||||
/** @var CrmAttributeGroup $group */
|
||||
foreach ($this->selectionGroups as $group) {
|
||||
/** @var CrmSelectionGroup $group */
|
||||
if (false === isset($crmSelections[$group->label])) {
|
||||
$crmSelections[$group->label] = [];
|
||||
}
|
||||
foreach ($group->attributes as $attribute) {
|
||||
/** @var CrmAttribute $attribute */
|
||||
foreach ($group->selections as $attribute) {
|
||||
/** @var CrmSelection $attribute */
|
||||
if (false === $attribute->selected) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class CrmAttribute
|
||||
class CrmSelection
|
||||
{
|
||||
public ?int $id = null;
|
||||
public ?string $label = null;
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class CrmSelectionGroup
|
||||
{
|
||||
/**
|
||||
* Maps BusPro IDs of CRM selection groups representing
|
||||
* included services
|
||||
* @var array|string[]
|
||||
*/
|
||||
public static array $includedServicesMapping = [
|
||||
7 => 'Skipass',
|
||||
71 => 'Verpflegung',
|
||||
85 => 'Übernachtungen',
|
||||
86 => 'Programm',
|
||||
];
|
||||
|
||||
public ?int $id = null;
|
||||
public ?string $label = null;
|
||||
public ?array $selections = null;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class MutableData
|
||||
{
|
||||
public const CATEGORY_PARTICIPANT_COUNT = 'participant_count';
|
||||
public const CATEGORY_PARTICIPANT_DATA = 'participant_data';
|
||||
public const CATEGORY_TRANSPORTATION = 'transportation';
|
||||
public const CATEGORY_PICKUP = 'pickup';
|
||||
public const CATEGORY_ACCOMMODATION = 'accommodation';
|
||||
public const CATEGORY_ADDITIONAL_SERVICES = 'additional_services';
|
||||
|
||||
public function __construct(string $category, bool $mutable, ?\DateTimeImmutable $mutableUntil = null)
|
||||
{
|
||||
$this->category = $category;
|
||||
$this->mutable = $mutable;
|
||||
$this->mutableBefore = $mutableUntil;
|
||||
}
|
||||
|
||||
public ?string $category = null;
|
||||
public bool $mutable = false;
|
||||
public ?\DateTimeImmutable $mutableBefore = null;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class MutableField
|
||||
{
|
||||
public function __construct(string $type, bool $mutable, ?\DateTimeImmutable $mutableUntil = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->mutable = $mutable;
|
||||
$this->mutableBefore = $mutableUntil;
|
||||
}
|
||||
|
||||
public ?string $type = null;
|
||||
public bool $mutable = false;
|
||||
public ?\DateTimeImmutable $mutableBefore = null;
|
||||
}
|
||||
@@ -4,9 +4,8 @@ namespace App\BusProNet\Model;
|
||||
|
||||
class Service
|
||||
{
|
||||
public const TYPE_INCLUDED = 'included';
|
||||
public const TYPE_ADDITIONAL = 'additional';
|
||||
public const TYPE_TRANSPORTATION = 'transportation';
|
||||
public const CATEGORY_ADDITIONAL = 'additional';
|
||||
public const CATEGORY_TRANSPORTATION = 'transportation';
|
||||
|
||||
public const TOKEN_COURSES = 'KUR';
|
||||
public const TOKEN_SKI_PASS = 'SPA';
|
||||
@@ -15,6 +14,7 @@ class Service
|
||||
public const TOKEN_RENTALS = ['VER', 'VE2', 'VE3', 'VE4', 'VE5', 'VE6', 'VE7', 'VE8'];
|
||||
|
||||
public ?int $id = null;
|
||||
public ?string $category = null;
|
||||
public ?string $status = null;
|
||||
public bool $mandatory = false;
|
||||
public ?string $label = null;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Model;
|
||||
|
||||
class Surcharge
|
||||
{
|
||||
public ?string $label = null;
|
||||
public array $mapping = [];
|
||||
public ?float $totalPrice = null;
|
||||
public array $individualPrice = [];
|
||||
}
|
||||
@@ -13,9 +13,15 @@ class Travel
|
||||
public ?float $priceFrom = null;
|
||||
public array $selectionGroups = [];
|
||||
public array $additionalServices = [];
|
||||
public bool $additionalServicesMutable = true;
|
||||
public array $transportationServices = [];
|
||||
public bool $transportationServicesMutable = true;
|
||||
public array $pickups = [];
|
||||
public bool $pickupsMutable = true;
|
||||
public array $rooms = [];
|
||||
public bool $roomsMutable = true;
|
||||
public bool $participantDataMutable = true;
|
||||
public bool $participantCountMutable = true;
|
||||
|
||||
public function getAdditionalServicesByGroup(mixed $group, bool $availableOnly = true): array
|
||||
{
|
||||
@@ -34,4 +40,17 @@ class Travel
|
||||
&& (false === $availableOnly || $service->available > 0);
|
||||
});
|
||||
}
|
||||
|
||||
public function getIncludedServices(): array
|
||||
{
|
||||
$services = [];
|
||||
|
||||
foreach (CrmSelectionGroup::$includedServicesMapping as $id => $label) {
|
||||
if (isset($this->selectionGroups[$id])) {
|
||||
$services[] = $this->selectionGroups[$id];
|
||||
}
|
||||
}
|
||||
|
||||
return $services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user