53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Groups\AccommodationBooking;
|
|
use App\Repository\Groups\AccommodationPriceRepository;
|
|
|
|
class AccommodationBookingBreakdownCalculator
|
|
{
|
|
public function __construct(
|
|
private readonly GroupsPriceCalculator $priceCalculator,
|
|
private readonly AccommodationPriceRepository $priceRepo,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Recomputes the price breakdown from the booking's frozen snapshot data and current
|
|
* accommodation prices for the same date range.
|
|
*
|
|
* @return array<string, mixed>|null null when no accommodation or dates are set
|
|
*/
|
|
public function compute(AccommodationBooking $booking): ?array
|
|
{
|
|
$accommodation = $booking->getAccommodation();
|
|
$dateFrom = $booking->getDateFrom();
|
|
$dateTo = $booking->getDateTo();
|
|
|
|
if (null === $accommodation || null === $dateFrom || null === $dateTo) {
|
|
return null;
|
|
}
|
|
|
|
$prices = $this->priceRepo->findByHotelCodeAndDateRange(
|
|
$accommodation->getCalendarCode() ?? '',
|
|
$dateFrom,
|
|
$dateTo,
|
|
);
|
|
|
|
return $this->priceCalculator->calculateFromSnapshots(
|
|
$booking->getPaxCount(),
|
|
$booking->getMinorsCount(),
|
|
$booking->getNights(),
|
|
$dateFrom,
|
|
$dateTo,
|
|
$prices,
|
|
$booking->getBoardServicePrice(),
|
|
$booking->getAdditionalServices(),
|
|
$accommodation->getCurrency(),
|
|
);
|
|
}
|
|
}
|