155 lines
4.6 KiB
PHP
155 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\BusProNet\Model;
|
|
|
|
class Booking
|
|
{
|
|
public ?int $id = null;
|
|
public ?int $agencyId = null;
|
|
public ?int $bookingNumber = null;
|
|
public ?string $status = null;
|
|
public ?int $applicantId = null;
|
|
public ?PersonalData $applicant = null;
|
|
public ?int $participantCount = null;
|
|
public ?float $price = null;
|
|
public ?\DateTimeImmutable $bookingDate = null;
|
|
public ?string $travel = null;
|
|
public ?int $travelId = null;
|
|
public ?string $travelCode = null;
|
|
public ?\DateTimeImmutable $travelDate = null;
|
|
public ?Travel $travelData = null;
|
|
public ?int $hotelId = null;
|
|
public ?string $hotelName = null;
|
|
public bool $hasDocuments = false;
|
|
public ?float $payment = null;
|
|
public ?string $paymentId = null;
|
|
public ?string $paymentType = null;
|
|
public ?string $paymentLabel = null;
|
|
public ?BankAccount $bankAccount = null;
|
|
public array $participantsStatus = [];
|
|
public array $participants = [];
|
|
public array $transportationServices = [];
|
|
public array $additionalServices = [];
|
|
public array $rooms = [];
|
|
public array $pickupsTo = [];
|
|
public array $pickupsFro = [];
|
|
public array $surcharges = [];
|
|
public ?int $invoiceNumber = null;
|
|
public ?float $totalPrice = null;
|
|
public ?string $travelInfoUrl = null;
|
|
|
|
public function getBalance(): float
|
|
{
|
|
if (null === $this->payment) {
|
|
return $this->price;
|
|
}
|
|
|
|
return $this->price - $this->payment;
|
|
}
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
public function getAdditionalServicesForParticipantByGroup(int $participantIndex, mixed $group): array
|
|
{
|
|
$selectedServices = $this->getAdditionalServicesByGroup($group);
|
|
|
|
return array_filter($selectedServices, function (Service $service) use ($participantIndex) {
|
|
return in_array($participantIndex, $service->mapping);
|
|
});
|
|
}
|
|
|
|
public function getTransportationServiceForParticipantAndDirection(
|
|
int $participantIndex,
|
|
string $direction
|
|
): ?Service {
|
|
foreach ($this->transportationServices as $service) {
|
|
if ($service->direction !== $direction) {
|
|
continue;
|
|
}
|
|
if (in_array($participantIndex, $service->mapping)) {
|
|
return $service;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getPickupForParticipant(int $participantIndex): ?Pickup
|
|
{
|
|
foreach ($this->pickupsTo as $pickup) {
|
|
if (in_array($participantIndex, $pickup->mapping)) {
|
|
return $pickup;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getRoomForParticipant(int $participantIndex): ?Room
|
|
{
|
|
foreach ($this->rooms as $room) {
|
|
if (in_array($participantIndex, $room->mapping)) {
|
|
return $room;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getPriceForParticipant(int $participantIndex): float
|
|
{
|
|
$price = 0.0;
|
|
|
|
// Sum up all services
|
|
foreach ([...$this->transportationServices, ...$this->additionalServices] as $service) {
|
|
if (in_array($participantIndex, $service->mapping) || true === $service->mandatory) {
|
|
$price += $service->individualPrice[$participantIndex];
|
|
}
|
|
}
|
|
|
|
// Sum up all surcharges
|
|
foreach ($this->surcharges as $surcharge) {
|
|
if (in_array($participantIndex, $surcharge->mapping)) {
|
|
$price += $surcharge->individualPrice[$participantIndex];
|
|
}
|
|
}
|
|
|
|
$room = $this->getRoomForParticipant($participantIndex);
|
|
$price += $room->individualPrice[$participantIndex];
|
|
|
|
return $price;
|
|
}
|
|
|
|
public function getSurchargesForParticipant(int $participantIndex): array
|
|
{
|
|
return array_filter($this->surcharges, function (Surcharge $surcharge) use ($participantIndex) {
|
|
return in_array($participantIndex, $surcharge->mapping);
|
|
});
|
|
}
|
|
|
|
public function getCalculatedTotalPrice(): float
|
|
{
|
|
$totalPrice = 0.0;
|
|
|
|
foreach ($this->participants as $index => $participant) {
|
|
$totalPrice += $this->getPriceForParticipant($index);
|
|
}
|
|
|
|
return $totalPrice;
|
|
}
|
|
|
|
public function isEditable(): bool
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
|
|
return $this->travelDate > $now && false === in_array($this->status, ['S', 'U']);
|
|
}
|
|
}
|