fix: skip discounts with value 0€

This commit is contained in:
Björn Fromme
2026-08-18 13:07:31 +02:00
parent ef24c9a616
commit d3666c4618
2 changed files with 22 additions and 2 deletions
@@ -51,11 +51,14 @@ class AccommodationBookingBreakdownCalculator
$discountSum = 0; $discountSum = 0;
foreach ($buckets as [$label, $percent, $base]) { foreach ($buckets as [$label, $percent, $base]) {
if (null === $percent) { $amount = self::discountAmount($base, $percent);
// Nothing to show for a discount of 0 %, or one on a bucket this booking has no
// price in — a " 0,00 €" row only raises questions.
if (0 === $amount) {
continue; continue;
} }
$amount = self::discountAmount($base, $percent);
$discountSum += $amount; $discountSum += $amount;
$discounts[] = ['label' => $label, 'percent' => $percent, 'amount' => $amount]; $discounts[] = ['label' => $label, 'percent' => $percent, 'amount' => $amount];
} }
@@ -72,6 +72,23 @@ class AccommodationBookingBreakdownCalculatorTest extends TestCase
self::assertSame(12345 - 50, $breakdown['discountedTotal']); self::assertSame(12345 - 50, $breakdown['discountedTotal']);
} }
public function testWithDiscountsSkipsDiscountsThatAmountToNothing(): void
{
$booking = new AccommodationBooking();
$booking->setAccommodationDiscount(0);
// A discount on a bucket this booking has no price in.
$booking->setAdditionalServicesDiscount(20);
$breakdown = $this->createCalculator()->withDiscounts($booking, [
'total' => 12345,
'basePrice' => 8000,
'servicesPrice' => 0,
]);
self::assertSame([], $breakdown['discounts']);
self::assertSame(12345, $breakdown['discountedTotal']);
}
public function testWithoutDiscountsTheDiscountedTotalIsTheTotal(): void public function testWithoutDiscountsTheDiscountedTotalIsTheTotal(): void
{ {
$breakdown = $this->createCalculator()->withDiscounts(new AccommodationBooking(), $this->breakdown()); $breakdown = $this->createCalculator()->withDiscounts(new AccommodationBooking(), $this->breakdown());