99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Form\Model\BookingDto;
|
|
|
|
/**
|
|
* Computes numeric price totals for bookings and individual participants.
|
|
*
|
|
* All methods return floats or arrays of floats — no display formatting.
|
|
* For display-ready pricing breakdowns, use BookingPricingAssembler.
|
|
*/
|
|
class BookingPriceCalculator
|
|
{
|
|
public function __construct(
|
|
private readonly RoomPricingCalculator $roomPricingCalculator,
|
|
private readonly BookingPricingAssembler $pricingAssembler,
|
|
private readonly ParticipantPricingCalculator $participantPricingCalculator,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Calculates the grand total for the entire booking.
|
|
*/
|
|
public function calculateGrandTotal(
|
|
BookingDto $bookingDto,
|
|
string $roomPricingMode = RoomPricingCalculator::PRICING_MODE_ASSIGNMENT,
|
|
): float {
|
|
return $this->roomPricingCalculator->calculateRoomTotal($bookingDto, $roomPricingMode)
|
|
+ $this->calculateServiceTotal($bookingDto);
|
|
}
|
|
|
|
/**
|
|
* Calculates total price for all rooms.
|
|
*/
|
|
public function calculateRoomTotal(
|
|
BookingDto $bookingDto,
|
|
string $roomPricingMode = RoomPricingCalculator::PRICING_MODE_ASSIGNMENT,
|
|
): float {
|
|
return $this->roomPricingCalculator->calculateRoomTotal($bookingDto, $roomPricingMode);
|
|
}
|
|
|
|
/**
|
|
* Calculates total price for all services across all eligible participants.
|
|
*
|
|
* Delegates to BookingPricingAssembler to guarantee the same insurance-tier
|
|
* resolution used in the display breakdown (including bulk-family-insurance
|
|
* price-tier adjustment per dependent). This keeps the numeric total and the
|
|
* displayed total in sync.
|
|
*/
|
|
public function calculateServiceTotal(BookingDto $bookingDto): float
|
|
{
|
|
return array_sum(array_column(
|
|
$this->pricingAssembler->calculateServicePricing($bookingDto),
|
|
'groupTotal'
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Calculates the total price for an individual participant.
|
|
*/
|
|
public function calculateIndividualParticipantPrice(BookingDto $bookingDto, int $participantIndex): float
|
|
{
|
|
return $this->participantPricingCalculator->calculateIndividualParticipantPrice($bookingDto, $participantIndex);
|
|
}
|
|
|
|
/**
|
|
* Calculates individual prices for all participants in a booking.
|
|
*
|
|
* @return array<int, float>
|
|
*/
|
|
public function calculateAllParticipantIndividualPrices(BookingDto $bookingDto): array
|
|
{
|
|
return $this->participantPricingCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
|
}
|
|
|
|
/**
|
|
* Calculates the total price for an individual participant excluding insurance.
|
|
*
|
|
* Used for insurance eligibility filtering to avoid circular dependency where
|
|
* insurance selection affects travel price which affects insurance eligibility.
|
|
*
|
|
* Only includes services where versicherungsberechnung='J' in the XML. Services with
|
|
* versicherungsberechnung='N' (like CO2 compensation) are excluded as per BPN API
|
|
* requirements for insurance tier determination.
|
|
*/
|
|
public function calculateIndividualParticipantPriceExcludingInsurance(
|
|
BookingDto $bookingDto,
|
|
int $participantIndex,
|
|
): float {
|
|
return $this->participantPricingCalculator->calculateIndividualParticipantPriceExcludingInsurance(
|
|
$bookingDto,
|
|
$participantIndex
|
|
);
|
|
}
|
|
}
|