feat: refactor to cards
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,332 @@
|
||||
# MyEP Next Booking - Project Overview
|
||||
|
||||
**Symfony 6.4 travel booking application** integrating with Bus Pro Net (BPN) XML API.
|
||||
|
||||
## Core Architecture
|
||||
|
||||
### Multi-Step Booking Flow
|
||||
1. **Step 1**: Room selection and dates (`Create\Step1Controller`)
|
||||
2. **Step 2**: Participant details with card-based UI (`Create\Step2Controller`)
|
||||
3. **Step 3**: Payment method selection (`Create\Step3Controller`)
|
||||
4. **Step 4**: Final confirmation and submission to BPN API (`Create\Step4Controller`)
|
||||
5. **Edit Flow**: Similar card-based UI for existing bookings (`Edit\IndexController`)
|
||||
|
||||
### Card-Based UI Pattern (Production)
|
||||
- **Overview**: Grid of participant cards with lazy-loaded individual forms
|
||||
- **Performance**: Handles 50+ participants efficiently via HTMX
|
||||
- **Controllers**:
|
||||
- `Create\Step2Controller` - create flow with validation before step 3
|
||||
- `Edit\IndexController` - edit flow with validation before API submission
|
||||
- **Shared Logic**:
|
||||
- `ParticipantCardFlowTrait` - Card rendering and form handling
|
||||
- `ParticipantValidationTrait` - Validation error extraction for card indicators
|
||||
- **Validation Pattern**:
|
||||
- Both controllers use validation-only forms (`BookingCreateStep2Type`, `BookingEditType`)
|
||||
- Standard Symfony form flow: `handleRequest()` → `isSubmitted()` → `isValid()`
|
||||
- On invalid: Extract error indices, display error banner, highlight cards, disable submit button
|
||||
- On valid: Proceed to next step (create) or submit to API (edit)
|
||||
|
||||
## Key Architectural Layers
|
||||
|
||||
### BusProNet Integration (`src/BusProNet/`)
|
||||
- `ApiClient` - XML API communication
|
||||
- `XmlParser/` - Response parsers (travels, hotels, bookings)
|
||||
- `XmlLoader/` - Data loaders with caching
|
||||
- `DataProcessor/` - Transform API data to DTOs
|
||||
|
||||
### Form System (`src/Form/`)
|
||||
- **DTOs**: `BookingCreateDto`, `ParticipantDto` (session-stored)
|
||||
- **Field Handlers**: 15+ specialized handlers in `src/Form/Service/`
|
||||
- Registered via service tags with dependency resolution
|
||||
- Process in dependency order via `ParticipantFieldHandlerRegistry`
|
||||
- **Conditional Fields**: Universal condition system (`FieldConditionInterface`)
|
||||
- Age-based, field-dependent, service-specific conditions
|
||||
- Applied via `CreateFieldStateProvider` / `EditFieldStateProvider`
|
||||
- **HTMX Integration**: Real-time updates for dynamic fields
|
||||
|
||||
### Service Layer (`src/Service/`)
|
||||
- `BookingService` - Core booking workflow
|
||||
- `BookingPriceCalculatorService` - Real-time pricing
|
||||
- `BookingFingerprintService` - Dirty state detection for edit mode
|
||||
- `TravelDataService` - API integration and caching
|
||||
- `ParticipantCardDataService` - Card display data
|
||||
- `InsuranceMatchingService` - Insurance eligibility and auto-reassignment
|
||||
- `RoomAssignmentService` - Automatic room assignment
|
||||
|
||||
## Critical Patterns
|
||||
|
||||
### Field Handler Pattern
|
||||
```php
|
||||
// Handlers process in dependency order (topological sort)
|
||||
// Example: insurance handler depends on ALL price-affecting fields
|
||||
$this->fieldHandlerRegistry->processFieldsForParticipant(
|
||||
$participantData,
|
||||
$bookingDto,
|
||||
$index
|
||||
);
|
||||
```
|
||||
|
||||
**Important**: Field handlers use "sync pattern" - only sync fields present in original submission to avoid validation errors.
|
||||
|
||||
### HTMX Block-Based Rendering
|
||||
```php
|
||||
// All HTMX swaps target #main-content with innerHTML
|
||||
// OOB swaps for sidebar: #booking-summary
|
||||
return $this->htmxOobResponse(
|
||||
'booking/_participant_form.html.twig',
|
||||
['participant_form', 'booking_summary'],
|
||||
$templateData
|
||||
);
|
||||
```
|
||||
|
||||
### Service Enrichment Pattern
|
||||
Services from BPN API may lack complete data (especially prices). Always enrich from travel data:
|
||||
```php
|
||||
// BookingDataProcessor::enrichParticipantServicesFromTravel()
|
||||
// Looks up each service in travel data and replaces with full version
|
||||
```
|
||||
|
||||
### Notification System
|
||||
Field handlers generate notifications (auto-changes) → collected by controller → sent via HX-Trigger → displayed as toasts.
|
||||
|
||||
### Dirty State Detection (Edit Mode)
|
||||
Fingerprint-based change detection to warn users about unsaved modifications:
|
||||
- **BookingFingerprintService** generates SHA-256 hash of all mutable booking data
|
||||
- Original fingerprint stored in `BookingDto::$originalFingerprint` on API load
|
||||
- `isDirty()` compares current state with original to detect changes
|
||||
- Yellow warning banner displays when changes detected
|
||||
- Update button conditionally shown only when dirty
|
||||
- Fingerprint persists in session, survives page refreshes
|
||||
- Resets on submission, "Änderungen verwerfen", or "Zurück" actions
|
||||
|
||||
**Unavailable Services Handling:**
|
||||
- Services with `available <= 0` included in edit mode (not filtered out)
|
||||
- `ParticipantFieldOptionsProvider::shouldMakeServiceReadonly()` implements intelligent readonly logic:
|
||||
- **Create mode**: Uses standard availability calculator (filters out unavailable services)
|
||||
- **Edit mode**: Services participants already have remain editable even if now fully booked
|
||||
- **Edit mode**: Unavailable services participant doesn't have are marked readonly
|
||||
- Prevents fingerprint false positives when services become fully booked during editing session
|
||||
- Ensures service IDs remain consistent in form submissions for accurate dirty detection
|
||||
|
||||
## Key Service Dependencies
|
||||
|
||||
### Field Handler Execution Order
|
||||
Critical for correct pricing and auto-reassignment:
|
||||
1. Age-dependent fields (dateOfBirth)
|
||||
2. Price-affecting services (skiPass, rentals, courses, board, transportation, pickup, parking)
|
||||
3. **Insurance handler LAST** (depends on all price-affecting fields)
|
||||
4. Bulk insurance handler (applicant only)
|
||||
|
||||
### Insurance System
|
||||
- **3-pass parsing**: Referenced IDs → Individual insurances → Packages with family detection
|
||||
- **Auto-reassignment**: Maintains insurance type when price tier changes
|
||||
- **Age constraints**: Absolute age (at travel date) vs birth year
|
||||
- **Hydration**: `TravelDataService::hydrateInsurancePackageRelationships()` rebuilds package relationships after cache deserialization
|
||||
|
||||
### Transportation Services
|
||||
- **Unified pickup field**: Single field for both directions (BPN API limitation)
|
||||
- **Conditional visibility**: Pickup vs parking fields mutually exclusive
|
||||
- **Direction mapping**: `DirectionMapper` translates API ↔ internal codes
|
||||
|
||||
## Important Field Dependencies
|
||||
|
||||
### Ski Pass → Rentals → Insurance → Body Dimensions
|
||||
- Rentals filtered by ski pass duration (exact date matching)
|
||||
- Rental insurance only shown when rentals selected
|
||||
- Body dimensions only shown when rentals selected
|
||||
- All cleared automatically when dependencies removed
|
||||
|
||||
### Date of Birth → Age-Dependent Services
|
||||
- Courses, additional services, board, insurance hidden until DOB provided
|
||||
- Age evaluated at travel start date, not current date
|
||||
- Dual constraint types: absolute_age, birth_year, mixed
|
||||
|
||||
### Bulk Insurance Booking
|
||||
- Applicant enables bulk → applies to all participants
|
||||
- `BulkInsuranceBookingCondition` hides dependent participant insurance fields
|
||||
- Uses `InsuranceMatchingService::batchAssignInsuranceToParticipants()` for price tier matching
|
||||
|
||||
## Data Flow
|
||||
|
||||
### Create Flow
|
||||
1. Load/create DTO from session
|
||||
2. Enrich with fresh API availability data
|
||||
3. Auto-assign rooms, preselect mandatory services
|
||||
4. Render cards → user edits participant → field handlers process → save to session
|
||||
5. Validation check before step 3
|
||||
6. Final submission to BPN API
|
||||
|
||||
### Edit Flow
|
||||
1. Load booking from BPN API on first visit
|
||||
2. Generate fingerprint of initial state for dirty detection
|
||||
3. Store in session with `MODE_EDIT`
|
||||
4. Apply mutability constraints via `EditFieldStateProvider`
|
||||
5. Same card-based UI as create flow
|
||||
6. Handle canceled participants (status 'S')
|
||||
7. Display warning banner when unsaved changes detected
|
||||
8. **Validation on submission**: Form wraps cards, validates all participants before API call
|
||||
9. Submit changes back to BPN API (only if validation passes)
|
||||
10. Staleness warnings after 5 minutes
|
||||
11. **Session cleanup**: "Zurück" button clears session via `app_booking_edit_cancel` action
|
||||
|
||||
## Common Development Tasks
|
||||
|
||||
### Adding a New Field Handler
|
||||
1. Create handler class extending `AbstractParticipantFieldHandler`
|
||||
2. Implement `shouldProcess()`, `process()`, `getDependencies()`
|
||||
3. Register in `services.yaml` with `participant.field_handler` tag
|
||||
4. Add field options to `ParticipantFieldOptionsProvider`
|
||||
5. Add conditional logic to `CreateFieldStateProvider` if needed
|
||||
6. Update template with HTMX refresh triggers
|
||||
|
||||
### Adding a New Conditional Field
|
||||
1. Create condition class implementing `FieldConditionInterface`
|
||||
2. Register in `CreateFieldStateProvider::registerFieldStateConditions()`
|
||||
3. Use composite conditions for complex logic (AND/OR/NOT)
|
||||
|
||||
### Debugging Field Handler Issues
|
||||
- Check execution order in `ParticipantFieldHandlerRegistry` (topological sort)
|
||||
- Verify `shouldProcess()` logic for mode awareness
|
||||
- Ensure dependencies declared correctly
|
||||
- Check sync pattern: only sync fields in original submission
|
||||
|
||||
## File Locations
|
||||
|
||||
### Key Design Patterns
|
||||
|
||||
**Service Availability in Edit Mode:**
|
||||
Edit mode requires special handling of unavailable services to prevent fingerprint false positives:
|
||||
```php
|
||||
// ParticipantFieldOptionsProvider - intelligent availability filtering
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_COURSES,
|
||||
BookingDto::MODE_CREATE === $bookingDto->getMode() // Only filter in create mode
|
||||
)
|
||||
|
||||
// shouldMakeServiceReadonly() - context-aware readonly logic
|
||||
// In edit mode: service readonly ONLY if unavailable AND participant doesn't have it
|
||||
private function shouldMakeServiceReadonly(Service $service, BookingDto $bookingDto, int $participantIndex, string $fieldName): bool
|
||||
{
|
||||
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
|
||||
return $this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
// Edit mode: allow keeping services participant already has
|
||||
if (null !== $service->available && $service->available > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$participantHasService = match ($fieldName) {
|
||||
'courses' => $this->hasServiceById($participant->courses, $service->id),
|
||||
'additionalServices' => $this->hasServiceById($participant->additionalServices, $service->id),
|
||||
// ... other field types
|
||||
};
|
||||
|
||||
return !$participantHasService; // Readonly only if participant doesn't have it
|
||||
}
|
||||
```
|
||||
|
||||
**Session Lifecycle Management:**
|
||||
Edit mode session requires proper cleanup to prevent dirty state persistence:
|
||||
- **Entry**: `IndexController::loadFormData()` initializes from API with original fingerprint
|
||||
- **Exit (save)**: `IndexController::index()` clears session on successful API update
|
||||
- **Exit (discard)**: `IndexController::reloadFromApi()` clears session and reloads from API
|
||||
- **Exit (cancel)**: `IndexController::cancelEdit()` clears session when user clicks "Zurück"
|
||||
- **Validation**: Dirty state persists across page refreshes until explicit action taken
|
||||
|
||||
### Controllers
|
||||
**Create Namespace** (`src/Controller/Booking/Create/`):
|
||||
- `IndexController.php` - Booking session initialization and error handling
|
||||
- `Step1Controller.php` - Room selection and dates
|
||||
- `Step2Controller.php` - Participant details with card-based UI
|
||||
- `Step3Controller.php` - Payment method selection
|
||||
- `Step4Controller.php` - Final confirmation and API submission
|
||||
- `SuccessController.php` - Success page after booking completion
|
||||
|
||||
**Edit Namespace** (`src/Controller/Booking/Edit/`):
|
||||
- `IndexController.php` - Edit flow with card-based UI, validation, and session management
|
||||
- `index()` - Main edit view with dirty state detection
|
||||
- `editParticipant()` - Individual participant form editing
|
||||
- `refreshParticipantForm()` - HTMX refresh without validation
|
||||
- `reloadFromApi()` - Discard changes and reload from API
|
||||
- `cancelEdit()` - Clean session exit to bookings list
|
||||
|
||||
**Root Booking Namespace** (`src/Controller/Booking/`):
|
||||
- `IndexController.php` - Bookings list
|
||||
- `DownloadController.php` - Booking document downloads
|
||||
|
||||
**Shared Traits** (`src/Controller/Booking/Traits/`):
|
||||
- `ParticipantCardFlowTrait` - Card rendering, form creation, summary calculation
|
||||
- `ParticipantValidationTrait` - Validation error extraction for card indicators
|
||||
- `BookingCreateTrait` - Create flow helpers
|
||||
- `BookingDataTrait` - API data fetching
|
||||
- `BookingExceptionHandlerTrait` - Error handling
|
||||
|
||||
### Templates
|
||||
**Create Flow**:
|
||||
- `templates/booking/create/step_1.html.twig` - Room selection
|
||||
- `templates/booking/create/step_2.html.twig` - Participant cards
|
||||
- `templates/booking/create/step_3.html.twig` - Payment method
|
||||
- `templates/booking/create/step_4.html.twig` - Confirmation
|
||||
- `templates/booking/create/success.html.twig` - Success page
|
||||
- `templates/booking/create/error.html.twig` - Error page
|
||||
|
||||
**Edit Flow**:
|
||||
- `templates/booking/edit/index.html.twig` - Edit with participant cards
|
||||
|
||||
**Shared Components**:
|
||||
- `templates/booking/_participant_card.html.twig` - Individual participant card
|
||||
- `templates/booking/_participant_form.html.twig` - Participant edit form
|
||||
- `templates/booking/_summary.html.twig` - Pricing summary sidebar
|
||||
|
||||
### Services
|
||||
- `src/Service/BookingService.php` - Core workflow and session management
|
||||
- `src/Service/BookingFingerprintService.php` - Dirty state detection via SHA-256 fingerprinting
|
||||
- `src/Service/ParticipantCardDataService.php` - Card data generation
|
||||
- `src/Form/Service/ParticipantFieldHandlerRegistry.php` - Handler orchestration
|
||||
- `src/Form/Service/ParticipantFieldOptionsProvider.php` - Field configuration with mode-aware availability
|
||||
- `src/Form/Service/CreateFieldStateProvider.php` - Conditional field states
|
||||
- `src/Form/Service/EditFieldStateProvider.php` - Edit mode mutability constraints
|
||||
|
||||
### Field Handlers
|
||||
- `src/Form/Service/Participant*FieldHandler.php` (15+ handlers)
|
||||
- Transportation, pickup, parking, ski pass, rentals, insurance, bulk insurance, etc.
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
./vendor/bin/phpunit # All tests
|
||||
./vendor/bin/phpunit tests/Service/ # Service layer
|
||||
./vendor/bin/phpunit tests/BusProNet/ # API integration
|
||||
./vendor/bin/php-cs-fixer fix # Code style (Symfony ruleset)
|
||||
```
|
||||
|
||||
## Development Environment
|
||||
|
||||
```bash
|
||||
ddev start # Start DDEV
|
||||
ddev composer install # Install dependencies
|
||||
ddev exec bin/console cache:clear # Clear cache
|
||||
ddev logs # Read PHP error logs
|
||||
ddev exec "php -r 'opcache_reset()';" # Clear opcache after code changes
|
||||
```
|
||||
|
||||
## Important Notes
|
||||
|
||||
- **Room prices are per person**
|
||||
- **Zero prices display without suffix** (e.g., "Vollpension" not "Vollpension (€0,00)")
|
||||
- **All services sorted by price** (cheapest first) via `SortByPriceTrait`
|
||||
- **Field sync pattern critical**: Only sync fields in original submission to avoid "extra fields" errors
|
||||
- **Insurance handler requires mode awareness**: Skips processing in edit mode (API doesn't return insurance data)
|
||||
- **Clear opcache after code changes** affecting hydration or serialization
|
||||
- **HTMX targeting consistency**: All swaps target `#main-content` with `innerHTML`, sidebar via OOB swap
|
||||
- **Validation pattern**: Both create and edit flows use validation-only forms that wrap card UI for standard Symfony form handling
|
||||
- **Card error indicators**: `ParticipantValidationTrait::extractParticipantErrorIndices()` parses form errors to highlight invalid participant cards
|
||||
- **Edit mode service availability**: Services with `available <= 0` remain visible and editable for participants who already have them (prevents fingerprint false positives)
|
||||
- **Session cleanup on exit**: All exit paths from edit mode (save, discard, cancel) properly clear session to reset dirty state
|
||||
|
||||
## References
|
||||
|
||||
- **Project conventions**: `../CLAUDE.md` (root level)
|
||||
- **User preferences**: `~/.claude/CLAUDE.md`
|
||||
- **Documentation index**: `README.md` (this directory)
|
||||
@@ -258,12 +258,8 @@ $grandTotal = $serviceTotal + $roomTotal;
|
||||
## 📚 Documentation
|
||||
|
||||
### Available Documentation
|
||||
- **[CLAUDE.md](CLAUDE.md)**: Development guidelines for AI assistance
|
||||
- **[Field State System](docs/FIELD_STATE_SYSTEM.md)**: Conditional field architecture
|
||||
- **[Form Processing](docs/FORM_PROCESSING.md)**: Form handler system details
|
||||
- **[Pricing Implementation](docs/PRICING_DISPLAY_IMPLEMENTATION.md)**: Pricing system documentation
|
||||
- **[Transportation Services](docs/TRANSPORTATION_SERVICES_IMPLEMENTATION_PLAN.md)**: Transportation feature details
|
||||
- **[Age-Based Fields](docs/AGE_BASED_FIELDS_PLAN.md)**: Age constraint system
|
||||
- **[PROJECT_OVERVIEW.md](PROJECT_OVERVIEW.md)**: Comprehensive architecture and implementation guide
|
||||
- **[CLAUDE.md](../CLAUDE.md)**: Development guidelines for AI assistance (root level)
|
||||
|
||||
### Architecture Documentation
|
||||
Each major system component has detailed documentation covering:
|
||||
@@ -110,12 +110,85 @@ class BookingDataProcessor
|
||||
$room = $booking->getRoomForParticipant($index);
|
||||
$participantData->assignedRoomId = $room?->id;
|
||||
|
||||
// Enrich services with data from travel (especially prices)
|
||||
$this->enrichParticipantServicesFromTravel($participantData, $travel);
|
||||
|
||||
$dto->participants[$index] = $participantData;
|
||||
}
|
||||
|
||||
return $dto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enriches participant service selections with data from travel model.
|
||||
*
|
||||
* Services extracted from booking API responses might not include all necessary data
|
||||
* (especially prices). This method looks up each service in the travel data and copies
|
||||
* over missing properties to ensure proper pricing calculations.
|
||||
*
|
||||
* @param ParticipantDto $participant The participant with service selections
|
||||
* @param Travel $travel The travel data containing full service information
|
||||
*/
|
||||
private function enrichParticipantServicesFromTravel(ParticipantDto $participant, Travel $travel): void
|
||||
{
|
||||
// Enrich courses
|
||||
foreach ($participant->courses as $key => $course) {
|
||||
if (isset($travel->additionalServices[$course->id])) {
|
||||
$participant->courses[$key] = $travel->additionalServices[$course->id];
|
||||
}
|
||||
}
|
||||
|
||||
// Enrich ski pass
|
||||
if (null !== $participant->skiPass && isset($travel->additionalServices[$participant->skiPass->id])) {
|
||||
$participant->skiPass = $travel->additionalServices[$participant->skiPass->id];
|
||||
}
|
||||
|
||||
// Enrich additional services
|
||||
foreach ($participant->additionalServices as $key => $service) {
|
||||
if (isset($travel->additionalServices[$service->id])) {
|
||||
$participant->additionalServices[$key] = $travel->additionalServices[$service->id];
|
||||
}
|
||||
}
|
||||
|
||||
// Enrich board
|
||||
foreach ($participant->board as $key => $board) {
|
||||
if (isset($travel->additionalServices[$board->id])) {
|
||||
$participant->board[$key] = $travel->additionalServices[$board->id];
|
||||
}
|
||||
}
|
||||
|
||||
// Enrich rentals
|
||||
foreach ($participant->rentals as $key => $rental) {
|
||||
if (isset($travel->additionalServices[$rental->id])) {
|
||||
$participant->rentals[$key] = $travel->additionalServices[$rental->id];
|
||||
}
|
||||
}
|
||||
|
||||
// Enrich rental insurance
|
||||
if (null !== $participant->rentalInsurance && isset($travel->additionalServices[$participant->rentalInsurance->id])) {
|
||||
$participant->rentalInsurance = $travel->additionalServices[$participant->rentalInsurance->id];
|
||||
}
|
||||
|
||||
// Enrich transportation services
|
||||
if (null !== $participant->transportationOutbound && isset($travel->transportationServices[$participant->transportationOutbound->id])) {
|
||||
$participant->transportationOutbound = $travel->transportationServices[$participant->transportationOutbound->id];
|
||||
}
|
||||
|
||||
if (null !== $participant->transportationInbound && isset($travel->transportationServices[$participant->transportationInbound->id])) {
|
||||
$participant->transportationInbound = $travel->transportationServices[$participant->transportationInbound->id];
|
||||
}
|
||||
|
||||
// Enrich pickup
|
||||
if (null !== $participant->pickup && isset($travel->pickupsOutbound[$participant->pickup->id])) {
|
||||
$participant->pickup = $travel->pickupsOutbound[$participant->pickup->id];
|
||||
}
|
||||
|
||||
// Enrich insurance
|
||||
if (null !== $participant->insurance && isset($travel->insurances[$participant->insurance->id])) {
|
||||
$participant->insurance = $travel->insurances[$participant->insurance->id];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an update request payload for the BusProNet API from booking form data.
|
||||
*
|
||||
|
||||
+8
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
@@ -23,7 +23,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
* without requiring random UID parameters. It creates fresh booking sessions
|
||||
* and redirects to the first step of the booking process.
|
||||
*/
|
||||
class CreateInitController extends AbstractController
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly BookingService $bookingService,
|
||||
@@ -42,7 +42,11 @@ class CreateInitController extends AbstractController
|
||||
* corresponding agency ID is stored in the booking. If not provided or invalid,
|
||||
* defaults to agency code '0001'.
|
||||
*/
|
||||
#[Route('/bookings/create/{dateId}/{hotelId}', name: 'app_booking_create_init', requirements: ['dateId' => '\d+', 'hotelId' => '\d+'])]
|
||||
#[Route(
|
||||
path: '/bookings/create/{dateId}/{hotelId}',
|
||||
name: 'app_booking_create_init',
|
||||
requirements: ['dateId' => '\d+', 'hotelId' => '\d+']
|
||||
)]
|
||||
public function init(Request $request, int $dateId, int $hotelId): Response
|
||||
{
|
||||
try {
|
||||
@@ -110,6 +114,6 @@ class CreateInitController extends AbstractController
|
||||
#[Route('/bookings/create/error', name: 'app_booking_create_error')]
|
||||
public function error(Request $request): Response
|
||||
{
|
||||
return $this->render('booking/create_error.html.twig');
|
||||
return $this->render('booking/create/error.html.twig');
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -2,8 +2,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\Controller\Booking\Traits\BookingCreateTrait;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Form\BookingCreateStep1Type;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingService;
|
||||
@@ -18,7 +20,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
* This controller manages room selection functionality where users
|
||||
* choose the types and quantities of rooms for their booking.
|
||||
*/
|
||||
class CreateStep1Controller extends AbstractController
|
||||
class Step1Controller extends AbstractController
|
||||
{
|
||||
use BookingCreateTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
@@ -81,7 +83,7 @@ class CreateStep1Controller extends AbstractController
|
||||
$groupedRooms = $this->bookingService->groupRoomsBySelectionType($availableRooms);
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($summary['selectedRooms'], $availableRooms);
|
||||
|
||||
return $this->render('booking/create_step_1.html.twig', [
|
||||
return $this->render('booking/create/step_1.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'roomSummary' => $summary['selectedRooms'],
|
||||
'participantCount' => $summary['participantCount'],
|
||||
@@ -121,7 +123,7 @@ class CreateStep1Controller extends AbstractController
|
||||
// The DTO is now updated with the latest selection.
|
||||
// We can now render the blocks with the fresh data.
|
||||
return $this->htmxOobResponse(
|
||||
'booking/create_step_1.html.twig',
|
||||
'booking/create/step_1.html.twig',
|
||||
['room_selection_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\Controller\Booking\Traits\BookingCreateTrait;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Controller\Booking\Traits\ParticipantCardFlowTrait;
|
||||
use App\Controller\Booking\Traits\ParticipantValidationTrait;
|
||||
use App\Form\BookingCreateStep2Type;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\ParticipantCardDataService;
|
||||
use App\Service\RoomAssignmentService;
|
||||
use App\Service\TravelDataService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
* Handles the second step of the booking creation process using card-based UI.
|
||||
*
|
||||
* This controller uses a card overview and lazy-loaded individual participant forms
|
||||
* for better performance and UX with large groups (50+ participants).
|
||||
*/
|
||||
class Step2Controller extends AbstractController
|
||||
{
|
||||
use BookingCreateTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
use HxTrait;
|
||||
use ParticipantCardFlowTrait;
|
||||
use ParticipantValidationTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly BookingService $bookingService,
|
||||
private readonly BookingPriceCalculatorService $priceCalculator,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly RoomAssignmentService $roomAssignmentService,
|
||||
private readonly ParticipantCardDataService $participantCardService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display card grid for all participants.
|
||||
*/
|
||||
#[Route('/bookings/create/participants', name: 'app_booking_create_step_2')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
// Load or create booking DTO
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
return $result;
|
||||
}
|
||||
$bookingCreateDto = $result;
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||
|
||||
// Validate step access
|
||||
if ($redirect = $this->validateStepAccess($bookingCreateDto, 2)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// Ensure correct number of participants
|
||||
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
|
||||
|
||||
// Auto-assign rooms if needed
|
||||
$this->autoAssignRoomsIfNeeded($bookingCreateDto);
|
||||
|
||||
// Preselect mandatory services
|
||||
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
|
||||
|
||||
// Save BookingDto to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
|
||||
// Create validation form
|
||||
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
||||
'validation_groups' => ['booking_create_step_2'],
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Handle form submission (clicking "Weiter")
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// All participants validated successfully, update current step
|
||||
$bookingCreateDto->currentStep = 3;
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
|
||||
// Proceed to Step 3
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_3'));
|
||||
}
|
||||
|
||||
// Extract participant indices with validation errors
|
||||
$participantErrors = [];
|
||||
if ($form->isSubmitted() && false === $form->isValid()) {
|
||||
$participantErrors = $this->extractParticipantErrorIndices($form);
|
||||
}
|
||||
|
||||
// Generate cards data
|
||||
$cardsData = $this->generateAllCardsData($bookingCreateDto);
|
||||
|
||||
// Calculate summary data
|
||||
$summaryData = $this->calculateSummaryData($bookingCreateDto);
|
||||
|
||||
// Get detailed pricing data for summary sidebar
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
|
||||
|
||||
$templateData = [
|
||||
'form' => $form->createView(),
|
||||
'bookingDto' => $bookingCreateDto,
|
||||
'cardsData' => $cardsData,
|
||||
'summaryData' => $summaryData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'participantErrors' => $participantErrors,
|
||||
];
|
||||
|
||||
// If HTMX request, render only blocks to avoid layout duplication
|
||||
if ($this->isHxRequest($request)) {
|
||||
return $this->htmxOobResponse(
|
||||
'booking/create/step_2.html.twig',
|
||||
['participant_cards', 'booking_summary'],
|
||||
$templateData
|
||||
);
|
||||
}
|
||||
|
||||
// Regular request: render full template
|
||||
return $this->render('booking/create/step_2.html.twig', $templateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show or submit individual participant form.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/create/participants/{index}',
|
||||
name: 'app_booking_create_step_2_participant',
|
||||
requirements: ['index' => '\d+']
|
||||
)]
|
||||
public function editParticipant(int $index, Request $request): Response
|
||||
{
|
||||
$bookingDto = $this->loadBookingDtoOrFail($request, BookingDto::MODE_CREATE);
|
||||
|
||||
// Validate participant index
|
||||
if (false === isset($bookingDto->participants[$index])) {
|
||||
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Create form with booking_context option
|
||||
$form = $this->createParticipantForm($bookingDto, $index, [
|
||||
'validation_groups' => ['booking_create_step_2'],
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// Save BookingDto to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_CREATE);
|
||||
|
||||
// HTMX redirect to cards view
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_2'));
|
||||
}
|
||||
|
||||
// Calculate summary data for sidebar
|
||||
$summaryData = $this->calculateSummaryData($bookingDto);
|
||||
|
||||
// Get detailed pricing data for summary sidebar
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
|
||||
|
||||
// Render form and sidebar with OOB swap using htmxOobResponse
|
||||
// This ensures both initial load and refresh use the same block-based rendering
|
||||
return $this->htmxOobResponse(
|
||||
'booking/_participant_form.html.twig',
|
||||
['participant_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
'participantIndex' => $index,
|
||||
'bookingDto' => $bookingDto,
|
||||
'summaryData' => $summaryData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'refreshRouteName' => 'app_booking_create_step_2_participant_refresh',
|
||||
'submitRouteName' => 'app_booking_create_step_2_participant',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTMX refresh endpoint for individual participant form.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/create/participants/{index}/refresh',
|
||||
name: 'app_booking_create_step_2_participant_refresh',
|
||||
requirements: ['index' => '\d+'],
|
||||
methods: ['POST']
|
||||
)]
|
||||
public function refreshParticipantForm(int $index, Request $request): Response
|
||||
{
|
||||
$bookingDto = $this->loadBookingDtoOrFail($request, BookingDto::MODE_CREATE);
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingDto);
|
||||
|
||||
// Validate participant index
|
||||
if (false === isset($bookingDto->participants[$index])) {
|
||||
throw $this->createNotFoundException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Use trait method for refresh handling
|
||||
return $this->handleParticipantRefresh(
|
||||
$request,
|
||||
$bookingDto,
|
||||
$index,
|
||||
'app_booking_create_step_2_participant_refresh',
|
||||
'app_booking_create_step_2_participant'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the booking DTO has the correct number of participant objects.
|
||||
*/
|
||||
private function ensureCorrectNumberOfParticipants(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||
|
||||
$participants = $bookingCreateDto->participants;
|
||||
$bookingCreateDto->participants = [];
|
||||
for ($i = 0; $i < $participantsCount; ++$i) {
|
||||
$participant = $participants[$i] ?? new ParticipantDto();
|
||||
$participant->index = $i;
|
||||
$bookingCreateDto->participants[$i] = $participant;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enriches travel data with cached availability information from BusProNet API.
|
||||
*/
|
||||
private function enrichWithFreshAvailabilities(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
$dateId = $bookingCreateDto->travel->id;
|
||||
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($dateId, true);
|
||||
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($bookingCreateDto->travel, $availabilities);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically assigns participants to rooms if they don't have room assignments yet.
|
||||
*/
|
||||
private function autoAssignRoomsIfNeeded(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
// Check if any participants need room assignment
|
||||
$needsAssignment = false;
|
||||
foreach ($bookingCreateDto->participants as $participant) {
|
||||
if (null === $participant->assignedRoomId) {
|
||||
$needsAssignment = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($needsAssignment) {
|
||||
$this->roomAssignmentService->assignParticipantsToRooms($bookingCreateDto);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+64
-49
@@ -2,16 +2,20 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits\BookingCreateTrait;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Form\BookingCreateStep3Type;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -19,7 +23,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
/**
|
||||
* Handles the third step of the booking creation process (payment method selection).
|
||||
*/
|
||||
class CreateStep3Controller extends AbstractController
|
||||
class Step3Controller extends AbstractController
|
||||
{
|
||||
use BookingCreateTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
@@ -37,7 +41,7 @@ class CreateStep3Controller extends AbstractController
|
||||
* Displays and processes the payment method form.
|
||||
*/
|
||||
#[Route('/bookings/create/payment', name: 'app_booking_create_step_3')]
|
||||
public function step3(Request $request): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
@@ -66,29 +70,23 @@ class CreateStep3Controller extends AbstractController
|
||||
$inquiryResponse = $this->apiClient->createBookingInquiry($bookingCreateDto);
|
||||
|
||||
if ($inquiryResponse instanceof Notification) {
|
||||
$this->logger->error('Booking inquiry failed', [
|
||||
'message' => $inquiryResponse->message,
|
||||
]);
|
||||
$this->addFlash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.');
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
return $this->handleInquiryError(
|
||||
'Booking inquiry failed',
|
||||
['message' => $inquiryResponse->message],
|
||||
'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
if (false === $inquiryResponse->isInquiryValid()) {
|
||||
$this->logger->error('Booking inquiry validation failed', [
|
||||
'status' => $inquiryResponse->status,
|
||||
]);
|
||||
$this->addFlash('error', 'Buchung konnte nicht validiert werden.');
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
return $this->handleInquiryError(
|
||||
'Booking inquiry validation failed',
|
||||
['status' => $inquiryResponse->status],
|
||||
'Buchung konnte nicht validiert werden.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
// Validate price match (exact comparison)
|
||||
@@ -96,18 +94,17 @@ class CreateStep3Controller extends AbstractController
|
||||
$calculatedTotal = $this->priceCalculator->calculateGrandTotal($bookingCreateDto);
|
||||
|
||||
if ($apiTotal !== $calculatedTotal) {
|
||||
$this->logger->error('Price mismatch detected - payload incomplete', [
|
||||
return $this->handleInquiryError(
|
||||
'Price mismatch detected - payload incomplete',
|
||||
[
|
||||
'apiTotal' => $apiTotal,
|
||||
'calculatedTotal' => $calculatedTotal,
|
||||
'difference' => abs($apiTotal - $calculatedTotal),
|
||||
]);
|
||||
$this->addFlash('error', 'Ein technischer Fehler ist aufgetreten.');
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
],
|
||||
'Ein technischer Fehler ist aufgetreten.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
// Validation successful - proceed to confirmation step
|
||||
@@ -116,32 +113,26 @@ class CreateStep3Controller extends AbstractController
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_4'));
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Booking inquiry exception', [
|
||||
return $this->handleInquiryError(
|
||||
'Booking inquiry exception',
|
||||
[
|
||||
'exception' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
|
||||
$this->addFlash('error', 'Ein technischer Fehler ist aufgetreten.');
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
],
|
||||
'Ein technischer Fehler ist aufgetreten.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles HTMX refresh when payment method changes.
|
||||
*/
|
||||
#[Route('/bookings/create/payment/refresh', name: 'app_booking_create_step_3_refresh')]
|
||||
#[Route('/bookings/create/payment/refresh', name: 'app_booking_create_step_3_refresh', methods: ['POST'])]
|
||||
public function refresh(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
@@ -157,7 +148,31 @@ class CreateStep3Controller extends AbstractController
|
||||
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
return $this->render('booking/create_step_3.html.twig', [
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles inquiry errors by logging, adding flash message, and rendering the form.
|
||||
*/
|
||||
private function handleInquiryError(
|
||||
string $logMessage,
|
||||
array $context,
|
||||
string $flashMessage,
|
||||
BookingDto $bookingCreateDto,
|
||||
FormInterface $form,
|
||||
): Response {
|
||||
$this->logger->error($logMessage, $context);
|
||||
$this->addFlash('error', $flashMessage);
|
||||
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the step 3 form with standard template variables.
|
||||
*/
|
||||
private function renderStepForm(BookingDto $bookingCreateDto, FormInterface $form): Response
|
||||
{
|
||||
return $this->render('booking/create/step_3.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
+54
-28
@@ -2,15 +2,19 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits\BookingCreateTrait;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Form\BookingCreateStep4Type;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingService;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -18,7 +22,7 @@ use Symfony\Component\Routing\Attribute\Route;
|
||||
/**
|
||||
* Handles the fourth step of the booking creation process (confirmation).
|
||||
*/
|
||||
class CreateStep4Controller extends AbstractController
|
||||
class Step4Controller extends AbstractController
|
||||
{
|
||||
use BookingCreateTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
@@ -35,7 +39,7 @@ class CreateStep4Controller extends AbstractController
|
||||
* Displays booking summary and confirmation form.
|
||||
*/
|
||||
#[Route('/bookings/create/confirmation', name: 'app_booking_create_step_4')]
|
||||
public function step4(Request $request): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
@@ -64,47 +68,69 @@ class CreateStep4Controller extends AbstractController
|
||||
$bookingResponse = $this->apiClient->createBooking($bookingCreateDto);
|
||||
|
||||
if ($bookingResponse instanceof Notification) {
|
||||
$this->addFlash('error', $bookingResponse->message);
|
||||
|
||||
return $this->render('booking/create_step_4.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
return $this->handleBookingError(
|
||||
'Booking creation failed - API notification',
|
||||
['message' => $bookingResponse->message],
|
||||
$bookingResponse->message,
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
if (false === $bookingResponse->isBookingSuccessful()) {
|
||||
$this->addFlash('error', 'Buchung konnte nicht erstellt werden.');
|
||||
|
||||
return $this->render('booking/create_step_4.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
return $this->handleBookingError(
|
||||
'Booking creation unsuccessful',
|
||||
['status' => $bookingResponse->status],
|
||||
'Buchung konnte nicht erstellt werden.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
// Success: Store booking number in flash and clear session
|
||||
$this->addFlash('booking_number', $bookingResponse->transactionNumber);
|
||||
$this->bookingService->clearBookingCreateDto($request);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_success'));
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_success'));
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Booking creation failed', [
|
||||
return $this->handleBookingError(
|
||||
'Booking creation exception',
|
||||
[
|
||||
'exception' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
],
|
||||
'Ein technischer Fehler ist aufgetreten.',
|
||||
$bookingCreateDto,
|
||||
$form
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addFlash('error', 'Ein technischer Fehler ist aufgetreten.');
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
return $this->render('booking/create_step_4.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Handles booking errors by logging, adding flash message, and rendering the form.
|
||||
*/
|
||||
private function handleBookingError(
|
||||
string $logMessage,
|
||||
array $context,
|
||||
string $flashMessage,
|
||||
BookingDto $bookingCreateDto,
|
||||
FormInterface $form,
|
||||
): Response {
|
||||
$this->logger->error($logMessage, $context);
|
||||
$this->addFlash('error', $flashMessage);
|
||||
|
||||
return $this->renderStepForm($bookingCreateDto, $form);
|
||||
}
|
||||
|
||||
return $this->render('booking/create_step_4.html.twig', [
|
||||
/**
|
||||
* Renders the step 4 form with standard template variables.
|
||||
*/
|
||||
private function renderStepForm(BookingDto $bookingCreateDto, FormInterface $form): Response
|
||||
{
|
||||
return $this->render('booking/create/step_4.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'form' => $form->createView(),
|
||||
...$this->getSummaryVariables($bookingCreateDto),
|
||||
+7
-4
@@ -2,16 +2,19 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Create;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class BookingSuccessController extends AbstractController
|
||||
/**
|
||||
* Handles the success page after completing the booking creation flow.
|
||||
*/
|
||||
class SuccessController extends AbstractController
|
||||
{
|
||||
#[Route('/bookings/success', name: 'app_booking_success')]
|
||||
#[Route('/bookings/create/success', name: 'app_booking_create_success')]
|
||||
public function success(Request $request): Response
|
||||
{
|
||||
$bookingNumber = $request->getSession()->getFlashBag()->get('booking_number')[0] ?? null;
|
||||
@@ -21,7 +24,7 @@ class BookingSuccessController extends AbstractController
|
||||
return $this->redirect('https://www.ep-reisen.de');
|
||||
}
|
||||
|
||||
return $this->render('booking/success.html.twig', [
|
||||
return $this->render('booking/create/success.html.twig', [
|
||||
'bookingNumber' => $bookingNumber,
|
||||
]);
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\Form\BookingCreateStep2Type;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\RoomAssignmentService;
|
||||
use App\Service\TravelDataService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
* Handles the second step of the booking creation process.
|
||||
*
|
||||
* This controller manages participant information collection including
|
||||
* dynamic room assignment functionality with HTMX-based form updates.
|
||||
*/
|
||||
class CreateStep2Controller extends AbstractController
|
||||
{
|
||||
use BookingCreateTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
use HxTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly BookingService $bookingService,
|
||||
private readonly BookingPriceCalculatorService $priceCalculator,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly RoomAssignmentService $roomAssignmentService,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays and processes the participant information form.
|
||||
*/
|
||||
#[Route('/bookings/create/participants', name: 'app_booking_create_step_2')]
|
||||
public function participants(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDto($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
return $result;
|
||||
}
|
||||
$bookingCreateDto = $result;
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||
|
||||
// Validate step access
|
||||
if ($redirect = $this->validateStepAccess($bookingCreateDto, 2)) {
|
||||
return $redirect;
|
||||
}
|
||||
|
||||
// Ensure correct number of participants
|
||||
$this->ensureCorrectNumberOfParticipants($bookingCreateDto);
|
||||
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||
|
||||
// Auto-assign participants to rooms if not already assigned
|
||||
$this->autoAssignRoomsIfNeeded($bookingCreateDto);
|
||||
|
||||
// Pre-select mandatory services for participants with birth dates
|
||||
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
|
||||
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
|
||||
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
||||
'attr' => [
|
||||
'novalidate' => 'novalidate',
|
||||
'hx-post' => $this->generateUrl('app_booking_create_step_2'),
|
||||
'hx-target' => '#form-wrapper',
|
||||
'hx-select' => '#form-wrapper',
|
||||
'hx-swap' => 'outerHTML',
|
||||
],
|
||||
'validation_groups' => ['booking_create_step_2'],
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$bookingCreateDto->currentStep = 3;
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_3'));
|
||||
}
|
||||
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingCreateDto);
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($bookingCreateDto->getSelectedRooms(), $availableRooms);
|
||||
$participantPrices = $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingCreateDto);
|
||||
|
||||
return $this->render('booking/create_step_2.html.twig', [
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'participantsCount' => $participantsCount,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'participantPrices' => $participantPrices,
|
||||
'form' => $form->createView(),
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles HTMX requests for dynamic form updates when room selections change by submitting the form
|
||||
* without validation and returning a freshly rendered instance.
|
||||
*/
|
||||
#[Route('/bookings/create/participants/refresh', name: 'app_booking_create_step_2_refresh', methods: ['POST'])]
|
||||
public function refreshParticipantForm(Request $request): Response
|
||||
{
|
||||
$result = $this->getOrCreateBookingCreateDtoForHtmx($this->bookingService, $request);
|
||||
if ($result instanceof Response) {
|
||||
return $result;
|
||||
}
|
||||
$bookingCreateDto = $result;
|
||||
|
||||
// Enrich with fresh availability data
|
||||
$this->enrichWithFreshAvailabilities($bookingCreateDto);
|
||||
|
||||
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||
|
||||
// Process form data without validation to capture current state
|
||||
$form = $this->createForm(BookingCreateStep2Type::class, $bookingCreateDto, [
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'validation_groups' => false,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Pre-select mandatory services after form processing but before pricing calculation
|
||||
$this->bookingService->preselectMandatoryServices($bookingCreateDto);
|
||||
|
||||
$this->bookingService->saveBookingDto($request, $bookingCreateDto, BookingDto::MODE_CREATE);
|
||||
|
||||
// Collect notifications from all participants
|
||||
$notifications = $this->collectParticipantNotifications($bookingCreateDto);
|
||||
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingCreateDto);
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingCreateDto);
|
||||
$availableRooms = $bookingCreateDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType($bookingCreateDto->getSelectedRooms(), $availableRooms);
|
||||
$participantPrices = $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingCreateDto);
|
||||
|
||||
// The DTO is now updated with the latest selection and submitted data has been cleaned.
|
||||
// We can now render the blocks with the fresh data.
|
||||
$response = $this->htmxOobResponse(
|
||||
'booking/create_step_2.html.twig',
|
||||
['participants_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
'bookingCreateDto' => $bookingCreateDto,
|
||||
'participantsCount' => $participantsCount,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'participantPrices' => $participantPrices,
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]
|
||||
);
|
||||
|
||||
// Add notifications to HTMX trigger header if any exist
|
||||
if ([] !== $notifications) {
|
||||
$response->headers->set('HX-Trigger', json_encode([
|
||||
'showNotifications' => ['notifications' => $notifications],
|
||||
]));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the booking DTO has the correct number of participant objects.
|
||||
*
|
||||
* Creates or reuses participant DTOs to match the required participant count
|
||||
* based on room selections. Preserves existing participant data when possible
|
||||
* and assigns proper index values.
|
||||
*
|
||||
* @param BookingDto $bookingCreateDto The booking DTO to update
|
||||
*/
|
||||
private function ensureCorrectNumberOfParticipants(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
$participantsCount = $this->getParticipantsCount($bookingCreateDto);
|
||||
|
||||
$participants = $bookingCreateDto->participants;
|
||||
$bookingCreateDto->participants = [];
|
||||
for ($i = 0; $i < $participantsCount; ++$i) {
|
||||
$participant = $participants[$i] ?? new ParticipantDto();
|
||||
$participant->index = $i;
|
||||
$bookingCreateDto->participants[$i] = $participant;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enriches travel data with cached availability information from BusProNet API.
|
||||
*
|
||||
* Fetches availability data with short-term caching and patches the travel object
|
||||
* to ensure service availability is reasonably up-to-date while reducing API calls.
|
||||
* This is essential for accurate pricing and service selection during the booking process.
|
||||
*
|
||||
* @param BookingDto $bookingCreateDto The booking DTO containing travel data to enrich
|
||||
*/
|
||||
private function enrichWithFreshAvailabilities(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
$dateId = $bookingCreateDto->travel->id;
|
||||
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($dateId, true);
|
||||
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($bookingCreateDto->travel, $availabilities);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically assigns participants to rooms if they don't have room assignments yet.
|
||||
*
|
||||
* This is called when entering Step 2 to ensure all participants have room assignments
|
||||
* based on the selected rooms from Step 1. Only assigns if participants are unassigned.
|
||||
*
|
||||
* @param BookingDto $bookingCreateDto The booking DTO with participants and room selections
|
||||
*/
|
||||
private function autoAssignRoomsIfNeeded(BookingDto $bookingCreateDto): void
|
||||
{
|
||||
// Check if any participants need room assignment
|
||||
$needsAssignment = false;
|
||||
foreach ($bookingCreateDto->participants as $participant) {
|
||||
if (null === $participant->assignedRoomId) {
|
||||
$needsAssignment = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($needsAssignment) {
|
||||
$this->roomAssignmentService->assignParticipantsToRooms($bookingCreateDto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all notifications from participants and clears them.
|
||||
*
|
||||
* @param BookingDto $bookingCreateDto The booking DTO containing participants
|
||||
*
|
||||
* @return array<array{type: string, message: string}> Array of notification messages
|
||||
*/
|
||||
private function collectParticipantNotifications(BookingDto $bookingCreateDto): array
|
||||
{
|
||||
$notifications = [];
|
||||
|
||||
foreach ($bookingCreateDto->participants as $participant) {
|
||||
if ([] !== $participant->notifications) {
|
||||
foreach ($participant->notifications as $notification) {
|
||||
$notifications[] = $notification;
|
||||
}
|
||||
// Clear notifications after collection
|
||||
$participant->notifications = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace App\Controller\Booking;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Traits\BookingDataTrait;
|
||||
use App\Controller\Booking\Traits\BookingDataTrait;
|
||||
use App\Entity\User;
|
||||
use App\Security\Crypt;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
@@ -0,0 +1,523 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Edit;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\Controller\Booking\Traits;
|
||||
use App\Controller\Booking\Traits\BookingDataTrait;
|
||||
use App\Controller\Booking\Traits\BookingExceptionHandlerTrait;
|
||||
use App\Controller\Booking\Traits\ParticipantValidationTrait;
|
||||
use App\Entity\User;
|
||||
use App\Form\BookingEditType;
|
||||
use App\Form\BookingParticipantType;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\ParticipantFieldHandlerRegistry;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Security\Crypt;
|
||||
use App\Service\BookingFingerprintService;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\ParticipantCardDataService;
|
||||
use App\Service\TravelDataService;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
/**
|
||||
* Edit controller using card-based participant interface.
|
||||
*
|
||||
* This controller implements the card-based UI for editing existing bookings:
|
||||
* - Card overview with lazy-loaded individual participant forms
|
||||
* - Handles canceled participants (status 'S')
|
||||
* - Applies mutability constraints via EditFieldStateProvider
|
||||
* - Final submission calls ApiClient::updateBooking()
|
||||
*/
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
use BookingDataTrait;
|
||||
use BookingExceptionHandlerTrait;
|
||||
use HxTrait;
|
||||
use Traits\ParticipantCardFlowTrait;
|
||||
use ParticipantValidationTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly BookingDataProcessor $bookingDataProcessor,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly BookingService $bookingService,
|
||||
private readonly BookingFingerprintService $fingerprintService,
|
||||
private readonly BookingPriceCalculatorService $priceCalculator,
|
||||
private readonly ParticipantCardDataService $participantCardService,
|
||||
private readonly ParticipantFieldHandlerRegistry $fieldHandlerRegistry,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly Security $security,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display participant cards overview.
|
||||
*/
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function index(int $id, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$email = $user->getEmail();
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
|
||||
// Load form data from session (or API on first load)
|
||||
$bookingDto = $this->loadFormData($request, $id, $email, $password);
|
||||
if (null === $bookingDto) {
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Reset staleness timer when first loading the cards view (not HTMX requests)
|
||||
// This prevents false staleness warnings from old edit sessions
|
||||
if (false === $this->isHxRequest($request)) {
|
||||
$bookingDto->lastSessionUpdate = new \DateTimeImmutable();
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||
}
|
||||
|
||||
// Fetch booking data for display (surcharges, canceled status, etc.)
|
||||
$bookingData = $this->fetchBookingData($email, $password, $id);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Fetch mutable data for form constraints
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
|
||||
// Create validation form (same pattern as CreateStep2Controller)
|
||||
$form = $this->createForm(BookingEditType::class, $bookingDto, [
|
||||
'validation_groups' => ['booking_edit'],
|
||||
]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Handle form submission (clicking "Buchung aktualisieren")
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// All participants validated successfully, submit to API
|
||||
$this->logger->info('Initiated booking update', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->updateBooking($bookingDto, true);
|
||||
if ($response instanceof Notification) {
|
||||
if (true === $response->isError()) {
|
||||
$this->addFlash('error', $response->message);
|
||||
} else {
|
||||
$this->addFlash('info', $response->message);
|
||||
}
|
||||
$this->logger->error('Booking update not successful', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
'message' => $response->message,
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
$cacheKey = sprintf('bpn_booking_%d', $id);
|
||||
$this->cache->delete($cacheKey);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
}
|
||||
|
||||
// Clear session on successful save
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
|
||||
$this->logger->info('Booking update successful', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Es ist ein Fehler in der Kommunikation mit dem Buchungssystem aufgetreten');
|
||||
}
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
// Extract participant indices with validation errors
|
||||
$participantErrors = [];
|
||||
if ($form->isSubmitted() && false === $form->isValid()) {
|
||||
$participantErrors = $this->extractParticipantErrorIndices($form);
|
||||
}
|
||||
|
||||
// Generate card data for all participants
|
||||
$cardsData = $this->participantCardService->getAllCardsData($bookingDto);
|
||||
|
||||
// Calculate summary data for sidebar
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($bookingDto);
|
||||
|
||||
// Group selected rooms for summary display
|
||||
$availableRooms = $bookingDto->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType(
|
||||
$bookingDto->getSelectedRooms(),
|
||||
$availableRooms
|
||||
);
|
||||
|
||||
$templateData = [
|
||||
'form' => $form->createView(),
|
||||
'bookingDto' => $bookingDto,
|
||||
'bookingData' => $bookingData,
|
||||
'mutableData' => $mutableData,
|
||||
'cardsData' => $cardsData,
|
||||
'participantsCount' => count($bookingDto->participants),
|
||||
'pricingData' => $summary['pricing'],
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'isDirty' => $this->fingerprintService->isDirty($bookingDto),
|
||||
'hasValidationErrors' => count($participantErrors) > 0,
|
||||
'participantErrors' => $participantErrors,
|
||||
];
|
||||
|
||||
// If HTMX request, render only blocks to avoid layout duplication
|
||||
if ($this->isHxRequest($request)) {
|
||||
return $this->htmxOobResponse(
|
||||
'booking/edit/index.html.twig',
|
||||
['participant_cards', 'booking_summary'],
|
||||
$templateData
|
||||
);
|
||||
}
|
||||
|
||||
// Regular request: render full template
|
||||
return $this->render('booking/edit/index.html.twig', $templateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit single participant form.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/participants/{index}',
|
||||
name: 'app_booking_edit_participant',
|
||||
requirements: ['id' => '\d+', 'index' => '\d+']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function editParticipant(int $id, int $index, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$email = $user->getEmail();
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
|
||||
// Load form data from session
|
||||
$bookingDto = $this->bookingService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
if (null === $bookingDto) {
|
||||
$this->addFlash('error', 'Sitzung abgelaufen. Bitte neu laden.');
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
$participant = $bookingDto->participants[$index] ?? null;
|
||||
|
||||
if (null === $participant) {
|
||||
throw new \InvalidArgumentException('Invalid participant index');
|
||||
}
|
||||
|
||||
// Fetch booking data to check for canceled status
|
||||
$bookingData = $this->fetchBookingData($email, $password, $id);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Check if participant is canceled
|
||||
$isCanceled = ($bookingData->participantsStatus[$index] ?? null) === 'S';
|
||||
|
||||
if ($isCanceled) {
|
||||
// Redirect back to cards - canceled participants cannot be edited
|
||||
$this->addFlash('warning', 'Stornierte Teilnehmer können nicht bearbeitet werden');
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
// Create form for participant with booking context
|
||||
$form = $this->createForm(BookingParticipantType::class, $participant, [
|
||||
'booking_context' => $bookingDto,
|
||||
'edit_mode' => true,
|
||||
'validation_groups' => ['booking_edit'],
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// Save updated booking data to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||
|
||||
// Redirect back to cards
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
// Calculate summary data using trait helper
|
||||
$summaryData = $this->calculateSummaryData($bookingDto);
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
|
||||
|
||||
// Fetch mutable data for form constraints
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
|
||||
// Render form and sidebar with OOB swap using htmxOobResponse
|
||||
// This ensures both initial load and refresh use the same block-based rendering
|
||||
return $this->htmxOobResponse(
|
||||
'booking/_participant_form.html.twig',
|
||||
['participant_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
'participantIndex' => $index,
|
||||
'bookingDto' => $bookingDto,
|
||||
'bookingData' => $bookingData,
|
||||
'mutableData' => $mutableData,
|
||||
'summaryData' => $summaryData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'refreshRouteName' => 'app_booking_edit_participant_refresh',
|
||||
'refreshRouteParams' => ['id' => $id, 'index' => $index],
|
||||
'submitRouteName' => 'app_booking_edit_participant',
|
||||
'submitRouteParams' => ['id' => $id, 'index' => $index],
|
||||
'cancelRouteName' => 'app_booking_edit',
|
||||
'cancelRouteParams' => ['id' => $id],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* HTMX endpoint for refreshing participant form without validation.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/participants/{index}/refresh',
|
||||
name: 'app_booking_edit_participant_refresh',
|
||||
requirements: ['id' => '\d+', 'index' => '\d+'],
|
||||
methods: ['POST']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function refreshParticipantForm(int $id, int $index, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$email = $user->getEmail();
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
|
||||
// Load form data from session
|
||||
$bookingDto = $this->bookingService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
if (null === $bookingDto) {
|
||||
return new Response('Session expired. Please reload page.', Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Refresh availability data
|
||||
$availabilities = $this->travelDataService->getAvailabilityDataCached($bookingDto->travel->id);
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($bookingDto->travel, $availabilities);
|
||||
}
|
||||
|
||||
// Fetch booking data and mutable data
|
||||
$bookingData = $this->fetchBookingData($email, $password, $id);
|
||||
$mutableData = null !== $bookingData && !($bookingData instanceof Notification)
|
||||
? $this->travelDataService->getMutabilityData($bookingData->dateId)
|
||||
: null;
|
||||
|
||||
// Create form with validation disabled
|
||||
$form = $this->createForm(BookingParticipantType::class, $bookingDto->participants[$index], [
|
||||
'booking_context' => $bookingDto,
|
||||
'edit_mode' => true,
|
||||
'validation_groups' => false,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Save updated booking data to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, BookingDto::MODE_EDIT);
|
||||
|
||||
// Collect notifications from participant DTO
|
||||
$participant = $bookingDto->participants[$index] ?? null;
|
||||
$notifications = $participant?->notifications ?? [];
|
||||
|
||||
// Clear notifications after collecting
|
||||
if (null !== $participant) {
|
||||
$participant->notifications = [];
|
||||
}
|
||||
|
||||
// Calculate summary data using trait helper
|
||||
$summaryData = $this->calculateSummaryData($bookingDto);
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
|
||||
|
||||
// Render form + sidebar using htmxOobResponse
|
||||
$response = $this->htmxOobResponse(
|
||||
'booking/_participant_form.html.twig',
|
||||
['participant_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form,
|
||||
'participantIndex' => $index,
|
||||
'bookingDto' => $bookingDto,
|
||||
'bookingData' => $bookingData,
|
||||
'mutableData' => $mutableData,
|
||||
'summaryData' => $summaryData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'refreshRouteName' => 'app_booking_edit_participant_refresh',
|
||||
'refreshRouteParams' => ['id' => $id, 'index' => $index],
|
||||
'submitRouteName' => 'app_booking_edit_participant',
|
||||
'submitRouteParams' => ['id' => $id, 'index' => $index],
|
||||
'cancelRouteName' => 'app_booking_edit',
|
||||
'cancelRouteParams' => ['id' => $id],
|
||||
]
|
||||
);
|
||||
|
||||
// Add notifications to HX-Trigger header if present
|
||||
if ([] !== $notifications) {
|
||||
$response->headers->set('HX-Trigger', json_encode([
|
||||
'showNotifications' => ['notifications' => $notifications],
|
||||
]));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads booking data from API, discarding all session changes.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/reload',
|
||||
name: 'app_booking_edit_reload',
|
||||
requirements: ['id' => '\d+'],
|
||||
methods: ['POST']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function reloadFromApi(int $id, Request $request): Response
|
||||
{
|
||||
// Clear session to discard all changes
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
$this->addFlash('success', 'Änderungen verworfen, Daten neu geladen');
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles "Zurück" button - clears session and returns to bookings list.
|
||||
*/
|
||||
#[Route(
|
||||
path: '/bookings/{id}/edit/cancel',
|
||||
name: 'app_booking_edit_cancel',
|
||||
requirements: ['id' => '\d+'],
|
||||
methods: ['POST']
|
||||
)]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function cancelEdit(Request $request): Response
|
||||
{
|
||||
// Clear session to discard dirty state
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_bookings'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads form data from session or initializes from API on first load.
|
||||
*
|
||||
* @return BookingDto|null The form data, or null on error
|
||||
*/
|
||||
private function loadFormData(Request $request, int $bookingId, string $email, string $password): ?BookingDto
|
||||
{
|
||||
// Try to load from session first
|
||||
$formData = $this->bookingService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
if (null === $formData) {
|
||||
// First load: initialize from API
|
||||
return $this->initializeFromApi($request, $bookingId, $email, $password);
|
||||
}
|
||||
|
||||
// Subsequent load: refresh from session with staleness check
|
||||
return $this->refreshFromSession($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes form data from API on first load and stores in session.
|
||||
*
|
||||
* @return BookingDto|null The form data, or null on error
|
||||
*/
|
||||
private function initializeFromApi(Request $request, int $bookingId, string $email, string $password): ?BookingDto
|
||||
{
|
||||
$bookingData = $this->fetchBookingData($email, $password, $bookingId);
|
||||
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('EDIT', $bookingData);
|
||||
|
||||
$travelData = $this->travelDataService->getTravelData($bookingData->dateId);
|
||||
if (null === $travelData) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId);
|
||||
|
||||
if (null === $mutableData || null === $availabilities) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->travelDataService->patchAvailabilities($travelData, $availabilities);
|
||||
$this->travelDataService->patchMutability($travelData, $mutableData);
|
||||
|
||||
$formData = $this->bookingDataProcessor->createBookingDtoFromBooking($bookingData, $travelData);
|
||||
|
||||
// Set original fingerprint for dirty state detection
|
||||
error_log('[Fingerprint] === GENERATING ORIGINAL FINGERPRINT ===');
|
||||
$formData->originalFingerprint = $this->fingerprintService->generateFingerprint($formData, true);
|
||||
|
||||
$this->bookingService->saveBookingDto($request, $formData, BookingDto::MODE_EDIT);
|
||||
|
||||
return $formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes form data loaded from session with latest availability.
|
||||
*
|
||||
* @return BookingDto The refreshed form data
|
||||
*/
|
||||
private function refreshFromSession(BookingDto $formData): BookingDto
|
||||
{
|
||||
// Refresh availability data
|
||||
$availabilities = $this->travelDataService->getAvailabilityDataCached($formData->travel->id);
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($formData->travel, $availabilities);
|
||||
}
|
||||
|
||||
// Show staleness warning if session is older than 5 minutes
|
||||
if (null !== $formData->lastSessionUpdate) {
|
||||
$ageInSeconds = (new \DateTimeImmutable())->getTimestamp() - $formData->lastSessionUpdate->getTimestamp();
|
||||
if ($ageInSeconds > 300) {
|
||||
$minutes = (int) ceil($ageInSeconds / 60);
|
||||
$this->addFlash('info', sprintf('Sie bearbeiten diese Buchung seit %d Minuten. Die Daten könnten veraltet sein.', $minutes));
|
||||
}
|
||||
}
|
||||
|
||||
return $formData;
|
||||
}
|
||||
}
|
||||
@@ -1,363 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\XmlLoader\PickupLoader;
|
||||
use App\Controller\Traits\BookingDataTrait;
|
||||
use App\Entity\User;
|
||||
use App\Form\BookingEditType;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Htmx\HxTrait;
|
||||
use App\Security\Crypt;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\TravelDataService;
|
||||
use Psr\Cache\InvalidArgumentException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class EditController extends AbstractController
|
||||
{
|
||||
use BookingDataTrait;
|
||||
use HxTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly BookingDataProcessor $bookingDataProcessor,
|
||||
private readonly TravelDataService $travelDataService,
|
||||
private readonly BookingService $bookingService,
|
||||
private readonly BookingPriceCalculatorService $priceCalculator,
|
||||
private readonly PickupLoader $pickupDataLoader,
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly Security $security,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/bookings/{id}/edit', name: 'app_booking_edit', requirements: ['id' => '\d+'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function edit(int $id, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$email = $user->getEmail();
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
|
||||
// Load form data from session (or API on first load)
|
||||
$formData = $this->loadFormData($request, $id, $email, $password);
|
||||
if (null === $formData) {
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Fetch booking data for display (surcharges, canceled status, etc.)
|
||||
$bookingData = $this->fetchBookingData($email, $password, $id);
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
}
|
||||
|
||||
// Fetch mutable data for form constraints
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
|
||||
// Calculate pricing data for template
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($formData);
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($formData);
|
||||
$participantPrices = $this->priceCalculator->calculateAllParticipantIndividualPrices($formData);
|
||||
|
||||
// Group selected rooms for summary display
|
||||
$availableRooms = $formData->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType(
|
||||
$formData->getSelectedRooms(),
|
||||
$availableRooms
|
||||
);
|
||||
|
||||
$form = $this->createForm(BookingEditType::class, $formData, [
|
||||
'attr' => [
|
||||
'novalidate' => 'novalidate',
|
||||
'hx-post' => $this->generateUrl('app_booking_edit', ['id' => $id]),
|
||||
'hx-target' => '#form-wrapper',
|
||||
'hx-select' => '#form-wrapper',
|
||||
'hx-swap' => 'outerHTML',
|
||||
],
|
||||
'validation_groups' => ['booking_edit'],
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->logger->info('Initiated booking update', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->updateBooking($formData, true);
|
||||
if ($response instanceof Notification) {
|
||||
if (true === $response->isError()) {
|
||||
$this->addFlash('error', $response->message);
|
||||
} else {
|
||||
$this->addFlash('info', $response->message);
|
||||
}
|
||||
$this->logger->error('Booking update not successful', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
'message' => $response->message,
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
$cacheKey = sprintf('bpn_booking_%d', $id);
|
||||
$this->cache->delete($cacheKey);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
}
|
||||
|
||||
// Clear session on successful save
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
|
||||
$this->logger->info('Booking update successful', [
|
||||
'email' => $email,
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Es ist ein Fehler in der Kommunikation mit dem Buchungssystem aufgetreten');
|
||||
}
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
return $this->render('booking/edit.html.twig', [
|
||||
'bookingData' => $bookingData,
|
||||
'bookingEditDto' => $formData,
|
||||
'mutableData' => $mutableData,
|
||||
'form' => $form->createView(),
|
||||
'pricingData' => $summary['pricing'],
|
||||
'participantCount' => $summary['participantCount'],
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'participantPrices' => $participantPrices,
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads booking data from API, discarding all session changes.
|
||||
*/
|
||||
#[Route('/bookings/{id}/edit/reload', name: 'app_booking_edit_reload', requirements: ['id' => '\d+'], methods: ['POST'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function reloadFromApi(int $id, Request $request): Response
|
||||
{
|
||||
// Clear session to discard all changes
|
||||
$this->bookingService->clearBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
$this->addFlash('success', 'Änderungen verworfen, Daten neu geladen');
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_edit', ['id' => $id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* HTMX endpoint for refreshing the participant form without validation.
|
||||
*/
|
||||
#[Route('/bookings/{id}/edit/refresh', name: 'app_booking_edit_refresh', requirements: ['id' => '\d+'], methods: ['POST'])]
|
||||
#[IsGranted('ROLE_USER')]
|
||||
public function refreshParticipantForm(int $id, Request $request): Response
|
||||
{
|
||||
// Load form data from session
|
||||
$formData = $this->bookingService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
if (null === $formData) {
|
||||
return new Response('Session expired. Please reload page.', Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Refresh availability data
|
||||
$availabilities = $this->travelDataService->getAvailabilityDataCached($formData->travel->id);
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($formData->travel, $availabilities);
|
||||
}
|
||||
|
||||
// Process form without validation to capture current state
|
||||
$form = $this->createForm(BookingEditType::class, $formData, [
|
||||
'attr' => ['novalidate' => 'novalidate'],
|
||||
'validation_groups' => false,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Save updated DTO back to session
|
||||
$this->bookingService->saveBookingDto($request, $formData, BookingDto::MODE_EDIT);
|
||||
|
||||
// Collect notifications from all participants
|
||||
$notifications = $this->collectParticipantNotifications($formData);
|
||||
|
||||
// Fetch booking data and mutable data for display
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$email = $user->getEmail();
|
||||
$password = $this->crypt->decrypt($user->getPassword());
|
||||
|
||||
$bookingData = $this->fetchBookingData($email, $password, $id);
|
||||
$mutableData = null !== $bookingData && !($bookingData instanceof Notification)
|
||||
? $this->travelDataService->getMutabilityData($bookingData->dateId)
|
||||
: null;
|
||||
|
||||
// Calculate pricing and summary data
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($formData);
|
||||
$roomAssignmentCounts = $this->bookingService->getRoomAssignmentCounts($formData);
|
||||
$participantPrices = $this->priceCalculator->calculateAllParticipantIndividualPrices($formData);
|
||||
|
||||
// Group selected rooms for summary display
|
||||
$availableRooms = $formData->travel->getAvailableRooms();
|
||||
$groupedSelectedRooms = $this->bookingService->groupRoomSelectionsByType(
|
||||
$formData->getSelectedRooms(),
|
||||
$availableRooms
|
||||
);
|
||||
|
||||
// Render updated blocks with fresh data
|
||||
$response = $this->htmxOobResponse(
|
||||
'booking/edit.html.twig',
|
||||
['participants_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
'bookingEditDto' => $formData,
|
||||
'bookingData' => $bookingData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'participantCount' => $summary['participantCount'],
|
||||
'assignmentCounts' => $roomAssignmentCounts,
|
||||
'participantPrices' => $participantPrices,
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
'mutableData' => $mutableData,
|
||||
]
|
||||
);
|
||||
|
||||
// Add notifications to HTMX trigger header if any exist
|
||||
if ([] !== $notifications) {
|
||||
$response->headers->set('HX-Trigger', json_encode([
|
||||
'showNotifications' => ['notifications' => $notifications],
|
||||
]));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all notifications from participants and clears them.
|
||||
*
|
||||
* @return array<array{type: string, message: string}> Array of notification messages
|
||||
*/
|
||||
private function collectParticipantNotifications(BookingDto $bookingDto): array
|
||||
{
|
||||
$notifications = [];
|
||||
|
||||
foreach ($bookingDto->participants as $participant) {
|
||||
if ([] !== $participant->notifications) {
|
||||
foreach ($participant->notifications as $notification) {
|
||||
$notifications[] = $notification;
|
||||
}
|
||||
// Clear notifications after collecting
|
||||
$participant->notifications = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads form data from session or initializes from API on first load.
|
||||
*
|
||||
* @return BookingDto|null The form data, or null on error
|
||||
*/
|
||||
private function loadFormData(Request $request, int $bookingId, string $email, string $password): ?BookingDto
|
||||
{
|
||||
// Try to load from session first
|
||||
$formData = $this->bookingService->getBookingDto($request, BookingDto::MODE_EDIT);
|
||||
|
||||
if (null === $formData) {
|
||||
// First load: initialize from API
|
||||
return $this->initializeFromApi($request, $bookingId, $email, $password);
|
||||
}
|
||||
|
||||
// Subsequent load: refresh from session with staleness check
|
||||
return $this->refreshFromSession($formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes form data from API on first load and stores in session.
|
||||
*
|
||||
* @return BookingDto|null The form data, or null on error
|
||||
*/
|
||||
private function initializeFromApi(Request $request, int $bookingId, string $email, string $password): ?BookingDto
|
||||
{
|
||||
$bookingData = $this->fetchBookingData($email, $password, $bookingId);
|
||||
|
||||
if (null === $bookingData || $bookingData instanceof Notification) {
|
||||
$this->addFlash('error', 'Buchungsdaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('EDIT', $bookingData);
|
||||
|
||||
$travelData = $this->travelDataService->getTravelData($bookingData->dateId);
|
||||
if (null === $travelData) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$mutableData = $this->travelDataService->getMutabilityData($bookingData->dateId);
|
||||
$availabilities = $this->travelDataService->getAvailabilityData($bookingData->dateId);
|
||||
|
||||
if (null === $mutableData || null === $availabilities) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->travelDataService->patchAvailabilities($travelData, $availabilities);
|
||||
$this->travelDataService->patchMutability($travelData, $mutableData);
|
||||
|
||||
$formData = $this->bookingDataProcessor->createBookingDtoFromBooking($bookingData, $travelData);
|
||||
$this->bookingService->saveBookingDto($request, $formData, BookingDto::MODE_EDIT);
|
||||
|
||||
return $formData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes form data loaded from session with latest availability.
|
||||
*
|
||||
* @return BookingDto The refreshed form data
|
||||
*/
|
||||
private function refreshFromSession(BookingDto $formData): BookingDto
|
||||
{
|
||||
// Refresh availability data
|
||||
$availabilities = $this->travelDataService->getAvailabilityDataCached($formData->travel->id);
|
||||
if (null !== $availabilities) {
|
||||
$this->travelDataService->patchAvailabilities($formData->travel, $availabilities);
|
||||
}
|
||||
|
||||
// Show staleness warning if session is older than 5 minutes
|
||||
if (null !== $formData->lastSessionUpdate) {
|
||||
$ageInSeconds = (new \DateTimeImmutable())->getTimestamp() - $formData->lastSessionUpdate->getTimestamp();
|
||||
if ($ageInSeconds > 300) {
|
||||
$minutes = (int) ceil($ageInSeconds / 60);
|
||||
$this->addFlash('info', sprintf('Sie bearbeiten diese Buchung seit %d Minuten. Die Daten könnten veraltet sein.', $minutes));
|
||||
}
|
||||
}
|
||||
|
||||
return $formData;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Traits;
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Notification;
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking;
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\Exception\BookingSessionNotFoundException;
|
||||
use App\Exception\HotelNotFoundException;
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
use App\Form\BookingParticipantType;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\ParticipantCardDataService;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Shared controller logic for participant card-based booking flows.
|
||||
*
|
||||
* This trait provides common functionality for both create and edit controllers
|
||||
* that use the card-based UI pattern (card overview + lazy-loaded forms).
|
||||
*/
|
||||
trait ParticipantCardFlowTrait
|
||||
{
|
||||
/**
|
||||
* Load BookingDto from session or throw exception.
|
||||
*
|
||||
* @throws \RuntimeException When booking data not found in session
|
||||
*/
|
||||
private function loadBookingDtoOrFail(Request $request, string $mode): BookingDto
|
||||
{
|
||||
$bookingDto = $this->bookingService->getBookingDto($request, $mode);
|
||||
|
||||
if (null === $bookingDto) {
|
||||
throw new \RuntimeException(sprintf('Booking data not found in session for mode: %s', $mode));
|
||||
}
|
||||
|
||||
return $bookingDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate card data for all participants.
|
||||
*
|
||||
* @return array<int, array{name: string, roomName: string, price: string}>
|
||||
*/
|
||||
private function generateAllCardsData(BookingDto $bookingDto): array
|
||||
{
|
||||
return $this->participantCardService->getAllCardsData($bookingDto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create form for single participant.
|
||||
*
|
||||
* This creates an autonomous participant form with booking_context option
|
||||
* so it can process field handlers independently.
|
||||
*/
|
||||
private function createParticipantForm(
|
||||
BookingDto $bookingDto,
|
||||
int $index,
|
||||
array $options = [],
|
||||
): FormInterface {
|
||||
$participant = $bookingDto->participants[$index] ?? null;
|
||||
|
||||
if (null === $participant) {
|
||||
throw new \InvalidArgumentException(sprintf('Participant at index %d does not exist', $index));
|
||||
}
|
||||
|
||||
// Merge default options with provided options
|
||||
$formOptions = array_merge([
|
||||
'booking_context' => $bookingDto,
|
||||
'edit_mode' => BookingDto::MODE_EDIT === $bookingDto->getMode(),
|
||||
], $options);
|
||||
|
||||
return $this->createForm(BookingParticipantType::class, $participant, $formOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate summary data (pricing, room counts, etc.).
|
||||
*
|
||||
* @return array{
|
||||
* participantsCount: int,
|
||||
* totalPrice: string,
|
||||
* groupedSelectedRooms: array,
|
||||
* assignmentCounts: array
|
||||
* }
|
||||
*/
|
||||
private function calculateSummaryData(BookingDto $bookingDto): array
|
||||
{
|
||||
// Calculate individual prices for all participants
|
||||
$participantPrices = $this->priceCalculator->calculateAllParticipantIndividualPrices($bookingDto);
|
||||
|
||||
// Calculate total price
|
||||
$totalPrice = array_sum($participantPrices);
|
||||
|
||||
// Get room assignment counts
|
||||
$roomCounts = [];
|
||||
foreach ($bookingDto->participants as $participant) {
|
||||
if (null !== $participant->assignedRoomId) {
|
||||
$roomCounts[$participant->assignedRoomId] = ($roomCounts[$participant->assignedRoomId] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Group selected rooms with counts
|
||||
$groupedSelectedRooms = [];
|
||||
foreach ($roomCounts as $roomId => $count) {
|
||||
$room = $bookingDto->travel->getRoomById($roomId);
|
||||
if (null !== $room) {
|
||||
$groupedSelectedRooms[] = [
|
||||
'room' => $room,
|
||||
'count' => $count,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'participantsCount' => count($bookingDto->participants),
|
||||
'totalPrice' => number_format($totalPrice, 2, ',', '.').' €',
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
'assignmentCounts' => $roomCounts,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Process single participant form refresh.
|
||||
*
|
||||
* Handles HTMX form refresh without validation, updates sidebar via OOB swap.
|
||||
*/
|
||||
private function handleParticipantRefresh(
|
||||
Request $request,
|
||||
BookingDto $bookingDto,
|
||||
int $index,
|
||||
string $refreshRouteName,
|
||||
string $submitRouteName,
|
||||
): Response {
|
||||
// Create form with validation disabled
|
||||
$form = $this->createParticipantForm($bookingDto, $index, [
|
||||
'validation_groups' => false,
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
// Save updated booking data to session
|
||||
$this->bookingService->saveBookingDto($request, $bookingDto, $bookingDto->getMode());
|
||||
|
||||
// Collect notifications from participant DTO
|
||||
$participant = $bookingDto->participants[$index] ?? null;
|
||||
$notifications = $participant?->notifications ?? [];
|
||||
|
||||
// Clear notifications after collecting
|
||||
if (null !== $participant) {
|
||||
$participant->notifications = [];
|
||||
}
|
||||
|
||||
// Calculate summary data for sidebar
|
||||
$summaryData = $this->calculateSummaryData($bookingDto);
|
||||
|
||||
// Get detailed pricing data for summary sidebar
|
||||
$summary = $this->bookingService->getRoomSummaryAndParticipantCount($bookingDto);
|
||||
|
||||
// Render form and sidebar with OOB swap using htmxOobResponse
|
||||
// This renders ONLY the specific blocks, not the entire template
|
||||
$response = $this->htmxOobResponse(
|
||||
'booking/_participant_form_standalone.html.twig',
|
||||
['participant_form', 'booking_summary'],
|
||||
[
|
||||
'form' => $form->createView(),
|
||||
'participantIndex' => $index,
|
||||
'bookingDto' => $bookingDto,
|
||||
'summaryData' => $summaryData,
|
||||
'pricingData' => $summary['pricing'],
|
||||
'refreshRouteName' => $refreshRouteName,
|
||||
'submitRouteName' => $submitRouteName,
|
||||
]
|
||||
);
|
||||
|
||||
// Add notifications to HX-Trigger header if present
|
||||
if (false === empty($notifications)) {
|
||||
$response->headers->set('HX-Trigger', json_encode([
|
||||
'showNotifications' => $notifications,
|
||||
]));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required services - implementing controllers must inject these.
|
||||
*
|
||||
* Controllers using this trait must have the following properties:
|
||||
* - BookingService $bookingService
|
||||
* - ParticipantCardDataService $participantCardService
|
||||
* - BookingPriceCalculatorService $priceCalculator
|
||||
*/
|
||||
abstract private function createForm(string $type, $data = null, array $options = []): FormInterface;
|
||||
|
||||
abstract private function render(string $view, array $parameters = [], ?Response $response = null): Response;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Booking\Traits;
|
||||
|
||||
/**
|
||||
* Provides participant validation error extraction for card-based booking flows.
|
||||
*
|
||||
* Shared between CreateStep2Controller and EditController to identify which
|
||||
* participants have validation errors that should be displayed on their cards.
|
||||
*/
|
||||
trait ParticipantValidationTrait
|
||||
{
|
||||
/**
|
||||
* Extracts participant indices that have validation errors.
|
||||
*
|
||||
* Parses form errors to identify which participants have validation issues.
|
||||
* Returns an array of participant indices (e.g., [0, 2, 5]).
|
||||
*
|
||||
* @return array<int> Array of participant indices with errors
|
||||
*/
|
||||
private function extractParticipantErrorIndices($form): array
|
||||
{
|
||||
$errorIndices = [];
|
||||
$errors = $form->getErrors(true); // Get all errors recursively
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$propertyPath = $error->getCause()?->getPropertyPath();
|
||||
if (null === $propertyPath) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Property paths look like "participants[0].firstName" or "participants[1].email"
|
||||
if (preg_match('/participants\[(\d+)]/', $propertyPath, $matches)) {
|
||||
$index = (int) $matches[1];
|
||||
$errorIndices[$index] = true; // Use array key to avoid duplicates
|
||||
}
|
||||
}
|
||||
|
||||
return array_keys($errorIndices);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\ParticipantFieldHandlerRegistry;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form type for Step 2 of the booking process (participant data validation).
|
||||
*
|
||||
* This form is used in the card-based UI where participants are edited individually
|
||||
* in separate forms. This form validates the complete BookingDto before proceeding
|
||||
* to Step 3, ensuring all participants have valid and complete data.
|
||||
*/
|
||||
class BookingCreateStep2Type extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParticipantFieldHandlerRegistry $participantFieldHandlerRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData'])
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the initial form creation.
|
||||
*/
|
||||
public function onPreSetData(FormEvent $event): void
|
||||
{
|
||||
/** @var BookingDto|null $data */
|
||||
$data = $event->getData();
|
||||
if (null === $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->addParticipantsField($event->getForm());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles dynamic participant form field updates on POST requests (e.g., from HTMX).
|
||||
*
|
||||
* This listener synchronizes the BookingDto with the submitted participant data *before*
|
||||
* the form's children are processed. It then rebuilds the participants
|
||||
* field to ensure choice loaders are created with the fresh state.
|
||||
*/
|
||||
public function onPreSubmit(FormEvent $event): void
|
||||
{
|
||||
$form = $event->getForm();
|
||||
$submittedData = $event->getData();
|
||||
|
||||
/** @var BookingDto $bookingDto */
|
||||
$bookingDto = $form->getData();
|
||||
|
||||
// Process field handlers and synchronize submitted data with cleaned DTO state
|
||||
$cleanedSubmittedData = $this->participantFieldHandlerRegistry->processFieldsAndSync($submittedData, $bookingDto);
|
||||
$event->setData($cleanedSubmittedData);
|
||||
|
||||
// Rebuild the 'participants' field with the updated DTO.
|
||||
$this->addParticipantsField($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or replaces the 'participants' collection field on the form.
|
||||
*/
|
||||
private function addParticipantsField(FormInterface $form): void
|
||||
{
|
||||
$form->add('participants', CollectionType::class, [
|
||||
'entry_type' => BookingParticipantType::class,
|
||||
'entry_options' => [
|
||||
'edit_mode' => false,
|
||||
],
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
]);
|
||||
// No fields needed - participants are edited individually in their own forms
|
||||
// This form exists purely for validation and CSRF protection
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
@@ -1,71 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\ParticipantFieldHandlerRegistry;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
* Form type for edit booking validation.
|
||||
*
|
||||
* This form is used in the card-based UI where participants are edited individually.
|
||||
* This form validates the complete BookingDto before allowing updates,
|
||||
* ensuring all participants have valid and complete data.
|
||||
*/
|
||||
class BookingEditType extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ParticipantFieldHandlerRegistry $participantFieldHandlerRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData'])
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'onPreSubmit']);
|
||||
}
|
||||
|
||||
public function onPreSetData(FormEvent $event): void
|
||||
{
|
||||
/** @var BookingDto $data */
|
||||
$data = $event->getData();
|
||||
$form = $event->getForm();
|
||||
|
||||
$form->add('participants', CollectionType::class, [
|
||||
'entry_type' => BookingParticipantType::class,
|
||||
'entry_options' => [
|
||||
'edit_mode' => true,
|
||||
],
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onPreSubmit(FormEvent $event): void
|
||||
{
|
||||
$form = $event->getForm();
|
||||
$submittedData = $event->getData();
|
||||
|
||||
/** @var BookingDto $bookingDto */
|
||||
$bookingDto = $form->getData();
|
||||
|
||||
// Process field handlers and synchronize submitted data with cleaned DTO state
|
||||
$cleanedSubmittedData = $this->participantFieldHandlerRegistry->processFieldsAndSync($submittedData, $bookingDto);
|
||||
$event->setData($cleanedSubmittedData);
|
||||
|
||||
// Rebuild the 'participants' field with the updated DTO
|
||||
if ($form->has('participants')) {
|
||||
$form->remove('participants');
|
||||
}
|
||||
|
||||
$form->add('participants', CollectionType::class, [
|
||||
'entry_type' => BookingParticipantType::class,
|
||||
'entry_options' => [
|
||||
'edit_mode' => true,
|
||||
],
|
||||
'allow_add' => false,
|
||||
'allow_delete' => false,
|
||||
]);
|
||||
// No fields needed - participants are edited individually in their own forms
|
||||
// This form exists purely for validation
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
@@ -9,12 +9,12 @@ use App\Form\Service\Contract\FieldOptionsProviderInterface;
|
||||
use App\Form\Service\Contract\FieldStateProviderInterface;
|
||||
use App\Form\Service\CreateFieldStateProvider;
|
||||
use App\Form\Service\EditFieldStateProvider;
|
||||
use App\Form\Service\ParticipantFieldHandlerRegistry;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -31,6 +31,7 @@ class BookingParticipantType extends AbstractType
|
||||
private readonly FieldOptionsProviderInterface $fieldOptionsProvider,
|
||||
private readonly CreateFieldStateProvider $createFieldStateProvider,
|
||||
private readonly EditFieldStateProvider $editFieldStateProvider,
|
||||
private readonly ParticipantFieldHandlerRegistry $fieldHandlerRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -41,19 +42,60 @@ class BookingParticipantType extends AbstractType
|
||||
? $this->editFieldStateProvider
|
||||
: $this->createFieldStateProvider;
|
||||
|
||||
// Capture booking context for use in event listeners
|
||||
$bookingContext = $options['booking_context'];
|
||||
|
||||
$builder
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$this->onPreSetData($event);
|
||||
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($bookingContext) {
|
||||
$this->onPreSetData($event, $bookingContext);
|
||||
})
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
|
||||
$this->onPreSubmit($event);
|
||||
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($bookingContext) {
|
||||
// Process field handlers FIRST (before form binding and validation)
|
||||
// This ensures data is cleaned before Symfony processes it
|
||||
if (null !== $bookingContext) {
|
||||
$this->processFieldHandlers($event, $bookingContext);
|
||||
}
|
||||
|
||||
// Then rebuild fields with updated states
|
||||
$this->onPreSubmit($event, $bookingContext);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes field handlers for this participant.
|
||||
*
|
||||
* Field handlers are executed in PRE_SUBMIT to clean and transform data
|
||||
* before Symfony binds it to the form. This matches the pattern used in
|
||||
* the old BookingCreateStep2Type parent form.
|
||||
*/
|
||||
private function processFieldHandlers(FormEvent $event, BookingDto $bookingContext): void
|
||||
{
|
||||
$form = $event->getForm();
|
||||
$submittedData = $event->getData();
|
||||
|
||||
if (false === is_array($submittedData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var ParticipantDto $participant */
|
||||
$participant = $form->getData();
|
||||
|
||||
if (null === $participant || false === property_exists($participant, 'index')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Process all field handlers for this participant in dependency order
|
||||
$this->fieldHandlerRegistry->processFieldsForParticipant(
|
||||
$submittedData,
|
||||
$bookingContext,
|
||||
$participant->index
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds dynamic fields to the form based on participant data.
|
||||
*/
|
||||
private function onPreSetData(FormEvent $event): void
|
||||
private function onPreSetData(FormEvent $event, ?BookingDto $bookingContext): void
|
||||
{
|
||||
/** @var ParticipantDto|null $participantData */
|
||||
$participantData = $event->getData();
|
||||
@@ -63,8 +105,9 @@ class BookingParticipantType extends AbstractType
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the booking DTO from the root form
|
||||
$bookingDto = $this->fieldStateProvider->getBookingDtoFromForm($form);
|
||||
// Card flow: BookingDto passed via options
|
||||
// Accordion flow (if we had one): traverse form tree
|
||||
$bookingDto = $bookingContext ?? $this->fieldStateProvider->getBookingDtoFromForm($form);
|
||||
|
||||
if (null === $bookingDto) {
|
||||
return;
|
||||
@@ -80,7 +123,7 @@ class BookingParticipantType extends AbstractType
|
||||
/**
|
||||
* Handles form pre-submit events to update field states based on submitted data.
|
||||
*/
|
||||
private function onPreSubmit(FormEvent $event): void
|
||||
private function onPreSubmit(FormEvent $event, ?BookingDto $bookingContext): void
|
||||
{
|
||||
$submittedData = $event->getData();
|
||||
$form = $event->getForm();
|
||||
@@ -89,8 +132,9 @@ class BookingParticipantType extends AbstractType
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the booking DTO from the root form
|
||||
$bookingDto = $this->fieldStateProvider->getBookingDtoFromForm($form);
|
||||
// Card flow: BookingDto passed via options
|
||||
// Accordion flow (if we had one): traverse form tree
|
||||
$bookingDto = $bookingContext ?? $this->fieldStateProvider->getBookingDtoFromForm($form);
|
||||
|
||||
if (null === $bookingDto) {
|
||||
return;
|
||||
@@ -334,9 +378,11 @@ class BookingParticipantType extends AbstractType
|
||||
'data_class' => ParticipantDto::class,
|
||||
'selected_rooms' => [],
|
||||
'edit_mode' => false,
|
||||
'booking_context' => null,
|
||||
]);
|
||||
|
||||
$resolver->setAllowedTypes('selected_rooms', 'array');
|
||||
$resolver->setAllowedTypes('edit_mode', 'bool');
|
||||
$resolver->setAllowedTypes('booking_context', ['null', BookingDto::class]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class BookingDto
|
||||
|
||||
/**
|
||||
* Booking status code for API submission.
|
||||
* Values: 'F' (Final/Frei), 'A' (Anfrage/Inquiry)
|
||||
* Values: 'F' (Final/Frei), 'A' (Anfrage/Inquiry).
|
||||
*/
|
||||
public string $bookingStatus = 'F';
|
||||
|
||||
@@ -64,6 +64,13 @@ class BookingDto
|
||||
*/
|
||||
public ?\DateTimeImmutable $lastSessionUpdate = null;
|
||||
|
||||
/**
|
||||
* Fingerprint of the booking state when loaded from API (edit mode only).
|
||||
* This property stores the original state and is never updated after initial load.
|
||||
* Used to detect unsaved changes in edit mode by comparing with current state.
|
||||
*/
|
||||
public ?string $originalFingerprint = null;
|
||||
|
||||
public function __construct(public Travel $travel, public int $hotelId)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -100,6 +100,10 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
// Extract current service selections from submitted data
|
||||
$selectedServices = $this->getFieldValue($submittedData, $this->getFieldName()) ?? [];
|
||||
|
||||
// Debug: Log what was submitted
|
||||
$submittedIds = array_map(fn($s) => is_object($s) ? $s->id : $s, $selectedServices);
|
||||
error_log(sprintf('[AdditionalServices] Participant %d: Submitted service IDs: [%s]', $participantIndex, implode(', ', $submittedIds)));
|
||||
|
||||
// Get available additional services from travel data
|
||||
$availableServices = $bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_ADDITIONAL);
|
||||
|
||||
@@ -111,6 +115,10 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
$participantIndex
|
||||
);
|
||||
|
||||
// Debug: Log what passed validation
|
||||
$validIds = array_map(fn($s) => $s->id, $validSelections);
|
||||
error_log(sprintf('[AdditionalServices] Participant %d: Valid service IDs after filtering: [%s]', $participantIndex, implode(', ', $validIds)));
|
||||
|
||||
// Update participant with validated selections
|
||||
$participant->additionalServices = $validSelections;
|
||||
}
|
||||
@@ -173,17 +181,33 @@ class ParticipantAdditionalServicesFieldHandler extends AbstractParticipantField
|
||||
$service = $this->findServiceInAvailableServices($selectedService, $availableServices);
|
||||
|
||||
if (null === $service) {
|
||||
error_log(sprintf('[AdditionalServices] Participant %d: Service %s NOT FOUND in available services', $participantIndex, is_object($selectedService) ? $selectedService->id : $selectedService));
|
||||
return false; // Service not found in available services
|
||||
}
|
||||
|
||||
// Check if service has age constraints
|
||||
$ageEvaluator = new ServiceAgeEvaluator();
|
||||
if (false === $ageEvaluator->canEvaluate($service)) {
|
||||
error_log(sprintf('[AdditionalServices] Participant %d: Service %d (%s) has NO age constraints - VALID', $participantIndex, $service->id, $service->label));
|
||||
return true; // No age restrictions, service is valid
|
||||
}
|
||||
|
||||
// Validate service against participant's age
|
||||
return $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
$isValid = $ageEvaluator->isServiceAvailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
$age = $participant?->getAge($bookingDto->travel->dateFrom);
|
||||
|
||||
error_log(sprintf(
|
||||
'[AdditionalServices] Participant %d (age %s): Service %d (%s) age validation = %s. Constraints: %s',
|
||||
$participantIndex,
|
||||
$age ?? 'unknown',
|
||||
$service->id,
|
||||
$service->label,
|
||||
$isValid ? 'VALID' : 'INVALID',
|
||||
$ageEvaluator->getConstraintDescription($service)
|
||||
));
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,7 +133,7 @@ class ParticipantFieldHandlerRegistry
|
||||
}
|
||||
|
||||
// Let each handler decide if it should process this participant's data
|
||||
if ($handler->shouldProcess($participantData, $bookingDto->mode, (int) $participantIndex)) {
|
||||
if ($handler->shouldProcess($participantData, $bookingDto->getMode(), (int) $participantIndex)) {
|
||||
$handler->processField($participantData, $bookingDto, (int) $participantIndex);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class ParticipantFieldHandlerRegistry
|
||||
$handler = $this->handlers[$handlerName];
|
||||
|
||||
// Let each handler decide if it should process this participant's data
|
||||
if ($handler->shouldProcess($participantData, $bookingDto->mode, $participantIndex)) {
|
||||
if ($handler->shouldProcess($participantData, $bookingDto->getMode(), $participantIndex)) {
|
||||
$handler->processField($participantData, $bookingDto, $participantIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,10 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->filterServicesByAgeConstraints(
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_COURSES),
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_COURSES,
|
||||
BookingDto::MODE_CREATE === $bookingDto->getMode() // Only filter by availability in create mode
|
||||
),
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
),
|
||||
@@ -143,8 +146,8 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
$attributes['data-description'] = $service->description;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'courses')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -160,7 +163,10 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->filterServicesByAgeConstraints(
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_ADDITIONAL),
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_ADDITIONAL,
|
||||
BookingDto::MODE_EDIT !== $bookingDto->getMode() // Only filter by availability in create mode
|
||||
),
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
),
|
||||
@@ -187,7 +193,7 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable (only if not already mandatory)
|
||||
if (false === $service->mandatory && $this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
if (false === $service->mandatory && $this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'additionalServices')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -203,7 +209,10 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->filterServicesByAgeConstraints(
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_BOARD),
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_BOARD,
|
||||
BookingDto::MODE_CREATE === $bookingDto->getMode() // Only filter by availability in create mode
|
||||
),
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
),
|
||||
@@ -216,8 +225,8 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
|
||||
$attributes = [];
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'board')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -234,7 +243,11 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'required' => false,
|
||||
'choices' => $this->filterServicesByAgeConstraints(
|
||||
$this->filterRentalsBySkiPassDuration(
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_RENTALS, true, true),
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_RENTALS,
|
||||
BookingDto::MODE_CREATE === $bookingDto->getMode(), // Only filter by availability in create mode
|
||||
true // Filter by travel date range
|
||||
),
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
),
|
||||
@@ -255,8 +268,8 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
$attributes['data-description'] = $service->description;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'rentals')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -292,7 +305,11 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->filterServicesByAgeConstraints(
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(Constants::TOKEN_SKI_PASS, true, true),
|
||||
$bookingDto->travel->getAdditionalServicesBySubTypes(
|
||||
Constants::TOKEN_SKI_PASS,
|
||||
BookingDto::MODE_CREATE === $bookingDto->getMode(), // Only filter by availability in create mode
|
||||
true // Filter by travel date range
|
||||
),
|
||||
$bookingDto,
|
||||
$participantIndex
|
||||
),
|
||||
@@ -310,8 +327,8 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
$attributes['data-description'] = $service->description;
|
||||
}
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'skiPass')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
@@ -348,19 +365,14 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
|
||||
$attributes = [];
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'transportationOutbound')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
},
|
||||
'attr' => [
|
||||
'hx-post' => $this->urlGenerator->generate('app_booking_create_step_2_refresh'),
|
||||
'hx-swap' => 'none',
|
||||
'hx-trigger' => 'change',
|
||||
],
|
||||
];
|
||||
|
||||
// Inbound Transportation
|
||||
@@ -379,19 +391,14 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
|
||||
$attributes = [];
|
||||
|
||||
// Make readonly if service is unavailable
|
||||
if ($this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex)) {
|
||||
// Make readonly if service is unavailable (intelligently handles edit mode)
|
||||
if ($this->shouldMakeServiceReadonly($service, $bookingDto, $participantIndex, 'transportationInbound')) {
|
||||
$attributes['readonly'] = true;
|
||||
$attributes['data-tooltip'] = 'ausgebucht';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
},
|
||||
'attr' => [
|
||||
'hx-post' => $this->urlGenerator->generate('app_booking_create_step_2_refresh'),
|
||||
'hx-swap' => 'none',
|
||||
'hx-trigger' => 'change',
|
||||
],
|
||||
];
|
||||
|
||||
// Pickup (conditional - only shown when either transportation direction is bus)
|
||||
@@ -419,11 +426,6 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
$this->fieldOptionProviders['bulkInsuranceBooking'] = fn (BookingDto $bookingDto, int $participantIndex, array $options = []) => [
|
||||
'label' => 'Für alle Teilnehmer buchen',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'hx-post' => $this->urlGenerator->generate('app_booking_create_step_2_refresh'),
|
||||
'hx-swap' => 'none',
|
||||
'hx-trigger' => 'change',
|
||||
],
|
||||
];
|
||||
|
||||
// Insurance field provider - provides age and eligibility filtered insurances for participants
|
||||
@@ -434,11 +436,6 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'insurances' => $this->getEligibleInsurances($bookingDto, $participantIndex),
|
||||
'attr' => [
|
||||
'hx-post' => $this->urlGenerator->generate('app_booking_create_step_2_refresh'),
|
||||
'hx-swap' => 'none',
|
||||
'hx-trigger' => 'change',
|
||||
],
|
||||
];
|
||||
|
||||
// Future field providers would be added here, for example:
|
||||
@@ -601,6 +598,78 @@ class ParticipantFieldOptionsProvider extends AbstractFieldOptionsProvider
|
||||
return $this->serviceAvailabilityCalculator->isServiceUnavailable($service->id, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a service should be rendered as read-only.
|
||||
*
|
||||
* This method intelligently handles readonly state for services in both create and edit modes:
|
||||
*
|
||||
* - CREATE MODE: Uses existing availability calculator logic
|
||||
* - EDIT MODE: Services unavailable (available <= 0) are readonly ONLY if participant doesn't already have them
|
||||
*
|
||||
* This prevents fingerprint false positives in edit mode by allowing participants to keep
|
||||
* services they already have, even if those services are now fully booked.
|
||||
*
|
||||
* @param Service $service The service to check
|
||||
* @param BookingDto $bookingDto The booking DTO containing participant data
|
||||
* @param int $participantIndex Index of the participant currently selecting services
|
||||
* @param string $fieldName Name of the service field (e.g., 'courses', 'board', 'rentals')
|
||||
*
|
||||
* @return bool True if the service should be read-only
|
||||
*/
|
||||
private function shouldMakeServiceReadonly(Service $service, BookingDto $bookingDto, int $participantIndex, string $fieldName): bool
|
||||
{
|
||||
// In CREATE mode, use existing availability logic
|
||||
if (BookingDto::MODE_CREATE === $bookingDto->getMode()) {
|
||||
return $this->isServiceUnavailableForParticipant($service, $bookingDto, $participantIndex);
|
||||
}
|
||||
|
||||
// In EDIT mode, apply intelligent readonly logic
|
||||
// If service is available (available > 0), it's never readonly
|
||||
if (null !== $service->available && $service->available > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Service is unavailable - check if participant already has it
|
||||
$participant = $bookingDto->getParticipant($participantIndex);
|
||||
if (null === $participant) {
|
||||
return true; // Readonly if no participant data
|
||||
}
|
||||
|
||||
// Check if participant has this service based on field type
|
||||
$participantHasService = match ($fieldName) {
|
||||
'courses' => $this->hasServiceById($participant->courses, $service->id),
|
||||
'additionalServices' => $this->hasServiceById($participant->additionalServices, $service->id),
|
||||
'board' => $this->hasServiceById($participant->board, $service->id),
|
||||
'rentals' => $this->hasServiceById($participant->rentals, $service->id),
|
||||
'skiPass' => $participant->skiPass?->id === $service->id,
|
||||
'transportationOutbound' => $participant->transportationOutbound?->id === $service->id,
|
||||
'transportationInbound' => $participant->transportationInbound?->id === $service->id,
|
||||
default => false,
|
||||
};
|
||||
|
||||
// Make readonly only if participant doesn't have it
|
||||
return false === $participantHasService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a service array contains a service with the given ID.
|
||||
*
|
||||
* @param array $services Array of Service objects
|
||||
* @param int $serviceId Service ID to search for
|
||||
*
|
||||
* @return bool True if the service is found in the array
|
||||
*/
|
||||
private function hasServiceById(array $services, int $serviceId): bool
|
||||
{
|
||||
foreach ($services as $service) {
|
||||
if ($service->id === $serviceId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters services based on participant's age constraints.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Form\Model\BookingDto;
|
||||
|
||||
/**
|
||||
* Generates fingerprints of booking state for change detection in edit mode.
|
||||
*
|
||||
* Creates SHA-256 hashes of all mutable booking data to detect unsaved changes.
|
||||
* Used by EditController to determine if user modifications need to be saved.
|
||||
*/
|
||||
class BookingFingerprintService
|
||||
{
|
||||
/**
|
||||
* Generates a fingerprint (hash) of all mutable booking data.
|
||||
*
|
||||
* The fingerprint includes payment details and all participant data including
|
||||
* personal information, addresses, body dimensions, room assignments, and service selections.
|
||||
*/
|
||||
public function generateFingerprint(BookingDto $bookingDto, bool $logData = false): string
|
||||
{
|
||||
$data = [
|
||||
'paymentMethod' => $bookingDto->paymentMethod,
|
||||
'bankAccount' => [
|
||||
'iban' => $bookingDto->bankAccount?->iban,
|
||||
'accountHolder' => $bookingDto->bankAccount?->accountHolder,
|
||||
],
|
||||
'participants' => [],
|
||||
];
|
||||
|
||||
foreach ($bookingDto->participants as $index => $participant) {
|
||||
$data['participants'][$index] = [
|
||||
'personalData' => [
|
||||
'firstName' => $participant->firstName,
|
||||
'lastName' => $participant->lastName,
|
||||
'dateOfBirth' => $participant->dateOfBirth?->format('Y-m-d'),
|
||||
'email' => $participant->email,
|
||||
'mobile' => $participant->mobile,
|
||||
'gender' => $participant->gender,
|
||||
'nationality' => $participant->nationality,
|
||||
],
|
||||
'address' => [
|
||||
'street' => $participant->address?->street,
|
||||
'postCode' => $participant->address?->postCode,
|
||||
'city' => $participant->address?->city,
|
||||
'country' => $participant->address?->country,
|
||||
],
|
||||
'bodyDimensions' => [
|
||||
'height' => $participant->height,
|
||||
'weight' => $participant->weight,
|
||||
'shoeSize' => $participant->shoeSize,
|
||||
],
|
||||
'roomAssignment' => [
|
||||
'assignedRoomId' => $participant->assignedRoomId,
|
||||
'remarksRoom' => $participant->remarksRoom,
|
||||
],
|
||||
'licensePlate' => $participant->licensePlate,
|
||||
'services' => [
|
||||
'skiPass' => $participant->skiPass?->id,
|
||||
'courses' => $this->normalizeServiceArray($participant->courses),
|
||||
'board' => $this->normalizeServiceArray($participant->board),
|
||||
'rentals' => $this->normalizeServiceArray($participant->rentals),
|
||||
'rentalInsurance' => $participant->rentalInsurance?->id,
|
||||
'additionalServices' => $this->normalizeServiceArray($participant->additionalServices),
|
||||
'transportationOutbound' => $participant->transportationOutbound?->id,
|
||||
'transportationInbound' => $participant->transportationInbound?->id,
|
||||
'pickup' => $participant->pickup?->id,
|
||||
'parking' => $participant->parking,
|
||||
'insurance' => $participant->insurance?->id,
|
||||
'bulkInsuranceBooking' => $participant->bulkInsuranceBooking,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$fingerprint = hash('sha256', serialize($data));
|
||||
|
||||
if ($logData) {
|
||||
error_log(sprintf('[Fingerprint] Generated fingerprint: %s', $fingerprint));
|
||||
error_log(sprintf('[Fingerprint] Serialized data: %s', serialize($data)));
|
||||
}
|
||||
|
||||
return $fingerprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a service array to ensure consistent fingerprinting.
|
||||
*
|
||||
* Extracts service IDs, sorts them, and returns a simple indexed array.
|
||||
* This ensures that associative arrays, indexed arrays, and different orders
|
||||
* all produce the same fingerprint as long as the same services are present.
|
||||
*
|
||||
* @param array $services Array of Service objects
|
||||
*
|
||||
* @return array Sorted array of service IDs
|
||||
*/
|
||||
private function normalizeServiceArray(array $services): array
|
||||
{
|
||||
$ids = array_map(fn ($s) => $s->id, $services);
|
||||
sort($ids);
|
||||
|
||||
return array_values($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the booking has unsaved changes in edit mode.
|
||||
*
|
||||
* Compares the current state fingerprint with the original fingerprint
|
||||
* that was set when the booking was loaded from the API.
|
||||
*/
|
||||
public function isDirty(BookingDto $bookingDto): bool
|
||||
{
|
||||
if (BookingDto::MODE_EDIT !== $bookingDto->getMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (null === $bookingDto->originalFingerprint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentFingerprint = $this->generateFingerprint($bookingDto);
|
||||
$isDirty = $bookingDto->originalFingerprint !== $currentFingerprint;
|
||||
|
||||
// Debug logging to identify what changed
|
||||
if ($isDirty) {
|
||||
error_log(sprintf('[Fingerprint] DIRTY DETECTED! Original: %s, Current: %s', $bookingDto->originalFingerprint, $currentFingerprint));
|
||||
$this->logFingerprintDiff($bookingDto);
|
||||
}
|
||||
|
||||
return $isDirty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs detailed fingerprint data for debugging dirty state issues.
|
||||
*/
|
||||
private function logFingerprintDiff(BookingDto $bookingDto): void
|
||||
{
|
||||
foreach ($bookingDto->participants as $index => $participant) {
|
||||
$participantData = [
|
||||
'firstName' => $participant->firstName,
|
||||
'lastName' => $participant->lastName,
|
||||
'dateOfBirth' => $participant->dateOfBirth?->format('Y-m-d'),
|
||||
'email' => $participant->email,
|
||||
'mobile' => $participant->mobile,
|
||||
'gender' => $participant->gender,
|
||||
'nationality' => $participant->nationality,
|
||||
'address' => [
|
||||
'street' => $participant->address?->street,
|
||||
'postCode' => $participant->address?->postCode,
|
||||
'city' => $participant->address?->city,
|
||||
'country' => $participant->address?->country,
|
||||
],
|
||||
'services' => [
|
||||
'skiPass' => $participant->skiPass?->id,
|
||||
'courses' => $this->normalizeServiceArray($participant->courses),
|
||||
'board' => $this->normalizeServiceArray($participant->board),
|
||||
'rentals' => $this->normalizeServiceArray($participant->rentals),
|
||||
'rentalInsurance' => $participant->rentalInsurance?->id,
|
||||
'additionalServices' => $this->normalizeServiceArray($participant->additionalServices),
|
||||
'transportationOutbound' => $participant->transportationOutbound?->id,
|
||||
'transportationInbound' => $participant->transportationInbound?->id,
|
||||
'pickup' => $participant->pickup?->id,
|
||||
'parking' => $participant->parking,
|
||||
],
|
||||
];
|
||||
|
||||
error_log(sprintf('[Fingerprint] Participant %d data: %s', $index, json_encode($participantData)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,12 @@ class BookingPriceCalculatorService
|
||||
{
|
||||
$roomPricing = [];
|
||||
|
||||
// In edit mode, use room data from the booking entity
|
||||
if (BookingDto::MODE_EDIT === $bookingDto->getMode() && null !== $bookingDto->booking) {
|
||||
return $this->calculateRoomPricingFromBooking($bookingDto);
|
||||
}
|
||||
|
||||
// In create mode, use room selections from the form
|
||||
$selectedRooms = $bookingDto->getSelectedRooms();
|
||||
if (true === empty($selectedRooms)) {
|
||||
return $roomPricing;
|
||||
@@ -86,6 +92,61 @@ class BookingPriceCalculatorService
|
||||
return $roomPricing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates room pricing from booking entity data (edit mode).
|
||||
*
|
||||
* In edit mode, room prices come from the booking entity's individualPrice arrays.
|
||||
* Each participant has their room price stored in the room's individualPrice array.
|
||||
*
|
||||
* @param BookingDto $bookingDto The booking data with booking entity
|
||||
*
|
||||
* @return array Array of room pricing data with labels, quantities, and totals
|
||||
*/
|
||||
private function calculateRoomPricingFromBooking(BookingDto $bookingDto): array
|
||||
{
|
||||
$roomPricing = [];
|
||||
$roomGroups = [];
|
||||
|
||||
// Group participants by room and sum their individual prices
|
||||
foreach ($bookingDto->booking->rooms as $room) {
|
||||
if (false === isset($roomGroups[$room->id])) {
|
||||
$roomGroups[$room->id] = [
|
||||
'room' => $room,
|
||||
'participantCount' => 0,
|
||||
'totalPrice' => 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
// Sum individual prices for all participants in this room
|
||||
foreach ($room->mapping as $participantIndex) {
|
||||
$individualPrice = $room->individualPrice[$participantIndex] ?? 0.0;
|
||||
$roomGroups[$room->id]['totalPrice'] += $individualPrice;
|
||||
++$roomGroups[$room->id]['participantCount'];
|
||||
}
|
||||
}
|
||||
|
||||
// Build pricing array
|
||||
foreach ($roomGroups as $roomId => $data) {
|
||||
$room = $data['room'];
|
||||
$participantCount = $data['participantCount'];
|
||||
$totalPrice = $data['totalPrice'];
|
||||
|
||||
// Calculate average unit price (price per person)
|
||||
$unitPrice = $participantCount > 0 ? $totalPrice / $participantCount : 0.0;
|
||||
|
||||
$roomPricing[] = [
|
||||
'roomId' => $room->id,
|
||||
'label' => $room->label,
|
||||
'quantity' => $room->totalCount,
|
||||
'participantCount' => $participantCount,
|
||||
'unitPrice' => $unitPrice,
|
||||
'totalPrice' => $totalPrice,
|
||||
];
|
||||
}
|
||||
|
||||
return $roomPricing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates pricing for all selected services across all participants, grouped by subtype.
|
||||
*
|
||||
|
||||
@@ -98,7 +98,7 @@ class ParticipantCardDataService
|
||||
return 'Unbekanntes Zimmer';
|
||||
}
|
||||
|
||||
return $room->name;
|
||||
return $room->label;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
{# Compact participant card with name, room, price, and edit button #}
|
||||
{% set isCanceled = isCanceled|default(false) %}
|
||||
{% set hasErrors = hasErrors|default(false) %}
|
||||
{% set mode = mode|default('create') %}
|
||||
|
||||
<div id="participant-card-{{ index }}"
|
||||
class="border rounded p-4 flex justify-between items-center
|
||||
{{ isCanceled ? 'border-gray-400 bg-gray-50' : (hasErrors ? 'border-red-500 bg-red-50' : '') }}">
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<h3 class="font-semibold {{ hasErrors ? 'text-red-800' : (isCanceled ? 'text-gray-600' : '') }}">
|
||||
{{ cardData.name }}
|
||||
</h3>
|
||||
{% if isCanceled %}
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-700 text-white">
|
||||
storniert
|
||||
</span>
|
||||
{% elseif hasErrors %}
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-100 text-red-800">
|
||||
<svg class="w-3 h-3 mr-1" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
Unvollständig
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="text-sm text-gray-600">{{ cardData.roomName }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<span class="font-medium {{ isCanceled ? 'text-gray-500' : '' }}">{{ cardData.price }}</span>
|
||||
{% if isCanceled %}
|
||||
<button type="button"
|
||||
class="button bg-button bg-button--secondary opacity-50 cursor-not-allowed"
|
||||
disabled
|
||||
title="Stornierte Teilnehmer können nicht bearbeitet werden">
|
||||
Bearbeiten
|
||||
</button>
|
||||
{% else %}
|
||||
{% if mode == 'edit' %}
|
||||
<button type="button"
|
||||
class="button bg-button {{ hasErrors ? 'bg-button--primary' : 'bg-button--secondary' }}"
|
||||
hx-get="{{ path('app_booking_edit_participant', {id: bookingId, index: index}) }}"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML">
|
||||
Bearbeiten
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button"
|
||||
class="button bg-button {{ hasErrors ? 'bg-button--primary' : 'bg-button--secondary' }}"
|
||||
hx-get="{{ path('app_booking_create_step_2_participant', {index: index}) }}"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML">
|
||||
Bearbeiten
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,327 @@
|
||||
{% import _self as macros %}
|
||||
|
||||
{# Macro to render a field or placeholder with consistent fieldset structure #}
|
||||
{% macro service_field(form, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if form[fieldName] is defined %}
|
||||
{{ form_row(form[fieldName], options) }}
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{# Specialized macro for checkbox fields (like rental insurance) that need manual fieldset wrapping #}
|
||||
{% macro checkbox_field(form, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if form[fieldName] is defined %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
{{ form_row(form[fieldName], options) }}
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{# Standalone participant form view (replaces main content area) #}
|
||||
{% block participant_form %}
|
||||
{% import _self as macros %}
|
||||
<div id="participant-form-view">
|
||||
<h2>{{ participantIndex == 0 ? 'Anmelder:in' : 'Teilnehmer:in ' ~ (participantIndex + 1) }}</h2>
|
||||
|
||||
{{ form_start(form, {
|
||||
'attr': {
|
||||
'novalidate': 'novalidate',
|
||||
'hx-post': path(submitRouteName, submitRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
<div id="participant-form" class="space-y-4">
|
||||
{# Personal data section #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.firstName) }}
|
||||
{{ form_row(form.lastName) }}
|
||||
{{ form_row(form.dateOfBirth, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{{ form_row(form.gender) }}
|
||||
{{ form_row(form.nationality) }}
|
||||
</div>
|
||||
|
||||
{# Contact information #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.email) }}
|
||||
{{ form_row(form.mobile) }}
|
||||
</div>
|
||||
|
||||
{# Address #}
|
||||
{% if form.address is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.address.street) }}
|
||||
{{ form_row(form.address.postCode) }}
|
||||
{{ form_row(form.address.city) }}
|
||||
{{ form_row(form.address.country) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Body dimensions #}
|
||||
{% if form.bodyDimensions is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.bodyDimensions.height) }}
|
||||
{{ form_row(form.bodyDimensions.shoeSize) }}
|
||||
{{ form_row(form.bodyDimensions.weight) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Room assignment #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.assignedRoomId, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{% if form.remarksRoom is defined %}
|
||||
{{ form_row(form.remarksRoom) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# Eligibility checks #}
|
||||
{% set participantData = form.vars.data %}
|
||||
{% set hasDateOfBirth = participantData and participantData.dateOfBirth %}
|
||||
{% set isEligible = hasDateOfBirth and is_participant_eligible(bookingDto, participantIndex) %}
|
||||
|
||||
{% if not hasDateOfBirth %}
|
||||
<div class="my-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-blue-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-blue-800">
|
||||
Leistungen sind erst nach Angabe des Geburtsdatums buchbar
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% elseif not isEligible %}
|
||||
<div class="my-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-red-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-red-800">
|
||||
Buchung wegen des Alters von Teilnehmer:in {{ participantIndex + 1 }} nicht möglich
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Service selection #}
|
||||
{% if isEligible %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ macros.service_field(form, 'skiPass', 'Skipass', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ macros.service_field(form, 'courses', 'Kurse', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ macros.service_field(form, 'additionalServices', 'Zusatzleistungen', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ macros.service_field(form, 'rentals', 'Leihmaterial', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}, 'Bitte zuerst den Skipass auswählen') }}
|
||||
|
||||
{{ macros.checkbox_field(form, 'rentalInsurance', 'Leihmaterial-Versicherung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}, 'Nur bei Buchung von Leihmaterial') }}
|
||||
|
||||
{{ macros.service_field(form, 'board', 'Verpflegung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
|
||||
<div class="col-span-2">
|
||||
{# Insurance field OR assigned insurance display for dependent participants #}
|
||||
{% set showBulkInsurance = participantIndex > 0 and bookingDto.participants[0].bulkInsuranceBooking %}
|
||||
|
||||
{% if showBulkInsurance %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
<div class="text-sm text-gray-600">
|
||||
{% set applicantInsurance = bookingDto.participants[0].insurance %}
|
||||
{% if applicantInsurance %}
|
||||
{{ applicantInsurance.label }}
|
||||
{% if applicantInsurance.price and applicantInsurance.price > 0 %}
|
||||
<span class="text-gray-500">(€{{ applicantInsurance.price|number_format(2, ',', '.') }})</span>
|
||||
{% endif %}
|
||||
<span class="italic text-gray-500 ml-2">– wie Anmelder</span>
|
||||
{% else %}
|
||||
<span class="italic">wie Anmelder</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
|
||||
{# Bulk insurance booking checkbox (applicant only) #}
|
||||
{% if form.bulkInsuranceBooking is defined %}
|
||||
{{ form_row(form.bulkInsuranceBooking) }}
|
||||
{% endif %}
|
||||
|
||||
{% if form.insurance is defined %}
|
||||
{{ form_row(form.insurance, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
},
|
||||
'label': false
|
||||
}) }}
|
||||
{% else %}
|
||||
<div class="text-sm text-gray-500">Nicht wählbar</div>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{# Transportation Services Section #}
|
||||
<div class="mt-6 border-t pt-4">
|
||||
<h3 class="font-semibold text-lg mb-4">Anreise</h3>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
{% if form.transportationOutbound is defined %}
|
||||
{{ form_row(form.transportationOutbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
{% if form.pickup is defined or form.parking is defined or form.licensePlate is defined %}
|
||||
{% if form.pickup is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(form.pickup, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if form.parking is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(form.parking, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if form.licensePlate is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(form.licensePlate) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
{% if form.transportationInbound is defined %}
|
||||
{{ form_row(form.transportationInbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
|
||||
'hx-target': '#main-content', 'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between mt-8">
|
||||
{% if cancelRouteName is defined %}
|
||||
<button type="button"
|
||||
class="button bg-button bg-button--secondary"
|
||||
hx-get="{{ path(cancelRouteName, cancelRouteParams|default({})) }}"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML">
|
||||
Abbrechen
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="button"
|
||||
class="button bg-button bg-button--secondary"
|
||||
hx-get="{{ path('app_booking_create_step_2') }}"
|
||||
hx-target="#main-content"
|
||||
hx-swap="innerHTML">
|
||||
Abbrechen
|
||||
</button>
|
||||
{% endif %}
|
||||
<button type="submit" class="button bg-button bg-button--secondary">
|
||||
Speichern
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{# Sidebar summary with conditional OOB swap #}
|
||||
{% block booking_summary %}
|
||||
<div id="booking-summary"{% if htmx_oob_swap|default(false) %} hx-swap-oob="true"{% endif %}>
|
||||
{% include 'booking/_summary.html.twig' with {
|
||||
'bookingCreateDto': bookingDto,
|
||||
'participantCount': summaryData.participantsCount,
|
||||
'groupedSelectedRooms': summaryData.groupedSelectedRooms,
|
||||
'assignmentCounts': summaryData.assignmentCounts,
|
||||
'pricingData': pricingData
|
||||
} %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -19,20 +19,15 @@
|
||||
<div class="mt-2 text-sm text-red-700">
|
||||
{% for flash_message in app.flashes('error') %}
|
||||
<p>{{ flash_message }}</p>
|
||||
{% else %}
|
||||
<p>Es ist ein Fehler beim Starten des Buchungsvorgangs aufgetreten.</p>
|
||||
{% endfor %}
|
||||
|
||||
{% if app.flashes('error') is empty %}
|
||||
<p>Es ist ein Fehler beim Starten der Buchung aufgetreten. Bitte versuchen Sie es erneut.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<div class="flex space-x-2">
|
||||
<a href="#" class="button bg-button bg-button--secondary">
|
||||
<a href="https://www.ep-reisen.de" class="button bg-button bg-button--secondary">
|
||||
Zur Startseite
|
||||
</a>
|
||||
<button onclick="history.back()" class="button bg-button">
|
||||
Zurück
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,76 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
{% include '_partials/_flashes.html.twig' %}
|
||||
<div {{ stimulus_controller('toast') }}></div>
|
||||
<h1>Neue Buchung</h1>
|
||||
|
||||
<div class="grid grid-cols-3 gap-8">
|
||||
{# Main content area - cards grid #}
|
||||
{% block participant_cards %}
|
||||
<div id="main-content" class="col-span-2">
|
||||
{{ form_start(form, {
|
||||
'attr': {
|
||||
'hx-post': path('app_booking_create_step_2'),
|
||||
'hx-target': '#main-content',
|
||||
'hx-swap': 'innerHTML'
|
||||
}
|
||||
}) }}
|
||||
|
||||
<h2>Teilnehmer</h2>
|
||||
|
||||
{# Display form-level validation errors #}
|
||||
{% if form.vars.submitted and not form.vars.valid %}
|
||||
<div class="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||
<div class="flex items-start">
|
||||
<svg class="w-5 h-5 text-red-600 mr-2 mt-0.5 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<div>
|
||||
<p class="font-semibold text-red-800 mb-1">Bitte überprüfe die Teilnehmerdaten</p>
|
||||
<p class="text-sm text-red-700">Einige Teilnehmer haben noch unvollständige oder fehlerhafte Angaben. Bitte bearbeite die markierten Teilnehmer.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="participant-cards-grid" class="space-y-4">
|
||||
{% for cardData in cardsData %}
|
||||
{% set hasErrors = loop.index0 in participantErrors|default([]) %}
|
||||
{% include 'booking/_participant_card.html.twig' with {
|
||||
'cardData': cardData,
|
||||
'index': loop.index0,
|
||||
'mode': 'create',
|
||||
'hasErrors': hasErrors
|
||||
} %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between mt-8">
|
||||
<a href="{{ path('app_booking_create_step_1') }}" class="button bg-button bg-button--secondary">
|
||||
Zurück
|
||||
</a>
|
||||
<button type="submit" class="button bg-button bg-button--secondary">
|
||||
Weiter
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{# Sidebar summary #}
|
||||
{% block booking_summary %}
|
||||
<div id="booking-summary"{% if htmx_oob_swap|default(false) %} hx-swap-oob="true"{% endif %}>
|
||||
{% include 'booking/_summary.html.twig' with {
|
||||
'bookingCreateDto': bookingDto,
|
||||
'participantCount': summaryData.participantsCount,
|
||||
'groupedSelectedRooms': summaryData.groupedSelectedRooms,
|
||||
'assignmentCounts': summaryData.assignmentCounts,
|
||||
'pricingData': pricingData
|
||||
} %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -4,22 +4,15 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="max-w-2xl mx-auto text-center py-12">
|
||||
<div class="mb-8">
|
||||
<svg class="w-24 h-24 text-green-500 mx-auto" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<h1 class="text-3xl font-bold mb-4">Buchung erfolgreich abgeschlossen</h1>
|
||||
|
||||
<p class="text-xl mb-8">
|
||||
Ihre Buchungsnummer: <strong class="font-mono">{{ bookingNumber }}</strong>
|
||||
Deine Buchungsnummer lautet <strong class="font-mono">{{ bookingNumber }}</strong>
|
||||
</p>
|
||||
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-6 mb-8">
|
||||
<p class="text-gray-700">
|
||||
Sie erhalten in Kürze eine Bestätigungs-E-Mail mit allen Details zu Ihrer Buchung.
|
||||
Du erhältst in Kürze eine Bestätigungs-E-Mail mit allen Details zu Deiner Buchung.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,337 +0,0 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{# Local form theme override for consistent fieldset rendering #}
|
||||
{% use 'forms.html.twig' %}
|
||||
|
||||
{% block form_row %}
|
||||
{%- if form.vars.expanded is defined and form.vars.expanded -%}
|
||||
{# Expanded forms get fieldset wrapper #}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">
|
||||
{{- form.vars.label -}}
|
||||
</legend>
|
||||
{{- form_widget(form, {
|
||||
'attr': attr|default({})
|
||||
}) -}}
|
||||
{{- form_errors(form) -}}
|
||||
{{- form_help(form) -}}
|
||||
</fieldset>
|
||||
{%- else -%}
|
||||
{{- parent() -}}
|
||||
{%- endif -%}
|
||||
{% endblock %}
|
||||
|
||||
{% import _self as macros %}
|
||||
|
||||
{# Macro to render a field or placeholder with consistent fieldset structure #}
|
||||
{% macro service_field(participant, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if participant[fieldName] is defined %}
|
||||
{{ form_row(participant[fieldName], options) }}
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{# Specialized macro for checkbox fields (like rental insurance) that need manual fieldset wrapping #}
|
||||
{% macro checkbox_field(participant, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if participant[fieldName] is defined %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
{{ form_row(participant[fieldName], options) }}
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
{% include '_partials/_flashes.html.twig' %}
|
||||
<div {{ stimulus_controller('toast') }}></div>
|
||||
<h1>Neue Buchung</h1>
|
||||
<div class="grid grid-cols-3 gap-8">
|
||||
<div id="form-wrapper" class="col-span-2">
|
||||
<h2>Teilnehmer</h2>
|
||||
{{ form_start(form) }}
|
||||
{% do form.participants.setRendered %}
|
||||
{# This block contains the participant form fields #}
|
||||
{% block participants_form %}
|
||||
<div id="participants-form" class="space-y-8 pb-8"{% if htmx_oob_swap is defined and htmx_oob_swap %} hx-swap-oob="true"{% endif %}>
|
||||
{% for participant in form.participants %}
|
||||
{% set participantDataValid = participant.vars.valid %}
|
||||
{% set participantData = participant.vars.data %}
|
||||
{% set hasDateOfBirth = participantData and participantData.dateOfBirth %}
|
||||
{% set isEligible = hasDateOfBirth and is_participant_eligible(bookingCreateDto, loop.index0) %}
|
||||
<div class="{{ html_classes('border rounded px-4 py-2', { 'border-gray-300': participantDataValid, 'border-red-700': not participantDataValid }) }}" {{ stimulus_controller('toggle', {'storageKey': 'participant_' ~ loop.index0, 'open': participant.vars.valid == false}, { 'closed': 'hidden' }) }}>
|
||||
<fieldset>
|
||||
<legend class="w-full flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-bold text-xl">{{ loop.index == 1 ? 'Anmelder:in' : 'Teilnehmer:in ' ~ loop.index }}</span>
|
||||
{% if isEligible and participantPrices is defined and participantPrices[loop.index0] is defined and participantPrices[loop.index0] > 0.0 %}
|
||||
<span class="text-sm font-medium text-gray-600 bg-gray-100 px-2 py-1 rounded">
|
||||
€{{ participantPrices[loop.index0]|number_format(2, ',', '.') }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<button type="button" tabindex="0" {{ stimulus_action('toggle', 'toggle') }}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6" {{ stimulus_target('toggle', 'icon') }}>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
|
||||
</svg>
|
||||
</button>
|
||||
</legend>
|
||||
<div class="hidden py-4" {{ stimulus_target('toggle', 'toggle') }}>
|
||||
<div class="grid grid-cols-2 gap-4 pb-4">
|
||||
{{ form_row(participant.firstName) }}
|
||||
{{ form_row(participant.lastName) }}
|
||||
{{ form_row(participant.dateOfBirth, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{{ form_row(participant.gender) }}
|
||||
{{ form_row(participant.nationality) }}
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.email) }}
|
||||
{{ form_row(participant.mobile) }}
|
||||
</div>
|
||||
{% if participant.address is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.address.street) }}
|
||||
{{ form_row(participant.address.postCode) }}
|
||||
{{ form_row(participant.address.city) }}
|
||||
{{ form_row(participant.address.country) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.bodyDimensions is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.bodyDimensions.height) }}
|
||||
{{ form_row(participant.bodyDimensions.shoeSize) }}
|
||||
{{ form_row(participant.bodyDimensions.weight) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.assignedRoomId, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% if participant.remarksRoom is defined %}
|
||||
{{ form_row(participant.remarksRoom) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if not hasDateOfBirth %}
|
||||
<div class="my-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-blue-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-blue-800">
|
||||
Leistungen sind erst nach Angabe des Geburtsdatums buchbar
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% elseif not isEligible %}
|
||||
<div class="my-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-red-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-red-800">
|
||||
Buchung wegen des Alters von Teilnehmer:in {{ loop.index }} nicht möglich
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if isEligible %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ _self.service_field(participant, 'skiPass', 'Skipass', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'courses', 'Kurse', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'additionalServices', 'Zusatzleistungen', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'rentals', 'Leihmaterial', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}, 'Bitte zuerst den Skipass auswählen') }}
|
||||
|
||||
{{ _self.checkbox_field(participant, 'rentalInsurance', 'Leihmaterial-Versicherung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}, 'Nur bei Buchung von Leihmaterial') }}
|
||||
|
||||
{{ _self.service_field(participant, 'board', 'Verpflegung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
<div class="col-span-2">
|
||||
{# Insurance field OR assigned insurance display for dependent participants #}
|
||||
{% set participantData = participant.vars.data %}
|
||||
{% set showBulkInsurance = loop.index > 1 and form.vars.data.participants[0].bulkInsuranceBooking %}
|
||||
|
||||
{% if showBulkInsurance %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
<div class="text-sm text-gray-600">
|
||||
{% set applicantInsurance = form.vars.data.participants[0].insurance %}
|
||||
{% if applicantInsurance %}
|
||||
{{ applicantInsurance.label }}
|
||||
{% if applicantInsurance.price and applicantInsurance.price > 0 %}
|
||||
<span class="text-gray-500">(€{{ applicantInsurance.price|number_format(2, ',', '.') }})</span>
|
||||
{% endif %}
|
||||
<span class="italic text-gray-500 ml-2">– wie Anmelder</span>
|
||||
{% else %}
|
||||
<span class="italic">wie Anmelder</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
|
||||
{# Bulk insurance booking checkbox (applicant only) #}
|
||||
{% if participant.bulkInsuranceBooking is defined %}
|
||||
{{ form_row(participant.bulkInsuranceBooking) }}
|
||||
{% endif %}
|
||||
|
||||
{% if participant.insurance is defined %}
|
||||
{{ form_row(participant.insurance, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
},
|
||||
'label': false
|
||||
}) }}
|
||||
{% else %}
|
||||
<div class="text-sm text-gray-500">Nicht wählbar</div>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{# Transportation Services Section #}
|
||||
<div class="mt-6 border-t pt-4">
|
||||
<h3 class="font-semibold text-lg mb-4">Anreise</h3>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
{% if participant.transportationOutbound is defined %}
|
||||
{{ form_row(participant.transportationOutbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
{% if participant.pickup is defined or participant.parking is defined or participant.licensePlate is defined %}
|
||||
{% if participant.pickup is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.pickup, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.parking is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.parking, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.licensePlate is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.licensePlate) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
{% if participant.transportationInbound is defined %}
|
||||
{{ form_row(participant.transportationInbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_create_step_2_refresh'),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
<div class="flex justify-between">
|
||||
<a href="{{ path('app_booking_create_step_1') }}" class="button bg-button bg-button--secondary">Zurück</a>
|
||||
<button type="submit" class="button bg-button bg-button--secondary" {{ stimulus_action('loading', 'toggle') }}>Weiter</button>
|
||||
</div>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% block booking_summary %}
|
||||
<div id="booking-summary"{% if htmx_oob_swap is defined and htmx_oob_swap %} hx-swap-oob="true"{% endif %}>
|
||||
{% include 'booking/_summary.html.twig' with {
|
||||
'bookingCreateDto': bookingCreateDto,
|
||||
'participantCount': participantsCount,
|
||||
'groupedSelectedRooms': groupedSelectedRooms,
|
||||
'assignmentCounts': assignmentCounts
|
||||
} %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -1,394 +0,0 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{# Local form theme override for consistent fieldset rendering #}
|
||||
{% use 'forms.html.twig' %}
|
||||
|
||||
{% block form_row %}
|
||||
{%- if form.vars.expanded is defined and form.vars.expanded -%}
|
||||
{# Expanded forms get fieldset wrapper #}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">
|
||||
{{- form.vars.label -}}
|
||||
</legend>
|
||||
{{- form_widget(form, {
|
||||
'attr': attr|default({})
|
||||
}) -}}
|
||||
{{- form_errors(form) -}}
|
||||
{{- form_help(form) -}}
|
||||
</fieldset>
|
||||
{%- else -%}
|
||||
{{- parent() -}}
|
||||
{%- endif -%}
|
||||
{% endblock %}
|
||||
|
||||
{% import _self as macros %}
|
||||
|
||||
{# Macro to render a field or placeholder with consistent fieldset structure #}
|
||||
{% macro service_field(participant, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if participant[fieldName] is defined %}
|
||||
{{ form_row(participant[fieldName], options) }}
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{# Specialized macro for checkbox fields (like rental insurance) that need manual fieldset wrapping #}
|
||||
{% macro checkbox_field(participant, fieldName, label, options = {}, undefinedLabel = 'Nicht wählbar') %}
|
||||
{% if participant[fieldName] is defined %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
{{ form_row(participant[fieldName], options) }}
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">{{ label }}</legend>
|
||||
<div class="text-sm text-gray-500">{{ undefinedLabel }}</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% block content %}
|
||||
{% include '_partials/_flashes.html.twig' %}
|
||||
<div {{ stimulus_controller('toast') }}></div>
|
||||
|
||||
{# Header with reload button #}
|
||||
<div class="flex justify-between items-center pb-8">
|
||||
<h1 class="text-3xl font-semibold">Buchung bearbeiten</h1>
|
||||
|
||||
<button type="button"
|
||||
hx-post="{{ path('app_booking_edit_reload', {id: bookingData.id}) }}"
|
||||
hx-confirm="Alle nicht gespeicherten Änderungen gehen verloren. Fortfahren?"
|
||||
{{ stimulus_action('loading', 'toggle') }}
|
||||
class="px-4 py-2 bg-gray-200 hover:bg-gray-300 text-gray-800 rounded transition-colors">
|
||||
🔄 Änderungen verwerfen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{# Grid layout with 2/3 form + 1/3 summary #}
|
||||
<div class="grid grid-cols-3 gap-8">
|
||||
<div id="form-wrapper" class="col-span-2">
|
||||
<h2>Teilnehmer</h2>
|
||||
{{ form_start(form) }}
|
||||
{% do form.participants.setRendered %}
|
||||
{# This block contains the participant form fields #}
|
||||
{% block participants_form %}
|
||||
<div id="participants-form" class="space-y-8 pb-8"{% if htmx_oob_swap is defined and htmx_oob_swap %} hx-swap-oob="true"{% endif %}>
|
||||
{% for participant in form.participants %}
|
||||
{% set participantDataValid = participant.vars.valid %}
|
||||
{% set participantData = participant.vars.data %}
|
||||
{% set hasDateOfBirth = participantData and participantData.dateOfBirth %}
|
||||
{% set isEligible = hasDateOfBirth and is_participant_eligible(bookingEditDto, loop.index0) %}
|
||||
{% set isCanceled = participantData.status == 'S' %}
|
||||
|
||||
<div class="{{ html_classes('border rounded px-4 py-2', { 'border-gray-300': participantDataValid, 'border-red-700': not participantDataValid }) }}" {{ stimulus_controller('toggle', {'storageKey': 'participant_' ~ loop.index0, 'open': participant.vars.valid == false}, { 'closed': 'hidden' }) }}>
|
||||
<fieldset>
|
||||
<legend class="w-full flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-bold text-xl">{{ loop.index == 1 ? 'Anmelder:in' : 'Teilnehmer:in ' ~ loop.index }}</span>
|
||||
{% if isCanceled %}
|
||||
<span class="inline-block px-2 py-1 text-xs bg-red-700 text-white rounded">storniert</span>
|
||||
{% endif %}
|
||||
{% if isEligible and not isCanceled and participantPrices is defined and participantPrices[loop.index0] is defined and participantPrices[loop.index0] > 0.0 %}
|
||||
<span class="text-sm font-medium text-gray-600 bg-gray-100 px-2 py-1 rounded">
|
||||
€{{ participantPrices[loop.index0]|number_format(2, ',', '.') }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<button type="button" tabindex="0" {{ stimulus_action('toggle', 'toggle') }}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6" {{ stimulus_target('toggle', 'icon') }}>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
|
||||
</svg>
|
||||
</button>
|
||||
</legend>
|
||||
<div class="hidden py-4" {{ stimulus_target('toggle', 'toggle') }}>
|
||||
{% if isCanceled %}
|
||||
{# Show surcharges for canceled participants #}
|
||||
{% set surcharges = bookingData.surchargesForParticipant(participantData.index) %}
|
||||
{% if surcharges|length > 0 %}
|
||||
<div>
|
||||
<h3 class="text-xl font-semibold mb-2">
|
||||
Zuschläge
|
||||
</h3>
|
||||
<ul class="list-disc pl-4">
|
||||
{% for surcharge in surcharges %}
|
||||
<li>
|
||||
{{ surcharge.label }}: {{ surcharge.individualPrice[participantData.index]|format_currency('EUR') }}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{# Personal data section - readonly for applicant (edited via profile settings) #}
|
||||
<div class="grid grid-cols-2 gap-4 pb-4">
|
||||
{{ form_row(participant.firstName) }}
|
||||
{{ form_row(participant.lastName) }}
|
||||
{{ form_row(participant.dateOfBirth, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{{ form_row(participant.gender) }}
|
||||
{{ form_row(participant.nationality) }}
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.email) }}
|
||||
{% if loop.index0 == 0 and bookingData.applicant.communication and bookingData.applicant.communication.mobile %}
|
||||
{# First participant: use applicant's mobile as placeholder #}
|
||||
{{ form_row(participant.mobile, {'attr': {'placeholder': bookingData.applicant.communication.mobile}}) }}
|
||||
{% else %}
|
||||
{{ form_row(participant.mobile) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if participant.address is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{% if loop.index0 == 0 and bookingData.applicant.address %}
|
||||
{# First participant: use applicant's address as placeholder #}
|
||||
{{ form_row(participant.address.street, {'attr': {'placeholder': bookingData.applicant.address.street}}) }}
|
||||
{{ form_row(participant.address.postCode, {'attr': {'placeholder': bookingData.applicant.address.postCode}}) }}
|
||||
{{ form_row(participant.address.city, {'attr': {'placeholder': bookingData.applicant.address.city}}) }}
|
||||
{{ form_row(participant.address.country, {'attr': {'placeholder': bookingData.applicant.address.country}}) }}
|
||||
{% else %}
|
||||
{{ form_row(participant.address.street) }}
|
||||
{{ form_row(participant.address.postCode) }}
|
||||
{{ form_row(participant.address.city) }}
|
||||
{{ form_row(participant.address.country) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.bodyDimensions is defined %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(participant.bodyDimensions.height) }}
|
||||
{{ form_row(participant.bodyDimensions.shoeSize) }}
|
||||
{{ form_row(participant.bodyDimensions.weight) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Room assignment - editable dropdown #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{% if participant.assignedRoomId is defined %}
|
||||
{{ form_row(participant.assignedRoomId) }}
|
||||
{% endif %}
|
||||
{% if participant.remarksRoom is defined %}
|
||||
{{ form_row(participant.remarksRoom) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if not hasDateOfBirth %}
|
||||
<div class="my-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-blue-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-blue-800">
|
||||
Leistungen sind erst nach Angabe des Geburtsdatums buchbar
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% elseif not isEligible %}
|
||||
<div class="my-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||
<div class="flex items-center">
|
||||
<svg class="w-5 h-5 text-red-600 mr-2" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<p class="text-sm text-red-800">
|
||||
Buchung wegen des Alters von Teilnehmer:in {{ loop.index }} nicht möglich
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if isEligible %}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ _self.service_field(participant, 'skiPass', 'Skipass', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'courses', 'Kurse', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'additionalServices', 'Zusatzleistungen', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
{{ _self.service_field(participant, 'rentals', 'Leihmaterial', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}, 'Bitte zuerst den Skipass auswählen') }}
|
||||
|
||||
{{ _self.checkbox_field(participant, 'rentalInsurance', 'Leihmaterial-Versicherung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}, 'Nur bei Buchung von Leihmaterial') }}
|
||||
|
||||
{{ _self.service_field(participant, 'board', 'Verpflegung', {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
|
||||
<div class="col-span-2">
|
||||
{# Insurance field OR assigned insurance display for dependent participants #}
|
||||
{% set participantData = participant.vars.data %}
|
||||
{% set showBulkInsurance = loop.index > 1 and form.vars.data.participants[0].bulkInsuranceBooking %}
|
||||
|
||||
{% if showBulkInsurance %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
<div class="text-sm text-gray-600">
|
||||
{% set applicantInsurance = form.vars.data.participants[0].insurance %}
|
||||
{% if applicantInsurance %}
|
||||
<span class="italic text-gray-500">wie Anmelder: {{ applicantInsurance.label }}</span>
|
||||
{% else %}
|
||||
<span class="italic text-gray-500">wie Anmelder</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% else %}
|
||||
<fieldset class="mb-1">
|
||||
<legend class="font-semibold mb-1">Reiseversicherung</legend>
|
||||
|
||||
{# Bulk insurance booking checkbox (applicant only) #}
|
||||
{% if participant.bulkInsuranceBooking is defined %}
|
||||
{{ form_row(participant.bulkInsuranceBooking, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
|
||||
{% if participant.insurance is defined %}
|
||||
{{ form_row(participant.insurance, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
},
|
||||
'label': false
|
||||
}) }}
|
||||
{% else %}
|
||||
<div class="text-sm text-gray-500">Nicht wählbar</div>
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-span-2">
|
||||
<h3 class="text-xl font-semibold mb-4">Hin-/Rückreise</h3>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
{% if participant.transportationOutbound is defined %}
|
||||
{{ form_row(participant.transportationOutbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
{% if participant.pickup is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.pickup, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.parking is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.parking, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if participant.licensePlate is defined %}
|
||||
<div class="mt-4">
|
||||
{{ form_row(participant.licensePlate, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div>
|
||||
{% if participant.transportationInbound is defined %}
|
||||
{{ form_row(participant.transportationInbound, {
|
||||
'attr': {
|
||||
'hx-trigger': 'change',
|
||||
'hx-post': path('app_booking_edit_refresh', {'id': bookingData.id}),
|
||||
'hx-swap': 'none'
|
||||
}
|
||||
}) }}
|
||||
{% endif %}
|
||||
{# Pickup inbound removed - now unified with pickup field #}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
<div class="flex justify-between">
|
||||
<a href="{{ path('app_bookings') }}" class="button bg-button bg-button--secondary">Zurück</a>
|
||||
<button type="submit" class="button bg-button bg-button--secondary" {{ stimulus_action('loading', 'toggle') }}>Aktualisieren</button>
|
||||
</div>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% block booking_summary %}
|
||||
<div id="booking-summary"{% if htmx_oob_swap is defined and htmx_oob_swap %} hx-swap-oob="true"{% endif %}>
|
||||
{% include 'booking/_summary.html.twig' with {
|
||||
'bookingCreateDto': bookingEditDto,
|
||||
'participantCount': participantCount,
|
||||
'groupedSelectedRooms': groupedSelectedRooms,
|
||||
'assignmentCounts': assignmentCounts,
|
||||
'mutableData': mutableData|default(null)
|
||||
} %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,115 @@
|
||||
{% extends 'layout.html.twig' %}
|
||||
|
||||
{% block content %}
|
||||
{% include '_partials/_flashes.html.twig' %}
|
||||
<div {{ stimulus_controller('toast') }}></div>
|
||||
|
||||
{# Header with reload button #}
|
||||
<div class="flex justify-between items-center pb-8">
|
||||
<h1 class="text-3xl font-semibold">Buchung bearbeiten</h1>
|
||||
|
||||
<button type="button"
|
||||
hx-post="{{ path('app_booking_edit_reload', {id: bookingData.id}) }}"
|
||||
hx-confirm="Alle nicht gespeicherten Änderungen gehen verloren. Fortfahren?"
|
||||
{{ stimulus_action('loading', 'toggle') }}
|
||||
class="px-4 py-2 bg-gray-200 hover:bg-gray-300 text-gray-800 rounded transition-colors">
|
||||
Änderungen verwerfen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{# Grid layout with 2/3 cards + 1/3 summary #}
|
||||
<div class="grid grid-cols-3 gap-8">
|
||||
{# Main content area - cards grid #}
|
||||
<div id="main-content" class="col-span-2">
|
||||
{% block participant_cards %}
|
||||
{{ form_start(form) }}
|
||||
<div>
|
||||
<h2>Teilnehmer</h2>
|
||||
|
||||
{% if isDirty %}
|
||||
<div class="mb-6 p-4 bg-yellow-50 border border-yellow-400 rounded-lg">
|
||||
<div class="flex items-start">
|
||||
<svg class="w-6 h-6 text-yellow-600 mr-3 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
||||
</svg>
|
||||
<div>
|
||||
<h3 class="font-semibold text-yellow-800">Ungespeicherte Änderungen</h3>
|
||||
<p class="text-yellow-700 text-sm mt-1">
|
||||
Du hast Änderungen an der Buchung vorgenommen.
|
||||
Bitte denke daran, abschließend den 'Buchung aktualisieren' Button zu klicken.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Display validation errors #}
|
||||
{% if hasValidationErrors|default(false) %}
|
||||
<div class="mb-4 p-4 bg-red-50 border border-red-200 rounded-lg">
|
||||
<div class="flex items-start">
|
||||
<svg class="w-5 h-5 text-red-600 mr-2 mt-0.5 flex-shrink-0" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<div>
|
||||
<p class="font-semibold text-red-800 mb-1">Bitte überprüfe die Teilnehmerdaten</p>
|
||||
<p class="text-sm text-red-700">Einige Teilnehmer haben noch unvollständige oder fehlerhafte Angaben. Bitte bearbeite die markierten Teilnehmer.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div id="participant-cards-grid" class="space-y-4">
|
||||
{% for participant in bookingDto.participants %}
|
||||
{% set isCanceled = (bookingData.participantsStatus[loop.index0] ?? null) == 'S' %}
|
||||
{% set hasErrors = loop.index0 in participantErrors|default([]) %}
|
||||
{% include 'booking/_participant_card.html.twig' with {
|
||||
'cardData': cardsData[loop.index0],
|
||||
'index': loop.index0,
|
||||
'mode': 'edit',
|
||||
'isCanceled': isCanceled,
|
||||
'hasErrors': hasErrors,
|
||||
'bookingId': bookingData.id
|
||||
} %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between mt-8">
|
||||
<button type="button"
|
||||
hx-post="{{ path('app_booking_edit_cancel', {id: bookingData.id}) }}"
|
||||
{{ stimulus_action('loading', 'toggle') }}
|
||||
class="button bg-button bg-button--secondary">
|
||||
Zurück
|
||||
</button>
|
||||
{% if isDirty %}
|
||||
<button type="submit"
|
||||
{{ stimulus_action('loading', 'toggle') }}
|
||||
{% if hasValidationErrors|default(false) %}
|
||||
disabled
|
||||
title="Bitte behebe zuerst alle Validierungsfehler"
|
||||
{% endif %}
|
||||
class="button bg-button bg-button--secondary {{ hasValidationErrors|default(false) ? 'opacity-50 cursor-not-allowed' : '' }}">
|
||||
Buchung aktualisieren
|
||||
</button>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
{# Sidebar summary #}
|
||||
{% block booking_summary %}
|
||||
<div id="booking-summary"{% if htmx_oob_swap is defined and htmx_oob_swap %} hx-swap-oob="true"{% endif %}>
|
||||
{% include 'booking/_summary.html.twig' with {
|
||||
'bookingCreateDto': bookingDto,
|
||||
'participantCount': participantsCount,
|
||||
'pricingData': pricingData,
|
||||
'groupedSelectedRooms': groupedSelectedRooms,
|
||||
'assignmentCounts': assignmentCounts,
|
||||
'mutableData': mutableData|default(null)
|
||||
} %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user