diff --git a/src/Service/BookingPricingAssembler.php b/src/Service/BookingPricingAssembler.php index fdcbf3bb..587a1fa1 100644 --- a/src/Service/BookingPricingAssembler.php +++ b/src/Service/BookingPricingAssembler.php @@ -102,6 +102,11 @@ class BookingPricingAssembler $surchargePricing = []; foreach ($bookingData->surcharges as $surcharge) { + // BusPro reports a Zuschlag line even when it nets to nothing, e.g. Stornokosten of 0,00 € + if (0.0 === round($surcharge->totalPrice ?? 0.0, 2)) { + continue; + } + $surchargePricing[] = [ 'label' => $surcharge->label ?? 'unbekannt', 'participantCount' => count($surcharge->mapping), diff --git a/tests/Service/BookingPricingAssemblerTest.php b/tests/Service/BookingPricingAssemblerTest.php index 39b3bca8..9c309980 100644 --- a/tests/Service/BookingPricingAssemblerTest.php +++ b/tests/Service/BookingPricingAssemblerTest.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace App\Tests\Service; +use App\BusProNet\Model\Booking; use App\BusProNet\Model\Insurance; use App\BusProNet\Model\Pickup; use App\BusProNet\Model\Service; +use App\BusProNet\Model\Surcharge; use App\BusProNet\Model\Travel; use App\Form\Model\BookingDto; use App\Form\Model\ParticipantDto; @@ -356,6 +358,48 @@ class BookingPricingAssemblerTest extends TestCase $this->assertEqualsWithDelta($group['groupTotal'], $participantTotal, 0.001, 'Summary and per-participant totals must agree'); } + public function testSurchargePricingOmitsZeroAmountSurcharges(): void + { + $booking = new Booking(); + $booking->surcharges = [ + $this->createSurcharge('Stornokosten', 0.0, [1]), + $this->createSurcharge('unbekannt', -0.0, [0]), + $this->createSurcharge('Teamer', -53.2, [0, 1]), + ]; + + $surchargePricing = $this->assembler->calculateSurchargePricing($booking); + + $this->assertSame([ + ['label' => 'Teamer', 'participantCount' => 2, 'totalPrice' => -53.2], + ], $surchargePricing); + } + + public function testPricingBreakdownOmitsSurchargesWhenAllAreZero(): void + { + $travel = new Travel(); + $travel->insurances = []; + + $bookingDto = new BookingDto($travel, 1); + $bookingDto->participants = []; + $bookingDto->booking = new Booking(); + $bookingDto->booking->surcharges = [$this->createSurcharge('Stornokosten', 0.0, [0])]; + + $breakdown = $this->assembler->getPricingBreakdown($bookingDto); + + $this->assertArrayNotHasKey('surcharges', $breakdown); + } + + /** @param list $mapping */ + private function createSurcharge(string $label, float $totalPrice, array $mapping): Surcharge + { + $surcharge = new Surcharge(); + $surcharge->label = $label; + $surcharge->totalPrice = $totalPrice; + $surcharge->mapping = $mapping; + + return $surcharge; + } + private function createBusBookingDto(string $outboundSubType, string $inboundSubType): BookingDto { $travel = new Travel();