feat: split nights off an accommodation booking as separate periods

addresses #869f6z36v
This commit is contained in:
fromme committed 2026-09-30 18:06:20 +02:00
1 parent 972839286c
commit 7001bc0cf2
35 files changed
+2221 -25

No files matched your search

+94 -10
View File
@@ -48,6 +48,97 @@ class GroupsPriceCalculatorTest extends TestCase
self::assertSame(50, $result['undersubscriptionThreshold']);
}
public function testTheShortTermSurchargeIsJudgedOnTheWholeStay(): void
{
// Three nights priced for the group, but one night split off a four-night stay: the
// stay is not short-term, so the three nights must not pick up the 10 % surcharge.
$price = $this->price('2026-06-01', '2026-08-31', 20);
$split = $this->calculateMain('2026-07-02', '2026-07-05', '2026-07-01', 4, [$price]);
$unsplit = $this->calculateMain('2026-07-02', '2026-07-05', '2026-07-02', 3, [$price]);
self::assertSame(0, $split['shortTermSurcharge']);
self::assertSame(3, $split['nights']);
self::assertSame((int) round(($unsplit['basePrice'] + $unsplit['additionalPersonsPrice']) * 10 / 100), $unsplit['shortTermSurcharge']);
}
public function testTheShortTermSurchargeOfAShortStayIsChargedOnThePricedNightsOnly(): void
{
// A three-night stay with one night split off: 10 % on the two nights the group pays
// for, not 20 % for a two-night stay and not on the split-off night's lines.
$price = $this->price('2026-06-01', '2026-08-31', 20);
$result = $this->calculateMain('2026-07-02', '2026-07-04', '2026-07-01', 3, [$price]);
self::assertSame(2 * 100_00, $result['basePrice']);
self::assertSame((int) round(($result['basePrice'] + $result['additionalPersonsPrice']) * 10 / 100), $result['shortTermSurcharge']);
}
public function testTheIncludedPaxFloorComesFromTheStaysFirstNight(): void
{
// The stay starts in a price period with a floor of 30; the main group arrives a day
// later, in one with a floor of 50. Splitting the first night off must not raise the
// floor the 20 people are billed at.
$prices = [
$this->price('2026-06-01', '2026-07-01', 30),
$this->price('2026-07-02', '2026-08-31', 50),
];
$result = $this->calculateMain('2026-07-02', '2026-07-08', '2026-07-01', 7, $prices, paxCount: 20, boardServicePrice: 1500);
self::assertSame(30, $result['includedPax']);
self::assertSame(30, $result['effectivePax']);
self::assertSame(1500 * 30 * 6, $result['boardPrice']);
}
/**
* @param list<AccommodationPrice> $prices
*
* @return array<string, mixed>
*/
private function calculateMain(string $from, string $to, string $stayFrom, int $stayNights, array $prices, int $paxCount = 20, ?int $boardServicePrice = null): array
{
$dateFrom = new \DateTimeImmutable($from);
$dateTo = new \DateTimeImmutable($to);
return $this->calculator()->calculateFromSnapshots(
$paxCount,
0,
$dateFrom->diff($dateTo)->days,
$dateFrom,
$dateTo,
new \DateTimeImmutable($stayFrom),
$stayNights,
$prices,
$boardServicePrice,
[],
'EUR',
);
}
private function price(string $from, string $to, int $includedPax): AccommodationPrice
{
return (new AccommodationPrice())
->setDateFrom(new \DateTimeImmutable($from))
->setDateTo(new \DateTimeImmutable($to))
->setIncludedPax($includedPax)
->setPricePerNight(100_00)
->setPriceAdditionalPerson(10_00)
->setMinNights(1);
}
private function calculator(): GroupsPriceCalculator
{
return new GroupsPriceCalculator(new PriceTimelineBuilder(), [
'runningCostsEur' => 0,
'runningCostsChf' => 0,
'undersubscription30Eur' => 5.0,
'undersubscription30Chf' => 6.0,
'undersubscription40Eur' => 2.5,
'undersubscription40Chf' => 3.0,
]);
}
/**
* @return array<string, mixed>
*/
@@ -64,21 +155,14 @@ class GroupsPriceCalculatorTest extends TestCase
->setPriceAdditionalPerson(10_00)
->setMinNights(1);
$calculator = new GroupsPriceCalculator(new PriceTimelineBuilder(), [
'runningCostsEur' => 0,
'runningCostsChf' => 0,
'undersubscription30Eur' => 5.0,
'undersubscription30Chf' => 6.0,
'undersubscription40Eur' => 2.5,
'undersubscription40Chf' => 3.0,
]);
return $calculator->calculateFromSnapshots(
return $this->calculator()->calculateFromSnapshots(
$paxCount,
0,
self::NIGHTS,
$dateFrom,
$dateTo,
$dateFrom,
self::NIGHTS,
[$price],
$boardServicePrice,
[],