feat: surcharges and discounts per participant and in summary

This commit is contained in:
Björn Fromme
2026-03-16 11:59:11 +01:00
parent cc8500d0f4
commit cb38beb32c
3 changed files with 85 additions and 1 deletions
+41 -1
View File
@@ -42,11 +42,26 @@ class BookingPriceCalculatorService
$servicePricing = $this->calculateServicePricing($bookingDto);
$grandTotal = $this->calculateGrandTotal($bookingDto);
return [
$result = [
'rooms' => $roomPricing,
'services' => $servicePricing,
'grandTotal' => $grandTotal,
];
// Add surcharges if in edit mode with booking data
if (null !== $bookingDto->booking && [] !== $bookingDto->booking->surcharges) {
$surchargePricing = $this->calculateSurchargePricing($bookingDto->booking);
if ([] !== $surchargePricing) {
$result['surcharges'] = $surchargePricing;
// Add surcharge total to grand total
$surchargeTotal = array_sum(array_column($surchargePricing, 'totalPrice'));
$result['grandTotal'] += $surchargeTotal;
}
}
return $result;
}
/**
@@ -225,6 +240,31 @@ class BookingPriceCalculatorService
return array_sum(array_column($servicePricing, 'groupTotal'));
}
/**
* Calculates surcharge pricing grouped by label (edit mode only).
*
* Returns surcharges in a format similar to services for display in summary.
* Groups surcharges by label and counts participant assignments.
*
* @param \App\BusProNet\Model\Booking $bookingData The booking entity with surcharge information
*
* @return array Array of surcharge data with labels, counts, and totals
*/
public function calculateSurchargePricing(\App\BusProNet\Model\Booking $bookingData): array
{
$surchargePricing = [];
foreach ($bookingData->surcharges as $surcharge) {
$surchargePricing[] = [
'label' => $surcharge->label ?? 'unbekannt',
'participantCount' => count($surcharge->mapping),
'totalPrice' => $surcharge->totalPrice ?? 0.0,
];
}
return $surchargePricing;
}
/**
* Formats a price value for display with proper German formatting.
*