wip: modernized edit flow, fix insurance tier calculation
This commit is contained in:
@@ -8,7 +8,6 @@ use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
|
||||
@@ -57,10 +56,6 @@ class BookingPriceCalculatorService
|
||||
{
|
||||
$roomPricing = [];
|
||||
|
||||
if (false === $bookingDto instanceof BookingCreateDto) {
|
||||
return $roomPricing;
|
||||
}
|
||||
|
||||
$selectedRooms = $bookingDto->getSelectedRooms();
|
||||
if (true === empty($selectedRooms)) {
|
||||
return $roomPricing;
|
||||
@@ -196,16 +191,12 @@ class BookingPriceCalculatorService
|
||||
* including their room allocation (full room price) and all selected services.
|
||||
*
|
||||
* @param BookingDto $bookingDto The booking data containing all participants
|
||||
* @param int $participantIndex The index of the participant to calculate for
|
||||
* @param int $participantIndex The index of the participant to calculate for
|
||||
*
|
||||
* @return float The total price for the specified participant
|
||||
*/
|
||||
public function calculateIndividualParticipantPrice(BookingDto $bookingDto, int $participantIndex): float
|
||||
{
|
||||
if (false === $bookingDto instanceof BookingCreateDto) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
if (null === $participant) {
|
||||
return 0.0;
|
||||
@@ -237,10 +228,6 @@ class BookingPriceCalculatorService
|
||||
*/
|
||||
public function calculateAllParticipantIndividualPrices(BookingDto $bookingDto): array
|
||||
{
|
||||
if (false === $bookingDto instanceof BookingCreateDto) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$participantPrices = [];
|
||||
$participants = $bookingDto->getParticipants();
|
||||
|
||||
@@ -257,17 +244,17 @@ class BookingPriceCalculatorService
|
||||
* This method is used for insurance eligibility filtering to avoid circular dependency
|
||||
* where insurance selection affects travel price which affects insurance eligibility.
|
||||
*
|
||||
* @param BookingDto $bookingDto The booking data containing all participants
|
||||
* @param int $participantIndex The index of the participant to calculate for
|
||||
* Only includes services where versicherungsberechnung='J' in the XML. Services with
|
||||
* versicherungsberechnung='N' (like CO² compensation) are excluded from the calculation
|
||||
* as per BPN API requirements for insurance tier determination.
|
||||
*
|
||||
* @return float The total price for the specified participant excluding insurance
|
||||
* @param BookingDto $bookingDto The booking data containing all participants
|
||||
* @param int $participantIndex The index of the participant to calculate for
|
||||
*
|
||||
* @return float The total price for the specified participant excluding insurance and non-calculated services
|
||||
*/
|
||||
public function calculateIndividualParticipantPriceExcludingInsurance(BookingDto $bookingDto, int $participantIndex): float
|
||||
{
|
||||
if (false === $bookingDto instanceof BookingCreateDto) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
if (null === $participant) {
|
||||
return 0.0;
|
||||
@@ -285,7 +272,8 @@ class BookingPriceCalculatorService
|
||||
}
|
||||
|
||||
// Add service prices for this participant (excluding insurance)
|
||||
$totalPrice += $this->calculateParticipantServiceTotal($participant, false);
|
||||
// For insurance eligibility calculation, only include services marked with versicherungsberechnung='J'
|
||||
$totalPrice += $this->calculateParticipantServiceTotal($participant, false, null, true);
|
||||
|
||||
return $totalPrice;
|
||||
}
|
||||
@@ -528,23 +516,28 @@ class BookingPriceCalculatorService
|
||||
/**
|
||||
* Calculates the total service cost for a single participant.
|
||||
*
|
||||
* @param ParticipantDto $participant The participant to calculate services for
|
||||
* @param bool $includeInsurance Whether to include insurance pricing (default: true)
|
||||
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance resolution
|
||||
* @param ParticipantDto $participant The participant to calculate services for
|
||||
* @param bool $includeInsurance Whether to include insurance pricing (default: true)
|
||||
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance resolution
|
||||
* @param bool $onlyInsuranceCalculationServices Only include services with includeInInsuranceCalculation=true (default: false)
|
||||
*
|
||||
* @return float The total service cost for this participant
|
||||
*/
|
||||
private function calculateParticipantServiceTotal(ParticipantDto $participant, bool $includeInsurance = true, ?BookingDto $bookingDto = null): float
|
||||
private function calculateParticipantServiceTotal(ParticipantDto $participant, bool $includeInsurance = true, ?BookingDto $bookingDto = null, bool $onlyInsuranceCalculationServices = false): float
|
||||
{
|
||||
$serviceTotal = 0.0;
|
||||
|
||||
// Single service selections
|
||||
if (null !== $participant->skiPass && null !== $participant->skiPass->price) {
|
||||
$serviceTotal += $participant->skiPass->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $participant->skiPass->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $participant->skiPass->price;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $participant->rentalInsurance && null !== $participant->rentalInsurance->price) {
|
||||
$serviceTotal += $participant->rentalInsurance->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $participant->rentalInsurance->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $participant->rentalInsurance->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Get effective insurance (considering bulk insurance for dependent participants)
|
||||
@@ -555,11 +548,15 @@ class BookingPriceCalculatorService
|
||||
|
||||
// Transportation services
|
||||
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->price) {
|
||||
$serviceTotal += $participant->transportationOutbound->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $participant->transportationOutbound->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $participant->transportationOutbound->price;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $participant->transportationInbound && null !== $participant->transportationInbound->price) {
|
||||
$serviceTotal += $participant->transportationInbound->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $participant->transportationInbound->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $participant->transportationInbound->price;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $participant->pickup && null !== $participant->pickup->price) {
|
||||
@@ -567,7 +564,9 @@ class BookingPriceCalculatorService
|
||||
}
|
||||
|
||||
if (null !== $participant->parkingService && null !== $participant->parkingService->price) {
|
||||
$serviceTotal += $participant->parkingService->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $participant->parkingService->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $participant->parkingService->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Multiple service selections
|
||||
@@ -582,7 +581,9 @@ class BookingPriceCalculatorService
|
||||
if (true === is_array($serviceArray)) {
|
||||
foreach ($serviceArray as $service) {
|
||||
if ($service instanceof Service && null !== $service->price) {
|
||||
$serviceTotal += $service->price;
|
||||
if (false === $onlyInsuranceCalculationServices || true === $service->includeInInsuranceCalculation) {
|
||||
$serviceTotal += $service->price;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -594,7 +595,7 @@ class BookingPriceCalculatorService
|
||||
/**
|
||||
* Retrieves a room by ID from the booking's travel data.
|
||||
*/
|
||||
private function getRoomById(BookingCreateDto $bookingDto, ?int $roomId): ?Room
|
||||
private function getRoomById(BookingDto $bookingDto, ?int $roomId): ?Room
|
||||
{
|
||||
if (null === $roomId) {
|
||||
return null;
|
||||
@@ -644,7 +645,7 @@ class BookingPriceCalculatorService
|
||||
* This method is used for pricing calculations to show correct prices when bulk
|
||||
* insurance is enabled, even though the actual assignment happens in the processor.
|
||||
*
|
||||
* @param ParticipantDto $participant The participant to get insurance for
|
||||
* @param ParticipantDto $participant The participant to get insurance for
|
||||
* @param BookingDto|null $bookingDto Optional booking DTO for bulk insurance check
|
||||
*
|
||||
* @return Insurance|null The effective insurance for pricing purposes
|
||||
|
||||
Reference in New Issue
Block a user