From d3666c4618c82cec1f21816c0ed894ce8b92082d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 18 Aug 2026 13:07:31 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20skip=20discounts=20with=20value=200?= =?UTF-8?q?=E2=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccommodationBookingBreakdownCalculator.php | 7 +++++-- ...ommodationBookingBreakdownCalculatorTest.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Service/AccommodationBookingBreakdownCalculator.php b/src/Service/AccommodationBookingBreakdownCalculator.php index 6bf51b3..7a7088c 100644 --- a/src/Service/AccommodationBookingBreakdownCalculator.php +++ b/src/Service/AccommodationBookingBreakdownCalculator.php @@ -51,11 +51,14 @@ class AccommodationBookingBreakdownCalculator $discountSum = 0; 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; } - $amount = self::discountAmount($base, $percent); $discountSum += $amount; $discounts[] = ['label' => $label, 'percent' => $percent, 'amount' => $amount]; } diff --git a/tests/Service/AccommodationBookingBreakdownCalculatorTest.php b/tests/Service/AccommodationBookingBreakdownCalculatorTest.php index 734f997..246222b 100644 --- a/tests/Service/AccommodationBookingBreakdownCalculatorTest.php +++ b/tests/Service/AccommodationBookingBreakdownCalculatorTest.php @@ -72,6 +72,23 @@ class AccommodationBookingBreakdownCalculatorTest extends TestCase 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 { $breakdown = $this->createCalculator()->withDiscounts(new AccommodationBooking(), $this->breakdown());