Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b21bb00cb | ||
|
|
9d2aa11fdb | ||
|
|
eabed8295a | ||
|
|
7ec3903bdf | ||
|
|
c929d4da3b | ||
|
|
10d5356381 | ||
|
|
b323c120f9 |
No files matched your search
Generated
+263
-263
File diff suppressed because it is too large.
Load diff
@@ -8,6 +8,7 @@ league_oauth2_server:
|
||||
enable_auth_code_grant: true
|
||||
enable_refresh_token_grant: true
|
||||
enable_password_grant: false
|
||||
enable_implicit_grant: false
|
||||
access_token_ttl: PT10M
|
||||
resource_server:
|
||||
public_key: '%env(resolve:OAUTH_PUBLIC_KEY)%'
|
||||
|
||||
@@ -208,7 +208,6 @@ services:
|
||||
- 'App\Form\Service\ParticipantTransportationInboundFieldHandler'
|
||||
- 'App\Form\Service\ParticipantPickupFieldHandler'
|
||||
- 'App\Form\Service\ParticipantDropOffFieldHandler'
|
||||
- 'App\Form\Service\ParticipantParkingFieldHandler'
|
||||
- 'App\Form\Service\ParticipantRentalInsuranceFieldHandler'
|
||||
- 'App\Form\Service\ParticipantLicensePlateFieldHandler'
|
||||
# Complex handlers with dependencies - use service references
|
||||
@@ -218,6 +217,7 @@ services:
|
||||
- '@App\Form\Service\ParticipantInsuranceFieldHandler'
|
||||
- '@App\Form\Service\ParticipantPurchaseVoucherFieldHandler'
|
||||
- '@App\Form\Service\ParticipantPromoVoucherFieldHandler'
|
||||
- '@App\Form\Service\ParticipantParkingFieldHandler'
|
||||
|
||||
# Booking Status Rules
|
||||
App\BusProNet\Service\StatusRule\Selection1473StatusRule: ~
|
||||
|
||||
@@ -29,7 +29,7 @@ class ImportGroupsLegacyDataCommand extends Command
|
||||
private const int DEFAULT_MIN_NIGHTS = 1;
|
||||
private const Season DEFAULT_SEASON = Season::SECONDARY;
|
||||
|
||||
/** @var array<int, string> maps groupspriceoption "type" column to AdditionalServiceType */
|
||||
/** @var array<int, AdditionalServiceType> maps groupspriceoption "type" column to AdditionalServiceType */
|
||||
private const array OPTION_TYPE_MAP = [
|
||||
1 => AdditionalServiceType::Flat,
|
||||
2 => AdditionalServiceType::PerPerson,
|
||||
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Admin\Accommodation;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Form\Admin\Groups\AccommodationType;
|
||||
use App\Service\CmsDataProvider;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -52,10 +54,31 @@ class EditController extends AbstractController
|
||||
return $this->redirectToRoute('app_admin_accommodation_edit', ['id' => $accommodation->getId()]);
|
||||
}
|
||||
|
||||
$boardServices = $accommodation->getBoardServices()->toArray();
|
||||
usort($boardServices, $this->compareServices(...));
|
||||
|
||||
$additionalServices = $accommodation->getAdditionalServices()->toArray();
|
||||
usort($additionalServices, $this->compareServices(...));
|
||||
|
||||
return $this->render('admin/accommodation/edit.html.twig', [
|
||||
'accommodation' => $accommodation,
|
||||
'form' => $form,
|
||||
'cmsData' => $cmsData,
|
||||
'boardServices' => $boardServices,
|
||||
'additionalServices' => $additionalServices,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* DateFrom ascending, then free (price 0) before paid, then alphabetically by label.
|
||||
*/
|
||||
private function compareServices(BoardService|AdditionalService $a, BoardService|AdditionalService $b): int
|
||||
{
|
||||
$aFree = 0 === $a->getPrice() ? 0 : 1;
|
||||
$bFree = 0 === $b->getPrice() ? 0 : 1;
|
||||
|
||||
return $a->getDateFrom() <=> $b->getDateFrom()
|
||||
?: $aFree <=> $bFree
|
||||
?: strnatcasecmp($a->getLabel(), $b->getLabel());
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Controller\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Entity\Groups\AdditionalService;
|
||||
use App\Entity\Groups\BoardService;
|
||||
use App\Exception\AccommodationSessionNotFoundException;
|
||||
use App\Form\AccommodationBookingConfirmationType;
|
||||
use App\Form\AccommodationInquiryConfirmationType;
|
||||
@@ -138,7 +140,12 @@ class Step4Controller extends AbstractAccommodationController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{boardServices: array, additionalServices: array} $services
|
||||
* @param array{
|
||||
* boardServices: BoardService[],
|
||||
* additionalServices: AdditionalService[],
|
||||
* groupedAdditionalServices: array<string, AdditionalService[]>,
|
||||
* ungroupedAdditionalServices: AdditionalService[]
|
||||
* } $services
|
||||
*/
|
||||
private function persistBooking(Request $request, AccommodationBookingDto $dto, Accommodation $accommodation, array $services): void
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ interface BlameableEntityInterface
|
||||
{
|
||||
public function getCreatedBy(): ?User;
|
||||
|
||||
public function setCreatedBy(?User $createdBy);
|
||||
public function setCreatedBy(?User $createdBy): self;
|
||||
|
||||
public function getUpdatedBy(): ?User;
|
||||
|
||||
public function setUpdatedBy(?User $updatedBy);
|
||||
public function setUpdatedBy(?User $updatedBy): self;
|
||||
}
|
||||
@@ -4,11 +4,11 @@ namespace App\Entity;
|
||||
|
||||
interface TimestampableEntityInterface
|
||||
{
|
||||
public function getCreatedAt();
|
||||
public function getCreatedAt(): \DateTimeImmutable;
|
||||
|
||||
public function setCreatedAt(\DateTimeImmutable $createdAt);
|
||||
public function setCreatedAt(\DateTimeImmutable $createdAt): self;
|
||||
|
||||
public function getUpdatedAt();
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable;
|
||||
|
||||
public function setUpdatedAt(\DateTimeImmutable $updatedAt);
|
||||
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\BlameableEntityInterface;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
|
||||
use Doctrine\ORM\Event\PrePersistEventArgs;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
@@ -25,7 +26,13 @@ class BlamableEntityListener
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setCreatedBy($this->security->getUser());
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setCreatedBy($user);
|
||||
}
|
||||
|
||||
public function preUpdate(PreUpdateEventArgs $args): void
|
||||
@@ -36,6 +43,12 @@ class BlamableEntityListener
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setUpdatedBy($this->security->getUser());
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity->setUpdatedBy($user);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\Range;
|
||||
|
||||
/** @extends AbstractType<AccommodationBooking> */
|
||||
class AccommodationBookingType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
||||
@@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/** @extends AbstractType<AccommodationPrice> */
|
||||
class AccommodationPriceType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
||||
@@ -12,6 +12,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/** @extends AbstractType<Accommodation> */
|
||||
class AccommodationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
||||
@@ -15,6 +15,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/** @extends AbstractType<AdditionalService> */
|
||||
class AdditionalServiceType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
||||
@@ -13,6 +13,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/** @extends AbstractType<BoardService> */
|
||||
class BoardServiceType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
|
||||
@@ -8,6 +8,7 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/** @extends AbstractType<mixed> */
|
||||
class DatepickerType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
@@ -647,13 +647,28 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
$fieldOptions = [
|
||||
'label' => $this->serviceLabelFormatter->formatServiceLabelForServices(
|
||||
Constants::SERVICE_LABELS[Constants::TOKEN_PARKING],
|
||||
$parkingServices
|
||||
),
|
||||
'required' => false,
|
||||
];
|
||||
|
||||
// There's only ever one parking type, so check readonly state against the single service
|
||||
$parkingService = reset($parkingServices);
|
||||
|
||||
// Add service description as data attribute for frontend use
|
||||
if (null !== $parkingService->description && '' !== trim($parkingService->description)) {
|
||||
$fieldOptions['attr']['data-description'] = $parkingService->description;
|
||||
}
|
||||
|
||||
if ($this->shouldMakeServiceReadonly($parkingService, $bookingDto, $participantIndex, 'parking')) {
|
||||
$fieldOptions['attr']['readonly'] = true;
|
||||
$fieldOptions['attr']['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
|
||||
return $fieldOptions;
|
||||
};
|
||||
|
||||
// Bulk insurance booking checkbox (applicant only - controls insurance assignment for all participants)
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
|
||||
/**
|
||||
* Handles parking service selection for self-organized transportation.
|
||||
@@ -20,6 +21,11 @@ use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
*/
|
||||
class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ServiceAvailabilityCalculator $serviceAvailabilityCalculator,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFieldName(): string
|
||||
{
|
||||
return 'parking';
|
||||
@@ -73,7 +79,22 @@ class ParticipantParkingFieldHandler extends AbstractParticipantFieldHandler
|
||||
|
||||
// Store parking service object for pricing calculation
|
||||
if (true === $isParkingSelected) {
|
||||
$participant->parkingService = $this->findParkingService($bookingDto, $participantIndex);
|
||||
$parkingService = $this->findParkingService($bookingDto, $participantIndex);
|
||||
|
||||
// Reject the selection if the service is sold out, in case the client
|
||||
// bypassed the readonly UI state (e.g. a stale form or manual submission)
|
||||
if (
|
||||
null !== $parkingService
|
||||
&& BookingDto::MODE_EDIT !== $bookingDto->getMode()
|
||||
&& $this->serviceAvailabilityCalculator->isServiceUnavailable($parkingService->id, $bookingDto, $participantIndex)
|
||||
) {
|
||||
$participant->parking = false;
|
||||
$participant->parkingService = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$participant->parkingService = $parkingService;
|
||||
} else {
|
||||
$participant->parkingService = null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final readonly class CalendarDay
|
||||
{
|
||||
public function __construct(
|
||||
public string $date,
|
||||
public bool $hasPrice,
|
||||
public bool $hasBoard,
|
||||
public bool $hasAdditional,
|
||||
public bool $isBlocked,
|
||||
public ?string $tooltip,
|
||||
public bool $isToday,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final readonly class CalendarMonth
|
||||
{
|
||||
/**
|
||||
* @param array<int, CalendarDay> $days keyed by day-of-month number
|
||||
*/
|
||||
public function __construct(
|
||||
public string $label,
|
||||
public int $firstDow,
|
||||
public array $days,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
final readonly class PriceTimelineItem
|
||||
{
|
||||
public function __construct(
|
||||
public string $dateFrom,
|
||||
public string $dateTo,
|
||||
public ?string $season,
|
||||
public ?int $includedPax,
|
||||
public float $pricePerNight,
|
||||
public float $priceAdditionalPerson,
|
||||
public ?float $defaultPricePerNight,
|
||||
public ?float $defaultPriceAdditionalPerson,
|
||||
public string $currency,
|
||||
public ?string $type,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class AdditionalServiceRepository extends ServiceEntityRepository
|
||||
{
|
||||
/** @use FindsByAccommodationAndDateRangeTrait<AdditionalService> */
|
||||
use FindsByAccommodationAndDateRangeTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
|
||||
@@ -13,6 +13,7 @@ use Doctrine\Persistence\ManagerRegistry;
|
||||
*/
|
||||
class BoardServiceRepository extends ServiceEntityRepository
|
||||
{
|
||||
/** @use FindsByAccommodationAndDateRangeTrait<BoardService> */
|
||||
use FindsByAccommodationAndDateRangeTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
|
||||
@@ -5,13 +5,21 @@ declare(strict_types=1);
|
||||
namespace App\Repository\Groups;
|
||||
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
|
||||
/**
|
||||
* @template T of object
|
||||
*
|
||||
* @phpstan-require-extends ServiceEntityRepository<T>
|
||||
*/
|
||||
trait FindsByAccommodationAndDateRangeTrait
|
||||
{
|
||||
/**
|
||||
* Returns all records active during the given date range.
|
||||
*
|
||||
* Overlap condition: entity.dateFrom <= dateTo AND entity.dateTo >= dateFrom
|
||||
*
|
||||
* @return array<int, T>
|
||||
*/
|
||||
public function findByAccommodationAndDateRange(
|
||||
Accommodation $accommodation,
|
||||
|
||||
@@ -156,6 +156,12 @@ class AccommodationBookingService
|
||||
}
|
||||
}
|
||||
|
||||
$boardServices = $this->sortServicesByPriceThenLabel($boardServices);
|
||||
$ungrouped = $this->sortServicesByPriceThenLabel($ungrouped);
|
||||
foreach ($grouped as $groupName => $groupServices) {
|
||||
$grouped[$groupName] = $this->sortServicesByPriceThenLabel($groupServices);
|
||||
}
|
||||
|
||||
return [
|
||||
'boardServices' => $boardServices,
|
||||
'additionalServices' => $additionalServices,
|
||||
@@ -164,6 +170,27 @@ class AccommodationBookingService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Free services (price 0) first, then alphabetically; each group sorted alphabetically.
|
||||
*
|
||||
* @template T of BoardService|AdditionalService
|
||||
*
|
||||
* @param T[] $services
|
||||
*
|
||||
* @return T[]
|
||||
*/
|
||||
private function sortServicesByPriceThenLabel(array $services): array
|
||||
{
|
||||
usort($services, static function (BoardService|AdditionalService $a, BoardService|AdditionalService $b): int {
|
||||
$aFree = 0 === $a->getPrice() ? 0 : 1;
|
||||
$bFree = 0 === $b->getPrice() ? 0 : 1;
|
||||
|
||||
return $aFree <=> $bFree ?: strnatcasecmp($a->getLabel(), $b->getLabel());
|
||||
});
|
||||
|
||||
return $services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the booking must be treated as non-binding and why.
|
||||
*
|
||||
|
||||
@@ -18,6 +18,9 @@ class GroupsPriceCalculator
|
||||
/** @var array<string, int|float> */
|
||||
private array $config;
|
||||
|
||||
/**
|
||||
* @param array<string, int|float> $config
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly PriceTimelineBuilder $priceTimelineBuilder,
|
||||
array $config,
|
||||
@@ -134,9 +137,9 @@ class GroupsPriceCalculator
|
||||
): array {
|
||||
$items = array_map(
|
||||
fn(array $s) => [
|
||||
'label' => $s['label'] ?? '',
|
||||
'price' => $s['price'] ?? 0,
|
||||
'type' => AdditionalServiceType::tryFrom($s['type'] ?? '') ?? AdditionalServiceType::Flat,
|
||||
'label' => $s['label'],
|
||||
'price' => $s['price'],
|
||||
'type' => AdditionalServiceType::tryFrom($s['type']) ?? AdditionalServiceType::Flat,
|
||||
],
|
||||
$additionalServiceSnapshots,
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace App\Service;
|
||||
|
||||
use App\Entity\Groups\AccommodationPrice;
|
||||
use App\Enum\Groups\PriceType;
|
||||
use App\Model\PriceTimelineItem;
|
||||
|
||||
class PriceTimelineBuilder
|
||||
{
|
||||
@@ -33,6 +34,8 @@ class PriceTimelineBuilder
|
||||
* changes mid-discount period. A gap (no winner) resets both trackers.
|
||||
*
|
||||
* @param AccommodationPrice[] $prices
|
||||
*
|
||||
* @return list<PriceTimelineItem>
|
||||
*/
|
||||
public function buildTimeline(
|
||||
array $prices,
|
||||
@@ -101,20 +104,32 @@ class PriceTimelineBuilder
|
||||
// Step 3: extend the previous row if both the winner and the default-price entity
|
||||
// are unchanged; otherwise open a new row.
|
||||
if ($lastWinner === $winner && $lastDefault === $defaultWinner) {
|
||||
$rows[count($rows) - 1]['dateTo'] = $segDateTo->format('Y-m-d');
|
||||
$lastRow = $rows[count($rows) - 1];
|
||||
$rows[count($rows) - 1] = new PriceTimelineItem(
|
||||
dateFrom: $lastRow->dateFrom,
|
||||
dateTo: $segDateTo->format('Y-m-d'),
|
||||
season: $lastRow->season,
|
||||
includedPax: $lastRow->includedPax,
|
||||
pricePerNight: $lastRow->pricePerNight,
|
||||
priceAdditionalPerson: $lastRow->priceAdditionalPerson,
|
||||
defaultPricePerNight: $lastRow->defaultPricePerNight,
|
||||
defaultPriceAdditionalPerson: $lastRow->defaultPriceAdditionalPerson,
|
||||
currency: $lastRow->currency,
|
||||
type: $lastRow->type,
|
||||
);
|
||||
} else {
|
||||
$rows[] = [
|
||||
'dateFrom' => $segStart->format('Y-m-d'),
|
||||
'dateTo' => $segDateTo->format('Y-m-d'),
|
||||
'season' => $winner->getSeason()?->value,
|
||||
'includedPax' => $winner->getIncludedPax(),
|
||||
'pricePerNight' => round($winner->getPricePerNight() / 100, 2),
|
||||
'priceAdditionalPerson' => round($winner->getPriceAdditionalPerson() / 100, 2),
|
||||
'defaultPricePerNight' => $defaultWinner !== null ? round($defaultWinner->getPricePerNight() / 100, 2) : null,
|
||||
'defaultPriceAdditionalPerson' => $defaultWinner !== null ? round($defaultWinner->getPriceAdditionalPerson() / 100, 2) : null,
|
||||
'currency' => $currency,
|
||||
'type' => $winner->getType()?->value,
|
||||
];
|
||||
$rows[] = new PriceTimelineItem(
|
||||
dateFrom: $segStart->format('Y-m-d'),
|
||||
dateTo: $segDateTo->format('Y-m-d'),
|
||||
season: $winner->getSeason()?->value,
|
||||
includedPax: $winner->getIncludedPax(),
|
||||
pricePerNight: round($winner->getPricePerNight() / 100, 2),
|
||||
priceAdditionalPerson: round($winner->getPriceAdditionalPerson() / 100, 2),
|
||||
defaultPricePerNight: $defaultWinner !== null ? round($defaultWinner->getPricePerNight() / 100, 2) : null,
|
||||
defaultPriceAdditionalPerson: $defaultWinner !== null ? round($defaultWinner->getPriceAdditionalPerson() / 100, 2) : null,
|
||||
currency: $currency,
|
||||
type: $winner->getType()?->value,
|
||||
);
|
||||
$lastWinner = $winner;
|
||||
$lastDefault = $defaultWinner;
|
||||
}
|
||||
|
||||
@@ -173,6 +173,11 @@ class ServiceAvailabilityCalculator
|
||||
$serviceUsage[$participant->skiPass->id] = ($serviceUsage[$participant->skiPass->id] ?? 0) + 1;
|
||||
}
|
||||
|
||||
// Parking service (single selection)
|
||||
if (null !== $participant->parkingService && null !== $participant->parkingService->id) {
|
||||
$serviceUsage[$participant->parkingService->id] = ($serviceUsage[$participant->parkingService->id] ?? 0) + 1;
|
||||
}
|
||||
|
||||
// Transportation services (single selection each)
|
||||
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->id) {
|
||||
$serviceUsage[$participant->transportationOutbound->id] = ($serviceUsage[$participant->transportationOutbound->id] ?? 0) + 1;
|
||||
@@ -231,6 +236,7 @@ class ServiceAvailabilityCalculator
|
||||
Constants::TOKEN_RENTALS,
|
||||
Constants::TOKEN_SKI_PASS,
|
||||
Constants::TOKEN_BOARD,
|
||||
Constants::TOKEN_PARKING,
|
||||
];
|
||||
|
||||
foreach ($additionalServiceTokens as $token) {
|
||||
|
||||
@@ -8,6 +8,8 @@ use App\BpnConnect\ContingentsClient;
|
||||
use App\BpnConnect\Exception\BpnConnectException;
|
||||
use App\BpnConnect\Model\ContingentStatus;
|
||||
use App\Entity\Groups\Accommodation;
|
||||
use App\Model\CalendarDay;
|
||||
use App\Model\CalendarMonth;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
|
||||
@@ -33,6 +35,7 @@ class Calendar
|
||||
public Accommodation $accommodation;
|
||||
public ?string $startMonth = null;
|
||||
|
||||
/** @var list<CalendarMonth> */
|
||||
public array $months = [];
|
||||
public string $prevMonth = '';
|
||||
public string $nextMonth = '';
|
||||
@@ -119,6 +122,9 @@ class Calendar
|
||||
return $blocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CarbonImmutable[]
|
||||
*/
|
||||
private function collectAllDates(): array
|
||||
{
|
||||
$dates = [];
|
||||
@@ -151,6 +157,9 @@ class Calendar
|
||||
return $dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CarbonImmutable[] $dates
|
||||
*/
|
||||
private function determineStartMonth(array $dates): CarbonImmutable
|
||||
{
|
||||
$earliest = min($dates);
|
||||
@@ -163,6 +172,13 @@ class Calendar
|
||||
return CarbonImmutable::now()->startOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{
|
||||
* price: array{label: string, span: float, priority: int}|null,
|
||||
* board: array{label: string, span: float}|null,
|
||||
* additional: array{label: string, span: float}|null,
|
||||
* }>
|
||||
*/
|
||||
private function buildCoverageMap(): array
|
||||
{
|
||||
$map = [];
|
||||
@@ -224,7 +240,7 @@ class Calendar
|
||||
}
|
||||
|
||||
$typeLabel = $service->getType() !== null
|
||||
? (self::TYPE_LABELS[$service->getType()->value] ?? $service->getType()->value)
|
||||
? self::TYPE_LABELS[$service->getType()->value]
|
||||
: '';
|
||||
$label = sprintf('Zusatz: %s%s', $service->getLabel(), $typeLabel !== '' ? ' (' . $typeLabel . ')' : '');
|
||||
|
||||
@@ -246,7 +262,15 @@ class Calendar
|
||||
return $map;
|
||||
}
|
||||
|
||||
private function buildMonth(CarbonImmutable $month, array $map, array $blockedDates): array
|
||||
/**
|
||||
* @param array<string, array{
|
||||
* price: array{label: string, span: float, priority: int}|null,
|
||||
* board: array{label: string, span: float}|null,
|
||||
* additional: array{label: string, span: float}|null,
|
||||
* }> $map
|
||||
* @param array<string, true> $blockedDates
|
||||
*/
|
||||
private function buildMonth(CarbonImmutable $month, array $map, array $blockedDates): CalendarMonth
|
||||
{
|
||||
$start = $month->startOfMonth();
|
||||
$today = CarbonImmutable::now()->format('Y-m-d');
|
||||
@@ -275,21 +299,21 @@ class Calendar
|
||||
$parts[] = 'Buchungsstopp';
|
||||
}
|
||||
|
||||
$days[$d] = [
|
||||
'date' => $dateStr,
|
||||
'hasPrice' => isset($coverage['price']),
|
||||
'hasBoard' => isset($coverage['board']),
|
||||
'hasAdditional' => isset($coverage['additional']),
|
||||
'isBlocked' => $isBlocked,
|
||||
'tooltip' => !empty($parts) ? implode(' | ', $parts) : null,
|
||||
'isToday' => $dateStr === $today,
|
||||
];
|
||||
$days[$d] = new CalendarDay(
|
||||
date: $dateStr,
|
||||
hasPrice: isset($coverage['price']),
|
||||
hasBoard: isset($coverage['board']),
|
||||
hasAdditional: isset($coverage['additional']),
|
||||
isBlocked: $isBlocked,
|
||||
tooltip: !empty($parts) ? implode(' | ', $parts) : null,
|
||||
isToday: $dateStr === $today,
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'label' => self::MONTHS[$month->month] . ' ' . $month->year,
|
||||
'firstDow' => $firstDow,
|
||||
'days' => $days,
|
||||
];
|
||||
return new CalendarMonth(
|
||||
label: self::MONTHS[$month->month] . ' ' . $month->year,
|
||||
firstDow: $firstDow,
|
||||
days: $days,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for service in accommodation.boardServices %}
|
||||
{% for service in boardServices %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ service.dateFrom | date('d.m.Y') }} - {{ service.dateTo | date('d.m.Y') }}
|
||||
@@ -258,7 +258,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for service in accommodation.additionalServices %}
|
||||
{% for service in additionalServices %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ service.dateFrom | date('d.m.Y') }} - {{ service.dateTo | date('d.m.Y') }}
|
||||
|
||||
@@ -608,11 +608,12 @@
|
||||
{% set parkingService = bookingDto.travel.getAdditionalServicesBySubTypes(constant('App\\BusProNet\\Constants::TOKEN_PARKING'))|first %}
|
||||
{{ macros.checkbox_row(
|
||||
form.parking,
|
||||
'Parkplatz',
|
||||
parkingService.label|default('Parkplatz'),
|
||||
parkingService.price|default(null),
|
||||
null,
|
||||
null,
|
||||
htmxAttr
|
||||
form.parking.vars.attr['data-description']|default(null),
|
||||
'Info',
|
||||
htmxAttr,
|
||||
false
|
||||
) }}
|
||||
{% endif %}
|
||||
</table>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
{% endif %}
|
||||
{% for dayNum, day in month.days %}
|
||||
<div class="w-6 px-px">
|
||||
<div class="h-3 {{ day[row.key] ? row.color : 'bg-gray-100' }}"></div>
|
||||
<div class="h-3 {{ attribute(day, row.key) ? row.color : 'bg-gray-100' }}"></div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-32 text-right">
|
||||
<div>{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}</div>
|
||||
<div>{% if service.price == 0 %}inkl.{% else %}{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}{% endif %}</div>
|
||||
<div class="text-xs text-gray-500">pro Person und Nacht</div>
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-12 text-center">
|
||||
@@ -155,7 +155,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-32 text-right">
|
||||
<div>{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}</div>
|
||||
<div>{% if service.price == 0 %}inkl.{% else %}{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}{% endif %}</div>
|
||||
<div class="text-xs text-gray-500">{{ service.type.label | trans }}</div>
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-12 text-center">
|
||||
@@ -193,7 +193,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-32 text-right">
|
||||
<div>{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}</div>
|
||||
<div>{% if service.price == 0 %}inkl.{% else %}{{ (service.price / 100)|format_currency(ctx.accommodation.currency) }}{% endif %}</div>
|
||||
<div class="text-xs text-gray-500">{{ service.type.label | trans }}</div>
|
||||
</td>
|
||||
<td class="border border-primary-bg p-2 align-top w-12 text-center">
|
||||
|
||||
@@ -135,6 +135,64 @@ class ParticipantFieldOptionsProviderMandatoryServiceTest extends TestCase
|
||||
$this->assertSame('Parkplatz (€12,50)', $options['label']);
|
||||
}
|
||||
|
||||
public function testParkingIsReadonlyWhenSoldOut(): void
|
||||
{
|
||||
$parkingService = new Service();
|
||||
$parkingService->id = 3;
|
||||
$parkingService->label = 'Parkplatz';
|
||||
$parkingService->subType = Constants::TOKEN_PARKING;
|
||||
$parkingService->available = 0;
|
||||
$parkingService->price = 12.5;
|
||||
|
||||
$travel = $this->createTravelWithAdditionalServices([$parkingService]);
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$serviceAvailabilityCalculator = $this->createMock(ServiceAvailabilityCalculator::class);
|
||||
$serviceAvailabilityCalculator->method('isServiceUnavailable')
|
||||
->with($parkingService->id, $bookingDto, 0)
|
||||
->willReturn(true);
|
||||
|
||||
$provider = new ParticipantFieldOptionsProvider(
|
||||
$serviceAvailabilityCalculator,
|
||||
$this->createMock(InsuranceManager::class),
|
||||
$this->createMock(BookingPriceCalculator::class),
|
||||
new ServiceLabelFormatter(),
|
||||
$this->createMock(TranslatorInterface::class)
|
||||
);
|
||||
|
||||
$options = $provider->getFieldOptions('parking', $bookingDto, 0);
|
||||
|
||||
$this->assertTrue($options['attr']['readonly']);
|
||||
$this->assertSame('ausgebucht', $options['attr']['data-tooltip']);
|
||||
}
|
||||
|
||||
public function testParkingIsNotReadonlyWhenAvailable(): void
|
||||
{
|
||||
$parkingService = new Service();
|
||||
$parkingService->id = 3;
|
||||
$parkingService->label = 'Parkplatz';
|
||||
$parkingService->subType = Constants::TOKEN_PARKING;
|
||||
$parkingService->available = 10;
|
||||
$parkingService->price = 12.5;
|
||||
|
||||
$travel = $this->createTravelWithAdditionalServices([$parkingService]);
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$options = $this->provider->getFieldOptions('parking', $bookingDto, 0);
|
||||
|
||||
$this->assertArrayNotHasKey('attr', $options);
|
||||
}
|
||||
|
||||
public function testNullParticipantReturnsEmptyOptions(): void
|
||||
{
|
||||
$mandatoryService = $this->createMandatoryService(1, 'Ortstaxe');
|
||||
|
||||
@@ -7,9 +7,11 @@ namespace App\Tests\Form\Service;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\BusProNet\Constants;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantParkingFieldHandler;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
@@ -18,7 +20,7 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->handler = new ParticipantParkingFieldHandler();
|
||||
$this->handler = new ParticipantParkingFieldHandler(new ServiceAvailabilityCalculator());
|
||||
}
|
||||
|
||||
public function testGetFieldName(): void
|
||||
@@ -237,6 +239,50 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
$this->assertFalse($participant->parking);
|
||||
}
|
||||
|
||||
public function testProcessFieldRejectsParkingWhenSoldOut(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
$parkingService = $this->createParkingService(available: 0);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
|
||||
$participant->transportationOutbound = $pkwService;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [$parkingService->id => $parkingService];
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$submittedData = ['parking' => true];
|
||||
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
$this->assertFalse($participant->parking);
|
||||
$this->assertNull($participant->parkingService);
|
||||
}
|
||||
|
||||
public function testProcessFieldAllowsParkingWhenAvailable(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
$parkingService = $this->createParkingService(available: 5);
|
||||
|
||||
$participant = new ParticipantDto();
|
||||
$participant->dateOfBirth = new \DateTimeImmutable('-25 years');
|
||||
$participant->transportationOutbound = $pkwService;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [$parkingService->id => $parkingService];
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$submittedData = ['parking' => true];
|
||||
|
||||
$this->handler->processField($submittedData, $bookingDto, 0);
|
||||
|
||||
$this->assertTrue($participant->parking);
|
||||
$this->assertSame($parkingService, $participant->parkingService);
|
||||
}
|
||||
|
||||
public function testProcessFieldSetsParkingToFalseWhenNotSelected(): void
|
||||
{
|
||||
$pkwService = $this->createTransportationService(DirectionMapper::SUBTYPE_CAR_API);
|
||||
@@ -300,4 +346,15 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function createParkingService(int $available): Service
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = 200;
|
||||
$service->label = 'Parkplatz';
|
||||
$service->subType = Constants::TOKEN_PARKING;
|
||||
$service->available = $available;
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
@@ -34,15 +34,15 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('2026-01-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-03-31', $result[0]['dateTo']);
|
||||
$this->assertSame(150.0, $result[0]['pricePerNight']);
|
||||
$this->assertSame(20.0, $result[0]['priceAdditionalPerson']);
|
||||
$this->assertSame(2, $result[0]['includedPax']);
|
||||
$this->assertNull($result[0]['type']);
|
||||
$this->assertNull($result[0]['defaultPricePerNight']);
|
||||
$this->assertNull($result[0]['defaultPriceAdditionalPerson']);
|
||||
$this->assertSame('EUR', $result[0]['currency']);
|
||||
$this->assertSame('2026-01-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-03-31', $result[0]->dateTo);
|
||||
$this->assertSame(150.0, $result[0]->pricePerNight);
|
||||
$this->assertSame(20.0, $result[0]->priceAdditionalPerson);
|
||||
$this->assertSame(2, $result[0]->includedPax);
|
||||
$this->assertNull($result[0]->type);
|
||||
$this->assertNull($result[0]->defaultPricePerNight);
|
||||
$this->assertNull($result[0]->defaultPriceAdditionalPerson);
|
||||
$this->assertSame('EUR', $result[0]->currency);
|
||||
}
|
||||
|
||||
public function testBasePriceStartingBeforeYearIsClamped(): void
|
||||
@@ -52,8 +52,8 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('2026-01-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-03-31', $result[0]['dateTo']);
|
||||
$this->assertSame('2026-01-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-03-31', $result[0]->dateTo);
|
||||
}
|
||||
|
||||
public function testBasePriceEndingAfterYearIsClamped(): void
|
||||
@@ -63,8 +63,8 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('2026-10-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-12-31', $result[0]['dateTo']);
|
||||
$this->assertSame('2026-10-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-12-31', $result[0]->dateTo);
|
||||
}
|
||||
|
||||
public function testDiscountSplitsBasePeriodIntoThreeRows(): void
|
||||
@@ -75,17 +75,17 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertSame('2026-01-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-01-14', $result[0]['dateTo']);
|
||||
$this->assertNull($result[0]['type']);
|
||||
$this->assertSame('2026-01-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-01-14', $result[0]->dateTo);
|
||||
$this->assertNull($result[0]->type);
|
||||
|
||||
$this->assertSame('2026-01-15', $result[1]['dateFrom']);
|
||||
$this->assertSame('2026-01-31', $result[1]['dateTo']);
|
||||
$this->assertSame('discount', $result[1]['type']);
|
||||
$this->assertSame('2026-01-15', $result[1]->dateFrom);
|
||||
$this->assertSame('2026-01-31', $result[1]->dateTo);
|
||||
$this->assertSame('discount', $result[1]->type);
|
||||
|
||||
$this->assertSame('2026-02-01', $result[2]['dateFrom']);
|
||||
$this->assertSame('2026-03-31', $result[2]['dateTo']);
|
||||
$this->assertNull($result[2]['type']);
|
||||
$this->assertSame('2026-02-01', $result[2]->dateFrom);
|
||||
$this->assertSame('2026-03-31', $result[2]->dateTo);
|
||||
$this->assertNull($result[2]->type);
|
||||
}
|
||||
|
||||
public function testDiscountRowIncludesDefaultPrice(): void
|
||||
@@ -96,10 +96,10 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$discountRow = $result[1];
|
||||
$this->assertSame(120.0, $discountRow['pricePerNight']);
|
||||
$this->assertSame(150.0, $discountRow['defaultPricePerNight']);
|
||||
$this->assertSame(20.0, $discountRow['priceAdditionalPerson']);
|
||||
$this->assertSame(30.0, $discountRow['defaultPriceAdditionalPerson']);
|
||||
$this->assertSame(120.0, $discountRow->pricePerNight);
|
||||
$this->assertSame(150.0, $discountRow->defaultPricePerNight);
|
||||
$this->assertSame(20.0, $discountRow->priceAdditionalPerson);
|
||||
$this->assertSame(30.0, $discountRow->defaultPriceAdditionalPerson);
|
||||
}
|
||||
|
||||
public function testBaseRowsHaveNullDefaultPriceFields(): void
|
||||
@@ -109,10 +109,10 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
|
||||
$result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertNull($result[0]['defaultPricePerNight']);
|
||||
$this->assertNull($result[0]['defaultPriceAdditionalPerson']);
|
||||
$this->assertNull($result[2]['defaultPricePerNight']);
|
||||
$this->assertNull($result[2]['defaultPriceAdditionalPerson']);
|
||||
$this->assertNull($result[0]->defaultPricePerNight);
|
||||
$this->assertNull($result[0]->defaultPriceAdditionalPerson);
|
||||
$this->assertNull($result[2]->defaultPricePerNight);
|
||||
$this->assertNull($result[2]->defaultPriceAdditionalPerson);
|
||||
}
|
||||
|
||||
public function testDiscountWithNoBasePriceHasNullDefaultPrice(): void
|
||||
@@ -122,8 +122,8 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('discount', $result[0]['type']);
|
||||
$this->assertNull($result[0]['defaultPricePerNight']);
|
||||
$this->assertSame('discount', $result[0]->type);
|
||||
$this->assertNull($result[0]->defaultPricePerNight);
|
||||
}
|
||||
|
||||
public function testGapBetweenTwoPricesIsOmitted(): void
|
||||
@@ -134,10 +134,10 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$first, $second], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertSame('2026-01-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-01-31', $result[0]['dateTo']);
|
||||
$this->assertSame('2026-03-01', $result[1]['dateFrom']);
|
||||
$this->assertSame('2026-03-31', $result[1]['dateTo']);
|
||||
$this->assertSame('2026-01-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-01-31', $result[0]->dateTo);
|
||||
$this->assertSame('2026-03-01', $result[1]->dateFrom);
|
||||
$this->assertSame('2026-03-31', $result[1]->dateTo);
|
||||
}
|
||||
|
||||
public function testOverrideSplitsBasePeriod(): void
|
||||
@@ -148,10 +148,10 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
$result = $this->builder->buildTimeline([$base, $override], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
$this->assertNull($result[0]['type']);
|
||||
$this->assertSame('override', $result[1]['type']);
|
||||
$this->assertSame(180.0, $result[1]['pricePerNight']);
|
||||
$this->assertNull($result[2]['type']);
|
||||
$this->assertNull($result[0]->type);
|
||||
$this->assertSame('override', $result[1]->type);
|
||||
$this->assertSame(180.0, $result[1]->pricePerNight);
|
||||
$this->assertNull($result[2]->type);
|
||||
}
|
||||
|
||||
public function testDiscountOverTwoDifferentBasePricesProducesTwoDiscountRows(): void
|
||||
@@ -166,23 +166,23 @@ class PriceTimelineBuilderTest extends TestCase
|
||||
|
||||
$this->assertCount(4, $result);
|
||||
|
||||
$this->assertSame('2026-01-01', $result[0]['dateFrom']);
|
||||
$this->assertSame('2026-01-14', $result[0]['dateTo']);
|
||||
$this->assertNull($result[0]['type']);
|
||||
$this->assertSame('2026-01-01', $result[0]->dateFrom);
|
||||
$this->assertSame('2026-01-14', $result[0]->dateTo);
|
||||
$this->assertNull($result[0]->type);
|
||||
|
||||
$this->assertSame('2026-01-15', $result[1]['dateFrom']);
|
||||
$this->assertSame('2026-01-20', $result[1]['dateTo']);
|
||||
$this->assertSame('discount', $result[1]['type']);
|
||||
$this->assertSame(100.0, $result[1]['defaultPricePerNight']); // baseA
|
||||
$this->assertSame('2026-01-15', $result[1]->dateFrom);
|
||||
$this->assertSame('2026-01-20', $result[1]->dateTo);
|
||||
$this->assertSame('discount', $result[1]->type);
|
||||
$this->assertSame(100.0, $result[1]->defaultPricePerNight); // baseA
|
||||
|
||||
$this->assertSame('2026-01-21', $result[2]['dateFrom']);
|
||||
$this->assertSame('2026-01-31', $result[2]['dateTo']);
|
||||
$this->assertSame('discount', $result[2]['type']);
|
||||
$this->assertSame(120.0, $result[2]['defaultPricePerNight']); // baseB
|
||||
$this->assertSame('2026-01-21', $result[2]->dateFrom);
|
||||
$this->assertSame('2026-01-31', $result[2]->dateTo);
|
||||
$this->assertSame('discount', $result[2]->type);
|
||||
$this->assertSame(120.0, $result[2]->defaultPricePerNight); // baseB
|
||||
|
||||
$this->assertSame('2026-02-01', $result[3]['dateFrom']);
|
||||
$this->assertSame('2026-03-31', $result[3]['dateTo']);
|
||||
$this->assertNull($result[3]['type']);
|
||||
$this->assertSame('2026-02-01', $result[3]->dateFrom);
|
||||
$this->assertSame('2026-03-31', $result[3]->dateTo);
|
||||
$this->assertNull($result[3]->type);
|
||||
}
|
||||
|
||||
// --- resolveWinner ---
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ServiceAvailabilityCalculatorTest extends TestCase
|
||||
{
|
||||
private ServiceAvailabilityCalculator $calculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->calculator = new ServiceAvailabilityCalculator();
|
||||
}
|
||||
|
||||
public function testParkingServiceIsUnavailableWhenSoldOut(): void
|
||||
{
|
||||
$parkingService = $this->createParkingService(id: 1, available: 0);
|
||||
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
|
||||
|
||||
$this->assertTrue($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
|
||||
}
|
||||
|
||||
public function testParkingServiceIsAvailableWhenQuotaRemains(): void
|
||||
{
|
||||
$parkingService = $this->createParkingService(id: 1, available: 5);
|
||||
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
|
||||
|
||||
$this->assertFalse($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
|
||||
}
|
||||
|
||||
public function testParkingSelectedByOtherParticipantCountsTowardUsage(): void
|
||||
{
|
||||
$parkingService = $this->createParkingService(id: 1, available: 1);
|
||||
$bookingDto = $this->createBookingDtoWithServices([$parkingService]);
|
||||
|
||||
$otherParticipant = new ParticipantDto();
|
||||
$otherParticipant->parkingService = $parkingService;
|
||||
$bookingDto->participants[1] = $otherParticipant;
|
||||
|
||||
// Only one parking slot remains, and another participant already claimed it,
|
||||
// so it must show unavailable for the current participant (index 0)
|
||||
$this->assertTrue($this->calculator->isServiceUnavailable(1, $bookingDto, 0));
|
||||
}
|
||||
|
||||
private function createParkingService(int $id, int $available): Service
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = $id;
|
||||
$service->label = 'Parkplatz';
|
||||
$service->subType = Constants::TOKEN_PARKING;
|
||||
$service->available = $available;
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function createBookingDtoWithServices(array $services): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
$indexed = [];
|
||||
foreach ($services as $service) {
|
||||
$indexed[$service->id] = $service;
|
||||
}
|
||||
$travel->additionalServices = $indexed;
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants[0] = new ParticipantDto();
|
||||
|
||||
return $bookingDto;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user