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.
|
* Aggregates all transportation-related services and pricing into separate line items.
|
||||||
*
|
*
|
||||||
* Creates separate entries for:
|
* 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
|
* - Parkplatz: Sum of all parking service prices
|
||||||
*
|
*
|
||||||
* Only includes transportation costs from eligible participants.
|
* 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
|
* @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
|
private function aggregateTransportationServices(BookingDto $bookingDto): array
|
||||||
{
|
{
|
||||||
$participants = $bookingDto->getParticipants();
|
$participants = $bookingDto->getParticipants();
|
||||||
|
|
||||||
$pickupTotal = 0.0; // All pickup prices and base transportation costs
|
$transportationPositiveTotal = 0.0; // Positive transportation/pickup costs
|
||||||
$parkingTotal = 0.0; // Parking service costs
|
$transportationDiscountTotal = 0.0; // Negative transportation prices (discounts)
|
||||||
|
$parkingTotal = 0.0; // Parking service costs
|
||||||
|
|
||||||
$pickupParticipants = 0;
|
$transportationParticipants = 0;
|
||||||
|
$discountParticipants = 0;
|
||||||
$parkingParticipants = 0;
|
$parkingParticipants = 0;
|
||||||
|
|
||||||
foreach ($participants as $participantIndex => $participant) {
|
foreach ($participants as $participantIndex => $participant) {
|
||||||
@@ -373,22 +374,35 @@ class BookingPriceCalculatorService
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$participantPickupCost = 0.0;
|
$participantTransportationPositiveCost = 0.0;
|
||||||
|
$participantTransportationDiscountCost = 0.0;
|
||||||
$participantParkingCost = 0.0;
|
$participantParkingCost = 0.0;
|
||||||
|
|
||||||
// Transportation service pricing (outbound)
|
// Transportation service pricing (outbound)
|
||||||
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->price) {
|
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)
|
// Transportation service pricing (inbound)
|
||||||
if (null !== $participant->transportationInbound && null !== $participant->transportationInbound->price) {
|
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)
|
// Pickup pricing (unified for both directions)
|
||||||
if (null !== $participant->pickup && null !== $participant->pickup->price) {
|
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
|
// Parking service pricing
|
||||||
@@ -396,10 +410,14 @@ class BookingPriceCalculatorService
|
|||||||
$participantParkingCost += $participant->parkingService->price;
|
$participantParkingCost += $participant->parkingService->price;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aggregate participant totals (count participants who have any transportation costs)
|
// Aggregate participant totals
|
||||||
if (0.0 !== $participantPickupCost) {
|
if ($participantTransportationPositiveCost > 0) {
|
||||||
$pickupTotal += $participantPickupCost;
|
$transportationPositiveTotal += $participantTransportationPositiveCost;
|
||||||
++$pickupParticipants;
|
++$transportationParticipants;
|
||||||
|
}
|
||||||
|
if ($participantTransportationDiscountCost < 0) {
|
||||||
|
$transportationDiscountTotal += $participantTransportationDiscountCost;
|
||||||
|
++$discountParticipants;
|
||||||
}
|
}
|
||||||
if ($participantParkingCost > 0) {
|
if ($participantParkingCost > 0) {
|
||||||
$parkingTotal += $participantParkingCost;
|
$parkingTotal += $participantParkingCost;
|
||||||
@@ -409,18 +427,30 @@ class BookingPriceCalculatorService
|
|||||||
|
|
||||||
$transportationItems = [];
|
$transportationItems = [];
|
||||||
|
|
||||||
// Add pickup entry (if any transportation/pickup costs exist)
|
// Add transportation entry (only positive costs)
|
||||||
if (0.0 !== $pickupTotal) {
|
if ($transportationPositiveTotal > 0) {
|
||||||
$transportationItems['transportation_pickup'] = [
|
$transportationItems['transportation_positive'] = [
|
||||||
'serviceId' => 'transportation_pickup',
|
'serviceId' => 'transportation_positive',
|
||||||
'label' => 'Zustieg',
|
'label' => 'Beförderung',
|
||||||
'unitPrice' => null,
|
'unitPrice' => null,
|
||||||
'participantCount' => $pickupParticipants,
|
'participantCount' => $transportationParticipants,
|
||||||
'totalPrice' => $pickupTotal,
|
'totalPrice' => $transportationPositiveTotal,
|
||||||
'subType' => Constants::GROUP_TRANSPORTATION,
|
'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)
|
// Add parking entry (only if positive costs)
|
||||||
if ($parkingTotal > 0) {
|
if ($parkingTotal > 0) {
|
||||||
$transportationItems['transportation_parking'] = [
|
$transportationItems['transportation_parking'] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user