feat: finalize voucher handling and discount display in summary and overview

This commit is contained in:
Björn Fromme
2026-03-16 11:59:12 +01:00
parent 2e40cbc7c7
commit 230c53875f
15 changed files with 762 additions and 46 deletions
+55
View File
@@ -47,4 +47,59 @@ class BookingResponse
{
return 'erfolgt' === $this->status;
}
/**
* Gets voucher discounts from price items (AKTION and KULANZGUTSCHEIN types).
*
* Promotional vouchers appear as negative price items with art="AKTION".
* Goodwill vouchers appear as negative price items with art="KULANZGUTSCHEIN".
*
* @return array<PriceItem> Price items representing voucher discounts
*/
public function getVoucherDiscountsFromPrices(): array
{
return array_filter(
$this->priceItems,
fn (PriceItem $item) => \in_array($item->type, ['AKTION', 'KULANZGUTSCHEIN'], true)
);
}
/**
* Gets total discount from price-based vouchers (promotional and goodwill).
*
* Returns the absolute sum of negative price items with AKTION or KULANZGUTSCHEIN types.
*/
public function getVoucherDiscountFromPrices(): float
{
$discount = 0.0;
foreach ($this->getVoucherDiscountsFromPrices() as $item) {
// Price items for vouchers are negative, so we take absolute value
$discount += abs($item->totalPrice);
}
return round($discount, 2);
}
/**
* Gets total discount from purchase vouchers in payment terms.
*/
public function getPurchaseVoucherDiscount(): float
{
return $this->paymentTerms?->getPurchaseVoucherDiscount() ?? 0.0;
}
/**
* Gets total voucher discount from all sources.
*
* Combines discounts from:
* - Price items (art="AKTION" for promotional, art="KULANZGUTSCHEIN" for goodwill)
* - Payment terms (kaufgutschein elements for purchase vouchers)
*/
public function getTotalVoucherDiscount(): float
{
return round(
$this->getVoucherDiscountFromPrices() + $this->getPurchaseVoucherDiscount(),
2
);
}
}