Compare commits

...
4 Commits
14 changed files with 218 additions and 133 deletions

No files matched your search

+6
View File
@@ -172,6 +172,7 @@ an error: it returns `200` with an empty `data` array and the usual `meta`.
{
"busProId": 12794,
"code": "PCJSER261226",
"productCode": "PCJSER",
"product": "Semesterende - Portes du Soleil - Joliment",
"dateFrom": "2026-12-26",
"dateTo": "2026-12-30",
@@ -212,6 +213,11 @@ an error: it returns `200` with an empty `data` array and the usual `meta`.
is always an int and never null; `hotel` is always an object and never null; `pickups` is always an array, possibly
empty, never null.
**`productCode`** is the code of the travel (product) the date belongs to, e.g. `DKIWE`. Key on it to
recognise dates of the same product. Do not derive it from the date `code` by cutting off the date: some
products run dates under a different code (`DWWMP` runs `DWWMW…`), and group travels carry each group's own
code on the date. It is `null` for the few travels that have no code upstream.
**`meta` describes the whole export, not the page.** `total`, `totalPages`, `skipped`, `pickupsWithoutMasterData`,
`sourceGeneratedAt` and `generatedAt` are identical on every page, so you can read them once on page 1 and decide whether to walk the
rest. `total` is the row count **after** skips, and `totalPages` is `ceil(total / perPage)`.
@@ -52,7 +52,7 @@ class IndexController extends AbstractController
$request->query->getInt('page', 1),
$request->query->getInt('limit', 20),
[
'defaultSortFieldName' => 'booking.createdAt',
'defaultSortFieldName' => 'booking.updatedAt',
'defaultSortDirection' => 'DESC',
]
);
@@ -6,8 +6,10 @@ namespace App\Controller\Admin\TravelMailing;
use App\BpnConnect\Exception\BpnConnectException;
use App\BpnConnect\TravelsClient;
use App\BusProNet\Utility\DateCodeUtility;
use App\Form\Admin\TravelMailingLookupType;
use App\Form\Model\TravelMailingLookupDto;
use App\Service\TravelDataProvider;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -19,6 +21,7 @@ class IndexController extends AbstractController
{
public function __construct(
private readonly TravelsClient $travelsClient,
private readonly TravelDataProvider $travelDataProvider,
) {
}
@@ -32,10 +35,16 @@ class IndexController extends AbstractController
$form->handleRequest($request);
$result = null;
$travelLabel = null;
$failed = false;
if ($form->isSubmitted() && $form->isValid()) {
// The local index matches codes exactly, so "lpjmp-281126" has to become "LPJMP281126"
// before the label lookup; bpn-connect gets the same code to keep both in step.
$travelCode = (new DateCodeUtility())->sanitize((string) $lookup->travelCode);
try {
$result = $this->travelsClient->getMailingRecipients((string) $lookup->travelCode);
$result = $this->travelsClient->getMailingRecipients($travelCode);
$travelLabel = $this->travelDataProvider->mapDateCodeToLabel($travelCode);
} catch (BpnConnectException) {
// The client has already logged the cause; the page only needs to say it failed.
$failed = true;
@@ -45,6 +54,7 @@ class IndexController extends AbstractController
return $this->render('admin/travel_mailing/index.html.twig', [
'form' => $form,
'result' => $result,
'travel_label' => $travelLabel,
'failed' => $failed,
]);
}
+12
View File
@@ -420,6 +420,18 @@ class TravelDataProvider
return $this->travelLookupService->mapDateCodeToId($dateCode);
}
/**
* Map date code to the travel's label.
*
* @param string $dateCode The date code to map
*
* @return string|null The travel label or null if not found
*/
public function mapDateCodeToLabel(string $dateCode): ?string
{
return $this->travelLookupService->mapDateCodeToLabel($dateCode);
}
/**
* Map hotel code to hotel ID.
*
+5
View File
@@ -157,9 +157,14 @@ class TravelExportBuilder
$pickupsWithoutMasterData,
);
// The product a date belongs to, from the enclosing <reise>. Not derivable from the
// date code: DWWMP runs dates coded DWWMW…, and group travels carry each group's code.
$productNode = $node->getNode(0)?->parentNode;
$travel = [
'busProId' => $travelId,
'code' => $node->attr('code'),
'productCode' => $productNode instanceof \DOMElement ? $this->trimOrNull($productNode->getAttribute('code')) : null,
'product' => $this->trimOrNull($this->getStringOrNullValue($node->filterXPath('.//text'))),
'dateFrom' => $dateFrom->format('Y-m-d'),
'dateTo' => $dateTo->format('Y-m-d'),
+18
View File
@@ -109,6 +109,24 @@ class TravelIndex
}
}
/**
* Resolve a date code to its travel label, e.g. "Davos - Sportclub Waldschlössli - Wochenende".
*
* @param string $dateCode The date code to resolve
*
* @return string|null The label, or null if the code is not found or the travel has none
*/
public function mapDateCodeToLabel(string $dateCode): ?string
{
$dateId = $this->mapDateCodeToId($dateCode);
if (null === $dateId) {
return null;
}
return $this->generateFilesMap()[$dateId]['label'] ?? null;
}
/**
* Convert a hotel code string to its corresponding hotel ID.
*
@@ -0,0 +1,98 @@
{#- Itemised price table, the same lines the customer sees in the offer. Context: booking, priceBreakdown, currency. -#}
<table class="w-full text-sm">
{% for period in priceBreakdown.periods | filter(p => p.position == 'leading') %}
{% include 'admin/accommodation_booking/_price_period.html.twig' %}
{% endfor %}
{% if priceBreakdown.periods is not empty %}
<tr class="border-t border-gray-200 font-medium">
<td class="pt-2 pb-1" colspan="2">
Gruppe · {{ booking.mainDateFrom | date('d.m.Y') }} – {{ booking.mainDateTo | date('d.m.Y') }},
{{ priceBreakdown.nights }} {{ priceBreakdown.nights != 1 ? 'Nächte' : 'Nacht' }}
</td>
</tr>
{% endif %}
{% if priceBreakdown.basePrice > 0 %}
<tr>
<td class="py-1">
Basispreis
<span class="text-xs text-gray-500">für {{ priceBreakdown.includedPax }} Pers.</span>
</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.basePrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.additionalPersonsPrice > 0 %}
<tr>
<td class="py-1">
Aufpreis Personenzahl
<span class="text-xs text-gray-500">für {{ priceBreakdown.effectivePax - priceBreakdown.includedPax }} Pers.</span>
</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.additionalPersonsPrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.shortTermSurcharge > 0 %}
<tr>
<td class="py-1">Aufpreis Kurzzeit</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.shortTermSurcharge / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.boardPrice > 0 %}
<tr>
<td class="py-1">Verpflegung</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.boardPrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.undersubscriptionSurcharge > 0 %}
<tr>
<td class="py-1">Verpflegungs-Aufschlag für Gruppen unter {{ priceBreakdown.undersubscriptionThreshold }} Personen</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.undersubscriptionSurcharge / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% for service in priceBreakdown.serviceDetails %}
{% if service.price > 0 %}
<tr>
<td class="py-1">{{ service.label }}</td>
<td class="py-1 text-right whitespace-nowrap">{{ (service.price / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% endfor %}
{% if priceBreakdown.runningCosts > 0 %}
<tr>
<td class="py-1">Strom- und Abfallgebühren</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.runningCosts / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% for period in priceBreakdown.periods | filter(p => p.position == 'trailing') %}
{% include 'admin/accommodation_booking/_price_period.html.twig' %}
{% endfor %}
<tr class="border-t border-gray-200 font-semibold">
<td class="pt-2">
Gesamtpreis
<span class="block text-xs font-normal text-gray-500">zzgl. ortsabhängiger Gebühren</span>
</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.total / 100) | format_currency(currency) }}</td>
</tr>
{% for discount in priceBreakdown.discounts %}
<tr class="text-green-700">
<td class="pt-1">{{ discount.label }} {{ discount.percent }}&nbsp;%</td>
<td class="pt-1 text-right whitespace-nowrap">– {{ (discount.amount / 100) | format_currency(currency) }}</td>
</tr>
{% endfor %}
{% if priceBreakdown.discountSubtotal is not null %}
<tr class="border-t border-gray-200">
<td class="pt-2">Zwischensumme</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.discountSubtotal / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.totalDiscountDetails is not null %}
<tr class="text-green-700">
<td class="pt-1">{{ priceBreakdown.totalDiscountDetails.label }}</td>
<td class="pt-1 text-right whitespace-nowrap">– {{ (priceBreakdown.totalDiscountDetails.amount / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.discounts is not empty or priceBreakdown.totalDiscountDetails is not null %}
<tr class="border-t border-gray-200 font-bold text-green-700">
<td class="pt-2">Gesamtpreis nach Rabatt</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.discountedTotal / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
</table>
@@ -1,4 +1,4 @@
{#- One split-off period of the price table on the detail page. Context: period, currency. -#}
{#- One split-off period of the admin price table. Context: period, currency. -#}
<tr class="border-t border-gray-200 font-medium">
<td class="pt-2 pb-1" colspan="2">
{% if period.label ?? null %}{{ period.label }} · {% endif %}
@@ -172,34 +172,7 @@
{% if priceBreakdown is not null %}
{% set currency = booking.pricingCurrency ?? priceBreakdown.currency %}
<twig:form:section title="Preis">
<table class="w-full text-sm">
{% if priceBreakdown.periods is not empty %}
<tr>
<td class="py-1">Gruppe</td>
<td class="py-1 text-right whitespace-nowrap">{{ ((priceBreakdown.total - priceBreakdown.periodsTotal) / 100) | format_currency(currency) }}</td>
</tr>
<tr>
<td class="py-1">Zeiträume</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.periodsTotal / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.discountedTotal != priceBreakdown.total %}
{% if priceBreakdown.periods is empty %}
<tr>
<td class="py-1">Preis</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.total / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
<tr class="text-green-700">
<td class="py-1">Rabatte</td>
<td class="py-1 text-right whitespace-nowrap">– {{ ((priceBreakdown.total - priceBreakdown.discountedTotal) / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
<tr class="border-t border-gray-200 font-bold">
<td class="pt-2">Gesamtpreis</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.discountedTotal / 100) | format_currency(currency) }}</td>
</tr>
</table>
{% include 'admin/accommodation_booking/_price_breakdown.html.twig' %}
<p class="text-xs text-gray-500 pt-2">
Stand der letzten Speicherung. Änderungen oben werden erst beim Speichern neu berechnet.
</p>
@@ -14,7 +14,7 @@
<thead>
<tr>
<th>
{{ knp_pagination_sortable(pagination, 'Eingang', 'booking.createdAt') }}
{{ knp_pagination_sortable(pagination, 'Letzte Bearb.', 'booking.updatedAt') }}
</th>
<th>
{{ knp_pagination_sortable(pagination, 'Gruppenhaus', 'accommodation.name') }}
@@ -45,7 +45,7 @@
{% set edit_url = path('app_admin_accommodationbooking_edit', { 'id': booking.id, 'r': return_url() }) %}
<tr>
<td>
<a href="{{ edit_url }}">{{ booking.createdAt | date('d.m.Y, H:i') }}</a>
<a href="{{ edit_url }}">{{ booking.updatedAt | date('d.m.Y, H:i') }}</a>
</td>
<td>
<a href="{{ edit_url }}">{{ booking.accommodation.name }}</a>
@@ -64,103 +64,7 @@
{% if priceBreakdown is not null %}
{% set currency = booking.pricingCurrency ?? priceBreakdown.currency %}
<twig:form:section title="Preise">
<table class="w-full text-sm">
{% for period in priceBreakdown.periods | filter(p => p.position == 'leading') %}
{% include 'admin/accommodation_booking/_price_period.html.twig' %}
{% endfor %}
{% if priceBreakdown.periods is not empty %}
<tr class="border-t border-gray-200 font-medium">
<td class="pt-2 pb-1" colspan="2">
Gruppe · {{ booking.mainDateFrom | date('d.m.Y') }} – {{ booking.mainDateTo | date('d.m.Y') }},
{{ priceBreakdown.nights }} {{ priceBreakdown.nights != 1 ? 'Nächte' : 'Nacht' }}
</td>
</tr>
{% endif %}
{% if priceBreakdown.basePrice > 0 %}
<tr>
<td class="py-1">
Basispreis
<span class="text-xs text-gray-500">für {{ priceBreakdown.includedPax }} Pers.</span>
</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.basePrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.additionalPersonsPrice > 0 %}
<tr>
<td class="py-1">
Aufpreis Personenzahl
<span class="text-xs text-gray-500">für {{ priceBreakdown.effectivePax - priceBreakdown.includedPax }} Pers.</span>
</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.additionalPersonsPrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.shortTermSurcharge > 0 %}
<tr>
<td class="py-1">Aufpreis Kurzzeit</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.shortTermSurcharge / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.boardPrice > 0 %}
<tr>
<td class="py-1">Verpflegung</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.boardPrice / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.undersubscriptionSurcharge > 0 %}
<tr>
<td class="py-1">Verpflegungs-Aufschlag für Gruppen unter {{ priceBreakdown.undersubscriptionThreshold }} Personen</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.undersubscriptionSurcharge / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% for service in priceBreakdown.serviceDetails %}
{% if service.price > 0 %}
<tr>
<td class="py-1">{{ service.label }}</td>
<td class="py-1 text-right whitespace-nowrap">{{ (service.price / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% endfor %}
{% if priceBreakdown.runningCosts > 0 %}
<tr>
<td class="py-1">Strom- und Abfallgebühren</td>
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.runningCosts / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% for period in priceBreakdown.periods | filter(p => p.position == 'trailing') %}
{% include 'admin/accommodation_booking/_price_period.html.twig' %}
{% endfor %}
<tr class="border-t border-gray-200 font-semibold">
<td class="pt-2">
Gesamtpreis
<span class="block text-xs font-normal text-gray-500">zzgl. ortsabhängiger Gebühren</span>
</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.total / 100) | format_currency(currency) }}</td>
</tr>
{% for discount in priceBreakdown.discounts %}
<tr class="text-green-700">
<td class="pt-1">{{ discount.label }} {{ discount.percent }}&nbsp;%</td>
<td class="pt-1 text-right whitespace-nowrap">– {{ (discount.amount / 100) | format_currency(currency) }}</td>
</tr>
{% endfor %}
{% if priceBreakdown.discountSubtotal is not null %}
<tr class="border-t border-gray-200">
<td class="pt-2">Zwischensumme</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.discountSubtotal / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.totalDiscountDetails is not null %}
<tr class="text-green-700">
<td class="pt-1">{{ priceBreakdown.totalDiscountDetails.label }}</td>
<td class="pt-1 text-right whitespace-nowrap">– {{ (priceBreakdown.totalDiscountDetails.amount / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
{% if priceBreakdown.discounts is not empty or priceBreakdown.totalDiscountDetails is not null %}
<tr class="border-t border-gray-200 font-bold text-green-700">
<td class="pt-2">Gesamtpreis nach Rabatt</td>
<td class="pt-2 text-right whitespace-nowrap">{{ (priceBreakdown.discountedTotal / 100) | format_currency(currency) }}</td>
</tr>
{% endif %}
</table>
{% include 'admin/accommodation_booking/_price_breakdown.html.twig' %}
</twig:form:section>
{% endif %}
@@ -29,9 +29,14 @@
messages: ['Keine Empfänger für <code>%s</code> gefunden: Reisecode unbekannt oder keine bestätigten Teilnehmer.'|format(result.travelCode|e)],
} %}
{% else %}
<p class="pb-4 text-sm text-gray-700">
{{ result.data|length }} Empfänger für <code>{{ result.travelCode }}</code>
</p>
<div class="pb-4">
<h2 class="text-lg font-semibold">
{{ travel_label|default('Reise nicht im lokalen Reisebestand') }}
</h2>
<p class="text-sm text-gray-700">
{{ result.data|length }} Empfänger für <code>{{ result.travelCode }}</code>
</p>
</div>
<div class="data-table-wrapper">
<div class="data-table-wrapper__inner text-sm">
<table class="data-table">
+16
View File
@@ -42,6 +42,7 @@ class TravelExportBuilderTest extends TestCase
self::assertSame(900, $row['busProId']);
self::assertIsInt($row['busProId']);
self::assertSame('SBW261226', $row['code']);
self::assertSame('SBW', $row['productCode']);
self::assertSame('Semesterende - Portes du Soleil', $row['product'], 'the product label is trimmed');
self::assertSame('2026-12-26', $row['dateFrom']);
self::assertSame('2026-12-30', $row['dateTo']);
@@ -56,6 +57,21 @@ class TravelExportBuilderTest extends TestCase
], $row['hotel']);
}
public function testCarriesTheProductCodeOfTheEnclosingTravelRatherThanTheDateCode(): void
{
$rows = $this->build('<?xml version="1.0"?><reisen><reise code="DWWMP "><termin idbuspro="1" termin="01.01.2027" bis="02.01.2027" code="DWWMW010127"><hotel idbuspro="1"/></termin></reise></reisen>')->rows;
self::assertSame('DWWMP', $rows[0]['productCode'], 'taken from <reise>, trimmed');
self::assertSame('DWWMW010127', $rows[0]['code']);
}
public function testTheProductCodeIsNullWhenTheTravelCarriesNone(): void
{
$rows = $this->build('<?xml version="1.0"?><reisen><reise code=""><termin idbuspro="1" termin="01.01.2027" bis="02.01.2027" code="SCE010127"><hotel idbuspro="1"/></termin></reise></reisen>')->rows;
self::assertNull($rows[0]['productCode']);
}
public function testResolvesBothZeitShapesAndRollsAnOvernightPickupOntoTheNextDay(): void
{
$pickups = array_column($this->rowFor('900-1')['pickups'], null, 'busProId');
+38
View File
@@ -148,6 +148,44 @@ class TravelIndexTest extends TestCase
$this->assertNull($result);
}
// -------------------------------------------------------------------------
// mapDateCodeToLabel
// -------------------------------------------------------------------------
public function testMapDateCodeToLabelReturnsTheTravelLabel(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([
42 => ['id' => 42, 'code' => 'WI25', 'label' => 'Davos - Sportclub Waldschlössli - Wochenende', 'hotels' => []],
]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('WI25');
$this->assertSame('Davos - Sportclub Waldschlössli - Wochenende', $result);
}
public function testMapDateCodeToLabelReturnsNullWhenNotFound(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('UNKNOWN');
$this->assertNull($result);
}
public function testMapDateCodeToLabelReturnsNullWhenTheTravelHasNoLabel(): void
{
$this->travelLoader->method('generateFilesMap')->willReturn([
42 => ['id' => 42, 'code' => 'WI25', 'label' => null, 'hotels' => []],
]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service()->mapDateCodeToLabel('WI25');
$this->assertNull($result);
}
// -------------------------------------------------------------------------
// mapHotelCodeToId
// -------------------------------------------------------------------------