fix: omit zero-amount surcharges from the booking summary
This commit is contained in:
1 parent
0afa4f4855
commit
553ec901f3
2 files changed
+49
No files matched your search
@@ -102,6 +102,11 @@ class BookingPricingAssembler
|
|||||||
$surchargePricing = [];
|
$surchargePricing = [];
|
||||||
|
|
||||||
foreach ($bookingData->surcharges as $surcharge) {
|
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[] = [
|
$surchargePricing[] = [
|
||||||
'label' => $surcharge->label ?? 'unbekannt',
|
'label' => $surcharge->label ?? 'unbekannt',
|
||||||
'participantCount' => count($surcharge->mapping),
|
'participantCount' => count($surcharge->mapping),
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Tests\Service;
|
namespace App\Tests\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Booking;
|
||||||
use App\BusProNet\Model\Insurance;
|
use App\BusProNet\Model\Insurance;
|
||||||
use App\BusProNet\Model\Pickup;
|
use App\BusProNet\Model\Pickup;
|
||||||
use App\BusProNet\Model\Service;
|
use App\BusProNet\Model\Service;
|
||||||
|
use App\BusProNet\Model\Surcharge;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\ParticipantDto;
|
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');
|
$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<int> $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
|
private function createBusBookingDto(string $outboundSubType, string $inboundSubType): BookingDto
|
||||||
{
|
{
|
||||||
$travel = new Travel();
|
$travel = new Travel();
|
||||||
|
|||||||
Reference in new issue
Block a user