feat: dedicated section for discounts in summary
addresses #869ay1724
This commit is contained in:
@@ -346,25 +346,26 @@ class BookingPriceCalculatorService
|
||||
* Aggregates all transportation-related services and pricing into separate line items.
|
||||
*
|
||||
* Creates separate entries for:
|
||||
* - Zustieg: Sum of all pickup prices and base transportation costs (positive and negative)
|
||||
* - Beförderung: Sum of all positive pickup prices and base transportation costs
|
||||
* - Beförderung - Rabatt: Sum of all negative transportation prices (discounts)
|
||||
* - Parkplatz: Sum of all parking service prices
|
||||
*
|
||||
* Only includes transportation costs from eligible participants.
|
||||
*
|
||||
* Note: Transportation discounts will be handled generically by groupServicesBySubtype as "Beförderung - Rabatt"
|
||||
*
|
||||
* @param BookingDto $bookingDto The booking data containing participants
|
||||
*
|
||||
* @return array Array of transportation line items (Zustieg, Parkplatz)
|
||||
* @return array Array of transportation line items (Beförderung, Rabatt, Parkplatz)
|
||||
*/
|
||||
private function aggregateTransportationServices(BookingDto $bookingDto): array
|
||||
{
|
||||
$participants = $bookingDto->getParticipants();
|
||||
|
||||
$pickupTotal = 0.0; // All pickup prices and base transportation costs
|
||||
$parkingTotal = 0.0; // Parking service costs
|
||||
$transportationPositiveTotal = 0.0; // Positive transportation/pickup costs
|
||||
$transportationDiscountTotal = 0.0; // Negative transportation prices (discounts)
|
||||
$parkingTotal = 0.0; // Parking service costs
|
||||
|
||||
$pickupParticipants = 0;
|
||||
$transportationParticipants = 0;
|
||||
$discountParticipants = 0;
|
||||
$parkingParticipants = 0;
|
||||
|
||||
foreach ($participants as $participantIndex => $participant) {
|
||||
@@ -373,22 +374,35 @@ class BookingPriceCalculatorService
|
||||
continue;
|
||||
}
|
||||
|
||||
$participantPickupCost = 0.0;
|
||||
$participantTransportationPositiveCost = 0.0;
|
||||
$participantTransportationDiscountCost = 0.0;
|
||||
$participantParkingCost = 0.0;
|
||||
|
||||
// Transportation service pricing (outbound)
|
||||
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->price) {
|
||||
$participantPickupCost += $participant->transportationOutbound->price;
|
||||
if ($participant->transportationOutbound->price < 0) {
|
||||
$participantTransportationDiscountCost += $participant->transportationOutbound->price;
|
||||
} else {
|
||||
$participantTransportationPositiveCost += $participant->transportationOutbound->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Transportation service pricing (inbound)
|
||||
if (null !== $participant->transportationInbound && null !== $participant->transportationInbound->price) {
|
||||
$participantPickupCost += $participant->transportationInbound->price;
|
||||
if ($participant->transportationInbound->price < 0) {
|
||||
$participantTransportationDiscountCost += $participant->transportationInbound->price;
|
||||
} else {
|
||||
$participantTransportationPositiveCost += $participant->transportationInbound->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Pickup pricing (unified for both directions)
|
||||
if (null !== $participant->pickup && null !== $participant->pickup->price) {
|
||||
$participantPickupCost += $participant->pickup->price;
|
||||
if ($participant->pickup->price < 0) {
|
||||
$participantTransportationDiscountCost += $participant->pickup->price;
|
||||
} else {
|
||||
$participantTransportationPositiveCost += $participant->pickup->price;
|
||||
}
|
||||
}
|
||||
|
||||
// Parking service pricing
|
||||
@@ -396,10 +410,14 @@ class BookingPriceCalculatorService
|
||||
$participantParkingCost += $participant->parkingService->price;
|
||||
}
|
||||
|
||||
// Aggregate participant totals (count participants who have any transportation costs)
|
||||
if (0.0 !== $participantPickupCost) {
|
||||
$pickupTotal += $participantPickupCost;
|
||||
++$pickupParticipants;
|
||||
// Aggregate participant totals
|
||||
if ($participantTransportationPositiveCost > 0) {
|
||||
$transportationPositiveTotal += $participantTransportationPositiveCost;
|
||||
++$transportationParticipants;
|
||||
}
|
||||
if ($participantTransportationDiscountCost < 0) {
|
||||
$transportationDiscountTotal += $participantTransportationDiscountCost;
|
||||
++$discountParticipants;
|
||||
}
|
||||
if ($participantParkingCost > 0) {
|
||||
$parkingTotal += $participantParkingCost;
|
||||
@@ -409,18 +427,30 @@ class BookingPriceCalculatorService
|
||||
|
||||
$transportationItems = [];
|
||||
|
||||
// Add pickup entry (if any transportation/pickup costs exist)
|
||||
if (0.0 !== $pickupTotal) {
|
||||
$transportationItems['transportation_pickup'] = [
|
||||
'serviceId' => 'transportation_pickup',
|
||||
'label' => 'Zustieg',
|
||||
// Add transportation entry (only positive costs)
|
||||
if ($transportationPositiveTotal > 0) {
|
||||
$transportationItems['transportation_positive'] = [
|
||||
'serviceId' => 'transportation_positive',
|
||||
'label' => 'Beförderung',
|
||||
'unitPrice' => null,
|
||||
'participantCount' => $pickupParticipants,
|
||||
'totalPrice' => $pickupTotal,
|
||||
'participantCount' => $transportationParticipants,
|
||||
'totalPrice' => $transportationPositiveTotal,
|
||||
'subType' => Constants::GROUP_TRANSPORTATION,
|
||||
];
|
||||
}
|
||||
|
||||
// Add discount entry (only negative costs)
|
||||
if ($transportationDiscountTotal < 0) {
|
||||
$transportationItems['transportation_discount'] = [
|
||||
'serviceId' => 'transportation_discount',
|
||||
'label' => 'Beförderung - Rabatt',
|
||||
'unitPrice' => null,
|
||||
'participantCount' => $discountParticipants,
|
||||
'totalPrice' => $transportationDiscountTotal,
|
||||
'subType' => Constants::GROUP_TRANSPORTATION.'_discount',
|
||||
];
|
||||
}
|
||||
|
||||
// Add parking entry (only if positive costs)
|
||||
if ($parkingTotal > 0) {
|
||||
$transportationItems['transportation_parking'] = [
|
||||
|
||||
Reference in New Issue
Block a user