- |
{{ price.dateFrom | date('d.m.Y') }}
|
{{ price.dateTo | date('d.m.Y') }}
|
+
+ {% if price.type is not null %}
+ {% if price.type.value == 'discount' %}
+ {{ icon('discount', 'w-5 h-5') }}
+ {% elseif price.type.value == 'override' %}
+ {{ icon('stack', 'w-5 h-5') }}
+ {% endif %}
+ {% endif %}
+ |
{{ price.season.token | trans }}
|
@@ -104,16 +114,10 @@
{{ price.includedPax }}
- {{ (price.effectivePricePerNight / 100) | format_currency(accommodation.currency) }}
- {% if price.pricePerNightOverride is not null %}
- {{ (price.pricePerNight / 100) | format_currency(accommodation.currency) }}
- {% endif %}
+ {{ (price.pricePerNight / 100) | format_currency(accommodation.currency) }}
|
- {{ (price.effectivePriceAdditionalPerson / 100) | format_currency(accommodation.currency) }}
- {% if price.priceAdditionalPersonOverride is not null %}
- {{ (price.priceAdditionalPerson / 100) | format_currency(accommodation.currency) }}
- {% endif %}
+ {{ (price.priceAdditionalPerson / 100) | format_currency(accommodation.currency) }}
|
{% if price.acceptUndersubscription %}
diff --git a/templates/admin/accommodation_price/_form.html.twig b/templates/admin/accommodation_price/_form.html.twig
index 7868db88..46964b87 100644
--- a/templates/admin/accommodation_price/_form.html.twig
+++ b/templates/admin/accommodation_price/_form.html.twig
@@ -2,15 +2,14 @@
{{ form_start(form) }}
-
+
{{ form_row(form.dateFrom) }}
{{ form_row(form.dateTo) }}
{{ form_row(form.season) }}
+ {{ form_row(form.type) }}
{{ form_row(form.pricePerNight) }}
- {{ form_row(form.pricePerNightOverride) }}
{{ form_row(form.priceAdditionalPerson) }}
- {{ form_row(form.priceAdditionalPersonOverride) }}
{{ form_row(form.includedPax) }}
{{ form_row(form.minNights) }}
{{ form_row(form.acceptUndersubscription) }}
diff --git a/templates/components/calendar/grid.html.twig b/templates/components/calendar/grid.html.twig
index ccca0cc5..af8ddb24 100644
--- a/templates/components/calendar/grid.html.twig
+++ b/templates/components/calendar/grid.html.twig
@@ -1,56 +1,71 @@
-
+{% set weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'] %}
+
{% for month in months %}
+ {% set totalCols = month.firstDow + (month.days | length) %}
- {{ month.label }}
-
-
- {% for header in ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'] %}
- {{ header }}
- {% endfor %}
-
- {% if month.firstDow > 0 %}
- {% for i in 1..month.firstDow %}
-
- {% endfor %}
- {% endif %}
-
- {% for dayNum, day in month.days %}
-
- {{ dayNum }}
-
- {% if day.hasPrice %}
-
- {% endif %}
- {% if day.hasBoard %}
-
- {% endif %}
- {% if day.hasAdditional %}
-
- {% endif %}
- {% if day.isBlocked %}
-
- {% endif %}
-
+ {{ month.label }}
+
+
+
+
+ {% for col in 0..(totalCols - 1) %}
+ {% set dow = col % 7 %}
+
+ {{ weekdays[dow] }}
+
+ {% endfor %}
- {% endfor %}
+
+
+ {% if month.firstDow > 0 %}
+ {% for i in 1..month.firstDow %}
+
+ {% endfor %}
+ {% endif %}
+ {% for dayNum, day in month.days %}
+
+ {{ dayNum }}
+
+ {% endfor %}
+
+ {% for row in [
+ {label: 'Preis', key: 'hasPrice', color: 'bg-blue-500'},
+ {label: 'Verpfl.', key: 'hasBoard', color: 'bg-green-500'},
+ {label: 'Zusatzl.', key: 'hasAdditional', color: 'bg-amber-500'},
+ {label: 'n. v.', key: 'isBlocked', color: 'bg-red-500'},
+ ] %}
+
+ {{ row.label }}
+ {% if month.firstDow > 0 %}
+ {% for i in 1..month.firstDow %}
+
+ {% endfor %}
+ {% endif %}
+ {% for dayNum, day in month.days %}
+
+ {% endfor %}
+
+ {% endfor %}
+
{% endfor %}
-
+
- Preiskonfigurationen
+ Preiskonfigurationen
- Verpflegungsleistungen
+ Verpflegungsleistungen
- optionale Zusatzleistungen
+ optionale Zusatzleistungen
- nicht verfügbar
+ nicht verfügbar
-
diff --git a/tests/Service/PriceTimelineBuilderTest.php b/tests/Service/PriceTimelineBuilderTest.php
new file mode 100644
index 00000000..74ea9e1c
--- /dev/null
+++ b/tests/Service/PriceTimelineBuilderTest.php
@@ -0,0 +1,261 @@
+builder = new PriceTimelineBuilder();
+ }
+
+ // --- buildTimeline ---
+
+ public function testReturnsEmptyArrayForNoPrices(): void
+ {
+ $result = $this->builder->buildTimeline([], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertSame([], $result);
+ }
+
+ public function testSingleBasePriceWithinYear(): void
+ {
+ $price = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000, priceAdditionalPerson: 2000, includedPax: 2);
+
+ $result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(1, $result);
+ $this->assertSame('2026-01-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-03-31', $result[0]['dateTo']);
+ $this->assertSame(150.0, $result[0]['pricePerNight']);
+ $this->assertSame(20.0, $result[0]['priceAdditionalPerson']);
+ $this->assertSame(2, $result[0]['includedPax']);
+ $this->assertNull($result[0]['type']);
+ $this->assertNull($result[0]['defaultPricePerNight']);
+ $this->assertNull($result[0]['defaultPriceAdditionalPerson']);
+ $this->assertSame('EUR', $result[0]['currency']);
+ }
+
+ public function testBasePriceStartingBeforeYearIsClamped(): void
+ {
+ $price = $this->makePrice('2025-12-01', '2026-03-31', pricePerNight: 10000);
+
+ $result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(1, $result);
+ $this->assertSame('2026-01-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-03-31', $result[0]['dateTo']);
+ }
+
+ public function testBasePriceEndingAfterYearIsClamped(): void
+ {
+ $price = $this->makePrice('2026-10-01', '2027-01-31', pricePerNight: 10000);
+
+ $result = $this->builder->buildTimeline([$price], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(1, $result);
+ $this->assertSame('2026-10-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-12-31', $result[0]['dateTo']);
+ }
+
+ public function testDiscountSplitsBasePeriodIntoThreeRows(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000, type: PriceType::DISCOUNT);
+
+ $result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(3, $result);
+ $this->assertSame('2026-01-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-01-14', $result[0]['dateTo']);
+ $this->assertNull($result[0]['type']);
+
+ $this->assertSame('2026-01-15', $result[1]['dateFrom']);
+ $this->assertSame('2026-01-31', $result[1]['dateTo']);
+ $this->assertSame('discount', $result[1]['type']);
+
+ $this->assertSame('2026-02-01', $result[2]['dateFrom']);
+ $this->assertSame('2026-03-31', $result[2]['dateTo']);
+ $this->assertNull($result[2]['type']);
+ }
+
+ public function testDiscountRowIncludesDefaultPrice(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000, priceAdditionalPerson: 3000);
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000, priceAdditionalPerson: 2000, type: PriceType::DISCOUNT);
+
+ $result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $discountRow = $result[1];
+ $this->assertSame(120.0, $discountRow['pricePerNight']);
+ $this->assertSame(150.0, $discountRow['defaultPricePerNight']);
+ $this->assertSame(20.0, $discountRow['priceAdditionalPerson']);
+ $this->assertSame(30.0, $discountRow['defaultPriceAdditionalPerson']);
+ }
+
+ public function testBaseRowsHaveNullDefaultPriceFields(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000, type: PriceType::DISCOUNT);
+
+ $result = $this->builder->buildTimeline([$base, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertNull($result[0]['defaultPricePerNight']);
+ $this->assertNull($result[0]['defaultPriceAdditionalPerson']);
+ $this->assertNull($result[2]['defaultPricePerNight']);
+ $this->assertNull($result[2]['defaultPriceAdditionalPerson']);
+ }
+
+ public function testDiscountWithNoBasePriceHasNullDefaultPrice(): void
+ {
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000, type: PriceType::DISCOUNT);
+
+ $result = $this->builder->buildTimeline([$discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(1, $result);
+ $this->assertSame('discount', $result[0]['type']);
+ $this->assertNull($result[0]['defaultPricePerNight']);
+ }
+
+ public function testGapBetweenTwoPricesIsOmitted(): void
+ {
+ $first = $this->makePrice('2026-01-01', '2026-01-31', pricePerNight: 10000);
+ $second = $this->makePrice('2026-03-01', '2026-03-31', pricePerNight: 20000);
+
+ $result = $this->builder->buildTimeline([$first, $second], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(2, $result);
+ $this->assertSame('2026-01-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-01-31', $result[0]['dateTo']);
+ $this->assertSame('2026-03-01', $result[1]['dateFrom']);
+ $this->assertSame('2026-03-31', $result[1]['dateTo']);
+ }
+
+ public function testOverrideSplitsBasePeriod(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $override = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 18000, type: PriceType::OVERRIDE);
+
+ $result = $this->builder->buildTimeline([$base, $override], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(3, $result);
+ $this->assertNull($result[0]['type']);
+ $this->assertSame('override', $result[1]['type']);
+ $this->assertSame(180.0, $result[1]['pricePerNight']);
+ $this->assertNull($result[2]['type']);
+ }
+
+ public function testDiscountOverTwoDifferentBasePricesProducesTwoDiscountRows(): void
+ {
+ // The discount spans two different base price periods. Even though the discount entity
+ // is the same, the rows must NOT be merged because defaultPricePerNight differs.
+ $baseA = $this->makePrice('2026-01-01', '2026-01-20', pricePerNight: 10000);
+ $baseB = $this->makePrice('2026-01-21', '2026-03-31', pricePerNight: 12000);
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 8000, type: PriceType::DISCOUNT);
+
+ $result = $this->builder->buildTimeline([$baseA, $baseB, $discount], new \DateTimeImmutable('2026-01-01'), new \DateTimeImmutable('2026-12-31'), 'EUR');
+
+ $this->assertCount(4, $result);
+
+ $this->assertSame('2026-01-01', $result[0]['dateFrom']);
+ $this->assertSame('2026-01-14', $result[0]['dateTo']);
+ $this->assertNull($result[0]['type']);
+
+ $this->assertSame('2026-01-15', $result[1]['dateFrom']);
+ $this->assertSame('2026-01-20', $result[1]['dateTo']);
+ $this->assertSame('discount', $result[1]['type']);
+ $this->assertSame(100.0, $result[1]['defaultPricePerNight']); // baseA
+
+ $this->assertSame('2026-01-21', $result[2]['dateFrom']);
+ $this->assertSame('2026-01-31', $result[2]['dateTo']);
+ $this->assertSame('discount', $result[2]['type']);
+ $this->assertSame(120.0, $result[2]['defaultPricePerNight']); // baseB
+
+ $this->assertSame('2026-02-01', $result[3]['dateFrom']);
+ $this->assertSame('2026-03-31', $result[3]['dateTo']);
+ $this->assertNull($result[3]['type']);
+ }
+
+ // --- resolveWinner ---
+
+ public function testResolveWinnerReturnsNullForEmptyArray(): void
+ {
+ $this->assertNull($this->builder->resolveWinner([]));
+ }
+
+ public function testResolveWinnerReturnsSingleCandidate(): void
+ {
+ $price = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 10000);
+
+ $this->assertSame($price, $this->builder->resolveWinner([$price]));
+ }
+
+ public function testResolveWinnerPrefersDiscountOverBase(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $discount = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000, type: PriceType::DISCOUNT);
+
+ $this->assertSame($discount, $this->builder->resolveWinner([$base, $discount]));
+ }
+
+ public function testResolveWinnerPrefersOverrideOverBase(): void
+ {
+ $base = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $override = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 18000, type: PriceType::OVERRIDE);
+
+ $this->assertSame($override, $this->builder->resolveWinner([$base, $override]));
+ }
+
+ public function testResolveWinnerPrefersDiscountOverOverride(): void
+ {
+ $override = $this->makePrice('2026-01-01', '2026-01-31', pricePerNight: 18000, type: PriceType::OVERRIDE);
+ $discount = $this->makePrice('2026-01-01', '2026-01-31', pricePerNight: 12000, type: PriceType::DISCOUNT);
+
+ $this->assertSame($discount, $this->builder->resolveWinner([$override, $discount]));
+ }
+
+ public function testResolveWinnerPrefersShorterPeriodOnEqualTypeTie(): void
+ {
+ $wide = $this->makePrice('2026-01-01', '2026-03-31', pricePerNight: 15000);
+ $narrow = $this->makePrice('2026-01-15', '2026-01-31', pricePerNight: 12000);
+
+ $this->assertSame($narrow, $this->builder->resolveWinner([$wide, $narrow]));
+ }
+
+ public function testResolveWinnerPrefersLaterStartOnEqualLengthTie(): void
+ {
+ // Both cover 30 days; the one starting later should win.
+ $earlier = $this->makePrice('2026-01-01', '2026-01-30', pricePerNight: 15000);
+ $later = $this->makePrice('2026-02-01', '2026-03-02', pricePerNight: 12000);
+
+ $this->assertSame($later, $this->builder->resolveWinner([$earlier, $later]));
+ }
+
+ private function makePrice(
+ string $dateFrom,
+ string $dateTo,
+ int $pricePerNight,
+ int $priceAdditionalPerson = 0,
+ int $includedPax = 2,
+ ?PriceType $type = null,
+ ): AccommodationPrice {
+ $price = new AccommodationPrice();
+ $price->setDateFrom(new \DateTimeImmutable($dateFrom));
+ $price->setDateTo(new \DateTimeImmutable($dateTo));
+ $price->setPricePerNight($pricePerNight);
+ $price->setPriceAdditionalPerson($priceAdditionalPerson);
+ $price->setIncludedPax($includedPax);
+ $price->setType($type);
+
+ return $price;
+ }
+}
|