feat: groups price calculator admin crud, booking/offer flow and api
This commit is contained in:
1 parent
eabed8295a
commit
9d2aa11fdb
258 files changed
+16231
-582
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<?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,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authoritative stored snapshot, falling back to current prices only for
|
||||
* bookings created before snapshot persistence was introduced.
|
||||
*
|
||||
* @return array<string, mixed>|null null when no accommodation or dates are set
|
||||
*/
|
||||
public function compute(AccommodationBooking $booking): ?array
|
||||
{
|
||||
if (null !== $booking->getPriceBreakdown()) {
|
||||
return $booking->getPriceBreakdown();
|
||||
}
|
||||
|
||||
return $this->computeCurrent($booking);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates against the current catalog. Use only while creating or explicitly editing
|
||||
* a booking, or as a compatibility fallback for records created before price snapshots.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function computeCurrent(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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user