Compare commits
27
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3dd122678 | ||
|
|
a628e96d06 | ||
|
|
2bb0148e49 | ||
|
|
289741d5d4 | ||
|
|
f070f4117c | ||
|
|
72ef3ff105 | ||
|
|
1301df80c2 | ||
|
|
56deb1e24b | ||
|
|
ec10ca3623 | ||
|
|
67c0c2fb0c | ||
|
|
eb45693257 | ||
|
|
5fdee68ccd | ||
|
|
7001bc0cf2 | ||
|
|
972839286c | ||
|
|
ede8fd840a | ||
|
|
6c700ea18b | ||
|
|
fe18ebf479 | ||
|
|
1d42565a84 | ||
|
|
272c811f4f | ||
|
|
c2c55bc8b2 | ||
|
|
8a6ce7606f | ||
|
|
7ec21c1cac | ||
|
|
f951242465 | ||
|
|
7dadb6806a | ||
|
|
6b539f43f3 | ||
|
|
1845441bc2 | ||
|
|
33c31d088c |
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: myep
|
name: myep
|
||||||
type: php
|
type: php
|
||||||
docroot: public
|
docroot: public
|
||||||
php_version: "8.4"
|
php_version: "8.5"
|
||||||
webserver_type: apache-fpm
|
webserver_type: apache-fpm
|
||||||
xdebug_enabled: false
|
xdebug_enabled: false
|
||||||
additional_hostnames:
|
additional_hostnames:
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import {Controller} from '@hotwired/stimulus'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keeps buttons disabled until the given fields pass the browser's constraint validation
|
||||||
|
* (required, min, max, step, …), which the form types render from the same rules the server
|
||||||
|
* validates. A text field holding only whitespace counts as empty, as NotBlank does.
|
||||||
|
*
|
||||||
|
* Works on forms with novalidate too: that only stops the browser from blocking the submit.
|
||||||
|
*/
|
||||||
|
export default class extends Controller {
|
||||||
|
static targets = ['field', 'button']
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
const invalid = this.fieldTargets.some(field => !field.checkValidity()
|
||||||
|
|| ('radio' !== field.type && 'checkbox' !== field.type && '' === field.value.trim()))
|
||||||
|
this.buttonTargets.forEach(button => button.disabled = invalid)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,10 +11,13 @@ export default class extends Controller {
|
|||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
this.itemsCountValue = this.fieldTargets.length
|
this.itemsCountValue = this.fieldTargets.length
|
||||||
|
// A running counter rather than the current count: after a remove, count + 1 can be an
|
||||||
|
// index a remaining entry still holds, and the two would submit into the same slot.
|
||||||
|
this.nextIndex = this.fieldTargets.length
|
||||||
}
|
}
|
||||||
|
|
||||||
addItem() {
|
addItem() {
|
||||||
const index = this.fieldTargets.length + 1
|
const index = this.nextIndex++
|
||||||
const prototype = JSON.parse(this.prototypeValue)
|
const prototype = JSON.parse(this.prototypeValue)
|
||||||
const newField = prototype.replace(/__name__/g, index)
|
const newField = prototype.replace(/__name__/g, index)
|
||||||
this.fieldsTarget.insertAdjacentHTML('beforeend', newField)
|
this.fieldsTarget.insertAdjacentHTML('beforeend', newField)
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {Controller} from '@hotwired/stimulus'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Shows an indicator over an iframe until its content has loaded.
|
||||||
|
*
|
||||||
|
* The controller sets the frame's src itself, after the load listener is attached, so a fast
|
||||||
|
* response cannot finish before anybody listens.
|
||||||
|
*/
|
||||||
|
export default class extends Controller {
|
||||||
|
static targets = ['frame', 'indicator']
|
||||||
|
static values = {src: String}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
this.loaded = this.loaded.bind(this)
|
||||||
|
this.frameTarget.addEventListener('load', this.loaded)
|
||||||
|
this.frameTarget.src = this.srcValue
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
this.frameTarget.removeEventListener('load', this.loaded)
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded() {
|
||||||
|
this.indicatorTarget.classList.add('hidden')
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
+3
-3
@@ -4,7 +4,7 @@
|
|||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.4",
|
"php": ">=8.5",
|
||||||
"ext-ctype": "*",
|
"ext-ctype": "*",
|
||||||
"ext-dom": "*",
|
"ext-dom": "*",
|
||||||
"ext-iconv": "*",
|
"ext-iconv": "*",
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
"league/flysystem-bundle": "^3.4",
|
"league/flysystem-bundle": "^3.4",
|
||||||
"league/flysystem-sftp-v3": "^3.29",
|
"league/flysystem-sftp-v3": "^3.29",
|
||||||
"league/oauth2-server-bundle": "^1.0",
|
"league/oauth2-server-bundle": "^1.0",
|
||||||
"nelexa/zip": "^4.0",
|
"maennchen/zipstream-php": "^3.2",
|
||||||
"nesbot/carbon": "^3.8",
|
"nesbot/carbon": "^3.8",
|
||||||
"phpdocumentor/reflection-docblock": "^5.6",
|
"phpdocumentor/reflection-docblock": "^5.6",
|
||||||
"phpoffice/phpspreadsheet": "^5.4",
|
"phpoffice/phpspreadsheet": "^5.4",
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
},
|
},
|
||||||
"sort-packages": true,
|
"sort-packages": true,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "8.4.24"
|
"php": "8.5.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
Generated
+245
-318
File diff suppressed because it is too large.
Load diff
@@ -228,11 +228,35 @@ services:
|
|||||||
$cache: '@bpn.cache'
|
$cache: '@bpn.cache'
|
||||||
$logger: '@monolog.logger.bpn'
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
|
App\Service\ProductExportBuilder:
|
||||||
|
arguments:
|
||||||
|
$cache: '@bpn.cache'
|
||||||
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
App\Service\VoucherValidator:
|
App\Service\VoucherValidator:
|
||||||
arguments:
|
arguments:
|
||||||
$cache: '@cache.app'
|
$cache: '@cache.app'
|
||||||
$logger: '@monolog.logger.bpn'
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
|
# Voucher purchase flow (/gutschein)
|
||||||
|
App\Service\VoucherTemplateProvider:
|
||||||
|
arguments:
|
||||||
|
$cache: '@bpn.cache'
|
||||||
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
|
App\Service\VoucherThumbnailResolver:
|
||||||
|
arguments:
|
||||||
|
$manifestPath: '%kernel.project_dir%/public/build/manifest.json'
|
||||||
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
|
App\Controller\Voucher\Step1Controller:
|
||||||
|
arguments:
|
||||||
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
|
App\Controller\Voucher\Step3Controller:
|
||||||
|
arguments:
|
||||||
|
$logger: '@monolog.logger.bpn'
|
||||||
|
|
||||||
# Field Handlers with dependencies
|
# Field Handlers with dependencies
|
||||||
App\Form\Service\ParticipantInsuranceFieldHandler: ~
|
App\Form\Service\ParticipantInsuranceFieldHandler: ~
|
||||||
App\Form\Service\ParticipantBulkInsuranceFieldHandler: ~
|
App\Form\Service\ParticipantBulkInsuranceFieldHandler: ~
|
||||||
|
|||||||
+179
-16
@@ -12,8 +12,8 @@ A Symfony application exposing a read-mostly JSON API under the `/api` prefix. A
|
|||||||
- Enabled grants: **client_credentials**, **authorization_code** (PKCE required for public clients), **refresh_token**. Password and implicit grants are disabled.
|
- Enabled grants: **client_credentials**, **authorization_code** (PKCE required for public clients), **refresh_token**. Password and implicit grants are disabled.
|
||||||
- Access token TTL is **10 minutes** for every grant.
|
- Access token TTL is **10 minutes** for every grant.
|
||||||
Do not hardcode it — read `expires_in` from the token response, it is authoritative and may be tuned.
|
Do not hardcode it — read `expires_in` from the token response, it is authoritative and may be tuned.
|
||||||
A token can therefore expire part-way through a long page walk of `GET /api/exports/travels`; re-request one on
|
A token can therefore expire part-way through a long page walk of `GET /api/exports/*`; re-request one on
|
||||||
401 and resume at the page you were on. At the default `perPage=500` the whole export is a single page today.
|
401 and resume at the page you were on. At the default `perPage=500` either export is a single page today.
|
||||||
- Available scopes: `email`, `id`, `profile`, `roles`, `api`. Default scope if none requested: `email`.
|
- Available scopes: `email`, `id`, `profile`, `roles`, `api`. Default scope if none requested: `email`.
|
||||||
- Each granted scope maps to a role `ROLE_OAUTH2_<SCOPE_UPPERCASE>` (e.g. scope `api` → `ROLE_OAUTH2_API`).
|
- Each granted scope maps to a role `ROLE_OAUTH2_<SCOPE_UPPERCASE>` (e.g. scope `api` → `ROLE_OAUTH2_API`).
|
||||||
- Send the token as `Authorization: Bearer <access_token>`.
|
- Send the token as `Authorization: Bearer <access_token>`.
|
||||||
@@ -52,7 +52,7 @@ There is no single error envelope; three shapes occur:
|
|||||||
|
|
||||||
Validation failures on endpoints using mapped query strings / payloads (`/api/contingents/*`, `/api/exports/*`, `/api/newsletter-subscriptions`) return **400** with Symfony's constraint-violation body. Missing/invalid token yields **401**; insufficient scope yields **403**.
|
Validation failures on endpoints using mapped query strings / payloads (`/api/contingents/*`, `/api/exports/*`, `/api/newsletter-subscriptions`) return **400** with Symfony's constraint-violation body. Missing/invalid token yields **401**; insufficient scope yields **403**.
|
||||||
|
|
||||||
`GET /api/exports/travels` deliberately uses real status codes throughout and never the 200-with-an-`error`-key shape: a failure there is a 5xx, so retry logic can key on the status code alone.
|
`GET /api/exports/*` deliberately uses real status codes throughout and never the 200-with-an-`error`-key shape: a failure there is a 5xx, so retry logic can key on the status code alone.
|
||||||
|
|
||||||
The HTTP methods listed below are the intended ones. Several read routes do not restrict methods server-side; clients should still use `GET` for them.
|
The HTTP methods listed below are the intended ones. Several read routes do not restrict methods server-side; clients should still use `GET` for them.
|
||||||
|
|
||||||
@@ -92,7 +92,9 @@ Product master data from the upstream BusProNet system, cached server-side for 1
|
|||||||
|
|
||||||
#### `GET /api/last-update` — scope `api`
|
#### `GET /api/last-update` — scope `api`
|
||||||
|
|
||||||
Timestamp of the last upstream data export: `{"timestamp": "YYYY-MM-DD HH:MM:SS"}`. Note: if no export marker file exists the current implementation errors (500) rather than returning null — treat a non-JSON/500 response as "unknown".
|
Timestamp of the last upstream data export: `{"timestamp": "YYYY-MM-DD HH:MM:SS"}` in `Europe/Berlin` local time.
|
||||||
|
If the export marker is missing or unreadable (for instance mid-sync), the answer is `{"timestamp": null}` with
|
||||||
|
status 200 — treat null as "unknown", not as "changed".
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ This is a full overwrite, not a merge.
|
|||||||
Bulk export of every travel date × hotel pair with its boarding points resolved, for clients that mirror the
|
Bulk export of every travel date × hotel pair with its boarding points resolved, for clients that mirror the
|
||||||
disposition locally. One request replaces a walk over `GET /api/travels` plus a per-pair detail call.
|
disposition locally. One request replaces a walk over `GET /api/travels` plus a per-pair detail call.
|
||||||
|
|
||||||
This is the only paginated endpoint and the only one with a `meta` envelope.
|
The two `/api/exports/*` endpoints are the only paginated ones and the only ones with a `meta` envelope.
|
||||||
|
|
||||||
It sits under `/api/exports`, not `/api/travels`, on purpose: `/api/travels/{dateCode}` accepts an
|
It sits under `/api/exports`, not `/api/travels`, on purpose: `/api/travels/{dateCode}` accepts an
|
||||||
arbitrary string, so an export hung off that collection would share a namespace with every date code.
|
arbitrary string, so an export hung off that collection would share a namespace with every date code.
|
||||||
@@ -188,7 +190,7 @@ an error: it returns `200` with an empty `data` array and the usual `meta`.
|
|||||||
"city": "Essen",
|
"city": "Essen",
|
||||||
"street": "Am Hauptbahnhof (Südausgang Fernbushaltestelle)",
|
"street": "Am Hauptbahnhof (Südausgang Fernbushaltestelle)",
|
||||||
"time": "20:15",
|
"time": "20:15",
|
||||||
"datetime": "2026-12-25T20:15:00+01:00"
|
"datetime": "2026-12-25T20:15:00"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -200,6 +202,7 @@ an error: it returns `200` with an empty `data` array and the usual `meta`.
|
|||||||
"totalPages": 1,
|
"totalPages": 1,
|
||||||
"skipped": 0,
|
"skipped": 0,
|
||||||
"pickupsWithoutMasterData": 0,
|
"pickupsWithoutMasterData": 0,
|
||||||
|
"sourceGeneratedAt": "2026-09-29T11:11:01+02:00",
|
||||||
"generatedAt": "2026-09-29T12:10:06+02:00"
|
"generatedAt": "2026-09-29T12:10:06+02:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,8 +212,8 @@ 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
|
is always an int and never null; `hotel` is always an object and never null; `pickups` is always an array, possibly
|
||||||
empty, never null.
|
empty, never null.
|
||||||
|
|
||||||
**`meta` describes the whole export, not the page.** `total`, `totalPages`, `skipped`, `pickupsWithoutMasterData`
|
**`meta` describes the whole export, not the page.** `total`, `totalPages`, `skipped`, `pickupsWithoutMasterData`,
|
||||||
and `generatedAt` are identical on every page, so you can read them once on page 1 and decide whether to walk the
|
`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)`.
|
rest. `total` is the row count **after** skips, and `totalPages` is `ceil(total / perPage)`.
|
||||||
|
|
||||||
- `skipped` — (travel, hotel) pairs dropped as unusable: a travel date that could not be parsed, or a hotel absent
|
- `skipped` — (travel, hotel) pairs dropped as unusable: a travel date that could not be parsed, or a hotel absent
|
||||||
@@ -222,12 +225,17 @@ rest. `total` is the row count **after** skips, and `totalPages` is `ceil(total
|
|||||||
|
|
||||||
**Pickup times.** `pickups` is in **source order** — the order the boarding list is driven in — not sorted by time.
|
**Pickup times.** `pickups` is in **source order** — the order the boarding list is driven in — not sorted by time.
|
||||||
|
|
||||||
- `time` is `"HH:MM"` for display; `datetime` is the same moment as a full ISO-8601 string with a
|
- `time` is `"HH:MM"` for display; `datetime` is the same reading with its date resolved, as
|
||||||
`Europe/Berlin` offset (`+01:00` / `+02:00` depending on DST). **Prefer `datetime`.**
|
`YYYY-MM-DDTHH:MM:SS` **without an offset**. **Prefer `datetime`.**
|
||||||
- Upstream states a boarding time either as a full date and time or as a bare time. A bare time is resolved
|
- Both are upstream's local clock readings, not instants: coaches are timetabled in plain clock times. A stop at
|
||||||
against the departure date and, where the sequence demands it, rolled onto the following calendar day — so an
|
`02:45` on the night the clocks go forward comes back as `…T02:45:00`, although that hour does not exist in
|
||||||
`02:15` listed after a `23:59` comes back on the next date, not the same one. `datetime` is emitted for
|
`Europe/Berlin`, and a stop in the hour repeated when the clocks go back passes through unchanged. Do not attach
|
||||||
bare-time sources too, and carries that resolution.
|
an offset to compare or sort them; they already sort correctly as strings.
|
||||||
|
- Upstream states a boarding time either as a full date and time, taken verbatim, or as a bare time. A bare time
|
||||||
|
takes the departure date (`dateFrom`), and moves to the following day if it would otherwise fall before the
|
||||||
|
latest full date and time **anywhere** in the same boarding list, whatever its position. So on a departure
|
||||||
|
dated 26.12. whose list also dates a stop `26.12. 23:59`, a bare `02:15` comes back as `…12-27T02:15:00`.
|
||||||
|
`datetime` carries that resolution for bare-time sources too.
|
||||||
- A boarding point with no time upstream comes back with **both** `time` and `datetime` null. They are always
|
- A boarding point with no time upstream comes back with **both** `time` and `datetime` null. They are always
|
||||||
null together.
|
null together.
|
||||||
- Caveat: where upstream states full datetimes for a whole boarding list, those dates are taken verbatim. Some
|
- Caveat: where upstream states full datetimes for a whole boarding list, those dates are taken verbatim. Some
|
||||||
@@ -238,6 +246,155 @@ rest. `total` is the row count **after** skips, and `totalPages` is `ceil(total
|
|||||||
under one cache tag, so all three move together on an upstream sync rather than drifting between your calls.
|
under one cache tag, so all three move together on an upstream sync rather than drifting between your calls.
|
||||||
It is cached for 3 hours; `generatedAt` is when the cached copy was assembled, not when you requested it.
|
It is cached for 3 hours; `generatedAt` is when the cached copy was assembled, not when you requested it.
|
||||||
|
|
||||||
|
**Page consistency.** `sourceGeneratedAt` is the timestamp of the upstream export the rows were built from — the
|
||||||
|
same value `GET /api/last-update` reports, as ISO-8601 — or `null` if it could not be read. An upstream sync can
|
||||||
|
replace the cached copy while you are walking the pages; if `sourceGeneratedAt` differs from the value you saw on
|
||||||
|
page 1, you have stitched two exports together. Discard what you have and restart from page 1.
|
||||||
|
|
||||||
|
#### `GET /api/exports/products` — scope `api`
|
||||||
|
|
||||||
|
Bulk export of every travel date × hotel pair with its **whole record**, for clients that import the product
|
||||||
|
catalogue: rooms with prices and availability, the pseudo price, all selection groups, the three service lists,
|
||||||
|
boarding points with prices, and the guide. Same grain, paging, query parameters, `meta` envelope, status codes and
|
||||||
|
page-consistency rule as `GET /api/exports/travels` above; only the rows differ.
|
||||||
|
|
||||||
|
**Unfiltered on purpose.** Nothing is dropped or rewritten for you. Return-leg (`RUECK`) services, `EIN` services,
|
||||||
|
`Buchungsstop` rooms and services, rooms without a price and boarding points with id `0` are all emitted. Which of
|
||||||
|
them a website shows, and how, is the client's rule, not this endpoint's.
|
||||||
|
|
||||||
|
At current volumes the export is ~420 rows and ~3.8 MB of JSON (a row is 4–24 kB), so the default `perPage=500`
|
||||||
|
returns it in one page.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"product": { "code": "DKIWE", "busProId": 1127 },
|
||||||
|
"date": {
|
||||||
|
"code": "DKIWE041226",
|
||||||
|
"busProId": 12437,
|
||||||
|
"from": "2026-12-04",
|
||||||
|
"to": "2026-12-06",
|
||||||
|
"type": "F"
|
||||||
|
},
|
||||||
|
"hotel": { "code": "DKIWEKT", "busProId": 222931 },
|
||||||
|
"pseudoPrice": null,
|
||||||
|
"selectionGroups": [
|
||||||
|
{
|
||||||
|
"busProId": 7,
|
||||||
|
"label": "Leistungen Skipass",
|
||||||
|
"selections": [ { "busProId": 92, "label": "3 Tage Skipass" } ]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transportServices": [
|
||||||
|
{ "busProId": 193804, "subType": "PKW", "label": "Eigene Anreise mit Rabatt", "price": -50, "status": "Frei", "direction": "HIN" }
|
||||||
|
],
|
||||||
|
"dateServices": [
|
||||||
|
{ "busProId": 193805, "subType": "SON", "label": "Keycard-Pfand (Pflichtabgabe)", "price": 5.4, "status": "Frei", "direction": null }
|
||||||
|
],
|
||||||
|
"hotelServices": [
|
||||||
|
{ "busProId": 193805, "subType": "SON", "label": "Keycard-Pfand (Pflichtabgabe)", "price": 5.4, "status": "Frei", "direction": null }
|
||||||
|
],
|
||||||
|
"rooms": [
|
||||||
|
{
|
||||||
|
"busProId": 74,
|
||||||
|
"code": "MBZET",
|
||||||
|
"label": "Bett im Mehrbettzimmer Etagendusche/-WC",
|
||||||
|
"category": "GR",
|
||||||
|
"minPax": 1,
|
||||||
|
"maxPax": 1,
|
||||||
|
"nights": 2,
|
||||||
|
"price": 229,
|
||||||
|
"available": 24,
|
||||||
|
"status": "Frei",
|
||||||
|
"boardCode": "Lt. Auss.",
|
||||||
|
"boardBusProId": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pickups": [
|
||||||
|
{
|
||||||
|
"busProId": 4,
|
||||||
|
"code": "FRA-Route",
|
||||||
|
"city": "Frankfurt",
|
||||||
|
"street": "Flughafen (P36 zwischen Terminal 1 und 2)",
|
||||||
|
"price": 5.9,
|
||||||
|
"datetime": "2026-12-03T23:30:00"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"guide": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"meta": {
|
||||||
|
"page": 1,
|
||||||
|
"perPage": 500,
|
||||||
|
"total": 419,
|
||||||
|
"totalPages": 1,
|
||||||
|
"skipped": 0,
|
||||||
|
"pickupsWithoutMasterData": 0,
|
||||||
|
"sourceGeneratedAt": "2026-09-30T11:11:01+02:00",
|
||||||
|
"generatedAt": "2026-09-30T14:05:00+02:00"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Row identity.** `(date.busProId, hotel.busProId)` is unique across the whole export — upsert on that pair.
|
||||||
|
`product.code` and `hotel.code` are verbatim and suitable for matching against your own records. No row depends on
|
||||||
|
hotel master data, so `skipped` counts only travel dates whose dates could not be parsed.
|
||||||
|
|
||||||
|
**Types.**
|
||||||
|
|
||||||
|
- Every price is a JSON **number** in euros, never a formatted string: `229`, `5.4`, `-50`. A price the source does
|
||||||
|
not state is `null`, and `0` means a stated zero ("included"). Do not treat the two alike.
|
||||||
|
- `selectionGroups`, `selections`, `transportServices`, `dateServices`, `hotelServices`, `rooms` and `pickups` are
|
||||||
|
always arrays, possibly empty, never null. `pseudoPrice` and `guide` are nullable.
|
||||||
|
- All arrays are in **source order**. Sort for display yourself; do not depend on the order.
|
||||||
|
|
||||||
|
**Rooms.** One entry per room offered on the date at that hotel.
|
||||||
|
|
||||||
|
- `code` is trimmed. `available` is a count of **rooms**, not persons — person capacity is `available × maxPax`.
|
||||||
|
- `status` is passed through verbatim: `Frei`, `Anfrage` or `Buchungsstop`.
|
||||||
|
- `available`, `price`, `minPax`, `maxPax`, `nights` and `boardBusProId` are `null` where the source leaves them
|
||||||
|
empty.
|
||||||
|
|
||||||
|
**`pseudoPrice`.** A struck-through comparison price for the date, carried upstream by a pseudo room with code
|
||||||
|
`PDGS`. It is lifted onto the row and never appears in `rooms`. It is `null` in most rows.
|
||||||
|
|
||||||
|
**Services.** Three lists, deliberately kept apart:
|
||||||
|
|
||||||
|
- `transportServices` — the date's transport services (bus, own arrival, train …). Both directions.
|
||||||
|
- `dateServices` — the date's general services.
|
||||||
|
- `hotelServices` — the services listed on this hotel for this date. Upstream repeats most date-level services
|
||||||
|
here, possibly with hotel-specific prices, so expect overlap with `dateServices`. If you merge the two, key by
|
||||||
|
`busProId`: it identifies a service across both lists.
|
||||||
|
|
||||||
|
`subType` is the upstream service subtype (`BUS`, `PKW`, `BAH`, `SON`, `SPA`, `VER`, `EIN`, …), passed through.
|
||||||
|
`direction` is `HIN` or `RUECK` on transport services and `null` on general ones. A negative `price` is a discount,
|
||||||
|
such as for arriving by car.
|
||||||
|
|
||||||
|
**Selection groups.** Every group on the date, not only the `Leistungen *` ones. Match groups by `busProId`, not by
|
||||||
|
`label`: labels are editorial and can be renamed upstream. The ids of the included-services groups are stable:
|
||||||
|
|
||||||
|
| `busProId` | Label |
|
||||||
|
|---|---|
|
||||||
|
| 7 | Leistungen Skipass |
|
||||||
|
| 8 | Leistungen Sonstige |
|
||||||
|
| 71 | Leistungen Verpflegung |
|
||||||
|
| 85 | Leistungen Übernachtung |
|
||||||
|
| 86 | Leistungen Programm |
|
||||||
|
| 87 | Leistungen Kurse |
|
||||||
|
| 89 | Leistungen Events |
|
||||||
|
| 90 | Leistungen Transport |
|
||||||
|
|
||||||
|
**Pickups.** Outbound boarding points only, in source order. `datetime` is resolved and formatted exactly as in
|
||||||
|
`GET /api/exports/travels` — a clock reading without an offset, `null` where upstream states no time — including
|
||||||
|
rolling a bare time past midnight onto the next day. There is no separate `time` field; format `datetime` for
|
||||||
|
display. `price` is the outbound boarding surcharge exactly as upstream states it: `null` where upstream states
|
||||||
|
none. It is not levelled against the return leg. An id absent from
|
||||||
|
`GET /api/pickups` is emitted with `code`, `city` and `street` null and counted in `pickupsWithoutMasterData`. An id
|
||||||
|
of `0` is emitted as-is but not counted.
|
||||||
|
|
||||||
|
**`guide`.** `{ "name": …, "phone": … }` for the first outbound bus service that has a guide assigned, else `null`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Travels
|
### Travels
|
||||||
@@ -398,14 +555,16 @@ Single booking by UUID. `404 {"message":"Not found"}` if unknown.
|
|||||||
"totalDiscountLabel": null,
|
"totalDiscountLabel": null,
|
||||||
"totalPrice": 123456,
|
"totalPrice": 123456,
|
||||||
"pricingCurrency": "EUR",
|
"pricingCurrency": "EUR",
|
||||||
"pricingVersion": 3,
|
"pricingVersion": 2,
|
||||||
"priceBreakdown": {}
|
"priceBreakdown": {}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`totalPrice` and `totalDiscountAmount` are integer **minor units** (cents) — unlike the contingent endpoints. The three `*Discount` fields are whole **percentages** (1–100) or `null`, not amounts. `dateFrom`/`dateTo` are `Y-m-d`; `acceptedAt` is a full ISO-8601 datetime and is `null` until accepted. `priceBreakdown` is a computed nested structure.
|
`totalPrice` and `totalDiscountAmount` are integer **minor units** (cents) — unlike the contingent endpoints. The three `*Discount` fields are whole **percentages** (1–100) or `null`, not amounts. `dateFrom`/`dateTo` are `Y-m-d`; `acceptedAt` is a full ISO-8601 datetime and is `null` until accepted. `priceBreakdown` is a computed nested structure.
|
||||||
|
|
||||||
The first three discounts each apply to one section of the breakdown: `accommodationDiscount` to `basePrice + additionalPersonsPrice`, `boardServiceDiscount` to `boardPrice`, `additionalServicesDiscount` to `servicesPrice`. Surcharges and running costs sit in `total` but in no section, so they are never discounted.
|
The first three discounts each apply to one section of the breakdown: `accommodationDiscount` to `basePrice + additionalPersonsPrice`, `boardServiceDiscount` to `boardPrice`, `additionalServicesDiscount` to `servicesPrice`. Surcharges, running costs and the lines of split-off periods sit in `total` but in no section, so the section discounts never reach them; only `totalDiscountAmount` does.
|
||||||
|
|
||||||
|
`dateFrom`/`dateTo`/`nights` span the whole stay. The office can split nights off its start or end, for example for an advance team arriving before the group. Such a split-off period has no headcount, board or services of its own; it is priced as free-form lines instead. `paxCount`, `minorsCount`, `childrenCount`, `boardService` and `additionalServices` describe the **group**, which stays for what remains between the split-off periods. The split-off periods are listed in `priceBreakdown.periods`, below. A booking nobody split has an empty list there, and its group stays for the whole stay.
|
||||||
|
|
||||||
`totalDiscountAmount` is a freely named discount on the whole price, labelled by `totalDiscountLabel`. It is a fixed sum, not a percentage, and is subtracted **after** the three section discounts have reduced `total`. It is capped at what is left of that subtotal, so `discountedTotal` is never negative and the amount shown in the breakdown may be smaller than `totalDiscountAmount` itself. The section discounts are each rounded to the nearest cent as they are applied.
|
`totalDiscountAmount` is a freely named discount on the whole price, labelled by `totalDiscountLabel`. It is a fixed sum, not a percentage, and is subtracted **after** the three section discounts have reduced `total`. It is capped at what is left of that subtotal, so `discountedTotal` is never negative and the amount shown in the breakdown may be smaller than `totalDiscountAmount` itself. The section discounts are each rounded to the nearest cent as they are applied.
|
||||||
|
|
||||||
@@ -413,6 +572,10 @@ The first three discounts each apply to one section of the breakdown: `accommoda
|
|||||||
|
|
||||||
| field | meaning |
|
| field | meaning |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
|
| `nights` | the group's nights, which are fewer than the booking's `nights` when periods were split off |
|
||||||
|
| `periods` | list of `{position, label, dateFrom, dateTo, nights, lines, total}`, at most one per side, in date order; `position` is `leading` (before the group) or `trailing` (after it), `label` is the office's name for the period or `null`, `lines` is a list of `{label, amount}`, and `total` is their sum |
|
||||||
|
| `periodsTotal` | the sum of all `periods[].total` |
|
||||||
|
| `total` | the price before discounts, the group's rows plus `periodsTotal` |
|
||||||
| `discounts` | list of `{label, percent, amount}` for the section discounts; entries rounding to `0` are omitted, and `label` already includes its `Rabatt ` prefix |
|
| `discounts` | list of `{label, percent, amount}` for the section discounts; entries rounding to `0` are omitted, and `label` already includes its `Rabatt ` prefix |
|
||||||
| `discountSubtotal` | `total` minus the section discounts — present only when `totalDiscountAmount` applies *and* at least one section discount did, otherwise `null` |
|
| `discountSubtotal` | `total` minus the section discounts — present only when `totalDiscountAmount` applies *and* at least one section discount did, otherwise `null` |
|
||||||
| `totalDiscountDetails` | `{label, amount}` for the total discount, or `null`; `amount` is the capped figure actually subtracted |
|
| `totalDiscountDetails` | `{label, amount}` for the total discount, or `null`; `amount` is the capped figure actually subtracted |
|
||||||
|
|||||||
@@ -312,6 +312,67 @@ answers `<reise id status>` plus per-service `status` ("buchbar"), `frei`, `prei
|
|||||||
`ZAHLUNG` reports a credit-card authorisation after booking; the amount must equal the confirmed
|
`ZAHLUNG` reports a credit-card authorisation after booking; the amount must equal the confirmed
|
||||||
`anzahlung` or errors `1011`-`1018` follow.
|
`anzahlung` or errors `1011`-`1018` follow.
|
||||||
|
|
||||||
|
## Selling vouchers (Kaufgutschein)
|
||||||
|
|
||||||
|
Used by the `/gutschein` flow, which replaces the BusProNet-hosted shop
|
||||||
|
(`maske_gutschein.php`). `ApiClient::TYPE_VOUCHER_*`; not to be confused with
|
||||||
|
`TYPE_PURCHASE_VOUCHER` (`GUTSCHEINPRUEFUNGEINLOESUNG`), which redeems a voucher in a booking.
|
||||||
|
|
||||||
|
| Satz | Request | Response |
|
||||||
|
|---|---|---|
|
||||||
|
| `GUTSCHEINVORLAGEN` | — | `gutscheinminbetrag`, `gutscheinmaxbetrag` (**undocumented**, measured), then `<gutscheine><gutschein idgutscheinvorlage="3"><gutscheinart>K</gutscheinart><bezeichnung>Allgemein</bezeichnung><hinweis/>` |
|
||||||
|
| `GUTSCHEINZAHLUNGSARTEN` | — | `<zahlungsarten><zahlungsart id="2" bezeichnung="Überweisung" art="UEBERW"/>` (measured; the attributes are echoed as `<zahlung>` below) |
|
||||||
|
| `GUTSCHEINVORSCHAU` | `idgutscheinvorlage`, `kaeufer`, `empfaenger`, `kaufpreis`, `text` | `<gutscheinpdf>data:application/pdf;base64,…` (measured, about 430 KB) |
|
||||||
|
| `ADRESSFELDERGUTSCHEIN` | — | which address fields to show and which are mandatory; not used, the flow fixes the live shop's fields |
|
||||||
|
| `GUTSCHEINBUCHUNG` | see below | `buchung=erfolgt`, `idgutschein`, `gutscheinnummer`, `einloesecode`, `preis`, `rechnungsnummer`, `email` |
|
||||||
|
| `GUTSCHEINDRUCK` | `idgutschein`, `einloesecode` | the voucher PDF; not used, BusPro mails the voucher itself once the payment has arrived |
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<satz typ="GUTSCHEINBUCHUNG"/>
|
||||||
|
<buchungsart>Anfrage|Buchung</buchungsart>
|
||||||
|
<gutscheinart>K</gutscheinart>
|
||||||
|
<idgutscheinvorlage>3</idgutscheinvorlage>
|
||||||
|
<kaeufer>…</kaeufer> <!-- "von", printed on the voucher -->
|
||||||
|
<empfaenger>…</empfaenger> <!-- "für", printed on the voucher -->
|
||||||
|
<kaufpreis>25</kaufpreis>
|
||||||
|
<text/> <!-- Zusatztext; the live shop sends it empty -->
|
||||||
|
<rechnungsempfänger>
|
||||||
|
<name/><vorname/><anrede/><titel/><geschlecht/><geburtsdatum/>
|
||||||
|
<anschrift><strasse/><plz/><ort/><ortsteil/><land>D</land></anschrift>
|
||||||
|
<kommunikation><telefonprivat/><email/><telefonmobil/></kommunikation>
|
||||||
|
</rechnungsempfänger>
|
||||||
|
<zahlung idzahlungsart="2" bezeichnung="Überweisung" art="UEBERW"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
`<preiszusaetze>` is documented but not sent; the total is the voucher value. `telefonmobil` is not
|
||||||
|
in the vendor's example, its name is the one `BUCHUNG` uses, and the test system accepts it. The
|
||||||
|
live shop also collects a business phone, whose element name is not documented anywhere, so the
|
||||||
|
flow does not collect it.
|
||||||
|
|
||||||
|
### Measured on the test system (2026-10-01)
|
||||||
|
|
||||||
|
`buchungsart=Anfrage` is a full dry run: a valid request answers `<buchung>möglich</buchung>` and
|
||||||
|
nothing else (no `idgutschein`, `gutscheinnummer`, `einloesecode`, `rechnungsnummer`), so nothing is
|
||||||
|
issued. `idagentur` is not required (619/620 never fired).
|
||||||
|
|
||||||
|
| Variant | Answer |
|
||||||
|
|---|---|
|
||||||
|
| Valid (control), 25 € | `möglich` |
|
||||||
|
| `kaufpreis` 6000 | `608 Gutscheinbetrag darf nicht größer als 5.000,00 Euro sein` |
|
||||||
|
| `kaufpreis` 5 | `607 Gutscheinbetrag darf nicht kleiner als 10,00 Euro sein` |
|
||||||
|
| `kaufpreis` 5000 | `möglich` (bounds inclusive) |
|
||||||
|
| `kaufpreis` 25,50 | `möglich` (cents accepted; the flow offers whole euros only) |
|
||||||
|
| `empfaenger` missing | `605 Empfängername fehlt` |
|
||||||
|
| `idgutscheinvorlage` 999 | `602 Gutscheine mit ID 999 nicht gefunden` (not 615 as documented) |
|
||||||
|
| `email` empty | `650 Fehlende Adress Daten. Bitte folgende Eingabefelder prüfen: Mail-Adresse` |
|
||||||
|
| `strasse` empty | `650 … Strasse` |
|
||||||
|
| `anrede` Herr, `telefonmobil` set | `möglich` |
|
||||||
|
|
||||||
|
Missing address data is a `650` and a hard rejection, as on `BUCHUNG`. The flow therefore treats
|
||||||
|
every `HINWEIS` on this path as a rejection and sends it back to the step that owns it
|
||||||
|
(`VoucherSaleRejectionMapper`). The design ids (3, 4, 5) match the thumbnail file names of the old
|
||||||
|
shop, which suggests they are shared with production; confirm on the first production read.
|
||||||
|
|
||||||
## Error codes
|
## Error codes
|
||||||
|
|
||||||
Returned as `<satz typ="HINWEIS"><nr>…</nr><text>…</text></satz>`. `#1#`/`#2#` are substituted at
|
Returned as `<satz typ="HINWEIS"><nr>…</nr><text>…</text></satz>`. `#1#`/`#2#` are substituted at
|
||||||
@@ -320,7 +381,7 @@ runtime.
|
|||||||
> **`650` is not a success code.** Its documented text is a bare `#1#` — a generic message
|
> **`650` is not a success code.** Its documented text is a bare `#1#` — a generic message
|
||||||
> carrier whose entire content is substituted. `Notification::isError()`
|
> carrier whose entire content is substituted. `Notification::isError()`
|
||||||
> (`src/BusProNet/Model/Notification.php:33-36`) treats it as success, which happens to hold on
|
> (`src/BusProNet/Model/Notification.php:33-36`) treats it as success, which happens to hold on
|
||||||
> the `KUNDENKONTO` paths but not on `BUCHUNG`/`BUCHUNGAENDERUNG`, where the same code delivers
|
> the `KUNDENKONTO` paths but not on `BUCHUNG`/`BUCHUNGAENDERUNG`/`GUTSCHEINBUCHUNG`, where the same code delivers
|
||||||
> real rejections such as *"Es wurde nicht jedem Teilnehmer eine Pflichtleistung zugeordnet"*.
|
> real rejections such as *"Es wurde nicht jedem Teilnehmer eine Pflichtleistung zugeordnet"*.
|
||||||
> `BookingEditSubmitter.php:81` therefore reports some genuine failures as INFO.
|
> `BookingEditSubmitter.php:81` therefore reports some genuine failures as INFO.
|
||||||
|
|
||||||
@@ -359,8 +420,11 @@ zugelassen** · 983 Anfragebuchung nicht zugelassen · 984 Leistung nicht fürs
|
|||||||
995/996 Gutschein · 997/998 Buchung-ID · 1001 Reisedatum fehlerhaft · 1002 Buchungsdatum
|
995/996 Gutschein · 997/998 Buchung-ID · 1001 Reisedatum fehlerhaft · 1002 Buchungsdatum
|
||||||
fehlerhaft · 1003 Status im Vorgang nicht korrekt · 1011-1018 Zahlungsabgleich
|
fehlerhaft · 1003 Status im Vorgang nicht korrekt · 1011-1018 Zahlungsabgleich
|
||||||
|
|
||||||
**Vouchers** — 600-608 Gutscheine · 610/611 Buchungsart · 612-621 Gutscheinart / Stamm /
|
**Vouchers** — 600-608 Gutscheine (602 Vorlage nicht gefunden, measured; 604 Käufername ·
|
||||||
Kapazität · 622 Einlösecode fehlt · 630-632 Aktionsgutschein
|
605 Empfängername · 606 Betrag fehlt · 607/608 Betrag kleiner/größer als #1# Euro) ·
|
||||||
|
610/611 Buchungsart · 612/613 Gutscheinart · 614/615 Gutscheinstamm · 616 Kapazität nicht
|
||||||
|
ausreichend · 617 Rechnungsempfänger fehlt · 618 Zahlungsart fehlt · 619/620 Agentur-ID ·
|
||||||
|
621 Gutscheindaten fehlen · 622 Einlösecode fehlt · 630-632 Aktionsgutschein
|
||||||
|
|
||||||
## Applying this: the teamer placeholder booking
|
## Applying this: the teamer placeholder booking
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split-off periods of an accommodation booking. No backfill: a booking without periods is
|
||||||
|
* priced exactly as before.
|
||||||
|
*/
|
||||||
|
final class Version20260930150445 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Adds accommodation_booking_period for nights split off the start or end of a stay.';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('CREATE TABLE accommodation_booking_period (id INT AUTO_INCREMENT NOT NULL, booking_id INT NOT NULL, position VARCHAR(10) NOT NULL, date_from DATE NOT NULL COMMENT \'(DC2Type:date_immutable)\', date_to DATE NOT NULL COMMENT \'(DC2Type:date_immutable)\', label VARCHAR(255) DEFAULT NULL, price_lines JSON NOT NULL COMMENT \'(DC2Type:json)\', INDEX IDX_ABFCF6B33301C60 (booking_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
||||||
|
$this->addSql('ALTER TABLE accommodation_booking_period ADD CONSTRAINT FK_ABFCF6B33301C60 FOREIGN KEY (booking_id) REFERENCES accommodation_booking (id) ON DELETE CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE accommodation_booking_period DROP FOREIGN KEY FK_ABFCF6B33301C60');
|
||||||
|
$this->addSql('DROP TABLE accommodation_booking_period');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\BusProNet;
|
namespace App\BusProNet;
|
||||||
|
|
||||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||||
|
use App\BusProNet\DataProcessor\VoucherSalePayloadBuilder;
|
||||||
use App\BusProNet\Exception\ApiClientException;
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
use App\BusProNet\Exception\ImmediateConnectionCloseException;
|
use App\BusProNet\Exception\ImmediateConnectionCloseException;
|
||||||
use App\BusProNet\Exception\ResponseParserException;
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
@@ -22,9 +23,14 @@ use App\BusProNet\Model\PurchaseVoucher;
|
|||||||
use App\BusProNet\Model\RegistrationResponse;
|
use App\BusProNet\Model\RegistrationResponse;
|
||||||
use App\BusProNet\Model\ServiceAvailabilityResponse;
|
use App\BusProNet\Model\ServiceAvailabilityResponse;
|
||||||
use App\BusProNet\Model\Travel;
|
use App\BusProNet\Model\Travel;
|
||||||
|
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||||
|
use App\BusProNet\Model\VoucherPreview;
|
||||||
|
use App\BusProNet\Model\VoucherSaleResponse;
|
||||||
|
use App\BusProNet\Model\VoucherTemplates;
|
||||||
use App\BusProNet\XmlParser\ApiResponseParser;
|
use App\BusProNet\XmlParser\ApiResponseParser;
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
use App\Form\Model\RegistrationDto;
|
use App\Form\Model\RegistrationDto;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
use App\Service\RequestIdGenerator;
|
use App\Service\RequestIdGenerator;
|
||||||
use League\Flysystem\FilesystemException;
|
use League\Flysystem\FilesystemException;
|
||||||
use League\Flysystem\FilesystemOperator;
|
use League\Flysystem\FilesystemOperator;
|
||||||
@@ -50,6 +56,11 @@ class ApiClient
|
|||||||
public const TYPE_AGENCIES = 'AGENTUREN';
|
public const TYPE_AGENCIES = 'AGENTUREN';
|
||||||
public const TYPE_PURCHASE_VOUCHER = 'GUTSCHEINPRUEFUNGEINLOESUNG';
|
public const TYPE_PURCHASE_VOUCHER = 'GUTSCHEINPRUEFUNGEINLOESUNG';
|
||||||
public const TYPE_PROMO_VOUCHER = 'AKTIONSGUTSCHEIN';
|
public const TYPE_PROMO_VOUCHER = 'AKTIONSGUTSCHEIN';
|
||||||
|
// Selling Kaufgutscheine. Not to be confused with TYPE_PURCHASE_VOUCHER, which redeems one in a booking.
|
||||||
|
public const TYPE_VOUCHER_TEMPLATES = 'GUTSCHEINVORLAGEN';
|
||||||
|
public const TYPE_VOUCHER_PAYMENT_METHODS = 'GUTSCHEINZAHLUNGSARTEN';
|
||||||
|
public const TYPE_VOUCHER_PREVIEW = 'GUTSCHEINVORSCHAU';
|
||||||
|
public const TYPE_VOUCHER_SALE = 'GUTSCHEINBUCHUNG';
|
||||||
|
|
||||||
/** @var array<string, mixed> */
|
/** @var array<string, mixed> */
|
||||||
private array $config;
|
private array $config;
|
||||||
@@ -64,6 +75,7 @@ class ApiClient
|
|||||||
private readonly FilesystemOperator $xmlDump,
|
private readonly FilesystemOperator $xmlDump,
|
||||||
private readonly LoggerInterface $logger,
|
private readonly LoggerInterface $logger,
|
||||||
private readonly BookingDataProcessor $bookingDataProcessor,
|
private readonly BookingDataProcessor $bookingDataProcessor,
|
||||||
|
private readonly VoucherSalePayloadBuilder $voucherSalePayloadBuilder,
|
||||||
private readonly RequestStack $requestStack,
|
private readonly RequestStack $requestStack,
|
||||||
private readonly RequestIdGenerator $requestIdGenerator,
|
private readonly RequestIdGenerator $requestIdGenerator,
|
||||||
array $options,
|
array $options,
|
||||||
@@ -532,6 +544,97 @@ class ApiClient
|
|||||||
return $this->sendRequest(static::TYPE_PROMO_VOUCHER, $data);
|
return $this->sendRequest(static::TYPE_PROMO_VOUCHER, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the voucher designs on sale and the amount bounds.
|
||||||
|
*
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function getVoucherTemplates(): Notification|VoucherTemplates
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $this->config['bpn_username'],
|
||||||
|
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_VOUCHER_TEMPLATES),
|
||||||
|
'satz' => ['@typ' => static::TYPE_VOUCHER_TEMPLATES],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->sendRequest(static::TYPE_VOUCHER_TEMPLATES, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the payment methods offered for voucher purchases.
|
||||||
|
*
|
||||||
|
* @return list<VoucherPaymentMethod>|Notification
|
||||||
|
*
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function getVoucherPaymentMethods(): array|Notification
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $this->config['bpn_username'],
|
||||||
|
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_VOUCHER_PAYMENT_METHODS),
|
||||||
|
'satz' => ['@typ' => static::TYPE_VOUCHER_PAYMENT_METHODS],
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->sendRequest(static::TYPE_VOUCHER_PAYMENT_METHODS, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the PDF preview of a voucher design with the entered data.
|
||||||
|
*
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function getVoucherPreview(VoucherPurchaseDto $voucherPurchaseDto): Notification|VoucherPreview
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $this->config['bpn_username'],
|
||||||
|
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_VOUCHER_PREVIEW),
|
||||||
|
'satz' => ['@typ' => static::TYPE_VOUCHER_PREVIEW],
|
||||||
|
...$this->voucherSalePayloadBuilder->buildPreviewPayload($voucherPurchaseDto),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->sendRequest(static::TYPE_VOUCHER_PREVIEW, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dry run of a voucher purchase: full validation, nothing is issued.
|
||||||
|
*
|
||||||
|
* Every HINWEIS is a rejection on this path, including 650 (missing address data), so the
|
||||||
|
* result must not be judged by Notification::isError().
|
||||||
|
*
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function createVoucherSaleInquiry(VoucherPurchaseDto $voucherPurchaseDto): Notification|VoucherSaleResponse
|
||||||
|
{
|
||||||
|
return $this->sendVoucherSale($voucherPurchaseDto, Constants::BOOKING_TYPE_INQUIRY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buys the voucher. BusPro mails it to the buyer once the payment has arrived.
|
||||||
|
*
|
||||||
|
* Every HINWEIS is a rejection on this path, including 650.
|
||||||
|
*
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
public function createVoucherSale(VoucherPurchaseDto $voucherPurchaseDto): Notification|VoucherSaleResponse
|
||||||
|
{
|
||||||
|
return $this->sendVoucherSale($voucherPurchaseDto, Constants::BOOKING_TYPE_BOOKING);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ApiClientException
|
||||||
|
*/
|
||||||
|
private function sendVoucherSale(VoucherPurchaseDto $voucherPurchaseDto, string $saleType): Notification|VoucherSaleResponse
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'user' => $this->config['bpn_username'],
|
||||||
|
'key' => $this->createKey($this->config['bpn_username'], $this->config['bpn_password'], static::TYPE_VOUCHER_SALE),
|
||||||
|
'satz' => ['@typ' => static::TYPE_VOUCHER_SALE],
|
||||||
|
...$this->voucherSalePayloadBuilder->buildSalePayload($voucherPurchaseDto, $saleType),
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->sendRequest(static::TYPE_VOUCHER_SALE, $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends raw XML to the BPN API with key regeneration and automatic retry.
|
* Sends raw XML to the BPN API with key regeneration and automatic retry.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\DataProcessor;
|
||||||
|
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the GUTSCHEINBUCHUNG and GUTSCHEINVORSCHAU payloads from the voucher purchase DTO.
|
||||||
|
*
|
||||||
|
* The buyer goes into <rechnungsempfänger> and nothing else: linking the purchase to a customer
|
||||||
|
* record is BusPro's business. The <zahlung> attributes are echoed from GUTSCHEINZAHLUNGSARTEN.
|
||||||
|
*/
|
||||||
|
class VoucherSalePayloadBuilder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $saleType Constants::BOOKING_TYPE_INQUIRY for the dry run, Constants::BOOKING_TYPE_BOOKING for the purchase
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function buildSalePayload(VoucherPurchaseDto $dto, string $saleType): array
|
||||||
|
{
|
||||||
|
if (null === $dto->template || null === $dto->paymentMethod) {
|
||||||
|
throw new \LogicException('A voucher sale needs a template and a payment method.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$communication = [
|
||||||
|
'telefonprivat' => $dto->phone,
|
||||||
|
'email' => $dto->email,
|
||||||
|
];
|
||||||
|
// Not in the vendor's GUTSCHEINBUCHUNG example; the element name is the one BUCHUNG uses.
|
||||||
|
if (null !== $dto->mobile && '' !== trim($dto->mobile)) {
|
||||||
|
$communication['telefonmobil'] = $dto->mobile;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'buchungsart' => $saleType,
|
||||||
|
'gutscheinart' => $dto->template->type,
|
||||||
|
'idgutscheinvorlage' => $dto->template->id,
|
||||||
|
'kaeufer' => $dto->from,
|
||||||
|
'empfaenger' => $dto->to,
|
||||||
|
'kaufpreis' => $dto->amount,
|
||||||
|
'text' => '',
|
||||||
|
'rechnungsempfänger' => [
|
||||||
|
'name' => $dto->lastName,
|
||||||
|
'vorname' => $dto->firstName,
|
||||||
|
'anrede' => $dto->salutation,
|
||||||
|
'titel' => $dto->title,
|
||||||
|
'geschlecht' => '',
|
||||||
|
'geburtsdatum' => '',
|
||||||
|
'anschrift' => $dto->address->toPayload(),
|
||||||
|
'kommunikation' => $communication,
|
||||||
|
],
|
||||||
|
'zahlung' => [
|
||||||
|
'@idzahlungsart' => $dto->paymentMethod->id,
|
||||||
|
'@bezeichnung' => $dto->paymentMethod->label,
|
||||||
|
'@art' => $dto->paymentMethod->type,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function buildPreviewPayload(VoucherPurchaseDto $dto): array
|
||||||
|
{
|
||||||
|
if (null === $dto->template) {
|
||||||
|
throw new \LogicException('A voucher preview needs a template.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'idgutscheinvorlage' => $dto->template->id,
|
||||||
|
'kaeufer' => $dto->from,
|
||||||
|
'empfaenger' => $dto->to,
|
||||||
|
'kaufpreis' => $dto->amount,
|
||||||
|
'text' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A payment method for voucher purchases (GUTSCHEINZAHLUNGSARTEN).
|
||||||
|
*
|
||||||
|
* Echoed unchanged as the <zahlung> attributes of GUTSCHEINBUCHUNG.
|
||||||
|
*/
|
||||||
|
final readonly class VoucherPaymentMethod
|
||||||
|
{
|
||||||
|
public const string TYPE_TRANSFER = 'UEBERW';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public int $id,
|
||||||
|
public string $label,
|
||||||
|
public string $type,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isTransfer(): bool
|
||||||
|
{
|
||||||
|
return self::TYPE_TRANSFER === $this->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GUTSCHEINVORSCHAU response, decoded from its data URI to the raw PDF bytes.
|
||||||
|
*/
|
||||||
|
final readonly class VoucherPreview
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public string $pdf,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A GUTSCHEINBUCHUNG response that is not a HINWEIS.
|
||||||
|
*
|
||||||
|
* The dry run (buchungsart Anfrage) answers <buchung>möglich</buchung> and nothing else, so every
|
||||||
|
* other field is only set by the actual purchase (buchungsart Buchung, <buchung>erfolgt</buchung>).
|
||||||
|
*
|
||||||
|
* The redemption code is deliberately not exposed to the customer before payment: BusPro mails the
|
||||||
|
* voucher itself once the transfer has arrived.
|
||||||
|
*/
|
||||||
|
final readonly class VoucherSaleResponse
|
||||||
|
{
|
||||||
|
public const string SALE_POSSIBLE = 'möglich';
|
||||||
|
public const string SALE_PROCESSED = 'erfolgt';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public string $status,
|
||||||
|
public ?int $voucherId = null,
|
||||||
|
public ?string $voucherNumber = null,
|
||||||
|
public ?string $redemptionCode = null,
|
||||||
|
public ?float $price = null,
|
||||||
|
public ?string $invoiceNumber = null,
|
||||||
|
public ?string $email = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isInquiryValid(): bool
|
||||||
|
{
|
||||||
|
return self::SALE_POSSIBLE === $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSaleSuccessful(): bool
|
||||||
|
{
|
||||||
|
return self::SALE_PROCESSED === $this->status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A voucher design offered for online sale (GUTSCHEINVORLAGEN).
|
||||||
|
*
|
||||||
|
* The id doubles as the key for the local thumbnail, see VoucherThumbnailResolver.
|
||||||
|
*/
|
||||||
|
final readonly class VoucherTemplate
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id,
|
||||||
|
public string $type,
|
||||||
|
public string $label,
|
||||||
|
public ?string $note = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The GUTSCHEINVORLAGEN response: the designs on sale plus BusPro's amount bounds.
|
||||||
|
*
|
||||||
|
* The bounds (gutscheinminbetrag/gutscheinmaxbetrag) are not in the vendor documentation,
|
||||||
|
* they were measured on the test system (10 and 5,000 €, both inclusive).
|
||||||
|
*/
|
||||||
|
final readonly class VoucherTemplates
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param list<VoucherTemplate> $templates
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public int $minAmount,
|
||||||
|
public int $maxAmount,
|
||||||
|
public array $templates,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find(int $id): ?VoucherTemplate
|
||||||
|
{
|
||||||
|
foreach ($this->templates as $template) {
|
||||||
|
if ($id === $template->id) {
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\BusProNet\Model;
|
namespace App\BusProNet\Model;
|
||||||
|
|
||||||
|
use League\Flysystem\FilesystemException;
|
||||||
|
use League\Flysystem\FilesystemOperator;
|
||||||
|
|
||||||
final readonly class XmlExportInfo
|
final readonly class XmlExportInfo
|
||||||
{
|
{
|
||||||
private const INFO_FILENAME = 'uebertragung.info';
|
private const INFO_FILENAME = 'uebertragung.info';
|
||||||
@@ -20,6 +23,26 @@ final readonly class XmlExportInfo
|
|||||||
return self::INFO_FILENAME;
|
return self::INFO_FILENAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the marker from a storage, or null when it is missing or unreadable.
|
||||||
|
*
|
||||||
|
* A marker caught mid-sync or truncated is treated as absent rather than as an error:
|
||||||
|
* callers only ever want to know which export they are looking at, and "unknown" is
|
||||||
|
* an answer they can act on.
|
||||||
|
*/
|
||||||
|
public static function fromStorage(FilesystemOperator $storage): ?self
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (false === $storage->fileExists(self::INFO_FILENAME)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::fromString($storage->read(self::INFO_FILENAME));
|
||||||
|
} catch (FilesystemException|\InvalidArgumentException) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function fromString(string $content): self
|
public static function fromString(string $content): self
|
||||||
{
|
{
|
||||||
$content = mb_convert_encoding($content, 'UTF-8', 'Windows-1252');
|
$content = mb_convert_encoding($content, 'UTF-8', 'Windows-1252');
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ trait TypeConversionTrait
|
|||||||
* This method is used primarily to parse pickup-times since data is
|
* This method is used primarily to parse pickup-times since data is
|
||||||
* either provided with date and time or time only. In this case a
|
* either provided with date and time or time only. In this case a
|
||||||
* date has to be provided which defaults to a travel's start date.
|
* date has to be provided which defaults to a travel's start date.
|
||||||
|
*
|
||||||
|
* Both shapes are read in the default date's zone, so a caller that needs plain clock
|
||||||
|
* readings can pass a UTC date and no daylight saving gap shifts the time.
|
||||||
*/
|
*/
|
||||||
protected function stringToDateTimeFuzzy(?string $string, \DateTimeImmutable $defaultDate): ?\DateTimeImmutable
|
protected function stringToDateTimeFuzzy(?string $string, \DateTimeImmutable $defaultDate): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
@@ -89,12 +92,12 @@ trait TypeConversionTrait
|
|||||||
try {
|
try {
|
||||||
if (1 === preg_match('/^\d{2}:\d{2}$/', $string)) {
|
if (1 === preg_match('/^\d{2}:\d{2}$/', $string)) {
|
||||||
// time only provided
|
// time only provided
|
||||||
$dateTime = Carbon::createFromFormat('H:i', $string);
|
$dateTime = Carbon::createFromFormat('H:i', $string, $defaultDate->getTimezone());
|
||||||
// assign default date
|
// assign default date
|
||||||
$dateTime->setDateFrom($defaultDate);
|
$dateTime->setDateFrom($defaultDate);
|
||||||
} else {
|
} else {
|
||||||
// date and time provided
|
// date and time provided
|
||||||
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16));
|
$dateTime = Carbon::createFromFormat('d.m.Y H:i', substr($string, 0, 16), $defaultDate->getTimezone());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dateTime->toDateTimeImmutable();
|
return $dateTime->toDateTimeImmutable();
|
||||||
|
|||||||
@@ -93,6 +93,14 @@ class ApiResponseParser extends AbstractParser
|
|||||||
return (new PurchaseVoucherParser())->parse($resultNode);
|
return (new PurchaseVoucherParser())->parse($resultNode);
|
||||||
case ApiClient::TYPE_PROMO_VOUCHER:
|
case ApiClient::TYPE_PROMO_VOUCHER:
|
||||||
return (new PromoVoucherParser())->parse($resultNode);
|
return (new PromoVoucherParser())->parse($resultNode);
|
||||||
|
case ApiClient::TYPE_VOUCHER_TEMPLATES:
|
||||||
|
return (new VoucherTemplatesParser())->parse($resultNode);
|
||||||
|
case ApiClient::TYPE_VOUCHER_PAYMENT_METHODS:
|
||||||
|
return (new VoucherPaymentMethodsParser())->parse($resultNode);
|
||||||
|
case ApiClient::TYPE_VOUCHER_PREVIEW:
|
||||||
|
return (new VoucherPreviewParser())->parse($resultNode);
|
||||||
|
case ApiClient::TYPE_VOUCHER_SALE:
|
||||||
|
return (new VoucherSaleResponseParser())->parse($resultNode);
|
||||||
}
|
}
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
throw new ResponseParserException('Invalid XML response structure: '.$e->getMessage(), 0, $e);
|
throw new ResponseParserException('Invalid XML response structure: '.$e->getMessage(), 0, $e);
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
namespace App\BusProNet\XmlParser;
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
use App\BusProNet\Model\File;
|
use App\BusProNet\Model\File;
|
||||||
use PhpZip\Exception\ZipException;
|
|
||||||
use PhpZip\ZipFile;
|
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
use ZipStream\Exception as ZipException;
|
||||||
|
use ZipStream\ZipStream;
|
||||||
|
|
||||||
class DocumentsParser
|
class DocumentsParser
|
||||||
{
|
{
|
||||||
@@ -28,17 +28,28 @@ class DocumentsParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In case of multiple documents create ZIP file
|
// In case of multiple documents create ZIP file
|
||||||
|
$stream = fopen('php://temp', 'w+b');
|
||||||
try {
|
try {
|
||||||
$zip = new ZipFile();
|
// Zero headers trip up some unzip clients, and the data is in memory anyway
|
||||||
|
$zip = new ZipStream(
|
||||||
|
outputStream: $stream,
|
||||||
|
defaultEnableZeroHeader: false,
|
||||||
|
sendHttpHeaders: false,
|
||||||
|
);
|
||||||
|
|
||||||
$documents->each(function (Crawler $node) use (&$zip) {
|
$documents->each(function (Crawler $node) use ($zip) {
|
||||||
[$filename, $pdfData] = $this->getFileInfo($node);
|
[$filename, $pdfData] = $this->getFileInfo($node);
|
||||||
$zip->addFromString($filename.'.pdf', $pdfData);
|
$zip->addFile($filename.'.pdf', $pdfData);
|
||||||
});
|
});
|
||||||
|
|
||||||
return new File('reisedokumente.zip', $zip->outputAsString(), 'application/zip');
|
$zip->finish();
|
||||||
|
rewind($stream);
|
||||||
|
|
||||||
|
return new File('reisedokumente.zip', stream_get_contents($stream), 'application/zip');
|
||||||
} catch (ZipException $e) {
|
} catch (ZipException $e) {
|
||||||
return null;
|
return null;
|
||||||
|
} finally {
|
||||||
|
fclose($stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Constants;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the parts of a `Ziel_*.xml` travel date that the product export carries, verbatim.
|
||||||
|
*
|
||||||
|
* Deliberately separate from TravelParser, which builds the booking path's models and
|
||||||
|
* applies the booking path's rules: it drops the PDGS pseudo room, excludes the
|
||||||
|
* hotel-nested services and levels boarding-point prices. The product export filters and
|
||||||
|
* rewrites nothing -- its consumer applies its own rules -- so it reads the nodes directly
|
||||||
|
* and returns plain arrays in source order.
|
||||||
|
*
|
||||||
|
* @see \App\Service\ProductExportBuilder
|
||||||
|
*/
|
||||||
|
class ProductExportParser extends AbstractParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Every selection group on the date, not only the `Leistungen *` ones.
|
||||||
|
*
|
||||||
|
* @return list<array{busProId: int, label: ?string, selections: list<array{busProId: int, label: ?string}>}>
|
||||||
|
*/
|
||||||
|
public function getSelectionGroups(Crawler $dateNode): array
|
||||||
|
{
|
||||||
|
return $this->children($dateNode, 'selektiongruppe')->each(fn (Crawler $group): array => [
|
||||||
|
'busProId' => (int) $group->attr('idbuspro'),
|
||||||
|
'label' => $group->attr('bezeichnung'),
|
||||||
|
'selections' => $this->children($group, 'selektion')->each(fn (Crawler $selection): array => [
|
||||||
|
'busProId' => (int) $selection->attr('idbuspro'),
|
||||||
|
'label' => $selection->attr('bezeichnung'),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Services of one `lei_*` list, keyed by nothing -- the consumer keys them by `busProId`.
|
||||||
|
*
|
||||||
|
* The per-list `id` attribute is not read: it restarts at 1 in every list, so it
|
||||||
|
* identifies nothing once a date-level and a hotel-level list are merged.
|
||||||
|
*
|
||||||
|
* @return list<array{busProId: int, subType: ?string, label: ?string, price: ?float, status: ?string, direction: ?string}>
|
||||||
|
*/
|
||||||
|
public function getServices(Crawler $serviceNodes): array
|
||||||
|
{
|
||||||
|
return $serviceNodes->each(fn (Crawler $service): array => [
|
||||||
|
'busProId' => (int) $service->attr('idbuspro'),
|
||||||
|
'subType' => $service->attr('unterart'),
|
||||||
|
'label' => $this->getStringOrNullValue($this->children($service, 'text')),
|
||||||
|
'price' => $this->getFloatOrNullValue($this->children($service, 'preis')),
|
||||||
|
'status' => $this->getStringOrNullValue($this->children($service, 'status')),
|
||||||
|
'direction' => $this->getStringOrNullValue($this->children($service, 'richtung')),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hotel's rooms, without the PDGS pseudo room.
|
||||||
|
*
|
||||||
|
* `available` is a count of rooms, not persons. Occupancy is read case-insensitively:
|
||||||
|
* the travel export writes `MinPax`/`MaxPax`.
|
||||||
|
*
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
public function getRooms(Crawler $hotelNode): array
|
||||||
|
{
|
||||||
|
$rooms = [];
|
||||||
|
|
||||||
|
$this->children($hotelNode, 'zimmer/preis')->each(function (Crawler $room) use (&$rooms) {
|
||||||
|
$code = $this->trimOrNull($this->getAttrOrNullValue($room, 'zimmercode'));
|
||||||
|
|
||||||
|
if (Constants::PSEUDO_PRICE_ROOM_CODE === $code) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rooms[] = [
|
||||||
|
'busProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_zimmer'),
|
||||||
|
'code' => $code,
|
||||||
|
'label' => $this->getAttrOrNullValue($room, 'zimmertext'),
|
||||||
|
'category' => $this->getAttrOrNullValue($room, 'kat'),
|
||||||
|
'minPax' => $this->getIntAttrOrNullValue($room, 'minpax'),
|
||||||
|
'maxPax' => $this->getIntAttrOrNullValue($room, 'maxpax'),
|
||||||
|
'nights' => $this->getIntAttrOrNullValue($room, 'naechte'),
|
||||||
|
'price' => $this->stringToFloat($this->getAttrOrNullValue($room, 'preis')),
|
||||||
|
'available' => $this->getIntAttrOrNullValue($room, 'verfuegbar'),
|
||||||
|
'status' => $this->getAttrOrNullValue($room, 'status'),
|
||||||
|
'boardCode' => $this->getAttrOrNullValue($room, 'vpcode'),
|
||||||
|
'boardBusProId' => $this->getIntAttrOrNullValue($room, 'idbuspro_vp'),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return $rooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The struck-through comparison price, carried by the PDGS pseudo room.
|
||||||
|
*/
|
||||||
|
public function getPseudoPrice(Crawler $hotelNode): ?float
|
||||||
|
{
|
||||||
|
foreach ($this->children($hotelNode, 'zimmer/preis') as $room) {
|
||||||
|
$room = new Crawler($room);
|
||||||
|
|
||||||
|
if (Constants::PSEUDO_PRICE_ROOM_CODE === $this->trimOrNull($this->getAttrOrNullValue($room, 'zimmercode'))) {
|
||||||
|
return $this->stringToFloat($this->getAttrOrNullValue($room, 'preis'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The guide of the first outbound bus that has one.
|
||||||
|
*
|
||||||
|
* Not TravelParser::getGuide(), which takes the first guide of any bus, return leg
|
||||||
|
* included.
|
||||||
|
*
|
||||||
|
* @return array{name: ?string, phone: ?string}|null
|
||||||
|
*/
|
||||||
|
public function getGuide(Crawler $dateNode): ?array
|
||||||
|
{
|
||||||
|
$guides = $this->children($dateNode, 'lei_befoerderung/leistung[@unterart="BUS"][not(richtung="RUECK")]/zustiegsplanung/reiseleiter');
|
||||||
|
|
||||||
|
if (0 === $guides->count()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$guide = $guides->first();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $this->getStringOrNullValue($this->children($guide, 'name')),
|
||||||
|
'phone' => $this->getStringOrNullValue($this->children($guide, 'telefon')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A path below the node's own children, never deeper.
|
||||||
|
*
|
||||||
|
* DomCrawler evaluates filterXPath() against a fake parent of the node, so `./x` finds
|
||||||
|
* nothing and `.//x` searches every descendant -- which would pull a hotel's
|
||||||
|
* `lei_sonstiges` into the date's list. A leading `*` step anchors the path at the
|
||||||
|
* node itself, whatever its name.
|
||||||
|
*/
|
||||||
|
public function children(Crawler $node, string $path): Crawler
|
||||||
|
{
|
||||||
|
return $node->filterXPath('*/'.$path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function trimOrNull(?string $value): ?string
|
||||||
|
{
|
||||||
|
if (null === $value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trimmed = trim($value);
|
||||||
|
|
||||||
|
return '' === $trimmed ? null : $trimmed;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses GUTSCHEINZAHLUNGSARTEN responses.
|
||||||
|
*
|
||||||
|
* Expected XML structure (test system, 2026-10-01):
|
||||||
|
* <ergebnis>
|
||||||
|
* <satz typ="GUTSCHEINZAHLUNGSARTEN"></satz>
|
||||||
|
* <zahlungsarten>
|
||||||
|
* <zahlungsart id="2" bezeichnung="Überweisung" art="UEBERW"></zahlungsart>
|
||||||
|
* </zahlungsarten>
|
||||||
|
* </ergebnis>
|
||||||
|
*/
|
||||||
|
final class VoucherPaymentMethodsParser extends AbstractParser
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return list<VoucherPaymentMethod>
|
||||||
|
*/
|
||||||
|
public function parse(Crawler $node): array
|
||||||
|
{
|
||||||
|
$paymentMethods = [];
|
||||||
|
$node->filterXPath('//zahlungsarten/zahlungsart')->each(function (Crawler $methodNode) use (&$paymentMethods): void {
|
||||||
|
$paymentMethods[] = new VoucherPaymentMethod(
|
||||||
|
id: (int) $this->getRequiredAttrValue($methodNode, 'id', 'voucher payment method'),
|
||||||
|
label: $this->getRequiredAttrValue($methodNode, 'bezeichnung', 'voucher payment method'),
|
||||||
|
type: $this->getRequiredAttrValue($methodNode, 'art', 'voucher payment method'),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $paymentMethods;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherPreview;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses GUTSCHEINVORSCHAU responses.
|
||||||
|
*
|
||||||
|
* Expected XML structure (test system, 2026-10-01):
|
||||||
|
* <ergebnis>
|
||||||
|
* <satz typ="GUTSCHEINVORSCHAU"/>
|
||||||
|
* <gutscheinpdf>data:application/pdf;base64,JVBERi0xLjQ…</gutscheinpdf>
|
||||||
|
* </ergebnis>
|
||||||
|
*/
|
||||||
|
final class VoucherPreviewParser extends AbstractParser
|
||||||
|
{
|
||||||
|
private const string DATA_URI_PREFIX = 'data:application/pdf;base64,';
|
||||||
|
|
||||||
|
public function parse(Crawler $node): VoucherPreview
|
||||||
|
{
|
||||||
|
$dataUri = trim($this->getStringOrNullValue($node->filterXPath('//gutscheinpdf')) ?? '');
|
||||||
|
if (!str_starts_with($dataUri, self::DATA_URI_PREFIX)) {
|
||||||
|
throw new \InvalidArgumentException('Missing or malformed PDF data URI in voucher preview response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$pdf = base64_decode(substr($dataUri, \strlen(self::DATA_URI_PREFIX)), true);
|
||||||
|
if (false === $pdf || '' === $pdf) {
|
||||||
|
throw new \InvalidArgumentException('Undecodable PDF in voucher preview response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new VoucherPreview($pdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherSaleResponse;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses GUTSCHEINBUCHUNG responses that are not a HINWEIS.
|
||||||
|
*
|
||||||
|
* Dry run (buchungsart Anfrage, measured on the test system 2026-10-01):
|
||||||
|
* <ergebnis><satz typ="GUTSCHEINBUCHUNG"></satz><buchung>möglich</buchung></ergebnis>
|
||||||
|
*
|
||||||
|
* Purchase (buchungsart Buchung, as documented by the vendor):
|
||||||
|
* <ergebnis>
|
||||||
|
* <satz typ="GUTSCHEINBUCHUNG"/>
|
||||||
|
* <buchung>erfolgt</buchung>
|
||||||
|
* <idgutschein/><gutscheinnummer/><einloesecode/><preis/><rechnungsnummer/><email/>
|
||||||
|
* </ergebnis>
|
||||||
|
*/
|
||||||
|
final class VoucherSaleResponseParser extends AbstractParser
|
||||||
|
{
|
||||||
|
public function parse(Crawler $node): VoucherSaleResponse
|
||||||
|
{
|
||||||
|
$status = trim($this->getStringOrNullValue($node->filterXPath('//buchung')) ?? '');
|
||||||
|
if ('' === $status) {
|
||||||
|
throw new \InvalidArgumentException('Missing required status in voucher sale response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new VoucherSaleResponse(
|
||||||
|
status: $status,
|
||||||
|
voucherId: $this->getIntOrNullValue($node->filterXPath('//idgutschein')),
|
||||||
|
voucherNumber: $this->trimmedOrNull($node->filterXPath('//gutscheinnummer')),
|
||||||
|
redemptionCode: $this->trimmedOrNull($node->filterXPath('//einloesecode')),
|
||||||
|
price: $this->getFloatOrNullValue($node->filterXPath('//preis')),
|
||||||
|
invoiceNumber: $this->trimmedOrNull($node->filterXPath('//rechnungsnummer')),
|
||||||
|
email: $this->trimmedOrNull($node->filterXPath('//email')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function trimmedOrNull(Crawler $node): ?string
|
||||||
|
{
|
||||||
|
$value = trim($this->getStringOrNullValue($node) ?? '');
|
||||||
|
|
||||||
|
return '' !== $value ? $value : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherTemplate;
|
||||||
|
use App\BusProNet\Model\VoucherTemplates;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses GUTSCHEINVORLAGEN responses.
|
||||||
|
*
|
||||||
|
* Expected XML structure (test system, 2026-10-01):
|
||||||
|
* <ergebnis>
|
||||||
|
* <satz typ="GUTSCHEINVORLAGEN"></satz>
|
||||||
|
* <gutscheinminbetrag>10</gutscheinminbetrag>
|
||||||
|
* <gutscheinmaxbetrag>5000</gutscheinmaxbetrag>
|
||||||
|
* <gutscheine>
|
||||||
|
* <gutschein idgutscheinvorlage="3">
|
||||||
|
* <gutscheinart>K</gutscheinart>
|
||||||
|
* <bezeichnung>Allgemein</bezeichnung>
|
||||||
|
* <hinweis></hinweis>
|
||||||
|
* </gutschein>
|
||||||
|
* </gutscheine>
|
||||||
|
* </ergebnis>
|
||||||
|
*/
|
||||||
|
final class VoucherTemplatesParser extends AbstractParser
|
||||||
|
{
|
||||||
|
public function parse(Crawler $node): VoucherTemplates
|
||||||
|
{
|
||||||
|
$minAmount = $this->getStringOrNullValue($node->filterXPath('//gutscheinminbetrag'));
|
||||||
|
$maxAmount = $this->getStringOrNullValue($node->filterXPath('//gutscheinmaxbetrag'));
|
||||||
|
if (null === $minAmount || '' === trim($minAmount) || null === $maxAmount || '' === trim($maxAmount)) {
|
||||||
|
throw new \InvalidArgumentException('Missing voucher amount bounds in voucher templates response.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$templates = [];
|
||||||
|
$node->filterXPath('//gutscheine/gutschein')->each(function (Crawler $templateNode) use (&$templates): void {
|
||||||
|
$note = $this->getStringOrNullValue($templateNode->filterXPath('//hinweis'));
|
||||||
|
|
||||||
|
$templates[] = new VoucherTemplate(
|
||||||
|
id: (int) $this->getRequiredAttrValue($templateNode, 'idgutscheinvorlage', 'voucher template'),
|
||||||
|
type: trim($this->getStringOrNullValue($templateNode->filterXPath('//gutscheinart')) ?? ''),
|
||||||
|
label: trim($this->getStringOrNullValue($templateNode->filterXPath('//bezeichnung')) ?? ''),
|
||||||
|
note: null !== $note && '' !== trim($note) ? trim($note) : null,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return new VoucherTemplates(
|
||||||
|
// whole euros: the flow only offers whole-euro amounts, so the bounds are kept as such
|
||||||
|
minAmount: (int) ceil($this->stringToFloat($minAmount)),
|
||||||
|
maxAmount: (int) floor($this->stringToFloat($maxAmount)),
|
||||||
|
templates: $templates,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Repository\UserRepository;
|
||||||
|
use App\Security\Role;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes local accounts that carry nothing worth keeping.
|
||||||
|
*
|
||||||
|
* Nothing here destroys customer data: BusPro owns the person, the bookings and the roles, and
|
||||||
|
* BpnAuthenticator rebuilds the local row on the next login (`findOneBy(email) ?? new User()`),
|
||||||
|
* re-deriving the roles, the hotel codes and the profile completeness from the CRM as it goes.
|
||||||
|
* An account is a cache of what BusPro says, so dropping one costs its owner nothing.
|
||||||
|
*
|
||||||
|
* One thing is not rebuilt, and it is the reason every removal gets a log line of its own: the
|
||||||
|
* uuid, minted in the constructor and exported as the OAuth2 `sub` claim (see UserinfoController).
|
||||||
|
* A returning account gets a fresh one, so the old subject cannot be tied to the new row by
|
||||||
|
* anything except that log entry. The SSO clients that gate on a role — E&P Team, E&P Hub — never
|
||||||
|
* see these accounts anyway, since the roles they require are exactly the ones excluded below.
|
||||||
|
*
|
||||||
|
* An account is removed when all of the following hold:
|
||||||
|
*
|
||||||
|
* - it holds no effective role beyond ROLE_CUSTOMER, that role being the fallback for an account
|
||||||
|
* with no privileges at all (see Role::withCustomerFallback()). An account left with no roles
|
||||||
|
* at all is the same state, spelled the way it was before the fallback landed;
|
||||||
|
* - it carries no pending nomination, which would otherwise disappear from /admin/user before
|
||||||
|
* anybody had ruled on it;
|
||||||
|
* - it holds no booking edit draft, and nothing in the Groups subsystem names it.
|
||||||
|
*
|
||||||
|
* --inactive-for adds a "has not signed in for N months" condition on top. It is off by default:
|
||||||
|
* a returning customer is recreated on sight, so age says nothing about whether a row may go.
|
||||||
|
*
|
||||||
|
* Deleting requires --force. The removal cannot be undone and the first run clears thousands of
|
||||||
|
* rows, so a bare invocation reports what it would do and stops. The guard is a flag rather than
|
||||||
|
* an $io->confirm() because the scheduler hands the command a StringInput, which reports itself
|
||||||
|
* as interactive — a confirmation would sit waiting on a STDIN nobody is attached to. A flag
|
||||||
|
* behaves the same way whether a person or cron is running it, and it makes the schedule entry
|
||||||
|
* say out loud that the task destroys data.
|
||||||
|
*/
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:cleanup:users',
|
||||||
|
description: 'Removes accounts that hold no role, no draft and no group booking reference',
|
||||||
|
)]
|
||||||
|
class CleanupUsersCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* How many accounts are removed between two flushes. The unit of work holds every scheduled
|
||||||
|
* removal until then, and the first run has thousands of rows to get through, so it is a
|
||||||
|
* memory bound rather than a policy one.
|
||||||
|
*/
|
||||||
|
private const BATCH_SIZE = 500;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly UserRepository $userRepository,
|
||||||
|
private readonly EntityManagerInterface $entityManager,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addOption(
|
||||||
|
'inactive-for',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'Only consider accounts without a login for this many months (default: no such limit)',
|
||||||
|
)
|
||||||
|
->addOption(
|
||||||
|
'limit',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'Maximum number of accounts to delete in one run (default: no limit)',
|
||||||
|
)
|
||||||
|
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Show what would be deleted without actually deleting')
|
||||||
|
->addOption('force', null, InputOption::VALUE_NONE, 'Actually delete; without it the command only reports what it would do')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$months = null !== $input->getOption('inactive-for') ? (int) $input->getOption('inactive-for') : null;
|
||||||
|
$limit = null !== $input->getOption('limit') ? (int) $input->getOption('limit') : null;
|
||||||
|
$dryRun = (bool) $input->getOption('dry-run');
|
||||||
|
$force = (bool) $input->getOption('force');
|
||||||
|
|
||||||
|
if ((null !== $months && $months < 1) || (null !== $limit && $limit < 1)) {
|
||||||
|
$io->error('--inactive-for and --limit have to be at least 1 when given.');
|
||||||
|
|
||||||
|
return Command::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inactiveSince = null !== $months ? new \DateTimeImmutable(sprintf('-%d months', $months)) : null;
|
||||||
|
|
||||||
|
$candidates = array_values(array_filter(
|
||||||
|
$this->userRepository->findCleanupCandidates($inactiveSince),
|
||||||
|
static fn (User $user): bool => self::isDisposable($user),
|
||||||
|
));
|
||||||
|
|
||||||
|
// After the role filter, never before it: --limit caps the accounts actually deleted, and
|
||||||
|
// the candidate query cannot tell which ones those are.
|
||||||
|
if (null !== $limit) {
|
||||||
|
$candidates = \array_slice($candidates, 0, $limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([] === $candidates) {
|
||||||
|
$io->success('No accounts to remove.');
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $dryRun || false === $force) {
|
||||||
|
$io->table(
|
||||||
|
['E-Mail', 'Letzter Login', 'Rollen'],
|
||||||
|
array_map(static fn (User $user): array => [
|
||||||
|
$user->getEmail(),
|
||||||
|
$user->getLastLoginAt()?->format('Y-m-d') ?? '-',
|
||||||
|
implode(', ', Role::assignedOnly($user->getRoles())) ?: '-',
|
||||||
|
], $candidates),
|
||||||
|
);
|
||||||
|
|
||||||
|
$io->note(sprintf('Would delete %d account(s).', \count($candidates)));
|
||||||
|
|
||||||
|
if (true === $dryRun) {
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not a dry run, just an invocation that forgot to say so. Reported as a failure so a
|
||||||
|
// schedule entry missing --force turns into a mail rather than a task that quietly
|
||||||
|
// does nothing every week.
|
||||||
|
$io->error('Refusing to delete without --force. Pass --dry-run to preview, or --force to delete.');
|
||||||
|
|
||||||
|
return Command::INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($candidates as $index => $user) {
|
||||||
|
// One line per account, before the removal rather than after: once the row is gone
|
||||||
|
// this is the only place left that records which account the uuid belonged to. Worth
|
||||||
|
// a log_entry row per deletion, including the several thousand the first run writes —
|
||||||
|
// they age out with the six-month log retention.
|
||||||
|
$this->logger->info('Deleting account without roles', [
|
||||||
|
'uuid' => $user->getUuid(),
|
||||||
|
'email' => $user->getEmail(),
|
||||||
|
'lastLoginAt' => $user->getLastLoginAt()?->format(\DateTimeInterface::ATOM),
|
||||||
|
'roles' => Role::assignedOnly($user->getRoles()),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->entityManager->remove($user);
|
||||||
|
|
||||||
|
if (0 === ($index + 1) % self::BATCH_SIZE) {
|
||||||
|
$this->entityManager->flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
$count = \count($candidates);
|
||||||
|
|
||||||
|
$this->logger->info('Deleted accounts without roles', [
|
||||||
|
'count' => $count,
|
||||||
|
'inactiveSince' => $inactiveSince?->format('Y-m-d'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$io->success(sprintf('Deleted %d account(s).', $count));
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the account's role set says it may go. ROLE_CUSTOMER is the fallback rather than a
|
||||||
|
* baseline, so "customer only" and "nothing at all" are the same state — the second being the
|
||||||
|
* spelling accounts kept that have not signed in since the fallback landed.
|
||||||
|
*
|
||||||
|
* Pending markers grant nothing, but they are a nomination waiting for an administrator, so an
|
||||||
|
* account carrying one stays until somebody has ruled on it.
|
||||||
|
*/
|
||||||
|
private static function isDisposable(User $user): bool
|
||||||
|
{
|
||||||
|
$roles = $user->getRoles();
|
||||||
|
|
||||||
|
return [] === Role::pendingOnly($roles)
|
||||||
|
&& [] === array_diff(Role::effectiveOnly($roles), [Role::CUSTOMER]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ use App\Form\Admin\Groups\AccommodationBookingType;
|
|||||||
use App\Repository\Groups\AdditionalServiceRepository;
|
use App\Repository\Groups\AdditionalServiceRepository;
|
||||||
use App\Repository\Groups\BoardServiceRepository;
|
use App\Repository\Groups\BoardServiceRepository;
|
||||||
use App\Repository\UserRepository;
|
use App\Repository\UserRepository;
|
||||||
|
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||||
use App\Service\AccommodationBookingService;
|
use App\Service\AccommodationBookingService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -33,6 +34,7 @@ class EditController extends AbstractController
|
|||||||
private readonly AdditionalServiceRepository $additionalServiceRepo,
|
private readonly AdditionalServiceRepository $additionalServiceRepo,
|
||||||
private readonly UserRepository $userRepo,
|
private readonly UserRepository $userRepo,
|
||||||
private readonly AccommodationBookingService $bookingService,
|
private readonly AccommodationBookingService $bookingService,
|
||||||
|
private readonly AccommodationBookingBreakdownCalculator $breakdownCalculator,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,10 +130,7 @@ class EditController extends AbstractController
|
|||||||
// The submitted changes stay on the entity but are never flushed, so the form
|
// The submitted changes stay on the entity but are never flushed, so the form
|
||||||
// comes back filled in with the error on it. Logging is safe here: the database
|
// comes back filled in with the error on it. Logging is safe here: the database
|
||||||
// handler writes through DBAL, not the EntityManager.
|
// handler writes through DBAL, not the EntityManager.
|
||||||
return $this->render('admin/accommodation_booking/edit.html.twig', [
|
return $this->renderForm($booking, $form);
|
||||||
'booking' => $booking,
|
|
||||||
'form' => $form,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Editing never moves the booking on and never mails the customer: every status
|
// Editing never moves the booking on and never mails the customer: every status
|
||||||
@@ -160,9 +159,22 @@ class EditController extends AbstractController
|
|||||||
return $this->redirectToRoute('app_admin_accommodationbooking_show', $parameters);
|
return $this->redirectToRoute('app_admin_accommodationbooking_show', $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->renderForm($booking, $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sidebar shows the stored price, not one computed from the submitted values: after a
|
||||||
|
* refused save the entity carries the unsaved changes, and the price there is labelled as the
|
||||||
|
* state of the last save.
|
||||||
|
*
|
||||||
|
* @param FormInterface<AccommodationBooking> $form
|
||||||
|
*/
|
||||||
|
private function renderForm(AccommodationBooking $booking, FormInterface $form): Response
|
||||||
|
{
|
||||||
return $this->render('admin/accommodation_booking/edit.html.twig', [
|
return $this->render('admin/accommodation_booking/edit.html.twig', [
|
||||||
'booking' => $booking,
|
'booking' => $booking,
|
||||||
'form' => $form,
|
'form' => $form,
|
||||||
|
'priceBreakdown' => $this->breakdownCalculator->compute($booking),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\AccommodationBooking;
|
||||||
|
|
||||||
|
use App\Entity\Groups\AccommodationBookingPeriod;
|
||||||
|
use App\Exception\ImplausibleBookingPriceException;
|
||||||
|
use App\Form\Admin\Groups\AccommodationBookingPeriodType;
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodDto;
|
||||||
|
use App\Htmx\HxTrait;
|
||||||
|
use App\Service\AccommodationBookingService;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\FormError;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
/** Changes the length and the lines of a split-off period; the main period absorbs the difference. */
|
||||||
|
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||||
|
class EditPeriodController extends AbstractController
|
||||||
|
{
|
||||||
|
use HxTrait;
|
||||||
|
use RedirectsToEditFormTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly AccommodationBookingService $bookingService,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/accommodation-booking-period/{id}/edit', name: 'app_admin_accommodationbooking_period_edit')]
|
||||||
|
public function index(AccommodationBookingPeriod $period, Request $request): Response
|
||||||
|
{
|
||||||
|
$booking = $period->getBooking() ?? throw $this->createNotFoundException();
|
||||||
|
|
||||||
|
$dto = AccommodationBookingPeriodDto::fromPeriod($period);
|
||||||
|
$form = $this->createForm(AccommodationBookingPeriodType::class, $dto, [
|
||||||
|
'currency' => $booking->getPricingCurrency() ?? $booking->getAccommodation()?->getCurrency() ?? 'EUR',
|
||||||
|
'hx_post' => $request->getRequestUri(),
|
||||||
|
]);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
try {
|
||||||
|
$violations = $this->bookingService->updatePeriod($booking, $period, $dto);
|
||||||
|
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$form->addError(new FormError((string) $violation->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === count($violations)) {
|
||||||
|
$this->addFlash('success', 'Der Zeitraum wurde aktualisiert.');
|
||||||
|
|
||||||
|
$this->logger->info('Updated a period of accommodation booking', [
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
'periodId' => $period->getId(),
|
||||||
|
'nights' => $dto->nights,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||||
|
}
|
||||||
|
} catch (ImplausibleBookingPriceException $e) {
|
||||||
|
$this->logger->error('Refused to update a period over an implausible accommodation booking total', [
|
||||||
|
'exception' => $e,
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
'periodId' => $period->getId(),
|
||||||
|
]);
|
||||||
|
$form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('admin/accommodation_booking/modal_period.html.twig', [
|
||||||
|
'booking' => $booking,
|
||||||
|
'form' => $form,
|
||||||
|
'title' => 'Zeitraum bearbeiten',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,12 +21,8 @@ class PdfController extends AbstractController
|
|||||||
#[Route('/admin/accommodation-booking/{id}/pdf', name: 'app_admin_accommodationbooking_pdf')]
|
#[Route('/admin/accommodation-booking/{id}/pdf', name: 'app_admin_accommodationbooking_pdf')]
|
||||||
public function index(AccommodationBooking $booking): Response
|
public function index(AccommodationBooking $booking): Response
|
||||||
{
|
{
|
||||||
if (false === $booking->isConfirmed()) {
|
// Offered in every status, so the office can check the document before it goes out
|
||||||
$this->addFlash('warning', 'Ein PDF kann nur für bestätigte Buchungen erstellt werden.');
|
// with the confirmation email; it labels itself Angebot or Buchung accordingly.
|
||||||
|
|
||||||
return $this->redirectToRoute('app_admin_accommodationbooking_show', ['id' => $booking->getId()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $this->pdfGenerator->createDownloadResponse($booking);
|
return $this->pdfGenerator->createDownloadResponse($booking);
|
||||||
} catch (\RuntimeException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\AccommodationBooking;
|
||||||
|
|
||||||
|
use App\Entity\Groups\AccommodationBooking;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the modals opened from the edit form: they save on their own and send the browser back to
|
||||||
|
* it, rebuilt with the new price.
|
||||||
|
*/
|
||||||
|
trait RedirectsToEditFormTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The return url is forwarded still encoded, the way return_url() handed it over, so that
|
||||||
|
* the edit page keeps leading back to the list the booking was opened from.
|
||||||
|
*/
|
||||||
|
private function editUrl(AccommodationBooking $booking, Request $request): string
|
||||||
|
{
|
||||||
|
$parameters = ['id' => $booking->getId()];
|
||||||
|
$returnUrl = $request->query->getString('r');
|
||||||
|
if ('' !== $returnUrl) {
|
||||||
|
$parameters['r'] = $returnUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->generateUrl('app_admin_accommodationbooking_edit', $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\AccommodationBooking;
|
||||||
|
|
||||||
|
use App\Entity\Groups\AccommodationBookingPeriod;
|
||||||
|
use App\Exception\ImplausibleBookingPriceException;
|
||||||
|
use App\Htmx\HxTrait;
|
||||||
|
use App\Service\AccommodationBookingService;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
/** Gives a split-off period's nights back to the main period, which reprices the booking. */
|
||||||
|
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||||
|
class RemovePeriodController extends AbstractController
|
||||||
|
{
|
||||||
|
use HxTrait;
|
||||||
|
use RedirectsToEditFormTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly AccommodationBookingService $bookingService,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/accommodation-booking-period/{id}/remove', name: 'app_admin_accommodationbooking_period_remove')]
|
||||||
|
public function index(AccommodationBookingPeriod $period, Request $request): Response
|
||||||
|
{
|
||||||
|
$booking = $period->getBooking() ?? throw $this->createNotFoundException();
|
||||||
|
|
||||||
|
if ($request->isMethod(Request::METHOD_POST)) {
|
||||||
|
if (!$this->isCsrfTokenValid('remove_accommodation_booking_period_'.$period->getId(), $request->request->getString('_token'))) {
|
||||||
|
throw $this->createAccessDeniedException('Invalid CSRF token.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$periodId = $period->getId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$violations = $this->bookingService->removePeriod($booking, $period);
|
||||||
|
} catch (ImplausibleBookingPriceException $e) {
|
||||||
|
$this->logger->error('Refused to remove a period over an implausible accommodation booking total', [
|
||||||
|
'exception' => $e,
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
'periodId' => $periodId,
|
||||||
|
]);
|
||||||
|
$this->addFlash('error', ImplausibleBookingPriceException::FORM_ERROR_MESSAGE);
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Removing only ever lengthens the main period, so this is reached only when the
|
||||||
|
// stay's dates were already inconsistent with the periods.
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$this->addFlash('error', (string) $violation->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === count($violations)) {
|
||||||
|
$this->addFlash('success', 'Der Zeitraum wurde entfernt.');
|
||||||
|
|
||||||
|
$this->logger->info('Removed a period of accommodation booking', [
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
'periodId' => $periodId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('admin/accommodation_booking/modal_remove_period.html.twig', [
|
||||||
|
'booking' => $booking,
|
||||||
|
'period' => $period,
|
||||||
|
'csrf_token_id' => 'remove_accommodation_booking_period_'.$period->getId(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin\AccommodationBooking;
|
||||||
|
|
||||||
|
use App\Entity\Groups\AccommodationBooking;
|
||||||
|
use App\Enum\Groups\AccommodationBookingPeriodPosition;
|
||||||
|
use App\Exception\ImplausibleBookingPriceException;
|
||||||
|
use App\Form\Admin\Groups\AccommodationBookingPeriodType;
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodDto;
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodLineDto;
|
||||||
|
use App\Htmx\HxTrait;
|
||||||
|
use App\Service\AccommodationBookingService;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\Form\FormError;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits nights off the start or the end of the stay, for a part of the group that arrives
|
||||||
|
* early or leaves late and is quoted as free-form lines instead of the booking's parameters.
|
||||||
|
* Each side can be split once; the period can be resized afterwards through its edit modal.
|
||||||
|
*/
|
||||||
|
#[IsGranted('ROLE_GROUPS_MANAGER')]
|
||||||
|
class SplitPeriodController extends AbstractController
|
||||||
|
{
|
||||||
|
use HxTrait;
|
||||||
|
use RedirectsToEditFormTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly AccommodationBookingService $bookingService,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route(
|
||||||
|
'/admin/accommodation-booking/{id}/period/split/{position}',
|
||||||
|
name: 'app_admin_accommodationbooking_period_split',
|
||||||
|
requirements: ['position' => 'leading|trailing'],
|
||||||
|
)]
|
||||||
|
public function index(AccommodationBooking $booking, AccommodationBookingPeriodPosition $position, Request $request): Response
|
||||||
|
{
|
||||||
|
// One period per side. The edit page only offers the free sides, so this catches a page
|
||||||
|
// that was open while somebody else split the same side.
|
||||||
|
if (!$booking->canSplitOffPeriod($position)) {
|
||||||
|
$this->addFlash('error', AccommodationBookingPeriodPosition::Leading === $position
|
||||||
|
? 'Am Anfang wurde bereits ein Zeitraum abgeteilt.'
|
||||||
|
: 'Am Ende wurde bereits ein Zeitraum abgeteilt.');
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dto = new AccommodationBookingPeriodDto(1, [new AccommodationBookingPeriodLineDto()]);
|
||||||
|
$form = $this->createForm(AccommodationBookingPeriodType::class, $dto, [
|
||||||
|
'currency' => $booking->getPricingCurrency() ?? $booking->getAccommodation()?->getCurrency() ?? 'EUR',
|
||||||
|
'hx_post' => $request->getRequestUri(),
|
||||||
|
]);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
|
try {
|
||||||
|
$violations = $this->bookingService->splitOffPeriod($booking, $position, $dto);
|
||||||
|
|
||||||
|
foreach ($violations as $violation) {
|
||||||
|
$form->addError(new FormError((string) $violation->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === count($violations)) {
|
||||||
|
$this->addFlash('success', 'Der Zeitraum wurde abgeteilt.');
|
||||||
|
|
||||||
|
$this->logger->info('Split off a period of accommodation booking', [
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
'position' => $position->value,
|
||||||
|
'nights' => $dto->nights,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->editUrl($booking, $request));
|
||||||
|
}
|
||||||
|
} catch (ImplausibleBookingPriceException $e) {
|
||||||
|
$this->logger->error('Refused to split off a period over an implausible accommodation booking total', [
|
||||||
|
'exception' => $e,
|
||||||
|
'id' => $booking->getId(),
|
||||||
|
]);
|
||||||
|
$form->addError(new FormError(ImplausibleBookingPriceException::FORM_ERROR_MESSAGE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderModal($booking, $position, $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param FormInterface<AccommodationBookingPeriodDto> $form */
|
||||||
|
private function renderModal(AccommodationBooking $booking, AccommodationBookingPeriodPosition $position, FormInterface $form): Response
|
||||||
|
{
|
||||||
|
return $this->render('admin/accommodation_booking/modal_period.html.twig', [
|
||||||
|
'booking' => $booking,
|
||||||
|
'form' => $form,
|
||||||
|
'title' => AccommodationBookingPeriodPosition::Leading === $position
|
||||||
|
? 'Zeitraum am Anfang abteilen'
|
||||||
|
: 'Zeitraum am Ende abteilen',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Controller\Api;
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
use App\Model\TravelExportQuery;
|
use App\Model\Export;
|
||||||
|
use App\Model\ExportQuery;
|
||||||
|
use App\Service\ProductExportBuilder;
|
||||||
use App\Service\TravelExportBuilder;
|
use App\Service\TravelExportBuilder;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
@@ -29,6 +31,7 @@ class ExportController extends AbstractController
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly TravelExportBuilder $travelExportBuilder,
|
private readonly TravelExportBuilder $travelExportBuilder,
|
||||||
|
private readonly ProductExportBuilder $productExportBuilder,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,13 +44,31 @@ class ExportController extends AbstractController
|
|||||||
#[Route(path: '/travels', name: 'api_exports_travels', methods: ['GET'])]
|
#[Route(path: '/travels', name: 'api_exports_travels', methods: ['GET'])]
|
||||||
public function travels(
|
public function travels(
|
||||||
#[MapQueryString(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)]
|
#[MapQueryString(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)]
|
||||||
TravelExportQuery $query = new TravelExportQuery(),
|
ExportQuery $query = new ExportQuery(),
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
// Deliberately not wrapped in a catch that answers 200 with an error body, the way
|
// Deliberately not wrapped in a catch that answers 200 with an error body, the way
|
||||||
// TravelController::hotelAvailability() does: the consumer's retry logic keys on
|
// TravelController::hotelAvailability() does: the consumer's retry logic keys on
|
||||||
// status codes, so a failure here has to surface as a 5xx.
|
// status codes, so a failure here has to surface as a 5xx.
|
||||||
$export = $this->travelExportBuilder->build();
|
return $this->paginate($this->travelExportBuilder->build(), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every travel date x hotel pair with its whole record, unfiltered, paginated.
|
||||||
|
*
|
||||||
|
* The website's product import. Same grain, envelope and failure behaviour as travels();
|
||||||
|
* the rows carry rooms, prices, services and selection groups instead of the
|
||||||
|
* disposition subset, and nothing is dropped for the consumer.
|
||||||
|
*/
|
||||||
|
#[Route(path: '/products', name: 'api_exports_products', methods: ['GET'])]
|
||||||
|
public function products(
|
||||||
|
#[MapQueryString(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)]
|
||||||
|
ExportQuery $query = new ExportQuery(),
|
||||||
|
): JsonResponse {
|
||||||
|
return $this->paginate($this->productExportBuilder->build(), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function paginate(Export $export, ExportQuery $query): JsonResponse
|
||||||
|
{
|
||||||
$total = count($export->rows);
|
$total = count($export->rows);
|
||||||
|
|
||||||
return $this->json([
|
return $this->json([
|
||||||
@@ -59,6 +80,7 @@ class ExportController extends AbstractController
|
|||||||
'totalPages' => (int) ceil($total / $query->perPage),
|
'totalPages' => (int) ceil($total / $query->perPage),
|
||||||
'skipped' => $export->skipped,
|
'skipped' => $export->skipped,
|
||||||
'pickupsWithoutMasterData' => $export->pickupsWithoutMasterData,
|
'pickupsWithoutMasterData' => $export->pickupsWithoutMasterData,
|
||||||
|
'sourceGeneratedAt' => $export->sourceGeneratedAt?->format('c'),
|
||||||
'generatedAt' => $export->generatedAt->format('c'),
|
'generatedAt' => $export->generatedAt->format('c'),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Controller\Api;
|
namespace App\Controller\Api;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\XmlExportInfo;
|
||||||
use League\Flysystem\FilesystemOperator;
|
use League\Flysystem\FilesystemOperator;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
@@ -16,23 +17,15 @@ class LastUpdateController extends AbstractController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A missing or unreadable marker answers `{"timestamp": null}`, never a 500: consumers
|
||||||
|
* poll this for change detection and treat null as "unknown".
|
||||||
|
*/
|
||||||
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
#[Route(path: '/last-update', name: 'api_last_update', methods: ['GET'])]
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
if (false === $this->xmlExport->has('uebertragung.info')) {
|
$info = XmlExportInfo::fromStorage($this->xmlExport);
|
||||||
$lastUploadAt = null;
|
|
||||||
} else {
|
|
||||||
$file = $this->xmlExport->read('uebertragung.info');
|
|
||||||
$lines = explode("\n", $file);
|
|
||||||
$line = trim($lines[0]);
|
|
||||||
|
|
||||||
if (true === empty($line)) {
|
return $this->json(['timestamp' => $info?->lastTransfer->format('Y-m-d H:i:s')]);
|
||||||
$lastUploadAt = null;
|
|
||||||
} else {
|
|
||||||
$lastUploadAt = \DateTime::createFromFormat('d.m.Y H:i:s', $line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->json(['timestamp' => $lastUploadAt->format('Y-m-d H:i:s')]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,9 +11,11 @@ use App\Exception\NoRoomsAvailableException;
|
|||||||
use App\Exception\TravelNotFoundException;
|
use App\Exception\TravelNotFoundException;
|
||||||
use App\Htmx\HxTrait;
|
use App\Htmx\HxTrait;
|
||||||
use App\Model\BookingQueryParams;
|
use App\Model\BookingQueryParams;
|
||||||
|
use App\Model\PurchaseFlow;
|
||||||
use App\Service\BookingConfigurator;
|
use App\Service\BookingConfigurator;
|
||||||
use App\Service\BookingSessionManager;
|
use App\Service\BookingSessionManager;
|
||||||
use App\Service\BookingSummaryAssembler;
|
use App\Service\BookingSummaryAssembler;
|
||||||
|
use App\Service\PurchaseFlowResolver;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -36,6 +38,7 @@ class IndexController extends AbstractController
|
|||||||
private readonly BookingSessionManager $bookingSessionService,
|
private readonly BookingSessionManager $bookingSessionService,
|
||||||
private readonly AgencyLoader $agencyLoader,
|
private readonly AgencyLoader $agencyLoader,
|
||||||
private readonly BookingSummaryAssembler $summaryDataService,
|
private readonly BookingSummaryAssembler $summaryDataService,
|
||||||
|
private readonly PurchaseFlowResolver $purchaseFlowResolver,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +106,7 @@ class IndexController extends AbstractController
|
|||||||
|
|
||||||
// Create fresh booking session with the provided parameters
|
// Create fresh booking session with the provided parameters
|
||||||
$bookingDto = $this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
|
$bookingDto = $this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
|
||||||
|
$this->purchaseFlowResolver->markStarted($request, PurchaseFlow::Booking);
|
||||||
|
|
||||||
// Warm the CMS cache early so data is available on the login page
|
// Warm the CMS cache early so data is available on the login page
|
||||||
$this->summaryDataService->getCmsDataForProduct(
|
$this->summaryDataService->getCmsDataForProduct(
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Form\Model\BookingDto;
|
use App\Form\Model\BookingDto;
|
||||||
|
use App\Model\PurchaseFlow;
|
||||||
use App\Service\BookingSessionManager;
|
use App\Service\BookingSessionManager;
|
||||||
use App\Service\BookingSummaryAssembler;
|
use App\Service\BookingSummaryAssembler;
|
||||||
|
use App\Service\PurchaseFlowResolver;
|
||||||
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
|
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -23,31 +25,31 @@ class SecurityController extends AbstractController
|
|||||||
BookingSessionManager $bookingSessionService,
|
BookingSessionManager $bookingSessionService,
|
||||||
BookingSummaryAssembler $summaryDataService,
|
BookingSummaryAssembler $summaryDataService,
|
||||||
ClientManagerInterface $clientManager,
|
ClientManagerInterface $clientManager,
|
||||||
|
PurchaseFlowResolver $purchaseFlowResolver,
|
||||||
): Response {
|
): Response {
|
||||||
// flag this request in the session as external OAuth2 request if
|
// flag this request in the session as external OAuth2 request if
|
||||||
// applicable to immediately logout the current user after successful
|
// applicable to immediately logout the current user after successful
|
||||||
// authentication (see App\EventListener\AuthorizationCodeListener).
|
// authentication (see App\EventListener\AuthorizationCodeListener).
|
||||||
// Read before the booking flow is decided, because it overrules it.
|
// Read before the purchase flow is decided, because it overrules it.
|
||||||
$session = $request->getSession();
|
$session = $request->getSession();
|
||||||
$targetPath = $session->get('_security.main.target_path');
|
$targetPath = $session->get('_security.main.target_path');
|
||||||
$isOauth2 = \is_string($targetPath) && str_contains($targetPath, '/authorize');
|
$isOauth2 = \is_string($targetPath) && str_contains($targetPath, '/authorize');
|
||||||
$session->set('_oauth2', $isOauth2);
|
$session->set('_oauth2', $isOauth2);
|
||||||
|
|
||||||
// Check if this is a booking flow (BookingDto exists in session)
|
// A purchase flow (booking or voucher) uses this page as its optional sign-in step
|
||||||
$bookingDto = $bookingSessionService->getBookingDto($request, BookingDto::MODE_CREATE);
|
$pendingFlow = $purchaseFlowResolver->resolvePending($request);
|
||||||
$hasPendingBooking = null !== $bookingDto;
|
|
||||||
|
|
||||||
// A pending authorization wins over a half-finished booking. Otherwise the target path
|
// A pending authorization wins over a half-finished purchase. Otherwise the target path
|
||||||
// below is overwritten with booking step 1, the user is sent there after logging in, and
|
// below is overwritten with the flow's first step, the user is sent there after logging in,
|
||||||
// the application that asked for the authorization never receives its code.
|
// and the application that asked for the authorization never receives its code.
|
||||||
$isBookingFlow = $hasPendingBooking && false === $isOauth2;
|
$purchaseFlow = false === $isOauth2 ? $pendingFlow : null;
|
||||||
|
|
||||||
// If authenticated and in booking flow, proceed to Step 1
|
// If authenticated and in a purchase flow, proceed to its first step
|
||||||
if (null !== $this->getUser() && true === $hasPendingBooking) {
|
if (null !== $this->getUser() && null !== $pendingFlow) {
|
||||||
return $this->redirectToRoute('app_booking_create_step_1');
|
return $this->redirectToRoute($pendingFlow->firstStepRoute());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If authenticated but not in booking flow, redirect to dashboard
|
// If authenticated but not in a purchase flow, redirect to dashboard
|
||||||
if (null !== $this->getUser()) {
|
if (null !== $this->getUser()) {
|
||||||
return $this->redirectToRoute('app_account');
|
return $this->redirectToRoute('app_account');
|
||||||
}
|
}
|
||||||
@@ -55,22 +57,25 @@ class SecurityController extends AbstractController
|
|||||||
$error = $authenticationUtils->getLastAuthenticationError();
|
$error = $authenticationUtils->getLastAuthenticationError();
|
||||||
$lastUsername = $authenticationUtils->getLastUsername();
|
$lastUsername = $authenticationUtils->getLastUsername();
|
||||||
|
|
||||||
// For booking flow, set target path to Step 1 (after successful auth, redirect there)
|
// For a purchase flow, continue with its first step after successful auth
|
||||||
if (true === $isBookingFlow) {
|
if (null !== $purchaseFlow) {
|
||||||
$session->set('_security.main.target_path', $this->generateUrl('app_booking_create_step_1'));
|
$session->set('_security.main.target_path', $this->generateUrl($purchaseFlow->firstStepRoute()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render booking login template if in booking flow, the self-explaining one when another
|
// Render the flow's login template if in a purchase flow, the self-explaining one when
|
||||||
// application sent them here to authorize it, otherwise standard login
|
// another application sent them here to authorize it, otherwise standard login
|
||||||
$template = match (true) {
|
$template = match (true) {
|
||||||
$isBookingFlow => 'booking/create/authenticate.html.twig',
|
null !== $purchaseFlow => $purchaseFlow->authenticateTemplate(),
|
||||||
$isOauth2 => 'security/login_oauth2.html.twig',
|
$isOauth2 => 'security/login_oauth2.html.twig',
|
||||||
default => 'security/login.html.twig',
|
default => 'security/login.html.twig',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch CMS data for booking flow (uses cache warmed in IndexController)
|
// Fetch travel and CMS data for the booking flow (uses cache warmed in IndexController)
|
||||||
|
$bookingDto = PurchaseFlow::Booking === $purchaseFlow
|
||||||
|
? $bookingSessionService->getBookingDto($request, BookingDto::MODE_CREATE)
|
||||||
|
: null;
|
||||||
$cmsData = null;
|
$cmsData = null;
|
||||||
if (true === $isBookingFlow) {
|
if (null !== $bookingDto) {
|
||||||
$cmsData = $summaryDataService->getCmsDataForProduct(
|
$cmsData = $summaryDataService->getCmsDataForProduct(
|
||||||
$bookingDto->travel->productCode,
|
$bookingDto->travel->productCode,
|
||||||
$bookingDto->travel->hotel?->code
|
$bookingDto->travel->hotel?->code
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use App\Htmx\HxTrait;
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use App\Service\VoucherThumbnailResolver;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared base for the steps of the voucher purchase flow.
|
||||||
|
*/
|
||||||
|
abstract class AbstractVoucherPurchaseController extends AbstractController
|
||||||
|
{
|
||||||
|
use HxTrait;
|
||||||
|
|
||||||
|
public const array STEP_ROUTES = [
|
||||||
|
1 => 'app_voucher_step_1',
|
||||||
|
2 => 'app_voucher_step_2',
|
||||||
|
3 => 'app_voucher_step_3',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected readonly VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
protected readonly VoucherThumbnailResolver $thumbnailResolver,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createSessionExpiredResponse(Request $request): Response
|
||||||
|
{
|
||||||
|
$this->addFlash('error', 'Deine Sitzung ist abgelaufen. Bitte starte den Gutscheinkauf neu.');
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->generateUrl('app_voucher_error'));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateStepAccess(VoucherPurchaseDto $dto, int $expectedStep): ?RedirectResponse
|
||||||
|
{
|
||||||
|
if ($expectedStep > $dto->currentStep) {
|
||||||
|
$this->addFlash('error', 'Bitte erst die vorherigen Schritte abschließen.');
|
||||||
|
|
||||||
|
return $this->redirectToStep($dto->currentStep);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function redirectToStep(int $step): RedirectResponse
|
||||||
|
{
|
||||||
|
return $this->redirectToRoute(self::STEP_ROUTES[$step] ?? self::STEP_ROUTES[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context shared by every step template: the sidebar summary and the step pagination.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
protected function createStepContext(VoucherPurchaseDto $dto): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'voucher' => $dto,
|
||||||
|
'voucherThumbnail' => null !== $dto->template ? $this->thumbnailResolver->resolve($dto->template) : null,
|
||||||
|
'stepRoutes' => self::STEP_ROUTES,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\Exception\VoucherShopUnavailableException;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use App\Htmx\HxTrait;
|
||||||
|
use App\Model\PurchaseFlow;
|
||||||
|
use App\Service\PurchaseFlowResolver;
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use App\Service\VoucherTemplateProvider;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry, cancellation and error pages of the voucher purchase flow, which replaces the voucher
|
||||||
|
* shop hosted by BusProNet (maske_gutschein.php).
|
||||||
|
*/
|
||||||
|
class IndexController extends AbstractController
|
||||||
|
{
|
||||||
|
use HxTrait;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
private readonly VoucherTemplateProvider $templateProvider,
|
||||||
|
private readonly PurchaseFlowResolver $purchaseFlowResolver,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders a loading page that posts to init, as the booking flow does.
|
||||||
|
*/
|
||||||
|
#[Route('/gutschein', name: 'app_voucher', methods: ['GET'])]
|
||||||
|
public function index(#[MapQueryParameter('r')] ?string $returnUrl = null): Response
|
||||||
|
{
|
||||||
|
return $this->render('voucher/index.html.twig', [
|
||||||
|
'returnUrl' => $returnUrl,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a fresh purchase and sends the visitor to the login page (sign in or continue as guest).
|
||||||
|
*
|
||||||
|
* POST-only for the same reason as app_booking_create_init: it resets session state and calls
|
||||||
|
* BusPro, so nothing that speculatively fetches URLs may trigger it.
|
||||||
|
*/
|
||||||
|
#[Route('/gutschein/init', name: 'app_voucher_init', methods: ['POST'])]
|
||||||
|
public function init(Request $request, #[MapQueryParameter('r')] ?string $returnUrl = null): Response
|
||||||
|
{
|
||||||
|
$this->sessionManager->clear($request);
|
||||||
|
$this->sessionManager->storeReturnUrl($request, $returnUrl);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$templates = $this->templateProvider->getTemplates();
|
||||||
|
$paymentMethod = $this->templateProvider->getPaymentMethod();
|
||||||
|
} catch (VoucherShopUnavailableException) {
|
||||||
|
$this->addFlash('error', 'Gutscheine können gerade nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->generateUrl('app_voucher_error'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$dto = new VoucherPurchaseDto();
|
||||||
|
$dto->minAmount = $templates->minAmount;
|
||||||
|
$dto->maxAmount = $templates->maxAmount;
|
||||||
|
$dto->paymentMethod = $paymentMethod;
|
||||||
|
if (1 === \count($templates->templates)) {
|
||||||
|
$dto->template = $templates->templates[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
$this->purchaseFlowResolver->markStarted($request, PurchaseFlow::Voucher);
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->generateUrl('app_login'));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/abbrechen', name: 'app_voucher_cancel', methods: ['GET', 'POST'])]
|
||||||
|
public function cancel(Request $request): Response
|
||||||
|
{
|
||||||
|
if (Request::METHOD_POST !== $request->getMethod()) {
|
||||||
|
return $this->render('voucher/modal_cancel.html.twig');
|
||||||
|
}
|
||||||
|
|
||||||
|
$returnUrl = $this->sessionManager->getReturnUrl($request);
|
||||||
|
$this->sessionManager->clear($request);
|
||||||
|
|
||||||
|
// Without this, a later login would send the user back into the cancelled purchase
|
||||||
|
$request->getSession()->remove('_security.main.target_path');
|
||||||
|
|
||||||
|
if (null !== $this->getUser()) {
|
||||||
|
$this->addFlash('info', 'Gutscheinkauf abgebrochen.');
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->generateUrl('app_account'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/fehler', name: 'app_voucher_error', methods: ['GET'])]
|
||||||
|
public function error(Request $request): Response
|
||||||
|
{
|
||||||
|
return $this->render('booking/create/error.html.twig', [
|
||||||
|
'returnUrl' => $this->sessionManager->getReturnUrl($request),
|
||||||
|
'defaultErrorMessage' => 'Es ist ein Fehler beim Gutscheinkauf aufgetreten.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Model\Notification;
|
||||||
|
use App\Exception\VoucherSessionNotFoundException;
|
||||||
|
use App\Exception\VoucherShopUnavailableException;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use App\Form\VoucherPurchaseStep1Type;
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use App\Service\VoucherTemplateProvider;
|
||||||
|
use App\Service\VoucherThumbnailResolver;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 1: design, von/für and value, with a PDF preview rendered by BusPro.
|
||||||
|
*/
|
||||||
|
class Step1Controller extends AbstractVoucherPurchaseController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
VoucherThumbnailResolver $thumbnailResolver,
|
||||||
|
private readonly VoucherTemplateProvider $templateProvider,
|
||||||
|
private readonly ApiClient $apiClient,
|
||||||
|
private readonly ValidatorInterface $validator,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
parent::__construct($sessionManager, $thumbnailResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/auswahl', name: 'app_voucher_step_1')]
|
||||||
|
public function index(Request $request): Response
|
||||||
|
{
|
||||||
|
$dto = $this->sessionManager->find($request);
|
||||||
|
if (null === $dto) {
|
||||||
|
return $this->createSessionExpiredResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form = $this->createStepForm($dto);
|
||||||
|
} catch (VoucherShopUnavailableException) {
|
||||||
|
return $this->createShopUnavailableResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||||
|
$dto->currentStep = 2;
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_voucher_step_2');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes over the current input without validating it and refreshes the summary.
|
||||||
|
*/
|
||||||
|
#[Route('/gutschein/auswahl/aktualisieren', name: 'app_voucher_step_1_refresh', methods: ['POST'])]
|
||||||
|
public function refresh(Request $request): Response
|
||||||
|
{
|
||||||
|
$dto = $this->sessionManager->find($request);
|
||||||
|
if (null === $dto) {
|
||||||
|
return $this->createSessionExpiredResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form = $this->createStepForm($dto, false);
|
||||||
|
} catch (VoucherShopUnavailableException) {
|
||||||
|
return $this->createShopUnavailableResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
|
||||||
|
return $this->htmxOobResponse('voucher/step_1.html.twig', ['voucher_summary'], [
|
||||||
|
...$this->createStepContext($dto),
|
||||||
|
'form' => $form->createView(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes over the current input like refresh() and opens the preview modal, whose frame loads
|
||||||
|
* the PDF from previewPdf().
|
||||||
|
*/
|
||||||
|
#[Route('/gutschein/auswahl/vorschau', name: 'app_voucher_preview', methods: ['POST'])]
|
||||||
|
public function preview(Request $request): Response
|
||||||
|
{
|
||||||
|
$dto = $this->sessionManager->find($request);
|
||||||
|
if (null === $dto) {
|
||||||
|
return $this->createSessionExpiredResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$form = $this->createStepForm($dto, false);
|
||||||
|
} catch (VoucherShopUnavailableException) {
|
||||||
|
return $this->createShopUnavailableResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
|
||||||
|
return $this->render('voucher/modal_preview.html.twig', [
|
||||||
|
'previewable' => $this->isPreviewable($dto),
|
||||||
|
// busts the browser cache of the frame, the URL is otherwise the same for every input
|
||||||
|
'previewVersion' => bin2hex(random_bytes(4)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/vorschau.pdf', name: 'app_voucher_preview_pdf', methods: ['GET'])]
|
||||||
|
public function previewPdf(Request $request): Response
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$dto = $this->sessionManager->get($request);
|
||||||
|
} catch (VoucherSessionNotFoundException) {
|
||||||
|
return $this->createPreviewErrorResponse('Deine Sitzung ist abgelaufen. Bitte starte den Gutscheinkauf neu.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $this->isPreviewable($dto)) {
|
||||||
|
return $this->createPreviewErrorResponse('Für die Vorschau bitte zuerst Motiv, Von, Für und Gutscheinwert angeben.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read-only from here on: release the session lock, so the page's other requests do not
|
||||||
|
// wait the seconds BusPro takes to render the PDF.
|
||||||
|
$request->getSession()->save();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$preview = $this->apiClient->getVoucherPreview($dto);
|
||||||
|
} catch (ApiClientException $e) {
|
||||||
|
$this->logger->error('Voucher preview failed', ['error' => $e->getMessage()]);
|
||||||
|
|
||||||
|
return $this->createPreviewErrorResponse('Die Vorschau ist gerade nicht verfügbar. Bitte versuche es später noch einmal.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($preview instanceof Notification) {
|
||||||
|
$this->logger->warning('Voucher preview rejected', ['code' => $preview->code, 'message' => $preview->message]);
|
||||||
|
|
||||||
|
return $this->createPreviewErrorResponse($preview->message ?? 'Die Vorschau ist gerade nicht verfügbar.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new Response($preview->pdf, Response::HTTP_OK, ['Content-Type' => 'application/pdf']);
|
||||||
|
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
|
||||||
|
ResponseHeaderBag::DISPOSITION_INLINE,
|
||||||
|
'gutschein-vorschau.pdf'
|
||||||
|
));
|
||||||
|
$response->setPrivate();
|
||||||
|
$response->headers->addCacheControlDirective('no-store');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return FormInterface<VoucherPurchaseDto>
|
||||||
|
*
|
||||||
|
* @throws VoucherShopUnavailableException
|
||||||
|
*/
|
||||||
|
private function createStepForm(VoucherPurchaseDto $dto, bool $validate = true): FormInterface
|
||||||
|
{
|
||||||
|
$templates = $this->templateProvider->getTemplates();
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'templates' => $templates->templates,
|
||||||
|
'min_amount' => $dto->minAmount,
|
||||||
|
'max_amount' => $dto->maxAmount,
|
||||||
|
];
|
||||||
|
if (false === $validate) {
|
||||||
|
$options['validation_groups'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->createForm(VoucherPurchaseStep1Type::class, $dto, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormInterface<VoucherPurchaseDto> $form
|
||||||
|
*/
|
||||||
|
private function renderStep(VoucherPurchaseDto $dto, FormInterface $form): Response
|
||||||
|
{
|
||||||
|
$templates = $this->templateProvider->getTemplates();
|
||||||
|
|
||||||
|
return $this->render('voucher/step_1.html.twig', [
|
||||||
|
...$this->createStepContext($dto),
|
||||||
|
'form' => $form,
|
||||||
|
'thumbnails' => $this->thumbnailResolver->resolveAll($templates->templates),
|
||||||
|
'previewable' => $this->isPreviewable($dto),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The preview takes what step 1 accepts: BusPro refuses it without the names (604/605), and
|
||||||
|
* this keeps the button and the route to one rule, the step's own validation group.
|
||||||
|
*/
|
||||||
|
private function isPreviewable(VoucherPurchaseDto $dto): bool
|
||||||
|
{
|
||||||
|
return 0 === \count($this->validator->validate($dto, null, ['voucher_step_1']));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createShopUnavailableResponse(Request $request): Response
|
||||||
|
{
|
||||||
|
$this->addFlash('error', 'Gutscheine können gerade nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->htmxRedirect($request, $this->generateUrl('app_voucher_error'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createPreviewErrorResponse(string $message): Response
|
||||||
|
{
|
||||||
|
return $this->render('voucher/preview_error.html.twig', ['message' => $message], new Response('', Response::HTTP_UNPROCESSABLE_ENTITY));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\Entity\User;
|
||||||
|
use App\Form\VoucherPurchaseStep2Type;
|
||||||
|
use App\Service\ParticipantDataPrefiller;
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use App\Service\VoucherThumbnailResolver;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 2: the buyer (rechnungsempfänger), prefilled for signed-in accounts. Payment is fixed to
|
||||||
|
* transfer.
|
||||||
|
*/
|
||||||
|
class Step2Controller extends AbstractVoucherPurchaseController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
VoucherThumbnailResolver $thumbnailResolver,
|
||||||
|
private readonly ParticipantDataPrefiller $personalDataPrefiller,
|
||||||
|
) {
|
||||||
|
parent::__construct($sessionManager, $thumbnailResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/kaeufer', name: 'app_voucher_step_2')]
|
||||||
|
public function index(Request $request): Response
|
||||||
|
{
|
||||||
|
$dto = $this->sessionManager->find($request);
|
||||||
|
if (null === $dto) {
|
||||||
|
return $this->createSessionExpiredResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $redirect = $this->validateStepAccess($dto, 2)) {
|
||||||
|
return $redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $this->getUser();
|
||||||
|
if ($user instanceof User && false === $dto->hasBuyerData()) {
|
||||||
|
$personalData = $this->personalDataPrefiller->fetchPersonalData($user);
|
||||||
|
if (null !== $personalData) {
|
||||||
|
$dto->prefillBuyer($personalData, $user->getEmail());
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $this->createForm(VoucherPurchaseStep2Type::class, $dto);
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||||
|
$dto->currentStep = 3;
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_voucher_step_3');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('voucher/step_2.html.twig', [
|
||||||
|
...$this->createStepContext($dto),
|
||||||
|
'form' => $form,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\TimeoutException;
|
||||||
|
use App\BusProNet\Model\Notification;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use App\Form\VoucherPurchaseStep3Type;
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use App\Service\VoucherSaleRejectionMapper;
|
||||||
|
use App\Service\VoucherThumbnailResolver;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 3: overview, the two required confirmations and the purchase.
|
||||||
|
*
|
||||||
|
* Every visit runs GUTSCHEINBUCHUNG as a dry run (buchungsart Anfrage) first, which applies BusPro's
|
||||||
|
* full validation without issuing anything, and the buy button is only offered when it passes. The
|
||||||
|
* purchase sends the same payload with buchungsart Buchung.
|
||||||
|
*
|
||||||
|
* Every HINWEIS is a rejection on this path, 650 included, so Notification::isError() is not used.
|
||||||
|
*/
|
||||||
|
class Step3Controller extends AbstractVoucherPurchaseController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
VoucherThumbnailResolver $thumbnailResolver,
|
||||||
|
private readonly ApiClient $apiClient,
|
||||||
|
private readonly VoucherSaleRejectionMapper $rejectionMapper,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
parent::__construct($sessionManager, $thumbnailResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/uebersicht', name: 'app_voucher_step_3')]
|
||||||
|
public function index(Request $request): Response
|
||||||
|
{
|
||||||
|
$dto = $this->sessionManager->find($request);
|
||||||
|
if (null === $dto) {
|
||||||
|
// also the second of two submits: the first one cleared the session before redirecting
|
||||||
|
return $this->createSessionExpiredResponse($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $redirect = $this->validateStepAccess($dto, 3)) {
|
||||||
|
return $redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
$form = $this->createForm(VoucherPurchaseStep3Type::class, $dto, [
|
||||||
|
'amount' => $dto->amount ?? 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (false === $request->isMethod(Request::METHOD_POST)) {
|
||||||
|
$dto->termsAccepted = false;
|
||||||
|
$dto->purchaseConfirmed = false;
|
||||||
|
|
||||||
|
return $this->runDryRun($request, $dto, $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->handleRequest($request);
|
||||||
|
|
||||||
|
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||||
|
return $this->purchase($request, $dto, $form);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormInterface<VoucherPurchaseDto> $form
|
||||||
|
*/
|
||||||
|
private function runDryRun(Request $request, VoucherPurchaseDto $dto, FormInterface $form): Response
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->apiClient->createVoucherSaleInquiry($dto);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->logger->error('Voucher sale inquiry failed', ['exception' => $e->getMessage()]);
|
||||||
|
$this->addFlash('error', 'Der Gutscheinkauf konnte gerade nicht geprüft werden. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response instanceof Notification) {
|
||||||
|
return $this->handleRejection($request, $dto, $form, $response, 'Voucher sale inquiry rejected');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $response->isInquiryValid()) {
|
||||||
|
$this->logger->error('Voucher sale inquiry unsuccessful', ['status' => $response->status]);
|
||||||
|
$this->addFlash('error', 'Der Gutschein kann gerade nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormInterface<VoucherPurchaseDto> $form
|
||||||
|
*/
|
||||||
|
private function purchase(Request $request, VoucherPurchaseDto $dto, FormInterface $form): Response
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->apiClient->createVoucherSale($dto);
|
||||||
|
} catch (TimeoutException $e) {
|
||||||
|
// The purchase may have gone through on BusPro's side, so a blind retry could buy twice
|
||||||
|
$this->logger->error('Voucher sale timeout', ['exception' => $e->getMessage()]);
|
||||||
|
$this->addFlash('error', 'Die Anfrage hat zu lange gedauert. Möglicherweise wurde der Gutschein trotzdem gekauft. Bitte wende dich an den Kundenservice, bevor du es erneut versuchst.');
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, false);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->logger->error('Voucher sale exception', ['exception' => $e->getMessage()]);
|
||||||
|
$this->addFlash('error', 'Ein technischer Fehler ist aufgetreten. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response instanceof Notification) {
|
||||||
|
return $this->handleRejection($request, $dto, $form, $response, 'Voucher sale rejected');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $response->isSaleSuccessful()) {
|
||||||
|
$this->logger->error('Voucher sale unsuccessful', ['status' => $response->status]);
|
||||||
|
$this->addFlash('error', 'Der Gutschein konnte nicht gekauft werden. Bitte versuche es später noch einmal.');
|
||||||
|
|
||||||
|
return $this->renderStep($dto, $form, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleared before the redirect, so a second submit finds no purchase and cannot buy twice
|
||||||
|
$this->sessionManager->clear($request);
|
||||||
|
|
||||||
|
// The redemption code stays out of the log and the page: the voucher is only paid for once
|
||||||
|
// the transfer arrives, and BusPro mails it then.
|
||||||
|
$this->logger->info('Voucher successfully sold.', [
|
||||||
|
'voucher_id' => $response->voucherId,
|
||||||
|
'voucher_number' => $response->voucherNumber,
|
||||||
|
'invoice_number' => $response->invoiceNumber,
|
||||||
|
'template_id' => $dto->template?->id,
|
||||||
|
'amount' => $dto->amount,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->addFlash('voucher_number', $response->voucherNumber);
|
||||||
|
$this->addFlash('voucher_invoice_number', $response->invoiceNumber);
|
||||||
|
$this->addFlash('voucher_total', $response->price ?? (float) $dto->amount);
|
||||||
|
$this->addFlash('voucher_label', $dto->template?->label);
|
||||||
|
$this->addFlash('voucher_email', $response->email ?? $dto->email);
|
||||||
|
|
||||||
|
return $this->redirectToRoute('app_voucher_success');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the visitor to the step that owns the complaint, or keeps them here without a buy
|
||||||
|
* button when the complaint is about nothing they can change.
|
||||||
|
*
|
||||||
|
* @param FormInterface<VoucherPurchaseDto> $form
|
||||||
|
*/
|
||||||
|
private function handleRejection(
|
||||||
|
Request $request,
|
||||||
|
VoucherPurchaseDto $dto,
|
||||||
|
FormInterface $form,
|
||||||
|
Notification $notification,
|
||||||
|
string $logMessage,
|
||||||
|
): Response {
|
||||||
|
$step = $this->rejectionMapper->stepFor($notification);
|
||||||
|
|
||||||
|
$this->logger->warning($logMessage, [
|
||||||
|
'code' => $notification->code,
|
||||||
|
'message' => $notification->message,
|
||||||
|
'step' => $step,
|
||||||
|
]);
|
||||||
|
$this->addFlash('error', $notification->message ?? 'Der Gutschein kann so nicht gekauft werden.');
|
||||||
|
|
||||||
|
if (VoucherSaleRejectionMapper::STEP_OVERVIEW === $step) {
|
||||||
|
return $this->renderStep($dto, $form, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dto->currentStep = $step;
|
||||||
|
$this->sessionManager->save($request, $dto);
|
||||||
|
|
||||||
|
return $this->redirectToStep($step);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param FormInterface<VoucherPurchaseDto> $form
|
||||||
|
*/
|
||||||
|
private function renderStep(VoucherPurchaseDto $dto, FormInterface $form, bool $purchasable): Response
|
||||||
|
{
|
||||||
|
return $this->render('voucher/step_3.html.twig', [
|
||||||
|
...$this->createStepContext($dto),
|
||||||
|
'form' => $form,
|
||||||
|
'purchasable' => $purchasable,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Voucher;
|
||||||
|
|
||||||
|
use App\Service\VoucherPurchaseSessionManager;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page after a completed voucher purchase. Its data comes as flashes, so a reload or a direct
|
||||||
|
* visit falls back to the return URL.
|
||||||
|
*/
|
||||||
|
class SuccessController extends AbstractController
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly VoucherPurchaseSessionManager $sessionManager,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/gutschein/erfolg', name: 'app_voucher_success')]
|
||||||
|
public function success(Request $request): Response
|
||||||
|
{
|
||||||
|
$returnUrl = $this->sessionManager->getReturnUrl($request);
|
||||||
|
$session = $request->getSession();
|
||||||
|
|
||||||
|
if (!$session instanceof FlashBagAwareSessionInterface) {
|
||||||
|
return $this->redirect($returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
$flashBag = $session->getFlashBag();
|
||||||
|
$voucherNumber = $flashBag->get('voucher_number')[0] ?? null;
|
||||||
|
$invoiceNumber = $flashBag->get('voucher_invoice_number')[0] ?? null;
|
||||||
|
$total = $flashBag->get('voucher_total')[0] ?? null;
|
||||||
|
$label = $flashBag->get('voucher_label')[0] ?? null;
|
||||||
|
$email = $flashBag->get('voucher_email')[0] ?? null;
|
||||||
|
|
||||||
|
// the total is always set on a completed purchase, the voucher number only if BusPro sends it
|
||||||
|
if (null === $total) {
|
||||||
|
return $this->redirect($returnUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render('voucher/success.html.twig', [
|
||||||
|
'voucherNumber' => $voucherNumber,
|
||||||
|
'invoiceNumber' => $invoiceNumber,
|
||||||
|
'total' => $total,
|
||||||
|
'label' => $label,
|
||||||
|
'email' => $email,
|
||||||
|
'returnUrl' => $returnUrl,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,10 +10,13 @@ use App\Entity\TimestampableEntity;
|
|||||||
use App\Entity\TimestampableEntityInterface;
|
use App\Entity\TimestampableEntityInterface;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||||
|
use App\Enum\Groups\AccommodationBookingPeriodPosition;
|
||||||
use App\Enum\Groups\AccommodationBookingStatus;
|
use App\Enum\Groups\AccommodationBookingStatus;
|
||||||
use App\Enum\Groups\AdditionalServiceType;
|
use App\Enum\Groups\AdditionalServiceType;
|
||||||
use App\Exception\ImplausibleBookingPriceException;
|
use App\Exception\ImplausibleBookingPriceException;
|
||||||
use App\Repository\Groups\AccommodationBookingRepository;
|
use App\Repository\Groups\AccommodationBookingRepository;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Uid\Uuid;
|
use Symfony\Component\Uid\Uuid;
|
||||||
@@ -195,9 +198,21 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
|||||||
#[ORM\JoinColumn(onDelete: 'SET NULL')]
|
#[ORM\JoinColumn(onDelete: 'SET NULL')]
|
||||||
private ?User $managedBy = null;
|
private ?User $managedBy = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nights split off the start or the end of the stay and quoted as free-form lines, at most
|
||||||
|
* one on each side. dateFrom and dateTo keep spanning the whole stay; the booking's own
|
||||||
|
* parameters price only the main period left between the leading and the trailing period.
|
||||||
|
*
|
||||||
|
* @var Collection<int, AccommodationBookingPeriod>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(targetEntity: AccommodationBookingPeriod::class, mappedBy: 'booking', cascade: ['persist'], orphanRemoval: true)]
|
||||||
|
#[ORM\OrderBy(['dateFrom' => 'ASC'])]
|
||||||
|
private Collection $periods;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->uuid = Uuid::v4()->toRfc4122();
|
$this->uuid = Uuid::v4()->toRfc4122();
|
||||||
|
$this->periods = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,10 +226,17 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
|||||||
* The price snapshot, the service snapshots and all four discounts are deliberately carried
|
* The price snapshot, the service snapshots and all four discounts are deliberately carried
|
||||||
* over untouched. A copy is made to vary an offer that was already quoted, so it has to show
|
* over untouched. A copy is made to vary an offer that was already quoted, so it has to show
|
||||||
* the same numbers as the record it came from rather than a re-quote at today's catalog
|
* the same numbers as the record it came from rather than a re-quote at today's catalog
|
||||||
* prices; saving it through the edit form recomputes it.
|
* prices; saving it through the edit form recomputes it. The split-off periods belong to
|
||||||
|
* that quote and are copied along with it.
|
||||||
*/
|
*/
|
||||||
public function __clone()
|
public function __clone()
|
||||||
{
|
{
|
||||||
|
$periods = $this->periods->toArray();
|
||||||
|
$this->periods = new ArrayCollection();
|
||||||
|
foreach ($periods as $period) {
|
||||||
|
$this->addPeriod(clone $period);
|
||||||
|
}
|
||||||
|
|
||||||
$this->id = null;
|
$this->id = null;
|
||||||
$this->uuid = Uuid::v4()->toRfc4122();
|
$this->uuid = Uuid::v4()->toRfc4122();
|
||||||
$this->status = AccommodationBookingStatus::Draft;
|
$this->status = AccommodationBookingStatus::Draft;
|
||||||
@@ -302,6 +324,174 @@ class AccommodationBooking implements BlameableEntityInterface, TimestampableEnt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* At most one period on each side, attached to its edge of the stay, and at least one night
|
||||||
|
* left for the main period in between. A change to the stay's dates that no longer fits the
|
||||||
|
* periods is reported on that date rather than silently moving the periods along.
|
||||||
|
*/
|
||||||
|
#[Assert\Callback]
|
||||||
|
public function validatePeriods(ExecutionContextInterface $context): void
|
||||||
|
{
|
||||||
|
if (null === $this->dateFrom || null === $this->dateTo || $this->periods->isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (AccommodationBookingPeriodPosition::cases() as $position) {
|
||||||
|
if (count($this->periodsAt($position)) > 1) {
|
||||||
|
$context->buildViolation('Es kann nur einen Zeitraum am Anfang und einen am Ende geben.')
|
||||||
|
->addViolation();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$leading = $this->getLeadingPeriod();
|
||||||
|
if (null !== $leading && (!self::sameDay($leading->getDateFrom(), $this->dateFrom) || $leading->getNights() < 1)) {
|
||||||
|
$context->buildViolation('Der Zeitraum am Anfang passt nicht mehr zur Anreise — bitte Anreise oder Zeitraum prüfen.')
|
||||||
|
->atPath('dateFrom')
|
||||||
|
->addViolation();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trailing = $this->getTrailingPeriod();
|
||||||
|
if (null !== $trailing && (!self::sameDay($trailing->getDateTo(), $this->dateTo) || $trailing->getNights() < 1)) {
|
||||||
|
$context->buildViolation('Der Zeitraum am Ende passt nicht mehr zur Abreise — bitte Abreise oder Zeitraum prüfen.')
|
||||||
|
->atPath('dateTo')
|
||||||
|
->addViolation();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->getMainNights() < 1) {
|
||||||
|
$context->buildViolation('Nach dem Abteilen der Zeiträume muss mindestens eine Nacht für die Gruppe bleiben.')
|
||||||
|
->atPath('dateTo')
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return Collection<int, AccommodationBookingPeriod> */
|
||||||
|
public function getPeriods(): Collection
|
||||||
|
{
|
||||||
|
return $this->periods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPeriod(AccommodationBookingPeriod $period): self
|
||||||
|
{
|
||||||
|
if (!$this->periods->contains($period)) {
|
||||||
|
$this->periods->add($period);
|
||||||
|
$period->setBooking($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canSplitOffPeriod(AccommodationBookingPeriodPosition $position): bool
|
||||||
|
{
|
||||||
|
return [] === $this->periodsAt($position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Splits $nights off the main period, at the edge of the stay that $position names. */
|
||||||
|
public function splitOffPeriod(AccommodationBookingPeriodPosition $position, int $nights): AccommodationBookingPeriod
|
||||||
|
{
|
||||||
|
if (null === $this->dateFrom || null === $this->dateTo) {
|
||||||
|
throw new \LogicException('A period can only be split off a booking with dates.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->canSplitOffPeriod($position)) {
|
||||||
|
throw new \LogicException(sprintf('The booking already has a %s period.', $position->value));
|
||||||
|
}
|
||||||
|
|
||||||
|
$period = new AccommodationBookingPeriod($position, $this->dateFrom, $this->dateTo);
|
||||||
|
$this->addPeriod($period);
|
||||||
|
$this->resizePeriod($period, $nights);
|
||||||
|
|
||||||
|
return $period;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gives $period a new length, keeping it at its edge of the stay; the main period absorbs the difference. */
|
||||||
|
public function resizePeriod(AccommodationBookingPeriod $period, int $nights): self
|
||||||
|
{
|
||||||
|
if (null === $this->dateFrom || null === $this->dateTo) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$period->isLeading()
|
||||||
|
? $period->setDates($this->dateFrom, $this->dateFrom->modify(sprintf('+%d days', $nights)))
|
||||||
|
: $period->setDates($this->dateTo->modify(sprintf('-%d days', $nights)), $this->dateTo);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Its nights go back to the main period. */
|
||||||
|
public function removePeriod(AccommodationBookingPeriod $period): self
|
||||||
|
{
|
||||||
|
if ($this->periods->removeElement($period) && $period->getBooking() === $this) {
|
||||||
|
$period->setBooking(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLeadingPeriod(): ?AccommodationBookingPeriod
|
||||||
|
{
|
||||||
|
return $this->periodsAt(AccommodationBookingPeriodPosition::Leading)[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTrailingPeriod(): ?AccommodationBookingPeriod
|
||||||
|
{
|
||||||
|
return $this->periodsAt(AccommodationBookingPeriodPosition::Trailing)[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Arrival of the group the booking's own parameters price: the stay's, unless a period leads it. */
|
||||||
|
public function getMainDateFrom(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->getLeadingPeriod()?->getDateTo() ?? $this->dateFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Departure of the group the booking's own parameters price: the stay's, unless a period trails it. */
|
||||||
|
public function getMainDateTo(): ?\DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->getTrailingPeriod()?->getDateFrom() ?? $this->dateTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMainNights(): int
|
||||||
|
{
|
||||||
|
$from = $this->getMainDateFrom();
|
||||||
|
$to = $this->getMainDateTo();
|
||||||
|
|
||||||
|
if (null === $from || null === $to || $from >= $to) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $from->diff($to)->days;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** In minor units, the sum of every line of every split-off period. */
|
||||||
|
public function getPeriodsTotal(): int
|
||||||
|
{
|
||||||
|
$total = 0;
|
||||||
|
foreach ($this->periods as $period) {
|
||||||
|
$total += $period->getTotal();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $total;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<AccommodationBookingPeriod> */
|
||||||
|
private function periodsAt(AccommodationBookingPeriodPosition $position): array
|
||||||
|
{
|
||||||
|
return array_values(array_filter(
|
||||||
|
$this->periods->toArray(),
|
||||||
|
fn (AccommodationBookingPeriod $p) => $p->getPosition() === $position,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function sameDay(\DateTimeImmutable $a, \DateTimeImmutable $b): bool
|
||||||
|
{
|
||||||
|
return $a->format('Y-m-d') === $b->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
public function getPaxCount(): int
|
public function getPaxCount(): int
|
||||||
{
|
{
|
||||||
return $this->paxCount;
|
return $this->paxCount;
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Entity\Groups;
|
||||||
|
|
||||||
|
use App\Entity\TimestampableEntityInterface;
|
||||||
|
use App\Entity\TimestampableParentAwareInterface;
|
||||||
|
use App\Enum\Groups\AccommodationBookingPeriodPosition;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A stretch of nights split off the start or the end of a stay, such as the day an advance team
|
||||||
|
* arrives before the group. It carries no pax, board or services of its own and is never priced
|
||||||
|
* from the catalog: the office quotes it as free-form lines, which are added to the booking's
|
||||||
|
* total and fall under its fixed total discount. The booking's own parameters price only what
|
||||||
|
* remains between the leading and the trailing periods.
|
||||||
|
*/
|
||||||
|
#[ORM\Entity]
|
||||||
|
class AccommodationBookingPeriod implements TimestampableParentAwareInterface
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\ManyToOne(inversedBy: 'periods')]
|
||||||
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||||
|
private ?AccommodationBooking $booking = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 10, enumType: AccommodationBookingPeriodPosition::class)]
|
||||||
|
private AccommodationBookingPeriodPosition $position;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||||
|
private \DateTimeImmutable $dateFrom;
|
||||||
|
|
||||||
|
// Exclusive, like the booking's: the departure day, not the last night.
|
||||||
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||||
|
private \DateTimeImmutable $dateTo;
|
||||||
|
|
||||||
|
/** What the price breakdown calls the period, e.g. "Vorausteam"; without one it shows the dates alone. */
|
||||||
|
#[ORM\Column(length: 255, nullable: true)]
|
||||||
|
private ?string $label = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Amounts in minor units of the booking's pricing currency; a line has no currency of its own.
|
||||||
|
*
|
||||||
|
* The column is not called `lines`: that is a reserved word in MariaDB, and the ORM does
|
||||||
|
* not quote column names in the statements it writes.
|
||||||
|
*
|
||||||
|
* @var list<array{label: string, amount: int}>
|
||||||
|
*/
|
||||||
|
#[ORM\Column(name: 'price_lines', type: Types::JSON)]
|
||||||
|
private array $lines = [];
|
||||||
|
|
||||||
|
public function __construct(AccommodationBookingPeriodPosition $position, \DateTimeImmutable $dateFrom, \DateTimeImmutable $dateTo)
|
||||||
|
{
|
||||||
|
$this->position = $position;
|
||||||
|
$this->dateFrom = $dateFrom;
|
||||||
|
$this->dateTo = $dateTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __clone()
|
||||||
|
{
|
||||||
|
$this->id = null;
|
||||||
|
$this->booking = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBooking(): ?AccommodationBooking
|
||||||
|
{
|
||||||
|
return $this->booking;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBooking(?AccommodationBooking $booking): self
|
||||||
|
{
|
||||||
|
$this->booking = $booking;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTimestampableParent(): ?TimestampableEntityInterface
|
||||||
|
{
|
||||||
|
return $this->booking;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPosition(): AccommodationBookingPeriodPosition
|
||||||
|
{
|
||||||
|
return $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLeading(): bool
|
||||||
|
{
|
||||||
|
return AccommodationBookingPeriodPosition::Leading === $this->position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateFrom(): \DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->dateFrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateTo(): \DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->dateTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDates(\DateTimeImmutable $dateFrom, \DateTimeImmutable $dateTo): self
|
||||||
|
{
|
||||||
|
$this->dateFrom = $dateFrom;
|
||||||
|
$this->dateTo = $dateTo;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLabel(): ?string
|
||||||
|
{
|
||||||
|
return $this->label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLabel(?string $label): self
|
||||||
|
{
|
||||||
|
$this->label = $label;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNights(): int
|
||||||
|
{
|
||||||
|
return $this->dateFrom < $this->dateTo ? $this->dateFrom->diff($this->dateTo)->days : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{label: string, amount: int}> */
|
||||||
|
public function getLines(): array
|
||||||
|
{
|
||||||
|
return $this->lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param list<array{label: string, amount: int}> $lines */
|
||||||
|
public function setLines(array $lines): self
|
||||||
|
{
|
||||||
|
$this->lines = $lines;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTotal(): int
|
||||||
|
{
|
||||||
|
return array_sum(array_column($this->lines, 'amount'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enum\Groups;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Which edge of the stay a split-off period sits at. Periods only ever come off the start or
|
||||||
|
* the end, so the main period — the one the booking's own parameters price — always stays a
|
||||||
|
* single contiguous range between them.
|
||||||
|
*/
|
||||||
|
enum AccommodationBookingPeriodPosition: string
|
||||||
|
{
|
||||||
|
case Leading = 'leading';
|
||||||
|
case Trailing = 'trailing';
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exception;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when a voucher purchase step is reached without a running purchase, either directly or
|
||||||
|
* because the purchase was completed or the session expired.
|
||||||
|
*/
|
||||||
|
class VoucherSessionNotFoundException extends HttpException
|
||||||
|
{
|
||||||
|
public function __construct(?\Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct(404, 'No valid voucher purchase session found. Please start a new purchase.', $previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thrown when BusPro cannot tell us what is on sale (GUTSCHEINVORLAGEN) or how it can be paid
|
||||||
|
* (GUTSCHEINZAHLUNGSARTEN), so the voucher purchase cannot be offered.
|
||||||
|
*/
|
||||||
|
class VoucherShopUnavailableException extends \RuntimeException
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Admin\Groups;
|
||||||
|
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodLineDto;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/** @extends AbstractType<AccommodationBookingPeriodLineDto> */
|
||||||
|
class AccommodationBookingPeriodLineType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('label', TextType::class, [
|
||||||
|
'label' => 'Bezeichnung',
|
||||||
|
])
|
||||||
|
->add('amount', MoneyType::class, [
|
||||||
|
'label' => 'Betrag',
|
||||||
|
'currency' => $options['currency'],
|
||||||
|
'divisor' => 100,
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => AccommodationBookingPeriodLineDto::class,
|
||||||
|
'empty_data' => static fn () => new AccommodationBookingPeriodLineDto(),
|
||||||
|
'currency' => 'EUR',
|
||||||
|
]);
|
||||||
|
$resolver->setAllowedTypes('currency', 'string');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Admin\Groups;
|
||||||
|
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodDto;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/** @extends AbstractType<AccommodationBookingPeriodDto> */
|
||||||
|
class AccommodationBookingPeriodType extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
// "Überschrift" rather than "Bezeichnung", which the lines below use for their own field.
|
||||||
|
->add('label', TextType::class, [
|
||||||
|
'label' => 'Überschrift (optional)',
|
||||||
|
'required' => false,
|
||||||
|
'attr' => ['placeholder' => 'z. B. Vorausteam'],
|
||||||
|
])
|
||||||
|
->add('nights', IntegerType::class, [
|
||||||
|
'label' => 'Nächte',
|
||||||
|
'attr' => ['min' => 1],
|
||||||
|
])
|
||||||
|
->add('lines', CollectionType::class, [
|
||||||
|
'label' => 'Positionen',
|
||||||
|
'entry_type' => AccommodationBookingPeriodLineType::class,
|
||||||
|
'entry_options' => ['label' => false, 'currency' => $options['currency']],
|
||||||
|
'allow_add' => true,
|
||||||
|
'allow_delete' => true,
|
||||||
|
'by_reference' => false,
|
||||||
|
'prototype' => true,
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => AccommodationBookingPeriodDto::class,
|
||||||
|
'currency' => 'EUR',
|
||||||
|
]);
|
||||||
|
$resolver->setAllowedTypes('currency', 'string');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Model;
|
||||||
|
|
||||||
|
use App\Entity\Groups\AccommodationBooking;
|
||||||
|
use App\Entity\Groups\AccommodationBookingPeriod;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What the split and edit modals submit for a split-off period. Whether the group keeps a
|
||||||
|
* night for itself depends on the booking, so that is left to the booking's own validation.
|
||||||
|
*/
|
||||||
|
class AccommodationBookingPeriodDto
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array<int, AccommodationBookingPeriodLineDto> $lines keyed as the form submits them, so not necessarily a list
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
#[Assert\NotNull(message: 'Bitte die Anzahl der Nächte angeben.')]
|
||||||
|
#[Assert\Range(min: 1, max: AccommodationBooking::MAX_NIGHTS)]
|
||||||
|
public ?int $nights = 1,
|
||||||
|
#[Assert\Valid]
|
||||||
|
public array $lines = [],
|
||||||
|
#[Assert\Length(max: 255)]
|
||||||
|
public ?string $label = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromPeriod(AccommodationBookingPeriod $period): self
|
||||||
|
{
|
||||||
|
return new self(
|
||||||
|
$period->getNights(),
|
||||||
|
array_map(
|
||||||
|
fn (array $line) => new AccommodationBookingPeriodLineDto($line['label'], $line['amount']),
|
||||||
|
$period->getLines(),
|
||||||
|
),
|
||||||
|
$period->getLabel(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{label: string, amount: int}> */
|
||||||
|
public function linesSnapshot(): array
|
||||||
|
{
|
||||||
|
return array_values(array_map(
|
||||||
|
fn (AccommodationBookingPeriodLineDto $line) => ['label' => (string) $line->label, 'amount' => (int) $line->amount],
|
||||||
|
$this->lines,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Model;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/** One free-form price line of a split-off period, as the office keys it in. */
|
||||||
|
class AccommodationBookingPeriodLineDto
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
#[Assert\NotBlank(message: 'Bitte eine Bezeichnung angeben.')]
|
||||||
|
#[Assert\Length(max: 255)]
|
||||||
|
public ?string $label = null,
|
||||||
|
/** In minor units of the booking's pricing currency. */
|
||||||
|
#[Assert\NotNull(message: 'Bitte einen Betrag angeben.')]
|
||||||
|
#[Assert\PositiveOrZero]
|
||||||
|
public ?int $amount = null,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form\Model;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Address;
|
||||||
|
use App\BusProNet\Model\PersonalData;
|
||||||
|
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||||
|
use App\BusProNet\Model\VoucherTemplate;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Session state of the voucher purchase flow (/gutschein).
|
||||||
|
*
|
||||||
|
* The fields are exactly what the BusProNet voucher shop collects, with its mandatory flags rather
|
||||||
|
* than those of ADRESSFELDERGUTSCHEIN (which would also demand a phone number and a gender). There
|
||||||
|
* is no Zusatztext: GUTSCHEINBUCHUNG is sent an empty <text/>, as the live shop does.
|
||||||
|
*
|
||||||
|
* Step 2 is validated with the groups ['voucher_step_2', 'personal_data']: the buyer address reuses
|
||||||
|
* the Address model, whose constraints live in the personal_data group.
|
||||||
|
*/
|
||||||
|
class VoucherPurchaseDto
|
||||||
|
{
|
||||||
|
public const string SALUTATION_MR = 'Herr';
|
||||||
|
public const string SALUTATION_MS = 'Frau';
|
||||||
|
|
||||||
|
public int $currentStep = 1;
|
||||||
|
|
||||||
|
// BusPro's bounds from GUTSCHEINVORLAGEN at the start of the flow. BusPro re-checks them on
|
||||||
|
// every GUTSCHEINBUCHUNG (607/608), so a change in between still surfaces as a step 1 error.
|
||||||
|
public int $minAmount = 0;
|
||||||
|
public int $maxAmount = 0;
|
||||||
|
|
||||||
|
// Fixed at the start of the flow from GUTSCHEINZAHLUNGSARTEN; transfer is the only one offered.
|
||||||
|
public ?VoucherPaymentMethod $paymentMethod = null;
|
||||||
|
|
||||||
|
// Step 1: voucher
|
||||||
|
#[Assert\NotNull(message: 'Bitte wähle ein Motiv', groups: ['voucher_step_1'])]
|
||||||
|
public ?VoucherTemplate $template = null;
|
||||||
|
|
||||||
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['voucher_step_1'])]
|
||||||
|
public ?string $from = null;
|
||||||
|
|
||||||
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['voucher_step_1'])]
|
||||||
|
public ?string $to = null;
|
||||||
|
|
||||||
|
#[Assert\NotNull(message: 'Bitte gib einen Gutscheinwert an', groups: ['voucher_step_1'])]
|
||||||
|
#[Assert\Range(
|
||||||
|
notInRangeMessage: 'Der Gutscheinwert muss zwischen {{ min }} und {{ max }} Euro liegen',
|
||||||
|
minPropertyPath: 'minAmount',
|
||||||
|
maxPropertyPath: 'maxAmount',
|
||||||
|
groups: ['voucher_step_1'],
|
||||||
|
)]
|
||||||
|
public ?int $amount = null;
|
||||||
|
|
||||||
|
// Step 2: buyer (rechnungsempfänger)
|
||||||
|
#[Assert\Choice(choices: [self::SALUTATION_MR, self::SALUTATION_MS], groups: ['voucher_step_2'])]
|
||||||
|
public ?string $salutation = null;
|
||||||
|
|
||||||
|
public ?string $title = null;
|
||||||
|
|
||||||
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['voucher_step_2'])]
|
||||||
|
public ?string $lastName = null;
|
||||||
|
|
||||||
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['voucher_step_2'])]
|
||||||
|
public ?string $firstName = null;
|
||||||
|
|
||||||
|
#[Assert\Valid]
|
||||||
|
public Address $address;
|
||||||
|
|
||||||
|
public ?string $phone = null;
|
||||||
|
|
||||||
|
public ?string $mobile = null;
|
||||||
|
|
||||||
|
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['voucher_step_2'])]
|
||||||
|
#[Assert\Email(message: 'Bitte eine gültige Adresse angeben', mode: 'strict', groups: ['voucher_step_2'])]
|
||||||
|
public ?string $email = null;
|
||||||
|
|
||||||
|
// Step 3: confirmation, reset on every visit so a stale tick never carries over
|
||||||
|
#[Assert\IsTrue(message: 'Bitte bestätige', groups: ['voucher_step_3'])]
|
||||||
|
public bool $termsAccepted = false;
|
||||||
|
|
||||||
|
#[Assert\IsTrue(message: 'Bitte bestätige', groups: ['voucher_step_3'])]
|
||||||
|
public bool $purchaseConfirmed = false;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->address = new Address();
|
||||||
|
$this->address->country = 'D';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerFullName(): string
|
||||||
|
{
|
||||||
|
return trim(sprintf('%s %s', $this->firstName ?? '', $this->lastName ?? ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasBuyerData(): bool
|
||||||
|
{
|
||||||
|
return null !== $this->lastName && '' !== $this->lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the buyer fields from the signed-in account's BusPro record.
|
||||||
|
*
|
||||||
|
* The e-mail is the one the account signed in with, not the record's communication address:
|
||||||
|
* a BusPro address can carry several e-mails for different persons.
|
||||||
|
*/
|
||||||
|
public function prefillBuyer(PersonalData $personalData, ?string $loginEmail): void
|
||||||
|
{
|
||||||
|
$this->salutation = \in_array($personalData->salutation, [self::SALUTATION_MR, self::SALUTATION_MS], true)
|
||||||
|
? $personalData->salutation
|
||||||
|
: null;
|
||||||
|
$this->title = $personalData->title;
|
||||||
|
$this->lastName = $personalData->name;
|
||||||
|
$this->firstName = $personalData->firstName;
|
||||||
|
$this->address = clone $personalData->address;
|
||||||
|
$this->address->normalize();
|
||||||
|
$this->address->country ??= 'D';
|
||||||
|
$this->phone = $personalData->communication->phone;
|
||||||
|
$this->mobile = $personalData->communication->mobile;
|
||||||
|
$this->email = $loginEmail;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherTemplate;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/** @extends AbstractType<VoucherPurchaseDto> */
|
||||||
|
class VoucherPurchaseStep1Type extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('template', ChoiceType::class, [
|
||||||
|
'label' => 'Motiv',
|
||||||
|
'choices' => $options['templates'],
|
||||||
|
'choice_value' => static fn (?VoucherTemplate $template) => $template?->id,
|
||||||
|
'choice_label' => static fn (VoucherTemplate $template) => $template->label,
|
||||||
|
'expanded' => true,
|
||||||
|
'placeholder' => false,
|
||||||
|
'invalid_message' => 'Bitte wähle ein Motiv',
|
||||||
|
])
|
||||||
|
->add('from', TextType::class, [
|
||||||
|
'label' => 'Von',
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('to', TextType::class, [
|
||||||
|
'label' => 'Für',
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('amount', IntegerType::class, [
|
||||||
|
'label' => 'Gutscheinwert in Euro',
|
||||||
|
'invalid_message' => 'Bitte gib einen ganzen Euro-Betrag an',
|
||||||
|
'attr' => [
|
||||||
|
'min' => $options['min_amount'],
|
||||||
|
'max' => $options['max_amount'],
|
||||||
|
'step' => 1,
|
||||||
|
'inputmode' => 'numeric',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => VoucherPurchaseDto::class,
|
||||||
|
'validation_groups' => ['voucher_step_1'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$resolver->setRequired(['templates', 'min_amount', 'max_amount']);
|
||||||
|
$resolver->setAllowedTypes('templates', VoucherTemplate::class.'[]');
|
||||||
|
$resolver->setAllowedTypes('min_amount', 'int');
|
||||||
|
$resolver->setAllowedTypes('max_amount', 'int');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The buyer, sent to BusPro as rechnungsempfänger. Mandatory fields as in the live voucher shop.
|
||||||
|
*
|
||||||
|
* @extends AbstractType<VoucherPurchaseDto>
|
||||||
|
*/
|
||||||
|
class VoucherPurchaseStep2Type extends AbstractType
|
||||||
|
{
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('salutation', ChoiceType::class, [
|
||||||
|
'label' => 'Anrede',
|
||||||
|
'choices' => [
|
||||||
|
'Herr' => VoucherPurchaseDto::SALUTATION_MR,
|
||||||
|
'Frau' => VoucherPurchaseDto::SALUTATION_MS,
|
||||||
|
],
|
||||||
|
'expanded' => true,
|
||||||
|
'required' => false,
|
||||||
|
'placeholder' => false,
|
||||||
|
])
|
||||||
|
->add('title', TextType::class, [
|
||||||
|
'label' => 'Titel',
|
||||||
|
'required' => false,
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('firstName', TextType::class, [
|
||||||
|
'label' => 'Vorname',
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('lastName', TextType::class, [
|
||||||
|
'label' => 'Name',
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('address', AddressType::class, [
|
||||||
|
'label' => false,
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
|
->add('email', EmailType::class, [
|
||||||
|
'label' => 'E-Mail',
|
||||||
|
])
|
||||||
|
->add('phone', TextType::class, [
|
||||||
|
'label' => 'Telefon privat',
|
||||||
|
'required' => false,
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
->add('mobile', TextType::class, [
|
||||||
|
'label' => 'Mobil',
|
||||||
|
'required' => false,
|
||||||
|
'sanitize_html' => true,
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => VoucherPurchaseDto::class,
|
||||||
|
// personal_data carries the constraints of the reused Address model
|
||||||
|
'validation_groups' => ['voucher_step_2', 'personal_data'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Form;
|
||||||
|
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
/** @extends AbstractType<VoucherPurchaseDto> */
|
||||||
|
class VoucherPurchaseStep3Type extends AbstractType
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly string $termsAndConditionsUrl,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
|
{
|
||||||
|
$termsLink = sprintf(
|
||||||
|
'<a href="%s" target="_blank" rel="noopener" class="underline">Allgemeinen Geschäftsbedingungen</a>',
|
||||||
|
htmlspecialchars($this->termsAndConditionsUrl, ENT_QUOTES, 'UTF-8')
|
||||||
|
);
|
||||||
|
|
||||||
|
$builder
|
||||||
|
->add('termsAccepted', CheckboxType::class, [
|
||||||
|
'label' => sprintf('Ja, ich habe die %s gelesen und akzeptiere diese.', $termsLink),
|
||||||
|
'label_html' => true,
|
||||||
|
])
|
||||||
|
->add('purchaseConfirmed', CheckboxType::class, [
|
||||||
|
'label' => sprintf(
|
||||||
|
'Ja, ich möchte den Gutschein jetzt zum Preis von %s € kaufen.',
|
||||||
|
number_format($options['amount'], 2, ',', '.')
|
||||||
|
),
|
||||||
|
])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
{
|
||||||
|
$resolver->setDefaults([
|
||||||
|
'data_class' => VoucherPurchaseDto::class,
|
||||||
|
'validation_groups' => ['voucher_step_3'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$resolver->setRequired('amount');
|
||||||
|
$resolver->setAllowedTypes('amount', 'int');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,26 +5,29 @@ declare(strict_types=1);
|
|||||||
namespace App\Model;
|
namespace App\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The whole travel-date x hotel export plus the counters that describe how it was built.
|
* A whole travel-date x hotel export plus the counters that describe how it was built.
|
||||||
*
|
*
|
||||||
* Held in the bpn.cache pool as one unit and paginated in the controller, which is what
|
* Held in the bpn.cache pool as one unit and paginated in the controller, which is what
|
||||||
* makes the counters identical on every page: they describe the export, not the page, so a
|
* makes the counters identical on every page: they describe the export, not the page, so a
|
||||||
* consumer can read them once and abort the page walk on the first response.
|
* consumer can read them once and abort the page walk on the first response.
|
||||||
*
|
*
|
||||||
* @see \App\Service\TravelExportBuilder
|
* @see \App\Service\TravelExportBuilder
|
||||||
|
* @see \App\Service\ProductExportBuilder
|
||||||
*/
|
*/
|
||||||
final readonly class TravelExport
|
final readonly class Export
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param list<array<string, mixed>> $rows one row per (travel, hotel) pair
|
* @param list<array<string, mixed>> $rows one row per (travel, hotel) pair
|
||||||
* @param int $skipped (travel, hotel) pairs dropped as unusable
|
* @param int $skipped (travel, hotel) pairs dropped as unusable
|
||||||
* @param int $pickupsWithoutMasterData distinct pickup ids absent from zustiege.xml
|
* @param int $pickupsWithoutMasterData distinct pickup ids absent from zustiege.xml
|
||||||
|
* @param \DateTimeImmutable|null $sourceGeneratedAt the uebertragung.info timestamp of the export read, null if unknown
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public array $rows,
|
public array $rows,
|
||||||
public int $skipped,
|
public int $skipped,
|
||||||
public int $pickupsWithoutMasterData,
|
public int $pickupsWithoutMasterData,
|
||||||
public \DateTimeImmutable $generatedAt,
|
public \DateTimeImmutable $generatedAt,
|
||||||
|
public ?\DateTimeImmutable $sourceGeneratedAt = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace App\Model;
|
|||||||
|
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
final readonly class TravelExportQuery
|
final readonly class ExportQuery
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Assert\Positive]
|
#[Assert\Positive]
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purchase flows that start on the login page (optional sign-in, or continue as a guest).
|
||||||
|
*/
|
||||||
|
enum PurchaseFlow: string
|
||||||
|
{
|
||||||
|
case Booking = 'booking';
|
||||||
|
case Voucher = 'voucher';
|
||||||
|
|
||||||
|
public function firstStepRoute(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Booking => 'app_booking_create_step_1',
|
||||||
|
self::Voucher => 'app_voucher_step_1',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authenticateTemplate(): string
|
||||||
|
{
|
||||||
|
return match ($this) {
|
||||||
|
self::Booking => 'booking/create/authenticate.html.twig',
|
||||||
|
self::Voucher => 'voucher/authenticate.html.twig',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\BookingEditDraft;
|
||||||
|
use App\Entity\Groups\Accommodation;
|
||||||
use App\Entity\Groups\AccommodationBooking;
|
use App\Entity\Groups\AccommodationBooking;
|
||||||
|
use App\Entity\Groups\AccommodationPrice;
|
||||||
|
use App\Entity\Groups\AdditionalService;
|
||||||
|
use App\Entity\Groups\BoardService;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Form\Model\Filter\UserFilterDto;
|
use App\Form\Model\Filter\UserFilterDto;
|
||||||
use App\Repository\Filter\AppliesListFiltersTrait;
|
use App\Repository\Filter\AppliesListFiltersTrait;
|
||||||
@@ -122,4 +127,87 @@ class UserRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
return $users;
|
return $users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entities that point at a User and would silently lose that pointer if the account were
|
||||||
|
* deleted. Every one of these join columns is ON DELETE SET NULL, so the database does not
|
||||||
|
* stand in the way — it just erases who created, last touched or looks after a group booking.
|
||||||
|
* The cleanup therefore has to ask, rather than let the constraint decide.
|
||||||
|
*
|
||||||
|
* @var array<class-string, string[]>
|
||||||
|
*/
|
||||||
|
private const USER_REFERENCES = [
|
||||||
|
Accommodation::class => ['createdBy', 'updatedBy'],
|
||||||
|
AccommodationPrice::class => ['createdBy', 'updatedBy'],
|
||||||
|
AccommodationBooking::class => ['createdBy', 'updatedBy', 'managedBy'],
|
||||||
|
AdditionalService::class => ['createdBy', 'updatedBy'],
|
||||||
|
BoardService::class => ['createdBy', 'updatedBy'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounts the cleanup may consider: holding no booking edit draft and named by nothing in the
|
||||||
|
* Groups subsystem. $inactiveSince narrows that to accounts dormant since then, and is the
|
||||||
|
* caller's choice rather than this method's default — BpnAuthenticator recreates an account on
|
||||||
|
* sight, so how long ago somebody last signed in says nothing about whether the row may go.
|
||||||
|
*
|
||||||
|
* Deliberately unbounded: the caller still has to drop everything whose roles disqualify it,
|
||||||
|
* so a LIMIT here would cap the rows examined rather than the rows acted on, and a caller
|
||||||
|
* asking for ten deletions would get however many of the first ten candidates survived the
|
||||||
|
* role filter. Ordered oldest login first so a caller that does cap the result takes the
|
||||||
|
* least recently seen accounts.
|
||||||
|
*
|
||||||
|
* The roles are deliberately not part of this query. They live in a JSON array column with no
|
||||||
|
* JSON_CONTAINS registered, and the column holds more than one spelling of the same set — rows
|
||||||
|
* written by different Doctrine versions differ in whitespace — so a LIKE or an equality test
|
||||||
|
* on the raw JSON would quietly miss accounts or, far worse, match the wrong ones. The caller
|
||||||
|
* filters the shortlist through Role::effectiveOnly(), which is the only thing that knows what
|
||||||
|
* a role set actually means.
|
||||||
|
*
|
||||||
|
* @return User[]
|
||||||
|
*/
|
||||||
|
public function findCleanupCandidates(?\DateTimeImmutable $inactiveSince = null): array
|
||||||
|
{
|
||||||
|
$qb = $this->createQueryBuilder('u');
|
||||||
|
|
||||||
|
if (null !== $inactiveSince) {
|
||||||
|
$qb
|
||||||
|
->andWhere('u.lastLoginAt IS NOT NULL')
|
||||||
|
->andWhere('u.lastLoginAt < :inactiveSince')
|
||||||
|
->setParameter('inactiveSince', $inactiveSince)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->not($qb->expr()->exists(
|
||||||
|
$this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select('draft.id')
|
||||||
|
->from(BookingEditDraft::class, 'draft')
|
||||||
|
->andWhere('draft.user = u')
|
||||||
|
->getDQL()
|
||||||
|
)));
|
||||||
|
|
||||||
|
$index = 0;
|
||||||
|
|
||||||
|
foreach (self::USER_REFERENCES as $class => $fields) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$alias = sprintf('ref%d%s', $index++, $field);
|
||||||
|
|
||||||
|
$qb->andWhere($qb->expr()->not($qb->expr()->exists(
|
||||||
|
$this->getEntityManager()->createQueryBuilder()
|
||||||
|
->select($alias.'.id')
|
||||||
|
->from($class, $alias)
|
||||||
|
->andWhere(sprintf('%s.%s = u', $alias, $field))
|
||||||
|
->getDQL()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var User[] $users */
|
||||||
|
$users = $qb
|
||||||
|
->orderBy('u.lastLoginAt', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult()
|
||||||
|
;
|
||||||
|
|
||||||
|
return $users;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,15 @@ class AccommodationBookingBreakdownCalculator
|
|||||||
{
|
{
|
||||||
$breakdown = $booking->getPriceBreakdown() ?? $this->computeCurrent($booking);
|
$breakdown = $booking->getPriceBreakdown() ?? $this->computeCurrent($booking);
|
||||||
|
|
||||||
return null !== $breakdown ? $this->withDiscounts($booking, $breakdown) : null;
|
if (null === $breakdown) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snapshots frozen before split-off periods existed (pricing version 1) read as a
|
||||||
|
// booking without any, so templates only ever handle one shape.
|
||||||
|
$breakdown += ['periods' => [], 'periodsTotal' => 0];
|
||||||
|
|
||||||
|
return $this->withDiscounts($booking, $breakdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,6 +108,10 @@ class AccommodationBookingBreakdownCalculator
|
|||||||
* Calculates against the current catalog. Use only while creating or explicitly editing
|
* Calculates against the current catalog. Use only while creating or explicitly editing
|
||||||
* a booking, or as a compatibility fallback for records created before price snapshots.
|
* a booking, or as a compatibility fallback for records created before price snapshots.
|
||||||
*
|
*
|
||||||
|
* The catalog prices the main period only; the split-off periods add their lines on top,
|
||||||
|
* so `total` is the grand total the discounts are taken from. The price rows are loaded for
|
||||||
|
* the whole stay, which the includedPax floor and the short-term surcharge are judged on.
|
||||||
|
*
|
||||||
* @return array<string, mixed>|null
|
* @return array<string, mixed>|null
|
||||||
*/
|
*/
|
||||||
public function computeCurrent(AccommodationBooking $booking): ?array
|
public function computeCurrent(AccommodationBooking $booking): ?array
|
||||||
@@ -118,16 +130,40 @@ class AccommodationBookingBreakdownCalculator
|
|||||||
$dateTo,
|
$dateTo,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->priceCalculator->calculateFromSnapshots(
|
$breakdown = $this->priceCalculator->calculateFromSnapshots(
|
||||||
$booking->getPaxCount(),
|
$booking->getPaxCount(),
|
||||||
$booking->getMinorsCount(),
|
$booking->getMinorsCount(),
|
||||||
$booking->getNights(),
|
$booking->getMainNights(),
|
||||||
|
$booking->getMainDateFrom() ?? $dateFrom,
|
||||||
|
$booking->getMainDateTo() ?? $dateTo,
|
||||||
$dateFrom,
|
$dateFrom,
|
||||||
$dateTo,
|
$booking->getNights(),
|
||||||
$prices,
|
$prices,
|
||||||
$booking->getBoardServicePrice(),
|
$booking->getBoardServicePrice(),
|
||||||
$booking->getAdditionalServices(),
|
$booking->getAdditionalServices(),
|
||||||
$accommodation->getCurrency(),
|
$accommodation->getCurrency(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$periods = [];
|
||||||
|
foreach (array_filter([$booking->getLeadingPeriod(), $booking->getTrailingPeriod()]) as $period) {
|
||||||
|
$periods[] = [
|
||||||
|
'position' => $period->getPosition()->value,
|
||||||
|
'label' => $period->getLabel(),
|
||||||
|
'dateFrom' => $period->getDateFrom()->format('Y-m-d'),
|
||||||
|
'dateTo' => $period->getDateTo()->format('Y-m-d'),
|
||||||
|
'nights' => $period->getNights(),
|
||||||
|
'lines' => $period->getLines(),
|
||||||
|
'total' => $period->getTotal(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$periodsTotal = $booking->getPeriodsTotal();
|
||||||
|
|
||||||
|
return [
|
||||||
|
...$breakdown,
|
||||||
|
'periods' => $periods,
|
||||||
|
'periodsTotal' => $periodsTotal,
|
||||||
|
'total' => $breakdown['total'] + $periodsTotal,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ class AccommodationBookingPdfGenerator
|
|||||||
$parts = array_filter([
|
$parts = array_filter([
|
||||||
$booking->getDateFrom()?->format('Y-m-d'),
|
$booking->getDateFrom()?->format('Y-m-d'),
|
||||||
$booking->getAccommodation()?->getCalendarCode(),
|
$booking->getAccommodation()?->getCalendarCode(),
|
||||||
'Buchung',
|
$booking->recordLabel(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return implode(' ', $parts).'.pdf';
|
return implode(' ', $parts).'.pdf';
|
||||||
|
|||||||
@@ -8,13 +8,16 @@ use App\Email\EmailAttachmentInterface;
|
|||||||
use App\Email\Mailer;
|
use App\Email\Mailer;
|
||||||
use App\Entity\Groups\Accommodation;
|
use App\Entity\Groups\Accommodation;
|
||||||
use App\Entity\Groups\AccommodationBooking;
|
use App\Entity\Groups\AccommodationBooking;
|
||||||
|
use App\Entity\Groups\AccommodationBookingPeriod;
|
||||||
use App\Entity\Groups\AccommodationPrice;
|
use App\Entity\Groups\AccommodationPrice;
|
||||||
use App\Entity\Groups\AdditionalService;
|
use App\Entity\Groups\AdditionalService;
|
||||||
use App\Entity\Groups\BoardService;
|
use App\Entity\Groups\BoardService;
|
||||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||||
|
use App\Enum\Groups\AccommodationBookingPeriodPosition;
|
||||||
use App\Enum\Groups\AccommodationBookingStatus;
|
use App\Enum\Groups\AccommodationBookingStatus;
|
||||||
use App\Exception\ImplausibleBookingPriceException;
|
use App\Exception\ImplausibleBookingPriceException;
|
||||||
use App\Form\Model\AccommodationBookingDto;
|
use App\Form\Model\AccommodationBookingDto;
|
||||||
|
use App\Form\Model\AccommodationBookingPeriodDto;
|
||||||
use App\Model\AccommodationBookingContext;
|
use App\Model\AccommodationBookingContext;
|
||||||
use App\Model\AccommodationBookingQueryParams;
|
use App\Model\AccommodationBookingQueryParams;
|
||||||
use App\Model\CmsHotelData;
|
use App\Model\CmsHotelData;
|
||||||
@@ -25,11 +28,16 @@ use App\Repository\Groups\AdditionalServiceRepository;
|
|||||||
use App\Repository\Groups\BoardServiceRepository;
|
use App\Repository\Groups\BoardServiceRepository;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
|
|
||||||
class AccommodationBookingService
|
class AccommodationBookingService
|
||||||
{
|
{
|
||||||
private const int PRICING_VERSION = 1;
|
/**
|
||||||
|
* 2: the breakdown carries the split-off `periods` and `periodsTotal`, and `total` includes
|
||||||
|
* them. Version 1 snapshots are read as bookings without periods.
|
||||||
|
*/
|
||||||
|
private const int PRICING_VERSION = 2;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly AccommodationRepository $accommodationRepo,
|
private readonly AccommodationRepository $accommodationRepo,
|
||||||
@@ -381,6 +389,54 @@ class AccommodationBookingService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The three period changes below each take effect at once, like the house change: they
|
||||||
|
* reprice the booking, and the office wants to see the new price before it goes on.
|
||||||
|
* On violations nothing is written and the violations are returned for the modal.
|
||||||
|
*
|
||||||
|
* @throws ImplausibleBookingPriceException if the new total is too large to be a real price
|
||||||
|
*/
|
||||||
|
public function splitOffPeriod(AccommodationBooking $booking, AccommodationBookingPeriodPosition $position, AccommodationBookingPeriodDto $dto): ConstraintViolationListInterface
|
||||||
|
{
|
||||||
|
$booking->splitOffPeriod($position, (int) $dto->nights)
|
||||||
|
->setLabel($dto->label)
|
||||||
|
->setLines($dto->linesSnapshot());
|
||||||
|
|
||||||
|
return $this->commitPeriodChange($booking);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @throws ImplausibleBookingPriceException if the new total is too large to be a real price */
|
||||||
|
public function updatePeriod(AccommodationBooking $booking, AccommodationBookingPeriod $period, AccommodationBookingPeriodDto $dto): ConstraintViolationListInterface
|
||||||
|
{
|
||||||
|
$booking->resizePeriod($period, (int) $dto->nights);
|
||||||
|
$period->setLabel($dto->label)->setLines($dto->linesSnapshot());
|
||||||
|
|
||||||
|
return $this->commitPeriodChange($booking);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @throws ImplausibleBookingPriceException if the new total is too large to be a real price */
|
||||||
|
public function removePeriod(AccommodationBooking $booking, AccommodationBookingPeriod $period): ConstraintViolationListInterface
|
||||||
|
{
|
||||||
|
$booking->removePeriod($period);
|
||||||
|
|
||||||
|
return $this->commitPeriodChange($booking);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function commitPeriodChange(AccommodationBooking $booking): ConstraintViolationListInterface
|
||||||
|
{
|
||||||
|
// Default only: the `edit` group asks for contact data, which a period change neither
|
||||||
|
// shows nor touches, and which the edit form already enforces where it belongs.
|
||||||
|
$violations = $this->validator->validate($booking, null, ['Default']);
|
||||||
|
if (count($violations) > 0) {
|
||||||
|
return $violations;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshPriceSnapshot($booking);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
|
||||||
|
return $violations;
|
||||||
|
}
|
||||||
|
|
||||||
public function sendNotificationEmail(AccommodationBooking $booking): void
|
public function sendNotificationEmail(AccommodationBooking $booking): void
|
||||||
{
|
{
|
||||||
$this->sendBookingEmail(
|
$this->sendBookingEmail(
|
||||||
|
|||||||
@@ -126,16 +126,21 @@ class BookingSessionManager
|
|||||||
*/
|
*/
|
||||||
public function storeReturnUrl(Request $request, ?string $returnUrl): void
|
public function storeReturnUrl(Request $request, ?string $returnUrl): void
|
||||||
{
|
{
|
||||||
$url = self::DEFAULT_RETURN_URL;
|
$request->getSession()->set(self::RETURN_URL_KEY, self::normalizeReturnUrl($returnUrl));
|
||||||
|
}
|
||||||
|
|
||||||
if (null !== $returnUrl && '' !== trim($returnUrl)) {
|
/**
|
||||||
if (false !== filter_var($returnUrl, \FILTER_VALIDATE_URL)
|
* Accepts an absolute http(s) URL and falls back to the default for anything else.
|
||||||
&& 1 === preg_match('#^https?://#i', $returnUrl)) {
|
*/
|
||||||
$url = $returnUrl;
|
public static function normalizeReturnUrl(?string $returnUrl): string
|
||||||
}
|
{
|
||||||
|
if (null !== $returnUrl && '' !== trim($returnUrl)
|
||||||
|
&& false !== filter_var($returnUrl, \FILTER_VALIDATE_URL)
|
||||||
|
&& 1 === preg_match('#^https?://#i', $returnUrl)) {
|
||||||
|
return $returnUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
$request->getSession()->set(self::RETURN_URL_KEY, $url);
|
return self::DEFAULT_RETURN_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class GroupsPriceCalculator
|
|||||||
$nights,
|
$nights,
|
||||||
$dateFrom,
|
$dateFrom,
|
||||||
$dateTo,
|
$dateTo,
|
||||||
|
$dateFrom,
|
||||||
|
$nights,
|
||||||
$prices,
|
$prices,
|
||||||
$boardService?->getPrice(),
|
$boardService?->getPrice(),
|
||||||
array_map(
|
array_map(
|
||||||
@@ -104,7 +106,12 @@ class GroupsPriceCalculator
|
|||||||
* Same calculation but using frozen snapshot data from an AccommodationBooking entity
|
* Same calculation but using frozen snapshot data from an AccommodationBooking entity
|
||||||
* instead of live catalog entities.
|
* instead of live catalog entities.
|
||||||
*
|
*
|
||||||
* @param AccommodationPrice[] $prices all prices overlapping the booking window
|
* $dateFrom/$dateTo/$nights are the nights being priced, which is the main period of a booking
|
||||||
|
* with split-off periods. $stayDateFrom and $stayNights describe the whole stay, which the
|
||||||
|
* includedPax floor and the short-term surcharge are judged on, so that splitting nights off
|
||||||
|
* never changes either.
|
||||||
|
*
|
||||||
|
* @param AccommodationPrice[] $prices all prices overlapping the whole stay
|
||||||
* @param list<array{label: string, price: int, type: string, originalServiceId: int|null}> $additionalServiceSnapshots
|
* @param list<array{label: string, price: int, type: string, originalServiceId: int|null}> $additionalServiceSnapshots
|
||||||
*
|
*
|
||||||
* @return array{
|
* @return array{
|
||||||
@@ -131,6 +138,8 @@ class GroupsPriceCalculator
|
|||||||
int $nights,
|
int $nights,
|
||||||
\DateTimeImmutable $dateFrom,
|
\DateTimeImmutable $dateFrom,
|
||||||
\DateTimeImmutable $dateTo,
|
\DateTimeImmutable $dateTo,
|
||||||
|
\DateTimeImmutable $stayDateFrom,
|
||||||
|
int $stayNights,
|
||||||
array $prices,
|
array $prices,
|
||||||
?int $boardServicePricePerPersonNight,
|
?int $boardServicePricePerPersonNight,
|
||||||
array $additionalServiceSnapshots,
|
array $additionalServiceSnapshots,
|
||||||
@@ -151,6 +160,8 @@ class GroupsPriceCalculator
|
|||||||
$nights,
|
$nights,
|
||||||
$dateFrom,
|
$dateFrom,
|
||||||
$dateTo,
|
$dateTo,
|
||||||
|
$stayDateFrom,
|
||||||
|
$stayNights,
|
||||||
$prices,
|
$prices,
|
||||||
$boardServicePricePerPersonNight,
|
$boardServicePricePerPersonNight,
|
||||||
$items,
|
$items,
|
||||||
@@ -186,15 +197,19 @@ class GroupsPriceCalculator
|
|||||||
int $nights,
|
int $nights,
|
||||||
\DateTimeImmutable $dateFrom,
|
\DateTimeImmutable $dateFrom,
|
||||||
\DateTimeImmutable $dateTo,
|
\DateTimeImmutable $dateTo,
|
||||||
|
\DateTimeImmutable $stayDateFrom,
|
||||||
|
int $stayNights,
|
||||||
array $prices,
|
array $prices,
|
||||||
?int $boardServicePricePerPersonNight,
|
?int $boardServicePricePerPersonNight,
|
||||||
array $additionalItems,
|
array $additionalItems,
|
||||||
string $currency,
|
string $currency,
|
||||||
): array {
|
): array {
|
||||||
// Derive effectivePax: children 0–3 don't count, but never drop below includedPax
|
// Derive effectivePax: children 0–3 don't count, but never drop below includedPax.
|
||||||
|
// The floor comes from the stay's first night, not the priced range's, so that splitting
|
||||||
|
// nights off the start cannot swap in another price row's floor.
|
||||||
$firstCandidates = array_values(array_filter(
|
$firstCandidates = array_values(array_filter(
|
||||||
$prices,
|
$prices,
|
||||||
fn (AccommodationPrice $p) => $p->getDateFrom() <= $dateFrom && $p->getDateTo() >= $dateFrom,
|
fn (AccommodationPrice $p) => $p->getDateFrom() <= $stayDateFrom && $p->getDateTo() >= $stayDateFrom,
|
||||||
));
|
));
|
||||||
$firstWinner = $this->priceTimelineBuilder->resolveWinner($firstCandidates);
|
$firstWinner = $this->priceTimelineBuilder->resolveWinner($firstCandidates);
|
||||||
$includedPaxFloor = $firstWinner?->getIncludedPax() ?? 1;
|
$includedPaxFloor = $firstWinner?->getIncludedPax() ?? 1;
|
||||||
@@ -239,10 +254,10 @@ class GroupsPriceCalculator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule 3: short-term surcharge
|
// Rule 3: short-term surcharge, judged on the whole stay but charged on the priced nights
|
||||||
$shortTermSurcharge = 0;
|
$shortTermSurcharge = 0;
|
||||||
if (isset(self::SHORT_TERM_FACTORS[$nights])) {
|
if (isset(self::SHORT_TERM_FACTORS[$stayNights])) {
|
||||||
$shortTermSurcharge = (int) round(($basePrice + $additionalPersonsPrice) * self::SHORT_TERM_FACTORS[$nights] / 100);
|
$shortTermSurcharge = (int) round(($basePrice + $additionalPersonsPrice) * self::SHORT_TERM_FACTORS[$stayNights] / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Board is only billable — and only triggers the catering surcharge — when it costs
|
// Board is only billable — and only triggers the catering surcharge — when it costs
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Service;
|
|||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
use App\BusProNet\Model\Address;
|
use App\BusProNet\Model\Address;
|
||||||
use App\BusProNet\Model\Notification;
|
use App\BusProNet\Model\Notification;
|
||||||
|
use App\BusProNet\Model\PersonalData;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Form\Model\ParticipantDto;
|
use App\Form\Model\ParticipantDto;
|
||||||
use App\Security\Crypt;
|
use App\Security\Crypt;
|
||||||
@@ -45,16 +46,52 @@ class ParticipantDataPrefiller
|
|||||||
* @return ParticipantDto The prepopulated participant (or unchanged if API fails)
|
* @return ParticipantDto The prepopulated participant (or unchanged if API fails)
|
||||||
*/
|
*/
|
||||||
public function prefillApplicantFromUser(User $user, ParticipantDto $applicant): ParticipantDto
|
public function prefillApplicantFromUser(User $user, ParticipantDto $applicant): ParticipantDto
|
||||||
|
{
|
||||||
|
$personalData = $this->fetchPersonalData($user);
|
||||||
|
if (null === $personalData) {
|
||||||
|
return $applicant;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary participant from personal data
|
||||||
|
$prepopulated = ParticipantDto::fromPersonalData($personalData);
|
||||||
|
|
||||||
|
// Copy personal data fields to the existing applicant
|
||||||
|
// Preserve booking-specific fields (roomId, services, etc.)
|
||||||
|
$applicant->addressId = $prepopulated->addressId;
|
||||||
|
$applicant->personId = $prepopulated->personId;
|
||||||
|
$applicant->firstName = $prepopulated->firstName;
|
||||||
|
$applicant->lastName = $prepopulated->lastName;
|
||||||
|
$applicant->title = $prepopulated->title;
|
||||||
|
$applicant->gender = $prepopulated->gender;
|
||||||
|
$applicant->nationality = $prepopulated->nationality;
|
||||||
|
$applicant->dateOfBirth = $prepopulated->dateOfBirth;
|
||||||
|
$applicant->email = $prepopulated->email;
|
||||||
|
$applicant->mobile = $prepopulated->mobile;
|
||||||
|
$applicant->address = $prepopulated->address;
|
||||||
|
$applicant->height = $prepopulated->height;
|
||||||
|
$applicant->weight = $prepopulated->weight;
|
||||||
|
$applicant->shoeSize = $prepopulated->shoeSize;
|
||||||
|
$applicant->remarksRoom = $prepopulated->remarksRoom;
|
||||||
|
$applicant->licensePlate = $prepopulated->licensePlate;
|
||||||
|
|
||||||
|
return $applicant;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the authenticated user's personal data from the BPN API for prefilling a form.
|
||||||
|
*
|
||||||
|
* Never throws: a failure is logged and returns null, so a purchase flow is never interrupted
|
||||||
|
* by a prefill.
|
||||||
|
*/
|
||||||
|
public function fetchPersonalData(User $user): ?PersonalData
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Decrypt user password for API authentication
|
// Decrypt user password for API authentication
|
||||||
$password = $this->crypt->decrypt($user->getPassword());
|
$password = $this->crypt->decrypt($user->getPassword());
|
||||||
$email = $user->getEmail();
|
$email = $user->getEmail();
|
||||||
|
|
||||||
// Fetch personal data from API
|
|
||||||
$result = $this->apiClient->getPersonalData($email, $password);
|
$result = $this->apiClient->getPersonalData($email, $password);
|
||||||
|
|
||||||
// Handle API error response
|
|
||||||
if ($result instanceof Notification) {
|
if ($result instanceof Notification) {
|
||||||
$this->logger->warning('Failed to fetch personal data for prepopulation', [
|
$this->logger->warning('Failed to fetch personal data for prepopulation', [
|
||||||
'email' => $email,
|
'email' => $email,
|
||||||
@@ -62,40 +99,18 @@ class ParticipantDataPrefiller
|
|||||||
'message' => $result->message,
|
'message' => $result->message,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $applicant;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a temporary participant from personal data
|
return $result;
|
||||||
$prepopulated = ParticipantDto::fromPersonalData($result);
|
|
||||||
|
|
||||||
// Copy personal data fields to the existing applicant
|
|
||||||
// Preserve booking-specific fields (roomId, services, etc.)
|
|
||||||
$applicant->addressId = $prepopulated->addressId;
|
|
||||||
$applicant->personId = $prepopulated->personId;
|
|
||||||
$applicant->firstName = $prepopulated->firstName;
|
|
||||||
$applicant->lastName = $prepopulated->lastName;
|
|
||||||
$applicant->title = $prepopulated->title;
|
|
||||||
$applicant->gender = $prepopulated->gender;
|
|
||||||
$applicant->nationality = $prepopulated->nationality;
|
|
||||||
$applicant->dateOfBirth = $prepopulated->dateOfBirth;
|
|
||||||
$applicant->email = $prepopulated->email;
|
|
||||||
$applicant->mobile = $prepopulated->mobile;
|
|
||||||
$applicant->address = $prepopulated->address;
|
|
||||||
$applicant->height = $prepopulated->height;
|
|
||||||
$applicant->weight = $prepopulated->weight;
|
|
||||||
$applicant->shoeSize = $prepopulated->shoeSize;
|
|
||||||
$applicant->remarksRoom = $prepopulated->remarksRoom;
|
|
||||||
$applicant->licensePlate = $prepopulated->licensePlate;
|
|
||||||
|
|
||||||
return $applicant;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Catch any unexpected exceptions (decryption failure, API errors, etc.)
|
// Catch any unexpected exceptions (decryption failure, API errors, etc.)
|
||||||
$this->logger->error('Exception during applicant prepopulation', [
|
$this->logger->error('Exception during personal data prepopulation', [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
'email' => $user->getEmail(),
|
'email' => $user->getEmail(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $applicant;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,230 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Pickup;
|
||||||
|
use App\BusProNet\Model\XmlExportInfo;
|
||||||
|
use App\BusProNet\Traits\TypeConversionTrait;
|
||||||
|
use App\BusProNet\XmlCrawlerFactory;
|
||||||
|
use App\BusProNet\XmlLoader\PickupLoader;
|
||||||
|
use App\BusProNet\XmlParser\ProductExportParser;
|
||||||
|
use App\BusProNet\XmlParser\TravelParser;
|
||||||
|
use App\Model\Export;
|
||||||
|
use League\Flysystem\FilesystemOperator;
|
||||||
|
use League\Flysystem\StorageAttributes;
|
||||||
|
use Psr\Cache\InvalidArgumentException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
use Symfony\Contracts\Cache\CacheInterface;
|
||||||
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flattens the BusPro XML export into one row per travel date x hotel, the whole record.
|
||||||
|
*
|
||||||
|
* The sibling of TravelExportBuilder at the same grain, for the website's product import
|
||||||
|
* rather than the disposition. It filters nothing: return legs, `EIN` services,
|
||||||
|
* `Buchungsstop` rooms and pickups without an id all reach the consumer, whose display
|
||||||
|
* rules decide what to drop. Folding those rules in here would make every change to the
|
||||||
|
* website a change to this endpoint.
|
||||||
|
*
|
||||||
|
* Hotels are identified by the code and id on the travel XML's own `<hotel>` node, so
|
||||||
|
* unlike the travel export no row depends on hotel.xml master data.
|
||||||
|
*
|
||||||
|
* Boarding-point prices are the export's, verbatim. APP_BPN_LEVEL_BOARDING_POINT_PRICES
|
||||||
|
* is a booking-path compensation and is deliberately not applied: TravelParser::getPickups()
|
||||||
|
* does not level, only TravelParser::parse() does.
|
||||||
|
*/
|
||||||
|
class ProductExportBuilder
|
||||||
|
{
|
||||||
|
use TypeConversionTrait;
|
||||||
|
|
||||||
|
private const CACHE_KEY = 'bpn_products_export';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly PickupLoader $pickupLoader,
|
||||||
|
private readonly TravelParser $travelParser,
|
||||||
|
private readonly ProductExportParser $productExportParser,
|
||||||
|
private readonly FilesystemOperator $xmlExport,
|
||||||
|
private readonly CacheInterface $cache,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assembles the whole export, cached as one unit alongside the sibling loaders.
|
||||||
|
*/
|
||||||
|
public function build(): Export
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->cache->get(self::CACHE_KEY, function (ItemInterface $item) {
|
||||||
|
$item->expiresAfter(3 * 60 * 60);
|
||||||
|
$item->tag(['xml-sync']);
|
||||||
|
|
||||||
|
return $this->assemble();
|
||||||
|
});
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
throw new \RuntimeException('Cache key error in ProductExportBuilder', 0, $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assemble(): Export
|
||||||
|
{
|
||||||
|
// Read before the walk and cached with the rows; see TravelExportBuilder::assemble().
|
||||||
|
$sourceGeneratedAt = XmlExportInfo::fromStorage($this->xmlExport)?->lastTransfer;
|
||||||
|
$pickupMasterData = $this->pickupLoader->loadAll();
|
||||||
|
|
||||||
|
/** @var array<string, array<string, mixed>> $rows keyed by dateId-hotelId */
|
||||||
|
$rows = [];
|
||||||
|
$skipped = 0;
|
||||||
|
/** @var array<int, true> $pickupsWithoutMasterData */
|
||||||
|
$pickupsWithoutMasterData = [];
|
||||||
|
|
||||||
|
$files = $this
|
||||||
|
->xmlExport
|
||||||
|
->listContents('.')
|
||||||
|
->filter(fn (StorageAttributes $attributes) => $attributes->isFile() && str_starts_with($attributes->path(), 'Ziel_'));
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$crawler = XmlCrawlerFactory::create($this->xmlExport->read($file->path()));
|
||||||
|
|
||||||
|
$crawler->filterXPath('//reisen/reise')->each(
|
||||||
|
function (Crawler $productNode) use (&$rows, &$skipped, &$pickupsWithoutMasterData, $pickupMasterData) {
|
||||||
|
$product = [
|
||||||
|
'code' => $productNode->attr('code'),
|
||||||
|
'busProId' => null !== $productNode->attr('idbuspro') ? (int) $productNode->attr('idbuspro') : null,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->productExportParser->children($productNode, 'termin')->each(
|
||||||
|
function (Crawler $dateNode) use (&$rows, &$skipped, &$pickupsWithoutMasterData, $pickupMasterData, $product) {
|
||||||
|
$this->collectDate($dateNode, $product, $rows, $skipped, $pickupsWithoutMasterData, $pickupMasterData);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Export(
|
||||||
|
array_values($rows),
|
||||||
|
$skipped,
|
||||||
|
count($pickupsWithoutMasterData),
|
||||||
|
new \DateTimeImmutable(),
|
||||||
|
$sourceGeneratedAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{code: ?string, busProId: ?int} $product
|
||||||
|
* @param array<string, array<string, mixed>> $rows
|
||||||
|
* @param array<int, true> $pickupsWithoutMasterData
|
||||||
|
* @param array<int|string, Pickup> $pickupMasterData
|
||||||
|
*/
|
||||||
|
private function collectDate(
|
||||||
|
Crawler $dateNode,
|
||||||
|
array $product,
|
||||||
|
array &$rows,
|
||||||
|
int &$skipped,
|
||||||
|
array &$pickupsWithoutMasterData,
|
||||||
|
array $pickupMasterData,
|
||||||
|
): void {
|
||||||
|
$hotelNodes = $this->productExportParser->children($dateNode, 'hotel');
|
||||||
|
|
||||||
|
$dateFrom = $this->stringToDate($dateNode->attr('termin'));
|
||||||
|
$dateTo = $this->stringToDate($dateNode->attr('bis'));
|
||||||
|
|
||||||
|
if (null === $dateFrom || null === $dateTo) {
|
||||||
|
$this->logger->warning('Product export: unparseable travel date', [
|
||||||
|
'travel_id' => $dateNode->attr('idbuspro'),
|
||||||
|
'termin' => $dateNode->attr('termin'),
|
||||||
|
'bis' => $dateNode->attr('bis'),
|
||||||
|
]);
|
||||||
|
$skipped += $hotelNodes->count();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateId = (int) $dateNode->attr('idbuspro');
|
||||||
|
|
||||||
|
// Everything above the hotel is shared by the date's hotel rows, so it is read once.
|
||||||
|
$shared = [
|
||||||
|
'product' => $product,
|
||||||
|
'date' => [
|
||||||
|
'code' => $dateNode->attr('code'),
|
||||||
|
'busProId' => $dateId,
|
||||||
|
'from' => $dateFrom->format('Y-m-d'),
|
||||||
|
'to' => $dateTo->format('Y-m-d'),
|
||||||
|
'type' => $dateNode->attr('reiseart'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$dateLevel = [
|
||||||
|
'selectionGroups' => $this->productExportParser->getSelectionGroups($dateNode),
|
||||||
|
'transportServices' => $this->productExportParser->getServices($this->productExportParser->children($dateNode, 'lei_befoerderung/leistung')),
|
||||||
|
'dateServices' => $this->productExportParser->getServices($this->productExportParser->children($dateNode, 'lei_sonstiges/leistung')),
|
||||||
|
];
|
||||||
|
$pickups = $this->buildPickups($dateNode, $dateFrom, $pickupMasterData, $pickupsWithoutMasterData);
|
||||||
|
$guide = $this->productExportParser->getGuide($dateNode);
|
||||||
|
|
||||||
|
$hotelNodes->each(function (Crawler $hotelNode) use (&$rows, $shared, $dateLevel, $pickups, $guide, $dateId) {
|
||||||
|
$hotelId = (int) $hotelNode->attr('idbuspro');
|
||||||
|
|
||||||
|
// Keyed by the pair the consumer upserts on, so a date repeated across files
|
||||||
|
// collapses last-wins instead of reaching it as a duplicate.
|
||||||
|
$rows[$dateId.'-'.$hotelId] = $shared + [
|
||||||
|
'hotel' => [
|
||||||
|
'code' => $hotelNode->attr('code'),
|
||||||
|
'busProId' => $hotelId,
|
||||||
|
],
|
||||||
|
'pseudoPrice' => $this->productExportParser->getPseudoPrice($hotelNode),
|
||||||
|
] + $dateLevel + [
|
||||||
|
// The list nested in this hotel, not the date-level one: the consumer
|
||||||
|
// merges the two per hotel.
|
||||||
|
'hotelServices' => $this->productExportParser->getServices($this->productExportParser->children($hotelNode, 'lei_sonstiges/leistung')),
|
||||||
|
'rooms' => $this->productExportParser->getRooms($hotelNode),
|
||||||
|
'pickups' => $pickups,
|
||||||
|
'guide' => $guide,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outbound boarding points joined against zustiege.xml, in source order.
|
||||||
|
*
|
||||||
|
* getPickups() resolves both zeit shapes and rolls a bare time past midnight onto the
|
||||||
|
* next day. Entries with id 0 are kept: the consumer drops them itself.
|
||||||
|
*
|
||||||
|
* `datetime` is BusPro's clock reading, without an offset. Resolving in Europe/Berlin
|
||||||
|
* would move a bare 02:45 on the spring-forward night to 03:45, so the dates are
|
||||||
|
* resolved in UTC, where no time is skipped or repeated.
|
||||||
|
*
|
||||||
|
* @param array<int|string, Pickup> $masterData
|
||||||
|
* @param array<int, true> $pickupsWithoutMasterData
|
||||||
|
*
|
||||||
|
* @return list<array<string, mixed>>
|
||||||
|
*/
|
||||||
|
private function buildPickups(Crawler $dateNode, \DateTimeImmutable $dateFrom, array $masterData, array &$pickupsWithoutMasterData): array
|
||||||
|
{
|
||||||
|
$resolved = [];
|
||||||
|
$clockDate = new \DateTimeImmutable($dateFrom->format('Y-m-d'), new \DateTimeZone('UTC'));
|
||||||
|
|
||||||
|
foreach ($this->travelParser->getPickups($this->productExportParser->children($dateNode, 'zustiege/zustieg'), $clockDate, true) as $pickup) {
|
||||||
|
$pickupId = (int) $pickup->id;
|
||||||
|
$details = $masterData[$pickupId] ?? null;
|
||||||
|
|
||||||
|
if (null === $details && 0 !== $pickupId) {
|
||||||
|
$pickupsWithoutMasterData[$pickupId] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$resolved[] = [
|
||||||
|
'busProId' => $pickupId,
|
||||||
|
'code' => $details?->code,
|
||||||
|
'city' => $details?->city,
|
||||||
|
'street' => $details?->street,
|
||||||
|
'price' => $pickup->price,
|
||||||
|
'datetime' => $pickup->time?->format('Y-m-d\TH:i:s'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Model\PurchaseFlow;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells the login page which purchase flow, if any, it is the entry to.
|
||||||
|
*
|
||||||
|
* Both a booking and a voucher purchase can be pending in the same session, e.g. when they were
|
||||||
|
* started in two tabs. The one started last wins, which is what the visitor just clicked.
|
||||||
|
*/
|
||||||
|
class PurchaseFlowResolver
|
||||||
|
{
|
||||||
|
public const string LAST_STARTED_KEY = 'purchase_flow_last_started';
|
||||||
|
|
||||||
|
public function markStarted(Request $request, PurchaseFlow $flow): void
|
||||||
|
{
|
||||||
|
$request->getSession()->set(self::LAST_STARTED_KEY, $flow->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolvePending(Request $request): ?PurchaseFlow
|
||||||
|
{
|
||||||
|
$session = $request->getSession();
|
||||||
|
$hasBooking = $session->has(BookingSessionManager::BOOKING_CREATE_KEY);
|
||||||
|
$hasVoucher = $session->has(VoucherPurchaseSessionManager::SESSION_KEY);
|
||||||
|
|
||||||
|
if (true === $hasBooking && true === $hasVoucher) {
|
||||||
|
return PurchaseFlow::tryFrom((string) $session->get(self::LAST_STARTED_KEY)) ?? PurchaseFlow::Booking;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match (true) {
|
||||||
|
$hasBooking => PurchaseFlow::Booking,
|
||||||
|
$hasVoucher => PurchaseFlow::Voucher,
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,12 +6,13 @@ namespace App\Service;
|
|||||||
|
|
||||||
use App\BusProNet\Model\Hotel;
|
use App\BusProNet\Model\Hotel;
|
||||||
use App\BusProNet\Model\Pickup;
|
use App\BusProNet\Model\Pickup;
|
||||||
|
use App\BusProNet\Model\XmlExportInfo;
|
||||||
use App\BusProNet\Traits\TypeConversionTrait;
|
use App\BusProNet\Traits\TypeConversionTrait;
|
||||||
use App\BusProNet\XmlCrawlerFactory;
|
use App\BusProNet\XmlCrawlerFactory;
|
||||||
use App\BusProNet\XmlLoader\HotelLoader;
|
use App\BusProNet\XmlLoader\HotelLoader;
|
||||||
use App\BusProNet\XmlLoader\PickupLoader;
|
use App\BusProNet\XmlLoader\PickupLoader;
|
||||||
use App\BusProNet\XmlParser\TravelParser;
|
use App\BusProNet\XmlParser\TravelParser;
|
||||||
use App\Model\TravelExport;
|
use App\Model\Export;
|
||||||
use League\Flysystem\FilesystemOperator;
|
use League\Flysystem\FilesystemOperator;
|
||||||
use League\Flysystem\StorageAttributes;
|
use League\Flysystem\StorageAttributes;
|
||||||
use Psr\Cache\InvalidArgumentException;
|
use Psr\Cache\InvalidArgumentException;
|
||||||
@@ -51,7 +52,7 @@ class TravelExportBuilder
|
|||||||
/**
|
/**
|
||||||
* Assembles the whole export, cached as one unit alongside the sibling loaders.
|
* Assembles the whole export, cached as one unit alongside the sibling loaders.
|
||||||
*/
|
*/
|
||||||
public function build(): TravelExport
|
public function build(): Export
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->cache->get(self::CACHE_KEY, function (ItemInterface $item) {
|
return $this->cache->get(self::CACHE_KEY, function (ItemInterface $item) {
|
||||||
@@ -65,8 +66,13 @@ class TravelExportBuilder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function assemble(): TravelExport
|
private function assemble(): Export
|
||||||
{
|
{
|
||||||
|
// Read before the walk and cached with the rows, so every page served from this
|
||||||
|
// copy names the same source export. A client that sees it change between pages
|
||||||
|
// knows xml-sync swapped the export underneath its walk.
|
||||||
|
$sourceGeneratedAt = XmlExportInfo::fromStorage($this->xmlExport)?->lastTransfer;
|
||||||
|
|
||||||
$hotels = $this->hotelLoader->loadAll();
|
$hotels = $this->hotelLoader->loadAll();
|
||||||
$pickupMasterData = $this->pickupLoader->loadAll();
|
$pickupMasterData = $this->pickupLoader->loadAll();
|
||||||
|
|
||||||
@@ -91,11 +97,12 @@ class TravelExportBuilder
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TravelExport(
|
return new Export(
|
||||||
array_values($rows),
|
array_values($rows),
|
||||||
$skipped,
|
$skipped,
|
||||||
count($pickupsWithoutMasterData),
|
count($pickupsWithoutMasterData),
|
||||||
new \DateTimeImmutable(),
|
new \DateTimeImmutable(),
|
||||||
|
$sourceGeneratedAt,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,8 +144,15 @@ class TravelExportBuilder
|
|||||||
// getPickups() is what buys stringToDateTimeFuzzy() for both zeit shapes and
|
// getPickups() is what buys stringToDateTimeFuzzy() for both zeit shapes and
|
||||||
// adjustOvernightTimes(), which rolls an 02:15 listed after a 23:59 onto the next
|
// adjustOvernightTimes(), which rolls an 02:15 listed after a 23:59 onto the next
|
||||||
// calendar day. Resolved once per travel date, then shared by its hotel rows.
|
// calendar day. Resolved once per travel date, then shared by its hotel rows.
|
||||||
|
//
|
||||||
|
// Resolved in UTC: the times are BusPro's clock readings, and in Europe/Berlin a
|
||||||
|
// bare 02:45 on the spring-forward night would move to 03:45.
|
||||||
$pickups = $this->buildPickups(
|
$pickups = $this->buildPickups(
|
||||||
$this->travelParser->getPickups($node->filterXPath('.//zustiege/zustieg'), $dateFrom, true),
|
$this->travelParser->getPickups(
|
||||||
|
$node->filterXPath('.//zustiege/zustieg'),
|
||||||
|
new \DateTimeImmutable($dateFrom->format('Y-m-d'), new \DateTimeZone('UTC')),
|
||||||
|
true,
|
||||||
|
),
|
||||||
$pickupMasterData,
|
$pickupMasterData,
|
||||||
$pickupsWithoutMasterData,
|
$pickupsWithoutMasterData,
|
||||||
);
|
);
|
||||||
@@ -227,8 +241,9 @@ class TravelExportBuilder
|
|||||||
'street' => $details?->street,
|
'street' => $details?->street,
|
||||||
'time' => $pickup->time?->format('H:i'),
|
'time' => $pickup->time?->format('H:i'),
|
||||||
// Emitted for time-only sources too: adjustOvernightTimes() has already
|
// Emitted for time-only sources too: adjustOvernightTimes() has already
|
||||||
// worked out the real day, and a null here would throw that away.
|
// worked out the real day, and a null here would throw that away. A clock
|
||||||
'datetime' => $pickup->time?->format('c'),
|
// reading without an offset, like `time`.
|
||||||
|
'datetime' => $pickup->time?->format('Y-m-d\TH:i:s'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Exception\VoucherSessionNotFoundException;
|
||||||
|
use App\Form\Model\VoucherPurchaseDto;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Owns the session state of the voucher purchase flow. Nothing of it is stored in the database.
|
||||||
|
*/
|
||||||
|
class VoucherPurchaseSessionManager
|
||||||
|
{
|
||||||
|
public const string SESSION_KEY = 'voucher_purchase';
|
||||||
|
public const string RETURN_URL_KEY = 'voucher_return_url';
|
||||||
|
|
||||||
|
public function find(Request $request): ?VoucherPurchaseDto
|
||||||
|
{
|
||||||
|
$dto = $request->getSession()->get(self::SESSION_KEY);
|
||||||
|
|
||||||
|
return $dto instanceof VoucherPurchaseDto ? $dto : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws VoucherSessionNotFoundException
|
||||||
|
*/
|
||||||
|
public function get(Request $request): VoucherPurchaseDto
|
||||||
|
{
|
||||||
|
return $this->find($request) ?? throw new VoucherSessionNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(Request $request, VoucherPurchaseDto $dto): void
|
||||||
|
{
|
||||||
|
$request->getSession()->set(self::SESSION_KEY, $dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear(Request $request): void
|
||||||
|
{
|
||||||
|
$request->getSession()->remove(self::SESSION_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeReturnUrl(Request $request, ?string $returnUrl): void
|
||||||
|
{
|
||||||
|
$request->getSession()->set(self::RETURN_URL_KEY, BookingSessionManager::normalizeReturnUrl($returnUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReturnUrl(Request $request): string
|
||||||
|
{
|
||||||
|
return $request->getSession()->get(self::RETURN_URL_KEY, BookingSessionManager::DEFAULT_RETURN_URL);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\Notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a rejected GUTSCHEINBUCHUNG back to the step that owns the complaint.
|
||||||
|
*
|
||||||
|
* Codes from the vendor documentation, corrected by the probes of 2026-10-01: an unknown template
|
||||||
|
* answers 602 rather than 615, and missing address data comes as 650, which is a hard rejection here.
|
||||||
|
*/
|
||||||
|
class VoucherSaleRejectionMapper
|
||||||
|
{
|
||||||
|
public const int STEP_VOUCHER = 1;
|
||||||
|
public const int STEP_BUYER = 2;
|
||||||
|
public const int STEP_OVERVIEW = 3;
|
||||||
|
|
||||||
|
private const array VOUCHER_CODES = [
|
||||||
|
602, // Gutschein(vorlage) nicht gefunden
|
||||||
|
604, // Käufername fehlt
|
||||||
|
605, // Empfängername fehlt
|
||||||
|
606, // Betrag fehlt
|
||||||
|
607, // Betrag kleiner als
|
||||||
|
608, // Betrag größer als
|
||||||
|
612, 613, // Gutscheinart
|
||||||
|
614, 615, // Gutscheinstamm
|
||||||
|
616, // Kapazität nicht ausreichend
|
||||||
|
621, // Gutscheindaten fehlen
|
||||||
|
];
|
||||||
|
|
||||||
|
private const array BUYER_CODES = [
|
||||||
|
617, // Rechnungsempfänger fehlt
|
||||||
|
650, // Fehlende Adress Daten …
|
||||||
|
];
|
||||||
|
|
||||||
|
public function stepFor(Notification $notification): int
|
||||||
|
{
|
||||||
|
return match (true) {
|
||||||
|
\in_array($notification->code, self::VOUCHER_CODES, true) => self::STEP_VOUCHER,
|
||||||
|
\in_array($notification->code, self::BUYER_CODES, true) => self::STEP_BUYER,
|
||||||
|
default => self::STEP_OVERVIEW,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Model\Notification;
|
||||||
|
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||||
|
use App\BusProNet\Model\VoucherTemplates;
|
||||||
|
use App\Exception\VoucherShopUnavailableException;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Contracts\Cache\ItemInterface;
|
||||||
|
use Symfony\Contracts\Cache\TagAwareCacheInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached access to what BusPro offers for sale as vouchers and how they can be paid.
|
||||||
|
*
|
||||||
|
* Failures are not cached: the exception escapes the cache callback, so the next request asks again.
|
||||||
|
*/
|
||||||
|
class VoucherTemplateProvider
|
||||||
|
{
|
||||||
|
public const string CACHE_TAG = 'voucher-shop';
|
||||||
|
private const int CACHE_TTL = 300;
|
||||||
|
private const string TEMPLATES_CACHE_KEY = 'voucher_shop.templates';
|
||||||
|
private const string PAYMENT_METHOD_CACHE_KEY = 'voucher_shop.payment_method';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly ApiClient $apiClient,
|
||||||
|
private readonly TagAwareCacheInterface $cache,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws VoucherShopUnavailableException
|
||||||
|
*/
|
||||||
|
public function getTemplates(): VoucherTemplates
|
||||||
|
{
|
||||||
|
return $this->cache->get(self::TEMPLATES_CACHE_KEY, function (ItemInterface $item): VoucherTemplates {
|
||||||
|
$item->expiresAfter(self::CACHE_TTL);
|
||||||
|
$item->tag([self::CACHE_TAG]);
|
||||||
|
|
||||||
|
$result = $this->request(fn () => $this->apiClient->getVoucherTemplates(), 'templates');
|
||||||
|
if ([] === $result->templates) {
|
||||||
|
$this->logger->error('BusPro offers no voucher templates for sale');
|
||||||
|
|
||||||
|
throw new VoucherShopUnavailableException('No voucher templates on sale.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transfer payment method, the only one the flow offers.
|
||||||
|
*
|
||||||
|
* @throws VoucherShopUnavailableException
|
||||||
|
*/
|
||||||
|
public function getPaymentMethod(): VoucherPaymentMethod
|
||||||
|
{
|
||||||
|
return $this->cache->get(self::PAYMENT_METHOD_CACHE_KEY, function (ItemInterface $item): VoucherPaymentMethod {
|
||||||
|
$item->expiresAfter(self::CACHE_TTL);
|
||||||
|
$item->tag([self::CACHE_TAG]);
|
||||||
|
|
||||||
|
/** @var list<VoucherPaymentMethod> $paymentMethods */
|
||||||
|
$paymentMethods = $this->request(fn () => $this->apiClient->getVoucherPaymentMethods(), 'payment methods');
|
||||||
|
foreach ($paymentMethods as $paymentMethod) {
|
||||||
|
if ($paymentMethod->isTransfer()) {
|
||||||
|
return $paymentMethod;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->error('BusPro offers no transfer payment method for vouchers', [
|
||||||
|
'payment_methods' => array_map(static fn (VoucherPaymentMethod $method) => $method->type, $paymentMethods),
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new VoucherShopUnavailableException('No transfer payment method for vouchers.');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
*
|
||||||
|
* @param callable(): (T|Notification) $call
|
||||||
|
*
|
||||||
|
* @return T
|
||||||
|
*
|
||||||
|
* @throws VoucherShopUnavailableException
|
||||||
|
*/
|
||||||
|
private function request(callable $call, string $what): mixed
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$result = $call();
|
||||||
|
} catch (ApiClientException $e) {
|
||||||
|
$this->logger->error(sprintf('Unable to fetch voucher %s', $what), ['error' => $e->getMessage()]);
|
||||||
|
|
||||||
|
throw new VoucherShopUnavailableException(sprintf('Unable to fetch voucher %s.', $what), 0, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result instanceof Notification) {
|
||||||
|
$this->logger->error(sprintf('BusPro rejected the voucher %s request', $what), [
|
||||||
|
'code' => $result->code,
|
||||||
|
'message' => $result->message,
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new VoucherShopUnavailableException(sprintf('BusPro rejected the voucher %s request.', $what));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\VoucherTemplate;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the local thumbnail of a voucher design, by convention muster_{idgutscheinvorlage}.jpg in
|
||||||
|
* assets/vouchers (copied by Encore to images/vouchers).
|
||||||
|
*
|
||||||
|
* The thumbnails are copied by hand from the old shop's host, so a design BusPro starts selling has
|
||||||
|
* none until somebody adds it. It then renders without a picture, and the warning gets it noticed.
|
||||||
|
*/
|
||||||
|
class VoucherThumbnailResolver
|
||||||
|
{
|
||||||
|
private const string ASSET_PATH = 'build/images/vouchers/muster_%d.jpg';
|
||||||
|
|
||||||
|
/** @var array<string, string>|null */
|
||||||
|
private ?array $manifest = null;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly string $manifestPath,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param list<VoucherTemplate> $templates
|
||||||
|
*
|
||||||
|
* @return array<int, string|null> asset path (for asset()) per template id
|
||||||
|
*/
|
||||||
|
public function resolveAll(array $templates): array
|
||||||
|
{
|
||||||
|
$thumbnails = [];
|
||||||
|
foreach ($templates as $template) {
|
||||||
|
$thumbnails[$template->id] = $this->resolve($template);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $thumbnails;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolve(VoucherTemplate $template): ?string
|
||||||
|
{
|
||||||
|
$path = sprintf(self::ASSET_PATH, $template->id);
|
||||||
|
if (isset($this->loadManifest()[$path])) {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->logger->warning('No thumbnail for voucher template', [
|
||||||
|
'template_id' => $template->id,
|
||||||
|
'template_label' => $template->label,
|
||||||
|
'expected_source' => sprintf('assets/vouchers/muster_%d.jpg', $template->id),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
private function loadManifest(): array
|
||||||
|
{
|
||||||
|
if (null !== $this->manifest) {
|
||||||
|
return $this->manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = is_file($this->manifestPath) ? file_get_contents($this->manifestPath) : false;
|
||||||
|
$manifest = false !== $content ? json_decode($content, true) : null;
|
||||||
|
|
||||||
|
return $this->manifest = \is_array($manifest) ? $manifest : [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<button type="button"
|
<button type="button"
|
||||||
hx-get="{{ path('app_booking_cancel') }}"
|
hx-get="{{ cancel_url ?? path('app_booking_cancel') }}"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-swap="beforeend"
|
hx-swap="beforeend"
|
||||||
class="inline-flex items-center justify-center bg-gray-200 rounded-md w-8 h-8 md:w-10 md:h-10">
|
class="inline-flex items-center justify-center bg-gray-200 rounded-md w-8 h-8 md:w-10 md:h-10">
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
{# Sign-in step of a purchase flow: the login form the booking and voucher flows share #}
|
||||||
|
<div>
|
||||||
|
<h2 class="text-white">
|
||||||
|
Mit bestehendem Account anmelden
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
{% include '_partials/_alert.html.twig' with { 'level': 'error', messages: [ error.messageKey|trans(error.messageData, 'security') ] } %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form action="{{ path('app_login') }}" method="post" hx-history="false">
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="username" class="mb-1 font-semibold text-white">
|
||||||
|
E-Mail:
|
||||||
|
</label>
|
||||||
|
<input type="email"
|
||||||
|
id="username"
|
||||||
|
name="_username"
|
||||||
|
value="{{ last_username }}"
|
||||||
|
class="form-field"
|
||||||
|
required
|
||||||
|
autocomplete="username">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-4" {{ stimulus_controller('password-reveal') }}>
|
||||||
|
<label for="password" class="mb-1 font-semibold text-white">
|
||||||
|
Passwort:
|
||||||
|
</label>
|
||||||
|
<div class="relative">
|
||||||
|
<input type="password"
|
||||||
|
id="password"
|
||||||
|
name="_password"
|
||||||
|
class="form-field"
|
||||||
|
{{ stimulus_target('password-reveal', 'field') }}
|
||||||
|
required
|
||||||
|
autocomplete="current-password">
|
||||||
|
<button type="button"
|
||||||
|
{{ stimulus_action('password-reveal', 'toggle') }}
|
||||||
|
class="absolute top-0 right-0 mt-2 mr-2">
|
||||||
|
{{ icon('eye', 'w-6 h-6 text-gray-500') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="button button--primary w-full md:w-auto">
|
||||||
|
Anmelden und fortfahren
|
||||||
|
</button>
|
||||||
|
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<a href="{{ path('app_reset_password') }}"
|
||||||
|
class="inline-block text-sm underline text-white mt-2">
|
||||||
|
Passwort vergessen?
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
{#- One split-off period on the edit page, with its actions. Context: booking, period. -#}
|
||||||
|
{% set period_params = { id: period.id } %}
|
||||||
|
{% if app.request.query.get('r') %}
|
||||||
|
{% set period_params = period_params | merge({ r: app.request.query.get('r') }) %}
|
||||||
|
{% endif %}
|
||||||
|
<tr class="border-t border-gray-200 align-top">
|
||||||
|
<td class="py-1 whitespace-nowrap">{{ period.dateFrom | date('d.m.Y') }} – {{ period.dateTo | date('d.m.Y') }}</td>
|
||||||
|
<td class="py-1 whitespace-nowrap">{{ period.nights }} {{ period.nights != 1 ? 'Nächte' : 'Nacht' }}</td>
|
||||||
|
<td class="py-1">
|
||||||
|
{% if period.label %}
|
||||||
|
<div class="font-medium">{{ period.label }}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% for line in period.lines %}
|
||||||
|
<div>{{ line.label }}</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="text-gray-500">keine Positionen</div>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td class="py-1 text-right whitespace-nowrap">
|
||||||
|
{{ (period.total / 100) | format_currency(booking.pricingCurrency ?? booking.accommodation.currency) }}
|
||||||
|
</td>
|
||||||
|
<td class="py-1 text-right">
|
||||||
|
<twig:dropdown>
|
||||||
|
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_period_edit', period_params) }}">
|
||||||
|
bearbeiten
|
||||||
|
</twig:dropdown:hxbutton>
|
||||||
|
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_period_remove', period_params) }}" warning>
|
||||||
|
entfernen
|
||||||
|
</twig:dropdown:hxbutton>
|
||||||
|
</twig:dropdown>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{#- One split-off period of the price table on the detail page. 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 %}
|
||||||
|
{{ period.dateFrom | date('d.m.Y') }} – {{ period.dateTo | date('d.m.Y') }},
|
||||||
|
{{ period.nights }} {{ period.nights != 1 ? 'Nächte' : 'Nacht' }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for line in period.lines %}
|
||||||
|
<tr>
|
||||||
|
<td class="py-1">{{ line.label }}</td>
|
||||||
|
<td class="py-1 text-right whitespace-nowrap">{{ (line.amount / 100) | format_currency(currency) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
@@ -22,78 +22,199 @@
|
|||||||
{% form_theme form 'forms_admin.html.twig' %}
|
{% form_theme form 'forms_admin.html.twig' %}
|
||||||
|
|
||||||
{{ form_start(form) }}
|
{{ form_start(form) }}
|
||||||
<div class="grid lg:grid-cols-2 gap-y-4 lg:gap-x-8">
|
{{ form_errors(form) }}
|
||||||
<h2 class="lg:col-span-2 text-base font-bold">Kontaktdaten</h2>
|
{# Ordered by what gets negotiated: the stay first, the contact data last. The sidebar keeps
|
||||||
{{ form_row(form.groupName) }}
|
status, price and the save button in view on wide screens. #}
|
||||||
{{ form_row(form.salutation) }}
|
<div class="xl:grid xl:grid-cols-3 xl:gap-6 xl:items-start space-y-6 xl:space-y-0">
|
||||||
{{ form_row(form.firstName) }}
|
<div class="xl:col-span-2 space-y-6">
|
||||||
{{ form_row(form.lastName) }}
|
<twig:form:section title="Aufenthalt">
|
||||||
{{ form_row(form.email) }}
|
<div class="grid sm:grid-cols-2 gap-4">
|
||||||
{{ form_row(form.phone) }}
|
{{ form_row(form.dateFrom) }}
|
||||||
{{ form_row(form.street) }}
|
{{ form_row(form.dateTo) }}
|
||||||
{{ form_row(form.zip) }}
|
</div>
|
||||||
{{ form_row(form.city) }}
|
<div class="grid sm:grid-cols-3 gap-4 pt-4">
|
||||||
|
{{ form_row(form.paxCount) }}
|
||||||
|
{{ form_row(form.minorsCount) }}
|
||||||
|
{{ form_row(form.childrenCount) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2 class="lg:col-span-2 text-base font-bold pt-2">Reisedaten</h2>
|
{# Saved by their own modals, which reprice the booking on the spot — see SplitPeriodController. #}
|
||||||
{{ form_row(form.dateFrom) }}
|
<div class="mt-6 border-t border-gray-200 pt-4">
|
||||||
{{ form_row(form.dateTo) }}
|
<div class="font-bold pb-1">Zeiträume</div>
|
||||||
{{ form_row(form.paxCount) }}
|
<p class="text-xs text-gray-500 pb-2">
|
||||||
{{ form_row(form.minorsCount) }}
|
Anreise und Abreise umfassen den ganzen Aufenthalt. Abgeteilte Zeiträume, etwa für ein
|
||||||
{{ form_row(form.childrenCount) }}
|
Vorausteam, werden mit eigenen Positionen berechnet; Personen und Leistungen gelten
|
||||||
|
nur für den Zeitraum der Gruppe.
|
||||||
|
</p>
|
||||||
|
<table class="w-full text-sm">
|
||||||
|
{% if booking.leadingPeriod %}
|
||||||
|
{% include 'admin/accommodation_booking/_period_row.html.twig' with { period: booking.leadingPeriod } %}
|
||||||
|
{% endif %}
|
||||||
|
<tr class="border-t border-gray-200">
|
||||||
|
<td class="py-1 whitespace-nowrap">{{ booking.mainDateFrom | date('d.m.Y') }} – {{ booking.mainDateTo | date('d.m.Y') }}</td>
|
||||||
|
<td class="py-1 whitespace-nowrap">{{ booking.mainNights }} {{ booking.mainNights != 1 ? 'Nächte' : 'Nacht' }}</td>
|
||||||
|
<td class="py-1" colspan="2">Gruppe</td>
|
||||||
|
<td class="py-1 text-right">
|
||||||
|
{# One period per side, so only the free sides are offered. #}
|
||||||
|
{% if booking.leadingPeriod is null or booking.trailingPeriod is null %}
|
||||||
|
<twig:dropdown>
|
||||||
|
{% if booking.leadingPeriod is null %}
|
||||||
|
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_period_split', back_params | merge({ position: 'leading' })) }}">
|
||||||
|
am Anfang abteilen
|
||||||
|
</twig:dropdown:hxbutton>
|
||||||
|
{% endif %}
|
||||||
|
{% if booking.trailingPeriod is null %}
|
||||||
|
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_period_split', back_params | merge({ position: 'trailing' })) }}">
|
||||||
|
am Ende abteilen
|
||||||
|
</twig:dropdown:hxbutton>
|
||||||
|
{% endif %}
|
||||||
|
</twig:dropdown>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% if booking.trailingPeriod %}
|
||||||
|
{% include 'admin/accommodation_booking/_period_row.html.twig' with { period: booking.trailingPeriod } %}
|
||||||
|
{% endif %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</twig:form:section>
|
||||||
|
|
||||||
{% if form.boardService is defined or form.selectedAdditionalServices is defined %}
|
{% if form.boardService is defined or form.selectedAdditionalServices is defined %}
|
||||||
<h2 class="lg:col-span-2 text-base font-bold pt-2">Leistungen</h2>
|
<twig:form:section title="Leistungen">
|
||||||
{% if form.boardService is defined %}
|
<div class="space-y-4">
|
||||||
{{ form_row(form.boardService) }}
|
{% if form.boardService is defined %}
|
||||||
|
{{ form_row(form.boardService) }}
|
||||||
|
{% endif %}
|
||||||
|
{% if form.selectedAdditionalServices is defined %}
|
||||||
|
<div>
|
||||||
|
{{ form_label(form.selectedAdditionalServices) }}
|
||||||
|
{# Rows written out here rather than through the theme's choice_widget_expanded,
|
||||||
|
whose first:pt-0 would shift only the first cell of the two columns. #}
|
||||||
|
<div class="grid sm:grid-cols-2 gap-x-8">
|
||||||
|
{% for child in form.selectedAdditionalServices %}
|
||||||
|
<div class="relative flex items-start py-1">
|
||||||
|
<div class="min-w-0 flex-1 text-sm leading-4">
|
||||||
|
<label for="{{ child.vars.id }}" class="select-none font-medium text-gray-900">
|
||||||
|
{{ child.vars.label }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="ml-3 flex h-4 items-center">
|
||||||
|
{{ form_widget(child) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{{ form_errors(form.selectedAdditionalServices) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</twig:form:section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if form.selectedAdditionalServices is defined %}
|
|
||||||
{{ form_row(form.selectedAdditionalServices) }}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<h2 class="lg:col-span-2 text-base font-bold pt-2">Status & Rabatt</h2>
|
<twig:form:section title="Rabatte">
|
||||||
{# Read-only: the status only ever moves through a named action on the detail page,
|
<div class="grid sm:grid-cols-3 gap-4">
|
||||||
so that it cannot be set without the email and timestamp that belong to it. #}
|
{{ form_row(form.accommodationDiscount) }}
|
||||||
<p class="lg:col-span-2 text-sm">
|
{{ form_row(form.boardServiceDiscount) }}
|
||||||
<span class="font-medium">Status:</span>
|
{{ form_row(form.additionalServicesDiscount) }}
|
||||||
{% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
</div>
|
||||||
<span class="text-gray-500">· Herkunft: {{ booking.origin.label }}</span>
|
<div class="grid sm:grid-cols-3 gap-4 pt-4">
|
||||||
</p>
|
{{ form_row(form.totalDiscountLabel, { row_attr: { class: 'sm:col-span-2' } }) }}
|
||||||
{% if booking.acceptedAt is not null %}
|
{{ form_row(form.totalDiscountAmount) }}
|
||||||
<p class="lg:col-span-2 text-xs text-gray-500">
|
</div>
|
||||||
Angenommen am {{ booking.acceptedAt | date('d.m.Y, H:i') }}
|
</twig:form:section>
|
||||||
</p>
|
|
||||||
{% endif %}
|
<twig:form:section title="Kontakt">
|
||||||
{% if booking.confirmedAt is not null %}
|
<div class="grid sm:grid-cols-2 gap-4">
|
||||||
<p class="lg:col-span-2 text-xs text-gray-500">
|
{{ form_row(form.groupName, { row_attr: { class: 'sm:col-span-2' } }) }}
|
||||||
Bestätigt am {{ booking.confirmedAt | date('d.m.Y, H:i') }}
|
{{ form_row(form.salutation) }}
|
||||||
</p>
|
<div class="hidden sm:block"></div>
|
||||||
{% endif %}
|
{{ form_row(form.firstName) }}
|
||||||
{% if form.managedBy is defined %}
|
{{ form_row(form.lastName) }}
|
||||||
<div class="lg:col-span-2">
|
{{ form_row(form.email) }}
|
||||||
{{ form_row(form.managedBy) }}
|
{{ form_row(form.phone) }}
|
||||||
|
{{ form_row(form.street, { row_attr: { class: 'sm:col-span-2' } }) }}
|
||||||
|
{{ form_row(form.zip) }}
|
||||||
|
{{ form_row(form.city) }}
|
||||||
|
</div>
|
||||||
|
</twig:form:section>
|
||||||
|
|
||||||
|
<twig:form:section title="Bemerkungen">
|
||||||
|
{{ form_widget(form.remarks) }}
|
||||||
|
{{ form_errors(form.remarks) }}
|
||||||
|
</twig:form:section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<aside class="space-y-6 xl:sticky xl:top-8">
|
||||||
|
<twig:form:section title="Status">
|
||||||
|
{# Read-only: the status only ever moves through a named action on the detail page,
|
||||||
|
so that it cannot be set without the email and timestamp that belong to it. #}
|
||||||
|
<dl class="grid grid-cols-2 gap-y-1 text-sm">
|
||||||
|
<dt class="text-gray-500">Status</dt>
|
||||||
|
<dd>{% include 'admin/accommodation_booking/_status_label.html.twig' %}</dd>
|
||||||
|
<dt class="text-gray-500">Herkunft</dt>
|
||||||
|
<dd>{{ booking.origin.label }}</dd>
|
||||||
|
{% if booking.acceptedAt is not null %}
|
||||||
|
<dt class="text-gray-500">Angenommen</dt>
|
||||||
|
<dd>{{ booking.acceptedAt | date('d.m.Y, H:i') }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
{% if booking.confirmedAt is not null %}
|
||||||
|
<dt class="text-gray-500">Bestätigt</dt>
|
||||||
|
<dd>{{ booking.confirmedAt | date('d.m.Y, H:i') }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
</dl>
|
||||||
|
{% if form.managedBy is defined %}
|
||||||
|
<div class="pt-4">
|
||||||
|
{{ form_row(form.managedBy) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</twig:form:section>
|
||||||
|
|
||||||
|
{% 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>
|
||||||
|
<p class="text-xs text-gray-500 pt-2">
|
||||||
|
Stand der letzten Speicherung. Änderungen oben werden erst beim Speichern neu berechnet.
|
||||||
|
</p>
|
||||||
|
</twig:form:section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<button type="submit" class="button button--primary button--small w-full">
|
||||||
|
speichern
|
||||||
|
</button>
|
||||||
|
<a href="{{ path('app_admin_accommodationbooking_show', back_params) }}" class="text-sm text-gray-500 hover:text-gray-900 hover:underline">
|
||||||
|
← zurück ohne speichern
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
</aside>
|
||||||
<div class="lg:col-span-2 grid lg:grid-cols-3 gap-y-4 lg:gap-x-8">
|
|
||||||
{{ form_row(form.accommodationDiscount) }}
|
|
||||||
{{ form_row(form.boardServiceDiscount) }}
|
|
||||||
{{ form_row(form.additionalServicesDiscount) }}
|
|
||||||
</div>
|
|
||||||
<div class="lg:col-span-2 grid lg:grid-cols-2 gap-y-4 lg:gap-x-8">
|
|
||||||
{{ form_row(form.totalDiscountLabel) }}
|
|
||||||
{{ form_row(form.totalDiscountAmount) }}
|
|
||||||
</div>
|
|
||||||
<div class="lg:col-span-2">
|
|
||||||
{{ form_row(form.remarks) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-between pt-8">
|
|
||||||
<a href="{{ path('app_admin_accommodationbooking_show', back_params) }}" class="button button--secondary button--small">
|
|
||||||
zurück
|
|
||||||
</a>
|
|
||||||
<button type="submit" class="button button--primary button--small">
|
|
||||||
speichern
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
{{ form_rest(form) }}
|
{{ form_rest(form) }}
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
|||||||
@@ -102,11 +102,9 @@
|
|||||||
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_duplicate', { 'id': booking.id, 'r': return_url() }) }}">
|
<twig:dropdown:hxbutton url="{{ path('app_admin_accommodationbooking_duplicate', { 'id': booking.id, 'r': return_url() }) }}">
|
||||||
duplizieren
|
duplizieren
|
||||||
</twig:dropdown:hxbutton>
|
</twig:dropdown:hxbutton>
|
||||||
{% if booking.confirmed %}
|
<twig:dropdown:link url="{{ path('app_admin_accommodationbooking_pdf', { 'id': booking.id }) }}">
|
||||||
<twig:dropdown:link url="{{ path('app_admin_accommodationbooking_pdf', { 'id': booking.id }) }}">
|
PDF herunterladen
|
||||||
PDF herunterladen
|
</twig:dropdown:link>
|
||||||
</twig:dropdown:link>
|
|
||||||
{% endif %}
|
|
||||||
{# A record that has been in front of the customer gets discarded,
|
{# A record that has been in front of the customer gets discarded,
|
||||||
not removed — see DeleteController. #}
|
not removed — see DeleteController. #}
|
||||||
{% if booking.draft %}
|
{% if booking.draft %}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
{% extends 'htmx_modal_admin.html.twig' %}
|
||||||
|
{% form_theme form 'forms_admin.html.twig' %}
|
||||||
|
|
||||||
|
{# One line as a row of bare widgets; the column headings above name them once for all rows.
|
||||||
|
Plain flex rather than an arbitrary grid template: the modal is loaded into a page whose
|
||||||
|
stylesheet may predate any class used only here. #}
|
||||||
|
{% macro line_row(line) %}
|
||||||
|
<div class="flex gap-2 items-start" data-form-collection-target="field">
|
||||||
|
<div class="flex-1 min-w-0">
|
||||||
|
{{ form_widget(line.label, { attr: { placeholder: 'z. B. Übernachtung' } }) }}
|
||||||
|
{{ form_errors(line.label) }}
|
||||||
|
</div>
|
||||||
|
<div class="w-32 shrink-0">
|
||||||
|
{{ form_widget(line.amount) }}
|
||||||
|
{{ form_errors(line.amount) }}
|
||||||
|
</div>
|
||||||
|
<button type="button"
|
||||||
|
class="shrink-0 mt-2 text-gray-400 hover:text-red-500"
|
||||||
|
data-action="form-collection#removeItem"
|
||||||
|
title="Position entfernen">
|
||||||
|
{{ icon('close', 'w-5 h-5') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% import _self as period %}
|
||||||
|
<div class="text-xl font-bold pb-1">
|
||||||
|
{{ title }}
|
||||||
|
</div>
|
||||||
|
<p class="text-sm text-gray-500 pb-6">
|
||||||
|
Die Nächte werden vom Zeitraum der Gruppe abgezogen, der neu berechnet wird. Die Positionen
|
||||||
|
kommen zum Gesamtpreis hinzu und fallen nur unter den Rabatt auf den Gesamtpreis.
|
||||||
|
</p>
|
||||||
|
{{ form_start(form) }}
|
||||||
|
{{ form_errors(form) }}
|
||||||
|
<div class="flex gap-4 items-start">
|
||||||
|
{{ form_row(form.label, { row_attr: { class: 'flex-1 min-w-0' } }) }}
|
||||||
|
{{ form_row(form.nights, { row_attr: { class: 'w-32 shrink-0' } }) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% set prototype %}{{ period.line_row(form.lines.vars.prototype) }}{% endset %}
|
||||||
|
<div class="mt-6 border border-gray-200 rounded-md" {{ stimulus_controller('form-collection', { prototype: prototype|json_encode }) }}>
|
||||||
|
<div class="flex gap-2 px-4 py-2 bg-gray-100 border-b border-gray-200 rounded-t-md text-sm font-bold">
|
||||||
|
<div class="flex-1">Position</div>
|
||||||
|
{# w-5 matches the remove button's icon, so the heading sits over the amounts. #}
|
||||||
|
<div class="w-32 shrink-0">Betrag</div>
|
||||||
|
<div class="w-5 shrink-0"></div>
|
||||||
|
</div>
|
||||||
|
<div class="p-4">
|
||||||
|
{{ form_errors(form.lines) }}
|
||||||
|
<div class="space-y-2" data-form-collection-target="fields">
|
||||||
|
{% for line in form.lines %}
|
||||||
|
{{ period.line_row(line) }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<button type="button"
|
||||||
|
class="mt-3 text-sm font-medium text-primary hover:underline"
|
||||||
|
data-action="form-collection#addItem">
|
||||||
|
+ Position hinzufügen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% do form.lines.setRendered %}
|
||||||
|
|
||||||
|
<div class="flex justify-end pt-6">
|
||||||
|
<button type="submit" class="button button--primary button--small">
|
||||||
|
speichern
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{{ form_rest(form) }}
|
||||||
|
{{ form_end(form) }}
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{% extends 'htmx_confirmation_modal.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Zeitraum entfernen{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div>
|
||||||
|
Möchtest du den Zeitraum {{ period.dateFrom | date('d.m.Y') }} – {{ period.dateTo | date('d.m.Y') }}
|
||||||
|
mit allen Positionen entfernen? Die Nächte gehen an den Zeitraum der Gruppe zurück, und der
|
||||||
|
Preis wird neu berechnet.
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block button_confirm %}entfernen{% endblock %}
|
||||||
@@ -1,94 +1,81 @@
|
|||||||
{% extends 'layout_admin.html.twig' %}
|
{% extends 'layout_admin.html.twig' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
{% set edit_params = { 'id': booking.id } %}
|
||||||
|
{% if app.request.query.get('r') %}
|
||||||
|
{% set edit_params = edit_params | merge({ 'r': app.request.query.get('r') }) %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<twig:page:heading>
|
<twig:page:heading>
|
||||||
{{ booking.recordLabel }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
{{ booking.recordLabel }} · {% include 'admin/accommodation_booking/_status_label.html.twig' %}
|
||||||
{{ booking.groupName }}
|
{{ booking.groupName }}
|
||||||
</twig:page:heading>
|
</twig:page:heading>
|
||||||
|
<p class="text-sm text-gray-500 mb-6">{{ booking.accommodation.name }}</p>
|
||||||
|
|
||||||
<div class="grid lg:grid-cols-2 gap-8">
|
{# Same arrangement as the edit form: what was booked in the main column, status, the next
|
||||||
<div>
|
step and the actions in a sidebar that stays in view on wide screens. #}
|
||||||
<h2 class="text-lg font-bold mb-4">Kontakt</h2>
|
<div class="xl:grid xl:grid-cols-3 xl:gap-6 xl:items-start space-y-6 xl:space-y-0">
|
||||||
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
<div class="xl:col-span-2 space-y-6">
|
||||||
<dt class="font-medium">Gruppenname</dt>
|
<twig:form:section title="Aufenthalt">
|
||||||
<dd>{{ booking.groupName }}</dd>
|
|
||||||
<dt class="font-medium">Anrede</dt>
|
|
||||||
<dd>{{ booking.salutation | default('–') }}</dd>
|
|
||||||
<dt class="font-medium">Name</dt>
|
|
||||||
<dd>{{ booking.firstName }} {{ booking.lastName }}</dd>
|
|
||||||
<dt class="font-medium">E-Mail</dt>
|
|
||||||
<dd>{{ booking.email }}</dd>
|
|
||||||
<dt class="font-medium">Telefon</dt>
|
|
||||||
<dd>{{ booking.phone | default('–') }}</dd>
|
|
||||||
<dt class="font-medium">Adresse</dt>
|
|
||||||
<dd>
|
|
||||||
{% if booking.street %}
|
|
||||||
{{ booking.street }}<br>
|
|
||||||
{{ booking.zip }} {{ booking.city }}
|
|
||||||
{% else %}
|
|
||||||
–
|
|
||||||
{% endif %}
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h2 class="text-lg font-bold mb-4">Reisedaten</h2>
|
|
||||||
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
|
||||||
<dt class="font-medium">Gruppenhaus</dt>
|
|
||||||
<dd>{{ booking.accommodation.name }}</dd>
|
|
||||||
<dt class="font-medium">Anreise</dt>
|
|
||||||
<dd>{{ booking.dateFrom | date('d.m.Y') }}</dd>
|
|
||||||
<dt class="font-medium">Abreise</dt>
|
|
||||||
<dd>{{ booking.dateTo | date('d.m.Y') }}</dd>
|
|
||||||
<dt class="font-medium">Nächte</dt>
|
|
||||||
<dd>{{ booking.nights }}</dd>
|
|
||||||
<dt class="font-medium">Anzahl Personen</dt>
|
|
||||||
<dd>{{ booking.paxCount }}</dd>
|
|
||||||
{% if booking.minorsCount > 0 %}
|
|
||||||
<dt class="font-medium">davon Kinder (0–3 Jahre)</dt>
|
|
||||||
<dd>{{ booking.minorsCount }}</dd>
|
|
||||||
{% endif %}
|
|
||||||
{% if booking.childrenCount > 0 %}
|
|
||||||
<dt class="font-medium">davon Kinder (4–{{ booking.accommodation.maxAdolescentAge }} Jahre)</dt>
|
|
||||||
<dd>{{ booking.childrenCount }}</dd>
|
|
||||||
{% endif %}
|
|
||||||
<dt class="font-medium">Herkunft</dt>
|
|
||||||
<dd>{{ booking.origin.label }}</dd>
|
|
||||||
<dt class="font-medium">Status</dt>
|
|
||||||
<dd>{% include 'admin/accommodation_booking/_status_label.html.twig' %}</dd>
|
|
||||||
{% if booking.acceptedAt is not null %}
|
|
||||||
<dt class="font-medium">Angenommen am</dt>
|
|
||||||
<dd>{{ booking.acceptedAt | date('d.m.Y, H:i') }}</dd>
|
|
||||||
{% endif %}
|
|
||||||
{% if booking.confirmedAt is not null %}
|
|
||||||
<dt class="font-medium">Bestätigt am</dt>
|
|
||||||
<dd>{{ booking.confirmedAt | date('d.m.Y, H:i') }}</dd>
|
|
||||||
{% endif %}
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if booking.boardServiceLabel or booking.additionalServices | length > 0 %}
|
|
||||||
<div>
|
|
||||||
<h2 class="text-lg font-bold mb-4">Gebuchte Leistungen</h2>
|
|
||||||
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
||||||
{% if booking.boardServiceLabel %}
|
<dt class="font-medium">Gruppenhaus</dt>
|
||||||
<dt class="font-medium">Verpflegung</dt>
|
<dd>{{ booking.accommodation.name }}</dd>
|
||||||
<dd>{{ booking.boardServiceLabel }}</dd>
|
<dt class="font-medium">Anreise</dt>
|
||||||
|
<dd>{{ booking.dateFrom | date('d.m.Y') }}</dd>
|
||||||
|
<dt class="font-medium">Abreise</dt>
|
||||||
|
<dd>{{ booking.dateTo | date('d.m.Y') }}</dd>
|
||||||
|
<dt class="font-medium">Nächte</dt>
|
||||||
|
<dd>{{ booking.nights }}</dd>
|
||||||
|
{% if booking.periods is not empty %}
|
||||||
|
<dt class="font-medium">Zeitraum Gruppe</dt>
|
||||||
|
<dd>
|
||||||
|
{{ booking.mainDateFrom | date('d.m.Y') }} – {{ booking.mainDateTo | date('d.m.Y') }},
|
||||||
|
{{ booking.mainNights }} {{ booking.mainNights != 1 ? 'Nächte' : 'Nacht' }}
|
||||||
|
</dd>
|
||||||
|
{% endif %}
|
||||||
|
<dt class="font-medium">Anzahl Personen</dt>
|
||||||
|
<dd>{{ booking.paxCount }}</dd>
|
||||||
|
{% if booking.minorsCount > 0 %}
|
||||||
|
<dt class="font-medium">davon Kinder (0–3 Jahre)</dt>
|
||||||
|
<dd>{{ booking.minorsCount }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
{% if booking.childrenCount > 0 %}
|
||||||
|
<dt class="font-medium">davon Kinder (4–{{ booking.accommodation.maxAdolescentAge }} Jahre)</dt>
|
||||||
|
<dd>{{ booking.childrenCount }}</dd>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for service in booking.additionalServices %}
|
|
||||||
<dt class="font-medium">{{ loop.first ? 'Zusatzleistungen' : '' }}</dt>
|
|
||||||
<dd>{{ service.label }}</dd>
|
|
||||||
{% endfor %}
|
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</twig:form:section>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if priceBreakdown is not null %}
|
{% if booking.boardServiceLabel or booking.additionalServices | length > 0 %}
|
||||||
<div>
|
<twig:form:section title="Leistungen">
|
||||||
<h2 class="text-lg font-bold mb-4">Preise</h2>
|
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
||||||
|
{% if booking.boardServiceLabel %}
|
||||||
|
<dt class="font-medium">Verpflegung</dt>
|
||||||
|
<dd>{{ booking.boardServiceLabel }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
{% for service in booking.additionalServices %}
|
||||||
|
<dt class="font-medium">{{ loop.first ? 'Zusatzleistungen' : '' }}</dt>
|
||||||
|
<dd>{{ service.label }}</dd>
|
||||||
|
{% endfor %}
|
||||||
|
</dl>
|
||||||
|
</twig:form:section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if priceBreakdown is not null %}
|
||||||
{% set currency = booking.pricingCurrency ?? priceBreakdown.currency %}
|
{% set currency = booking.pricingCurrency ?? priceBreakdown.currency %}
|
||||||
|
<twig:form:section title="Preise">
|
||||||
<table class="w-full text-sm">
|
<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 %}
|
{% if priceBreakdown.basePrice > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="py-1">
|
<td class="py-1">
|
||||||
@@ -139,6 +126,9 @@
|
|||||||
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.runningCosts / 100) | format_currency(currency) }}</td>
|
<td class="py-1 text-right whitespace-nowrap">{{ (priceBreakdown.runningCosts / 100) | format_currency(currency) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% 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">
|
<tr class="border-t border-gray-200 font-semibold">
|
||||||
<td class="pt-2">
|
<td class="pt-2">
|
||||||
Gesamtpreis
|
Gesamtpreis
|
||||||
@@ -171,136 +161,179 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</twig:form:section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if booking.remarks %}
|
<twig:form:section title="Kontakt">
|
||||||
<div class="lg:col-span-2">
|
<dl class="grid grid-cols-2 gap-y-2 text-sm">
|
||||||
<h2 class="text-lg font-bold mb-4">Bemerkungen</h2>
|
<dt class="font-medium">Gruppenname</dt>
|
||||||
<p class="text-sm">{{ booking.remarks | nl2br }}</p>
|
<dd>{{ booking.groupName }}</dd>
|
||||||
</div>
|
<dt class="font-medium">Anrede</dt>
|
||||||
{% endif %}
|
<dd>{{ booking.salutation | default('–') }}</dd>
|
||||||
</div>
|
<dt class="font-medium">Name</dt>
|
||||||
|
<dd>{{ booking.firstName }} {{ booking.lastName }}</dd>
|
||||||
|
<dt class="font-medium">E-Mail</dt>
|
||||||
|
<dd>{{ booking.email }}</dd>
|
||||||
|
<dt class="font-medium">Telefon</dt>
|
||||||
|
<dd>{{ booking.phone | default('–') }}</dd>
|
||||||
|
<dt class="font-medium">Adresse</dt>
|
||||||
|
<dd>
|
||||||
|
{% if booking.street %}
|
||||||
|
{{ booking.street }}<br>
|
||||||
|
{{ booking.zip }} {{ booking.city }}
|
||||||
|
{% else %}
|
||||||
|
–
|
||||||
|
{% endif %}
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</twig:form:section>
|
||||||
|
|
||||||
<div class="text-xs text-gray-400 mt-6">
|
{% if booking.remarks %}
|
||||||
Eingegangen: {{ booking.createdAt | date('d.m.Y, H:i') }}
|
<twig:form:section title="Bemerkungen">
|
||||||
{% if booking.updatedAt is not null and booking.updatedAt != booking.createdAt %}
|
<p class="text-sm">{{ booking.remarks | nl2br }}</p>
|
||||||
· Aktualisiert: {{ booking.updatedAt | date('d.m.Y, H:i') }}
|
</twig:form:section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
|
||||||
|
|
||||||
{% if booking.draft or booking.requested %}
|
|
||||||
<div class="mt-6 border-t border-gray-200 pt-6">
|
|
||||||
<h2 class="text-lg font-bold mb-2">Angebot</h2>
|
|
||||||
<p class="text-sm text-gray-500 mb-2">
|
|
||||||
Das Angebot wurde dem Kunden noch nicht zugestellt. Beim Versand wird der Zugangslink
|
|
||||||
erzeugt und die Buchung wartet anschließend auf die Annahme durch den Kunden.
|
|
||||||
</p>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<button type="button"
|
|
||||||
class="button button--primary button--small"
|
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_send_offer', { id: booking.id }) }}"
|
|
||||||
hx-target="body"
|
|
||||||
hx-swap="beforeend">
|
|
||||||
Angebot per E-Mail senden
|
|
||||||
</button>
|
|
||||||
<button type="button"
|
|
||||||
class="button button--secondary button--small"
|
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_generate_access_link', { id: booking.id }) }}"
|
|
||||||
hx-target="body"
|
|
||||||
hx-swap="beforeend">
|
|
||||||
Link erzeugen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if booking.received %}
|
<aside class="space-y-6 xl:sticky xl:top-8">
|
||||||
<div class="mt-6 border-t border-gray-200 pt-6">
|
<twig:form:section title="Status">
|
||||||
<h2 class="text-lg font-bold mb-2">Bestätigung</h2>
|
<dl class="grid grid-cols-2 gap-y-1 text-sm">
|
||||||
<p class="text-sm text-gray-500 mb-2">
|
<dt class="text-gray-500">Status</dt>
|
||||||
Die Buchung des Kunden ist eingegangen, aber es wurde noch keine Bestätigung verschickt.
|
<dd>{% include 'admin/accommodation_booking/_status_label.html.twig' %}</dd>
|
||||||
</p>
|
<dt class="text-gray-500">Herkunft</dt>
|
||||||
<button type="button"
|
<dd>{{ booking.origin.label }}</dd>
|
||||||
class="button button--primary button--small"
|
{% if booking.managedBy is not null %}
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_confirm', { id: booking.id }) }}"
|
<dt class="text-gray-500">Bearbeiter:in</dt>
|
||||||
hx-target="body"
|
<dd>{{ booking.managedBy.displayName }}</dd>
|
||||||
hx-swap="beforeend">
|
{% endif %}
|
||||||
Buchung per E-Mail bestätigen
|
{% if booking.acceptedAt is not null %}
|
||||||
</button>
|
<dt class="text-gray-500">Angenommen</dt>
|
||||||
</div>
|
<dd>{{ booking.acceptedAt | date('d.m.Y, H:i') }}</dd>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if booking.confirmedAt is not null %}
|
||||||
|
<dt class="text-gray-500">Bestätigt</dt>
|
||||||
|
<dd>{{ booking.confirmedAt | date('d.m.Y, H:i') }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
<dt class="text-gray-500">Eingegangen</dt>
|
||||||
|
<dd>{{ booking.createdAt | date('d.m.Y, H:i') }}</dd>
|
||||||
|
{% if booking.updatedAt is not null and booking.updatedAt != booking.createdAt %}
|
||||||
|
<dt class="text-gray-500">Aktualisiert</dt>
|
||||||
|
<dd>{{ booking.updatedAt | date('d.m.Y, H:i') }}</dd>
|
||||||
|
{% endif %}
|
||||||
|
</dl>
|
||||||
|
</twig:form:section>
|
||||||
|
|
||||||
<div class="mt-6 border-t border-gray-200 pt-6">
|
{# One pink button per page, for the next step; everything else is grey, and the one
|
||||||
<h2 class="text-lg font-bold mb-2">Zugangslink</h2>
|
destructive action is set apart below the others. #}
|
||||||
{% if not booking.customerAccessible %}
|
{% set has_next_step = booking.draft or booking.requested or booking.received %}
|
||||||
<p class="text-sm text-gray-500">
|
{% if booking.draft or booking.requested %}
|
||||||
Ein Zugangslink wird beim Versand des Angebots erzeugt.
|
<twig:form:section title="Nächster Schritt: Angebot">
|
||||||
</p>
|
<p class="text-sm text-gray-500 mb-3">
|
||||||
{% elseif accessLink %}
|
Das Angebot wurde dem Kunden noch nicht zugestellt. Beim Versand wird der Zugangslink
|
||||||
<div class="flex items-center gap-2">
|
erzeugt und die Buchung wartet anschließend auf die Annahme durch den Kunden.
|
||||||
<button type="button"
|
</p>
|
||||||
class="button button--secondary button--small"
|
<div class="flex flex-col gap-2">
|
||||||
data-controller="clipboard"
|
<button type="button"
|
||||||
data-clipboard-content-value="{{ accessLink }}"
|
class="button button--primary button--small w-full"
|
||||||
data-clipboard-label-value="Kopiert!"
|
hx-get="{{ path('app_admin_accommodationbooking_send_offer', { id: booking.id }) }}"
|
||||||
data-action="clipboard#copy">
|
hx-target="body"
|
||||||
{{ icon('copy', 'w-4 h-4') }} Link kopieren
|
hx-swap="beforeend">
|
||||||
</button>
|
Angebot per E-Mail senden
|
||||||
<button type="button"
|
</button>
|
||||||
class="button button--secondary button--small"
|
<button type="button"
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_send_access_link', { id: booking.id }) }}"
|
class="button button--neutral button--small w-full"
|
||||||
hx-target="body"
|
hx-get="{{ path('app_admin_accommodationbooking_generate_access_link', { id: booking.id }) }}"
|
||||||
hx-swap="beforeend">
|
hx-target="body"
|
||||||
Link senden
|
hx-swap="beforeend">
|
||||||
</button>
|
nur Link erzeugen
|
||||||
</div>
|
</button>
|
||||||
<p class="text-xs text-gray-500 mt-1">
|
</div>
|
||||||
Gültig bis {{ accessLinkExpiresAt | date('d.m.Y') }}
|
</twig:form:section>
|
||||||
{% if accessLinkExpiresAt < date() %}
|
{% elseif booking.received %}
|
||||||
<span class="text-red-600 font-medium">(abgelaufen)</span>
|
<twig:form:section title="Nächster Schritt: Bestätigung">
|
||||||
|
<p class="text-sm text-gray-500 mb-3">
|
||||||
|
Die Buchung des Kunden ist eingegangen, aber es wurde noch keine Bestätigung verschickt.
|
||||||
|
</p>
|
||||||
|
<button type="button"
|
||||||
|
class="button button--primary button--small w-full"
|
||||||
|
hx-get="{{ path('app_admin_accommodationbooking_confirm', { id: booking.id }) }}"
|
||||||
|
hx-target="body"
|
||||||
|
hx-swap="beforeend">
|
||||||
|
Buchung per E-Mail bestätigen
|
||||||
|
</button>
|
||||||
|
</twig:form:section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<twig:form:section title="Zugangslink">
|
||||||
|
{% if not booking.customerAccessible %}
|
||||||
|
<p class="text-sm text-gray-500">
|
||||||
|
Ein Zugangslink wird beim Versand des Angebots erzeugt.
|
||||||
|
</p>
|
||||||
|
{% elseif accessLink %}
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<button type="button"
|
||||||
|
class="button button--neutral button--small sm:text-xs w-full"
|
||||||
|
data-controller="clipboard"
|
||||||
|
data-clipboard-content-value="{{ accessLink }}"
|
||||||
|
data-clipboard-label-value="Kopiert!"
|
||||||
|
data-action="clipboard#copy">
|
||||||
|
{{ icon('copy', 'w-4 h-4') }} Link kopieren
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
class="button button--neutral button--small sm:text-xs w-full"
|
||||||
|
hx-get="{{ path('app_admin_accommodationbooking_send_access_link', { id: booking.id }) }}"
|
||||||
|
hx-target="body"
|
||||||
|
hx-swap="beforeend">
|
||||||
|
Link senden
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs text-gray-500 mt-2">
|
||||||
|
Gültig bis {{ accessLinkExpiresAt | date('d.m.Y') }}
|
||||||
|
{% if accessLinkExpiresAt < date() %}
|
||||||
|
<span class="text-red-600 font-medium">(abgelaufen)</span>
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<p class="text-sm text-gray-500">
|
||||||
|
Der Zugangslink wird beim Versand des Angebots erzeugt.
|
||||||
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</twig:form:section>
|
||||||
{% else %}
|
|
||||||
<p class="text-sm text-gray-500">
|
|
||||||
Der Zugangslink wird beim Versand des Angebots erzeugt.
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-between pt-8">
|
<twig:form:section title="Aktionen">
|
||||||
<a href="{{ returnUrl }}" class="button button--secondary button--small">
|
<div class="flex flex-col gap-2">
|
||||||
zurück
|
<a href="{{ path('app_admin_accommodationbooking_edit', edit_params) }}"
|
||||||
</a>
|
class="button {{ has_next_step ? 'button--neutral' : 'button--primary' }} button--small w-full">
|
||||||
<div class="flex items-center gap-2">
|
bearbeiten
|
||||||
{% if not booking.confirmed and not booking.discarded %}
|
</a>
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="button button--warning button--small"
|
class="button button--neutral button--small w-full"
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_discard', { id: booking.id }) }}"
|
hx-get="{{ path('app_admin_accommodationbooking_duplicate', edit_params) }}"
|
||||||
hx-target="body"
|
hx-target="body"
|
||||||
hx-swap="beforeend">
|
hx-swap="beforeend">
|
||||||
Absagen
|
duplizieren
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
<a href="{{ path('app_admin_accommodationbooking_pdf', { 'id': booking.id }) }}"
|
||||||
{% if booking.confirmed %}
|
class="button button--neutral button--small w-full">
|
||||||
<a href="{{ path('app_admin_accommodationbooking_pdf', { 'id': booking.id }) }}" class="button button--secondary button--small">
|
PDF herunterladen
|
||||||
PDF herunterladen
|
</a>
|
||||||
</a>
|
</div>
|
||||||
{% endif %}
|
{% if not booking.confirmed and not booking.discarded %}
|
||||||
{% set edit_params = { 'id': booking.id } %}
|
<div class="mt-4 pt-3 border-t border-gray-200 text-center">
|
||||||
{% if app.request.query.get('r') %}
|
<button type="button"
|
||||||
{% set edit_params = edit_params | merge({ 'r': app.request.query.get('r') }) %}
|
class="text-sm font-medium text-red-600 hover:underline"
|
||||||
{% endif %}
|
hx-get="{{ path('app_admin_accommodationbooking_discard', { id: booking.id }) }}"
|
||||||
<button type="button"
|
hx-target="body"
|
||||||
class="button button--secondary button--small"
|
hx-swap="beforeend">
|
||||||
hx-get="{{ path('app_admin_accommodationbooking_duplicate', edit_params) }}"
|
{{ booking.recordLabel }} absagen
|
||||||
hx-target="body"
|
</button>
|
||||||
hx-swap="beforeend">
|
</div>
|
||||||
duplizieren
|
{% endif %}
|
||||||
</button>
|
</twig:form:section>
|
||||||
<a href="{{ path('app_admin_accommodationbooking_edit', edit_params) }}" class="button button--primary button--small">
|
|
||||||
bearbeiten
|
<a href="{{ returnUrl }}" class="inline-block text-sm text-gray-500 hover:text-gray-900 hover:underline">
|
||||||
|
← zurück
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
|
{# step_routes defaults to the booking flow; other flows (the voucher purchase) pass their own #}
|
||||||
{% set current_step = current_step ?? 1 %}
|
{% set current_step = current_step ?? 1 %}
|
||||||
{% set step_routes = {
|
{% set step_routes = step_routes ?? {
|
||||||
1: 'app_booking_create_step_1',
|
1: 'app_booking_create_step_1',
|
||||||
2: 'app_booking_create_step_2',
|
2: 'app_booking_create_step_2',
|
||||||
3: 'app_booking_create_step_3',
|
3: 'app_booking_create_step_3',
|
||||||
4: 'app_booking_create_step_4'
|
4: 'app_booking_create_step_4'
|
||||||
} %}
|
} %}
|
||||||
<nav class="pagination">
|
<nav class="pagination">
|
||||||
{% for step in 1..4 %}
|
{% for step, step_route in step_routes %}
|
||||||
<div class="pagination-item">
|
<div class="pagination-item">
|
||||||
{% if step < current_step %}
|
{% if step < current_step %}
|
||||||
<a href="{{ path(step_routes[step]) }}"
|
<a href="{{ path(step_route) }}"
|
||||||
class="pagination-item__border">
|
class="pagination-item__border">
|
||||||
<span class="pagination-item__inner bg-primary-bg text-gray-800">
|
<span class="pagination-item__inner bg-primary-bg text-gray-800">
|
||||||
{{ step }}
|
{{ step }}
|
||||||
|
|||||||
@@ -36,60 +36,7 @@
|
|||||||
Als Gast fortfahren
|
Als Gast fortfahren
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
{% include '_partials/_purchase_login_form.html.twig' %}
|
||||||
<h2 class="text-white">
|
|
||||||
Mit bestehendem Account anmelden
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
{% if error %}
|
|
||||||
{% include '_partials/_alert.html.twig' with { 'level': 'error', messages: [ error.messageKey|trans(error.messageData, 'security') ] } %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<form action="{{ path('app_login') }}" method="post" hx-history="false">
|
|
||||||
<div class="mb-4">
|
|
||||||
<label for="username" class="mb-1 font-semibold text-white">
|
|
||||||
E-Mail:
|
|
||||||
</label>
|
|
||||||
<input type="email"
|
|
||||||
id="username"
|
|
||||||
name="_username"
|
|
||||||
value="{{ last_username }}"
|
|
||||||
class="form-field"
|
|
||||||
required
|
|
||||||
autocomplete="username">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-4" {{ stimulus_controller('password-reveal') }}>
|
|
||||||
<label for="password" class="mb-1 font-semibold text-white">
|
|
||||||
Passwort:
|
|
||||||
</label>
|
|
||||||
<div class="relative">
|
|
||||||
<input type="password"
|
|
||||||
id="password"
|
|
||||||
name="_password"
|
|
||||||
class="form-field"
|
|
||||||
{{ stimulus_target('password-reveal', 'field') }}
|
|
||||||
required
|
|
||||||
autocomplete="current-password">
|
|
||||||
<button type="button"
|
|
||||||
{{ stimulus_action('password-reveal', 'toggle') }}
|
|
||||||
class="absolute top-0 right-0 mt-2 mr-2">
|
|
||||||
{{ icon('eye', 'w-6 h-6 text-gray-500') }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button type="submit" class="button button--primary w-full md:w-auto">
|
|
||||||
Anmelden und fortfahren
|
|
||||||
</button>
|
|
||||||
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<a href="{{ path('app_reset_password') }}"
|
|
||||||
class="inline-block text-sm underline text-white mt-2">
|
|
||||||
Passwort vergessen?
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h3 class=" text-white">
|
<h3 class=" text-white">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container mx-auto px-4 py-8">
|
<div class="container mx-auto px-4 py-8">
|
||||||
<div class="max-w-lg mx-auto">
|
<div class="max-w-lg mx-auto">
|
||||||
{% set errorMessages = app.flashes('error')|default(['Es ist ein Fehler beim Starten des Buchungsvorgangs aufgetreten.']) %}
|
{% set errorMessages = app.flashes('error')|default([defaultErrorMessage ?? 'Es ist ein Fehler beim Starten des Buchungsvorgangs aufgetreten.']) %}
|
||||||
{% include '_partials/_alert.html.twig' with {
|
{% include '_partials/_alert.html.twig' with {
|
||||||
level: 'error',
|
level: 'error',
|
||||||
title: 'Das hat nicht geklappt',
|
title: 'Das hat nicht geklappt',
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{#- A titled panel grouping the fields of a long admin form. No overflow-hidden: the dots
|
||||||
|
dropdowns inside must be able to open past its edge. -#}
|
||||||
|
<div {{ attributes.defaults({class: 'bg-white border border-gray-200 rounded-md'}).without('title') }}>
|
||||||
|
<div class="flex items-center justify-between gap-4 px-4 py-2 bg-gray-100 border-b border-gray-200 rounded-t-md font-bold">
|
||||||
|
{{ title }}
|
||||||
|
{% block actions %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
<div class="p-4">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -11,6 +11,17 @@
|
|||||||
<h2>Preise</h2>
|
<h2>Preise</h2>
|
||||||
|
|
||||||
<table style="width: 100%; border-collapse: collapse; font-size: 14px;">
|
<table style="width: 100%; border-collapse: collapse; font-size: 14px;">
|
||||||
|
{% for period in priceBreakdown.periods|filter(p => p.position == 'leading') %}
|
||||||
|
{% include 'email/_price_breakdown_period.html.twig' %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if priceBreakdown.periods is not empty %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" style="{{ cell }} border-top: 1px solid #d1d5db; font-weight: bold;">
|
||||||
|
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 %}
|
{% if priceBreakdown.basePrice > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="{{ cell }}">
|
<td style="{{ cell }}">
|
||||||
@@ -64,6 +75,9 @@
|
|||||||
<td style="{{ amount }}">{{ (priceBreakdown.runningCosts / 100)|format_currency(currency) }}</td>
|
<td style="{{ amount }}">{{ (priceBreakdown.runningCosts / 100)|format_currency(currency) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for period in priceBreakdown.periods|filter(p => p.position == 'trailing') %}
|
||||||
|
{% include 'email/_price_breakdown_period.html.twig' %}
|
||||||
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="{{ cell }} border-top: 1px solid #d1d5db; font-weight: bold;">
|
<td style="{{ cell }} border-top: 1px solid #d1d5db; font-weight: bold;">
|
||||||
Gesamtpreis
|
Gesamtpreis
|
||||||
@@ -103,3 +117,4 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{#- One split-off period of _price_breakdown.html.twig: its range as a heading, then its lines.
|
||||||
|
Context: period, cell, amount, currency. -#}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" style="{{ cell }} border-top: 1px solid #d1d5db; font-weight: bold;">
|
||||||
|
{% if period.label ?? null %}{{ period.label }} · {% endif %}
|
||||||
|
{{ period.dateFrom|date('d.m.Y') }} – {{ period.dateTo|date('d.m.Y') }},
|
||||||
|
{{ period.nights }} {{ period.nights != 1 ? 'Nächte' : 'Nacht' }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for line in period.lines %}
|
||||||
|
<tr>
|
||||||
|
<td style="{{ cell }}">{{ line.label }}</td>
|
||||||
|
<td style="{{ amount }}">{{ (line.amount / 100)|format_currency(currency) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
@@ -19,6 +19,12 @@
|
|||||||
<td><strong>Nächte</strong></td>
|
<td><strong>Nächte</strong></td>
|
||||||
<td>{{ booking.nights }}</td>
|
<td>{{ booking.nights }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% if booking.periods is not empty %}
|
||||||
|
<tr>
|
||||||
|
<td><strong>Zeitraum Gruppe</strong></td>
|
||||||
|
<td>{{ booking.mainDateFrom|date('d.m.Y') }} – {{ booking.mainDateTo|date('d.m.Y') }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>Anzahl Personen</strong></td>
|
<td><strong>Anzahl Personen</strong></td>
|
||||||
<td>{{ booking.paxCount }}</td>
|
<td>{{ booking.paxCount }}</td>
|
||||||
|
|||||||
@@ -244,7 +244,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
<td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
|
||||||
<div style="font-family:Lato, Verdana, Arial, 'Helvetica neue', sans-serif;font-size:14px;line-height:18px;text-align:left;color:#FFFFFF;">E&P Reisen und Events GmbH <br /> Aachener Str. 326-328 <br /> 50933 Köln</div>
|
<div style="font-family:Lato, Verdana, Arial, 'Helvetica neue', sans-serif;font-size:14px;line-height:18px;text-align:left;color:#FFFFFF;">E&P Reisen und Events GmbH <br /> Neue Weyerstraße 6<br />50676 Köln</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -146,7 +146,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
{{ block('form_widget_simple') }}
|
{{ block('form_widget_simple') }}
|
||||||
<span class="{{ currency_class }}">€</span>
|
<span class="{{ currency_class }}">{{ money_pattern|replace({'{{ widget }}': ''})|trim }}</span>
|
||||||
</div>
|
</div>
|
||||||
{%- endblock money_widget -%}
|
{%- endblock money_widget -%}
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% for period in ctx.priceBreakdown.periods|filter(p => p.position == 'leading') %}
|
||||||
|
{% include 'groups/offer/_summary_period.html.twig' %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if ctx.priceBreakdown.periods is not empty %}
|
||||||
|
<tr class="border-t border-primary-bg font-semibold">
|
||||||
|
<td class="p-2" colspan="2">
|
||||||
|
Gruppe · {{ booking.mainDateFrom|date('d.m.Y') }} – {{ booking.mainDateTo|date('d.m.Y') }},
|
||||||
|
{{ ctx.priceBreakdown.nights }} {{ ctx.priceBreakdown.nights != 1 ? 'Nächte' : 'Nacht' }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% if ctx.priceBreakdown.basePrice > 0 %}
|
{% if ctx.priceBreakdown.basePrice > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="p-2">
|
<td class="p-2">
|
||||||
@@ -141,6 +152,9 @@
|
|||||||
<td class="p-2 text-right whitespace-nowrap">{{ (ctx.priceBreakdown.runningCosts / 100)|format_currency(currency) }}</td>
|
<td class="p-2 text-right whitespace-nowrap">{{ (ctx.priceBreakdown.runningCosts / 100)|format_currency(currency) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% for period in ctx.priceBreakdown.periods|filter(p => p.position == 'trailing') %}
|
||||||
|
{% include 'groups/offer/_summary_period.html.twig' %}
|
||||||
|
{% endfor %}
|
||||||
<tr class="border-t border-primary-bg font-semibold text-base">
|
<tr class="border-t border-primary-bg font-semibold text-base">
|
||||||
<td class="p-2">
|
<td class="p-2">
|
||||||
Gesamtpreis
|
Gesamtpreis
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{#- One split-off period of the offer summary: its range as a heading, then its lines.
|
||||||
|
Context: period, currency. -#}
|
||||||
|
<tr class="border-t border-primary-bg font-semibold">
|
||||||
|
<td class="p-2" colspan="2">
|
||||||
|
{% if period.label ?? null %}{{ period.label }} · {% endif %}
|
||||||
|
{{ period.dateFrom|date('d.m.Y') }} – {{ period.dateTo|date('d.m.Y') }},
|
||||||
|
{{ period.nights }} {{ period.nights != 1 ? 'Nächte' : 'Nacht' }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for line in period.lines %}
|
||||||
|
<tr>
|
||||||
|
<td class="p-2">{{ line.label }}</td>
|
||||||
|
<td class="p-2 text-right whitespace-nowrap">{{ (line.amount / 100)|format_currency(currency) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
Loaded 100 of 141 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user