From b1b09a6db4309bc88df366e4b5a7e9d0dc269c26 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 5 Nov 2026 12:45:46 +0100 Subject: [PATCH] Konfigurator: Ablauf im Zusammenhang aus dem Plan, Nachrichtenregeln, einheitliche Anfrage-/Buchungsansicht; Abnahmetests Co-Authored-By: Claude Sonnet 5.5 --- .../Channels/Pages/ChannelProcess.php | 49 +++ app/Process/ChannelProcessConfiguration.php | 16 +- app/Process/ProcessLanes.php | 62 ++++ .../Architektur/MODULMATRIX.md | 60 ++-- .../channels/channel-process.blade.php | 33 ++ .../Process/InquiryProcessTesterTest.php | 126 ++++++++ tests/Feature/Process/InquiryTemplateTest.php | 306 ++++++++++++++++++ 7 files changed, 616 insertions(+), 36 deletions(-) create mode 100644 app/Process/ProcessLanes.php create mode 100644 tests/Feature/Process/InquiryProcessTesterTest.php create mode 100644 tests/Feature/Process/InquiryTemplateTest.php diff --git a/app/Filament/Resources/Channels/Pages/ChannelProcess.php b/app/Filament/Resources/Channels/Pages/ChannelProcess.php index 33cdcc5..eacbe8c 100644 --- a/app/Filament/Resources/Channels/Pages/ChannelProcess.php +++ b/app/Filament/Resources/Channels/Pages/ChannelProcess.php @@ -3,9 +3,13 @@ namespace App\Filament\Resources\Channels\Pages; use App\Actions\ConfigureChannelProcess; +use App\Communication\CommunicationRules; use App\Enums\AdminMode; use App\Enums\Execution; use App\Enums\IntakeKind; +use App\Enums\Medium; +use App\Enums\MessageEffect; +use App\Enums\MessageIntent; use App\Enums\ProcessSetting; use App\Filament\Resources\Channels\ChannelResource; use App\Models\Booking; @@ -17,6 +21,7 @@ use App\Process\ConfigurationImpact; use App\Process\Models\ProcessModel; use App\Process\ProcessCatalogue; +use App\Process\ProcessLanes; use App\Process\ProcessProfile; use App\Process\ProcessSettings; use App\Process\Restriction; @@ -254,6 +259,50 @@ public function applyPreset(string $archetype): void $this->drafts[$this->intake]['steps'] = array_intersect_key($this->drafts[$this->intake]['steps'], array_flip($base->modules('standard', $presets[$archetype]['templates']))); } + /** + * The course as the runner executes it: parallel, waiting (with what for), event-driven, time-driven, not applying. + * + * @return array>> + */ + public function lanes(): array + { + return app(ProcessLanes::class)->of($this->steps()); + } + + /** + * What arrives here and how binding it is (the start of the course). + * + * @return array{event: string, binding: string, media: list} + */ + public function entry(): array + { + $rules = app(CommunicationRules::class); + $media = array_values(array_map(fn (Medium $medium): string => $medium->getLabel(), array_filter(Medium::cases(), fn (Medium $medium): bool => $rules->mediumActive($medium)))); + $booking = $this->intake === IntakeKind::Booking->value; + + return [ + 'event' => $booking ? 'Eine feste Buchung kommt über '.$this->record->name.' an (Portalmail, Kalender).' : ($this->record->isWebsite() ? 'Ein Gast fragt über die Webseite einen Aufenthalt an.' : 'Eine Anfrage kommt über '.$this->record->name.' an.'), + 'binding' => $booking ? 'Beim Portal bereits verbindlich – wir übernehmen, wir verbinden nichts neu.' : 'Unverbindlich – verbindlich wird sie durch unser Angebot und die Annahme des Gastes.', + 'media' => $media, + ]; + } + + /** + * What a message does here, by its intent – the rules (not a process): a general question creates no case. + * + * @return list, creates_case: bool}> + */ + public function messageRules(): array + { + $rules = app(CommunicationRules::class); + + return array_map(fn (MessageIntent $intent): array => [ + 'intent' => $intent->getLabel(), + 'effects' => array_map(fn (MessageEffect $effect): string => $effect->getLabel(), $rules->effects(Medium::Email, $intent)), + 'creates_case' => false, + ], MessageIntent::cases()); + } + /** * What the draft's change of templates means (modules, responsibilities, stored switches and settings). * diff --git a/app/Process/ChannelProcessConfiguration.php b/app/Process/ChannelProcessConfiguration.php index 12107b0..2c1006f 100644 --- a/app/Process/ChannelProcessConfiguration.php +++ b/app/Process/ChannelProcessConfiguration.php @@ -269,10 +269,12 @@ public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey // A model with slots does not narrow the guest communication itself: the portal's capability does. $messages = $model->slots() === [] ? null : (app(ChannelCapabilities::class)->resolve($channel)[ChannelCapabilities::MESSAGES_GUEST] ?? null); - $storedMessages = ProcessSetting::GuestMessages->normalize($stored[ProcessSetting::GuestMessages->value] ?? null); - if ($messages !== null && $messages->isKnown() && $messages->value === false && $storedMessages === Responsibility::Portal->value) { - $conflicts[] = ['setting' => ProcessSetting::GuestMessages, 'stored' => ProcessSetting::GuestMessages->describe($storedMessages), 'fixed' => ProcessSetting::GuestMessages->describe(Responsibility::Landlord->value), - 'text' => ProcessSetting::GuestMessages->question().' Bisher eingestellt: „'.ProcessSetting::GuestMessages->describe($storedMessages).'“. Laut Fähigkeit des Portals schreibt es den Gast aber nicht an; künftig: „'.ProcessSetting::GuestMessages->describe(Responsibility::Landlord->value).'“.']; + foreach ($model->slots() === [] ? [] : [ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoSender, ProcessSetting::ReviewRequestSender] as $sender) { + $storedSender = $sender->normalize($stored[$sender->value] ?? null); + if ($messages !== null && $messages->isKnown() && $messages->value === false && $storedSender === Responsibility::Portal->value) { + $conflicts[] = ['setting' => $sender, 'stored' => $sender->describe($storedSender), 'fixed' => $sender->describe(Responsibility::Landlord->value), + 'text' => $sender->question().' Bisher eingestellt: „'.$sender->describe($storedSender).'“. Laut Fähigkeit des Portals schreibt es den Gast aber nicht an; künftig: „'.$sender->describe(Responsibility::Landlord->value).'“.']; + } } return $conflicts; @@ -506,8 +508,10 @@ private function templateProblems(Channel $channel, ProcessModel $model, array $ } } $messages = app(ChannelCapabilities::class)->resolve($channel, $capabilities)[ChannelCapabilities::MESSAGES_GUEST] ?? null; - if (($draft['settings'][ProcessSetting::GuestMessages->value] ?? null) === Responsibility::Portal->value && $messages !== null && $messages->isKnown() && $messages->value === false) { - $problems[] = 'Gastkommunikation durch das Portal ist eingestellt, das Portal schreibt den Gast laut bestätigter Fähigkeit aber nicht an.'; + foreach ([ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoSender, ProcessSetting::ReviewRequestSender] as $sender) { + if (($draft['settings'][$sender->value] ?? null) === Responsibility::Portal->value && $messages !== null && $messages->isKnown() && $messages->value === false) { + $problems[] = $sender->question().' „Das Portal“ ist eingestellt, das Portal schreibt den Gast laut Fähigkeit aber nicht an.'; + } } return $problems; diff --git a/app/Process/ProcessLanes.php b/app/Process/ProcessLanes.php new file mode 100644 index 0000000..6f37604 --- /dev/null +++ b/app/Process/ProcessLanes.php @@ -0,0 +1,62 @@ + $rows the preview rows of a draft (ChannelProcessConfiguration::preview) + * @return array{parallel: list, waiting: list}>, event: list, later: list, off: list} + */ + public function of(array $rows): array + { + $active = []; + foreach ($rows as $row) { + if ($row['on']) { + $active[$row['module']] = $row['label']; + } + } + $lanes = ['parallel' => [], 'waiting' => [], 'event' => [], 'later' => [], 'off' => []]; + + foreach ($rows as $row) { + $definition = $this->catalogue->modules()[$row['module']]::definition(); + if (! $row['on']) { + $lanes['off'][] = ['module' => $row['module'], 'label' => $row['label'], 'note' => $row['reason']]; + + continue; + } + if ($row['module'] === 'intake.record') { + continue; + } + $hard = array_values(array_map(fn ($dependency): string => $active[$dependency->module], array_filter($definition->requires, fn ($dependency): bool => $dependency->hard && $dependency->module !== 'intake.record' && isset($active[$dependency->module])))); + $item = ['module' => $row['module'], 'label' => $row['label'], 'note' => $this->note($definition)]; + + $lanes[match (true) { + $hard !== [] => 'waiting', + $definition->toggle === ModuleDefinition::TOGGLE_EVENT_DRIVEN => 'event', + $definition->triggers !== [] && collect($definition->triggers)->every(fn (string $trigger): bool => str_starts_with($trigger, 'schedule:')) => 'later', + default => 'parallel', + }][] = $hard !== [] ? [...$item, 'after' => $hard] : $item; + } + + return $lanes; + } + + private function note(ModuleDefinition $definition): ?string + { + $waits = array_map(fn (string $wait): string => ['guest' => 'den Gast', 'portal' => 'das Portal', 'landlord' => 'Sie', 'time' => 'eine Frist'][$wait] ?? $wait, $definition->waits); + + return $waits === [] ? null : 'kann warten auf '.implode(', ', $waits); + } +} diff --git a/docs/Prozessarchitektur/Architektur/MODULMATRIX.md b/docs/Prozessarchitektur/Architektur/MODULMATRIX.md index 2931626..67b5ea4 100644 --- a/docs/Prozessarchitektur/Architektur/MODULMATRIX.md +++ b/docs/Prozessarchitektur/Architektur/MODULMATRIX.md @@ -2,33 +2,33 @@ # Modulmatrix (erzeugt) Erzeugt von `php artisan process:check --matrix` aus `config/process.php` – nicht von Hand ändern. Spalten: Modelle (Standardablauf; `V` = nur in einer Variante). -| Modul | Version | Phase | Aktivierung | Verfügbarkeit | hart abhängig von | a1.offer | a1.information | a2.offer | a2.information | a3.portal_booking | a4.portal_booking | a5.portal_booking | a6.internal | external.booking | Testgruppe | -|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| -| `intake.record` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:intake.record` | -| `guest.details` | 1 | P01 | mandatory | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | ● | `module:guest.details` | -| `guest.data_request` | 1 | P01 | optional | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | ● | `module:guest.data_request` | -| `hold` | 1 | P01 | conditional | production | intake.record | ● | ● | ● | ● | | | | | | `module:hold` | -| `availability.check` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | | | | | | `module:availability.check` | -| `binding.portal` | 1 | P02 | mandatory | production | intake.record | | | | | ● | ● | ● | | ● | `module:binding.portal` | -| `channels.block` | 1 | P02 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:channels.block` | -| `portal.confirmation` | 1 | P02 | conditional | production | intake.record | | | | | ● | ● | ● | | ● | `module:portal.confirmation` | -| `offer.information` | 1 | P02 | mandatory | production | intake.record | ● | ● | ● | ● | | | | | | `module:offer.information` | -| `offer.binding` | 2 | P02 | mandatory | production | guest.details, availability.check | ● | ● | ● | ● | | | | | | `module:offer.binding` | -| `offer.acceptance` | 1 | P02 | mandatory | production | offer.binding | ● | ● | ● | ● | | | | | | `module:offer.acceptance` | -| `documents.send` | 2 | P03 | mandatory | production | guest.details, portal.confirmation | ● | ● | ● | ● | ● | ● | ● | | ● | `module:documents.send` | -| `documents.booking_notice` | 1 | P03 | conditional | production | portal.confirmation, guest.details | | | | | ● | ● | ● | | ● | `module:documents.booking_notice` | -| `documents.stay_confirmation` | 1 | P03 | optional | production | | | | | | | | | ● | | `module:documents.stay_confirmation` | -| `case.tasks` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.tasks` | -| `change.proposal` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | | ● | `module:change.proposal` | -| `case.closure` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.closure` | -| `case.settlement` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.settlement` | -| `payments.monitor` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | ● | `module:payments.monitor` | -| `portal.payout` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | | `module:portal.payout` | -| `payments.internal` | 1 | P03 | conditional | production | | | | | | | | | ● | | `module:payments.internal` | -| `arrival.details` | 1 | P04 | optional | production | | ● | ● | ● | ● | ● | ● | ● | | ● | `module:arrival.details` | -| `arrival.info` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | ● | `module:arrival.info` | -| `stay` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:stay` | -| `review.request` | 1 | P05 | optional | production | stay | ● | ● | ● | ● | ● | ● | ● | | ● | `module:review.request` | -| `guest.address_check` | 1 | P01 | optional | tester_only | guest.details | V | | | | | | | | | `module:guest.address_check` | -| `guest.loyalty_status` | 1 | P01 | optional | tester_only | guest.details | V | | | | | | | | | `module:guest.loyalty_status` | -| `pricing.loyalty_discount` | 1 | P02 | optional | tester_only | guest.loyalty_status | V | | | | | | | | | `module:pricing.loyalty_discount` | +| Modul | Version | Phase | Aktivierung | Verfügbarkeit | hart abhängig von | a1.offer | a1.information | a2.offer | a2.information | a3.portal_booking | a4.portal_booking | a5.portal_booking | a6.internal | external.booking | inquiry.request | Testgruppe | +|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| +| `intake.record` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:intake.record` | +| `guest.details` | 1 | P01 | mandatory | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:guest.details` | +| `guest.data_request` | 1 | P01 | optional | production | intake.record | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:guest.data_request` | +| `hold` | 1 | P01 | conditional | production | intake.record | ● | ● | ● | ● | | | | | | ● | `module:hold` | +| `availability.check` | 1 | P01 | mandatory | production | | ● | ● | ● | ● | | | | | | ● | `module:availability.check` | +| `binding.portal` | 1 | P02 | mandatory | production | intake.record | | | | | ● | ● | ● | | ● | | `module:binding.portal` | +| `channels.block` | 1 | P02 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:channels.block` | +| `portal.confirmation` | 1 | P02 | conditional | production | intake.record | | | | | ● | ● | ● | | ● | | `module:portal.confirmation` | +| `offer.information` | 1 | P02 | mandatory | production | intake.record | ● | ● | ● | ● | | | | | | | `module:offer.information` | +| `offer.binding` | 2 | P02 | mandatory | production | guest.details, availability.check | ● | ● | ● | ● | | | | | | ● | `module:offer.binding` | +| `offer.acceptance` | 1 | P02 | mandatory | production | offer.binding | ● | ● | ● | ● | | | | | | ● | `module:offer.acceptance` | +| `documents.send` | 2 | P03 | mandatory | production | guest.details, portal.confirmation | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:documents.send` | +| `documents.booking_notice` | 1 | P03 | conditional | production | portal.confirmation, guest.details | | | | | ● | ● | ● | | ● | ● | `module:documents.booking_notice` | +| `documents.stay_confirmation` | 1 | P03 | optional | production | | | | | | | | | ● | | | `module:documents.stay_confirmation` | +| `case.tasks` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.tasks` | +| `change.proposal` | 1 | P03 | event_driven | production | | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:change.proposal` | +| `case.closure` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.closure` | +| `case.settlement` | 1 | P05 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:case.settlement` | +| `payments.monitor` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:payments.monitor` | +| `portal.payout` | 1 | P03 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | | | `module:portal.payout` | +| `payments.internal` | 1 | P03 | conditional | production | | | | | | | | | ● | | | `module:payments.internal` | +| `arrival.details` | 1 | P04 | optional | production | | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:arrival.details` | +| `arrival.info` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:arrival.info` | +| `stay` | 1 | P04 | mandatory | production | | ● | ● | ● | ● | ● | ● | ● | ● | ● | ● | `module:stay` | +| `review.request` | 1 | P05 | optional | production | stay | ● | ● | ● | ● | ● | ● | ● | | ● | ● | `module:review.request` | +| `guest.address_check` | 1 | P01 | optional | tester_only | guest.details | V | | | | | | | | | V | `module:guest.address_check` | +| `guest.loyalty_status` | 1 | P01 | optional | tester_only | guest.details | V | | | | | | | | | V | `module:guest.loyalty_status` | +| `pricing.loyalty_discount` | 1 | P02 | optional | tester_only | guest.loyalty_status | V | | | | | | | | | V | `module:pricing.loyalty_discount` | diff --git a/resources/views/filament/resources/channels/channel-process.blade.php b/resources/views/filament/resources/channels/channel-process.blade.php index f1dc860..acedb82 100644 --- a/resources/views/filament/resources/channels/channel-process.blade.php +++ b/resources/views/filament/resources/channels/channel-process.blade.php @@ -21,6 +21,20 @@ @endif + @php($entry = $this->entry()) + +

{{ $entry['binding'] }}

+

Eingangswege, die hier angeschaltet sind: {{ implode(', ', $entry['media']) }}. Das Medium bestimmt nur, wie etwas ankommt – nicht den Ablauf.

+
Was eine Nachricht auslöst (Nachrichtenregeln) + + @foreach ($this->messageRules() as $rule) + + @endforeach +
{{ $rule['intent'] }}{{ implode(' · ', $rule['effects']) }}
+

Eine allgemeine Frage legt keinen Vorgang an. Nachrichten zu einem Vorgang werden nur über einen sicheren Bezug zugeordnet. Die Regeln gelten für den ganzen Betrieb und lassen sich nur einschränken (System › Betrieb).

+
+
+ @if (! $this->record->isWebsite()) @php($capabilities = $this->capabilities()) @@ -160,6 +174,25 @@ @endif + @php($lanes = $this->lanes()) + + @php($laneTitles = ['parallel' => 'Läuft sofort, unabhängig voneinander', 'waiting' => 'Wartet auf andere Schritte', 'event' => 'Ereignisgesteuert (reagiert, wenn etwas eintrifft)', 'later' => 'Zeitgesteuert (zu seiner Zeit)', 'off' => 'Entfällt hier']) +
+ @foreach ($laneTitles as $lane => $title) + @if ($lanes[$lane] !== []) +
+ {{ $title }} +
    + @foreach ($lanes[$lane] as $item) +
  • {{ $item['label'] }}@if (! empty($item['after'])) – nach: {{ implode(', ', $item['after']) }}@endif @if ($item['note']) ({{ $item['note'] }})@endif
  • + @endforeach +
+
+ @endif + @endforeach +
+
+
Einzelschritte einstellen ({{ count($steps) }} Schritte) diff --git a/tests/Feature/Process/InquiryProcessTesterTest.php b/tests/Feature/Process/InquiryProcessTesterTest.php new file mode 100644 index 0000000..045dc5f --- /dev/null +++ b/tests/Feature/Process/InquiryProcessTesterTest.php @@ -0,0 +1,126 @@ +travelTo(CarbonImmutable::parse('2026-10-23 10:00')); + $this->seed([PropertySeeder::class, SiteSeeder::class]); + $this->property = Property::sole(); + Content::save(['contract.terms' => '

Echte Bedingungen

', 'stay.cancellation' => '

Echtes Storno

']); + Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'vermieter@example.org', 'process_defaults' => ['processing' => 'automatic', 'clarification_hold_auto_minutes' => 120, 'data_request_mode' => 'automatic']]); + $this->user = User::factory()->create(); + ProcessTesterTest::template(); + } + + public function test_a_general_question_creates_no_booking_case(): void + { + $report = $this->play(Channel::websiteOf($this->property), 'general_question_message', ['model' => 'inquiry.request'], 1); + + $this->assertNull($report['aborted'] ?? null, json_encode($report)); + $this->assertNull($report['plan'], 'no case, so no plan'); + $this->assertSame([], $report['violations']); + $this->assertSame(0, Booking::query()->count()); + } + + public function test_the_binding_offer_is_sent_and_accepted(): void + { + $report = $this->play(Channel::websiteOf($this->property), 'complete_request', ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']], 3); + + $this->assertNull($report['aborted'] ?? null, json_encode($report)); + $this->assertContains('inquiry.binding_offer@1', array_column($report['plan']['templates'], 'reference')); + [$sent, , $accepted] = $report['timeline']; + $this->assertSame('Angebot gesendet', $sent['status']); + $this->assertTrue($sent['calendar']['occupying'], 'the offer holds the dates'); + $this->assertSame('Bestätigt', $accepted['status']); + $this->assertContains('Gast nimmt das Angebot an', $sent['waiting']); + $this->assertSame(0, Booking::query()->count()); + } + + public function test_the_information_reserves_nothing(): void + { + $report = $this->play(Channel::websiteOf($this->property), 'complete_request', ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.information']], 2); + + $this->assertNull($report['aborted'] ?? null, json_encode($report)); + $this->assertContains('inquiry.information@1', array_column($report['plan']['templates'], 'reference')); + $first = $report['timeline'][0]; + $this->assertFalse($first['calendar']['occupying']); + $this->assertNull($first['calendar']['hold_until']); + $this->assertContains('Unverbindliche Auskunft senden (automatisch)', array_column($first['activities'], 'label')); + } + + public function test_data_collection_and_reservation_run_independently_and_the_strategy_is_free(): void + { + $website = Channel::websiteOf($this->property); + + $reserving = $this->play($website, 'missing_address', ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']], 3); + $early = $reserving['timeline'][0]; + $this->assertTrue($early['calendar']['occupying'], 'suggested strategy: the dates are held at once'); + $this->assertNotNull($early['calendar']['hold_until']); + $this->assertContains('Angaben für das Angebot vervollständigen', $early['waiting'], 'the details are missing – evidence is open'); + $this->assertStringContainsString('Bitte ergänzen Sie Ihre Angaben', implode(' ', array_column($early['mails'], 'subject')), 'the data request goes out although the offer waits'); + $this->assertSame('Angebot gesendet', $reserving['timeline'][2]['status']); + + $free = $this->play($website, 'missing_address', ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer'], 'settings' => ['pre_reservation' => '0']], 3); + $this->assertFalse($free['timeline'][0]['calendar']['occupying'], 'same answer, other strategy: nothing held at the request'); + $this->assertStringContainsString('Bitte ergänzen Sie Ihre Angaben', implode(' ', array_column($free['timeline'][0]['mails'], 'subject')), 'the data collection does not depend on the reservation'); + $this->assertSame('Angebot gesendet', $free['timeline'][2]['status'], 'and the offer still goes out once the details are there'); + $this->assertTrue($free['timeline'][2]['calendar']['occupying'], 'the offer itself holds the dates'); + $this->assertSame(0, Booking::query()->count()); + } + + public function test_a_portal_request_with_the_portal_as_standard_sender_shows_the_unconfirmed_capability(): void + { + $portal = Channel::factory()->for($this->property)->create(['name' => 'Anfrageportal', 'booking_model' => 'inquiry', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://anfrage.example/a.ics', 'portal_profile' => 'generic']]); + + $report = $this->play($portal, 'portal_inquiry', ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer', 'guest_communication' => 'guest_comm.portal']], 3); + + $this->assertNull($report['aborted'] ?? null, json_encode($report)); + $communication = collect($report['plan']['templates'])->firstWhere('reference', 'guest_comm.portal@1'); + $this->assertNotNull($communication); + $this->assertFalse($communication['capabilities'][0]['confirmed'], 'the portal writing to guests is not shown as proven'); + $sender = collect($report['plan']['configuration'])->firstWhere('question', 'Wer schickt dem Gast die Anreise-Informationen?'); + $this->assertSame(['Das Portal', 'Vorschlag der gewählten Funktionsschablone'], [$sender['value'], $sender['source']]); + $this->assertSame(0, Booking::query()->count()); + } + + /** + * @param array $draft + * @return array + */ + private function play(Channel $channel, string $scenario, array $draft, int $steps): array + { + return app(ProcessSandbox::class)->run($channel, IntakeKind::Inquiry, $draft, $scenario, ['arrival' => '2026-11-07', 'nights' => 3, 'guests' => 2, 'text' => 'question'], $steps, $this->user)->report; + } +} diff --git a/tests/Feature/Process/InquiryTemplateTest.php b/tests/Feature/Process/InquiryTemplateTest.php new file mode 100644 index 0000000..2661501 --- /dev/null +++ b/tests/Feature/Process/InquiryTemplateTest.php @@ -0,0 +1,306 @@ +travelTo(CarbonImmutable::parse('2026-10-23 10:00')); + $this->seed([PropertySeeder::class, SiteSeeder::class]); + $this->property = Property::sole(); + Storage::fake('local'); + Content::save(['contract.terms' => '

Echte Bedingungen

', 'stay.cancellation' => '

Echtes Storno

']); + config(['mail.default' => 'array']); + Mail::swap(new MailManager($this->app)); + Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org']); + Http::preventStrayRequests(); + } + + public function test_the_catalogue_with_the_request_base_process_is_consistent(): void + { + $this->assertSame([], app(ProcessCatalogue::class)->problems()); + $model = app(ProcessCatalogue::class)->model('inquiry.request'); + $this->assertEqualsCanonicalizing(['inquiry_answer', 'contract_documents', 'collection', 'guest_communication'], array_map(fn ($area): string => $area->value, $model->slots())); + foreach (['a1.offer', 'a1.information', 'a2.offer', 'a2.information'] as $legacy) { + $archetype = app(ProcessCatalogue::class)->model($legacy); + $this->assertTrue($archetype::isLegacy()); + $this->assertSame([], app(TemplateComposer::class)->problems($model, $archetype::presetTemplates()), $legacy.' is a valid combination of the base process'); + } + } + + /** + * @return array archetype, answer template, whether the portal sends the request + */ + public static function archetypes(): array + { + return [ + 'A1 offer' => ['a1.offer', 'inquiry.binding_offer', false], + 'A1 information' => ['a1.information', 'inquiry.information', false], + 'A2 offer' => ['a2.offer', 'inquiry.binding_offer', true], + 'A2 information' => ['a2.information', 'inquiry.information', true], + ]; + } + + #[DataProvider('archetypes')] + public function test_the_base_process_behaves_like_the_archetype_it_replaces(string $legacy, string $answer, bool $viaPortal): void + { + $channel = $viaPortal ? $this->portal() : Channel::websiteOf($this->property); + + $this->configure($channel, ['model' => $legacy]); + $old = $this->request($channel->fresh(), $viaPortal, '2026-11-07'); + $this->configure($channel->fresh(), ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => $answer]]); + $new = $this->request($channel->fresh(), $viaPortal, '2026-12-07'); + + $oldValues = $old->process()->values; + $newValues = $new->process()->values; + unset($oldValues['contract_template_id'], $newValues['contract_template_id']); + $this->assertEquals($oldValues, $newValues, 'identical effective configuration'); + $this->assertSame($old->case_type, $new->case_type); + $this->assertSame($old->hold_purpose, $new->hold_purpose); + $this->assertSame($old->hold_expires_at === null, $new->hold_expires_at === null, 'the same reservation behaviour'); + + $summarise = fn (Booking $booking): array => collect(CaseActivities::for($booking->fresh()))->map(fn ($activity): array => [$activity->key, $activity->label, $activity->state->value])->all(); + $this->assertSame($summarise($old), $summarise($new), 'identical activities and states'); + $this->assertSame('inquiry.request', ProcessPlan::of($new)->model); + $this->assertArrayHasKey('guest_communication', ProcessPlan::of($new)->templates); + } + + public function test_the_answer_template_does_not_force_a_reservation_strategy(): void + { + $website = Channel::websiteOf($this->property); + $configuration = app(ChannelProcessConfiguration::class); + + // Binding offer: reservation at the request is a suggestion – both strategies are admissible. + foreach ([null, '1', '0'] as $reservation) { + $draft = ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer'], 'settings' => $reservation === null ? [] : ['pre_reservation' => $reservation]]; + $this->assertSame([], $configuration->problems($website, IntakeKind::Inquiry, $draft), 'binding offer with reservation setting '.var_export($reservation, true)); + } + $this->assertTrue($configuration->profileWith($website, IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']])->preReservation()); + $this->assertSame(ProcessProfile::TEMPLATE_DEFAULT, $configuration->profileWith($website, IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']])->source(ProcessSetting::PreReservation)); + + // Information: by definition nothing is reserved – the documented rule, with its reason. + $problems = $configuration->problems($website, IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.information'], 'settings' => ['pre_reservation' => '1']]); + $this->assertStringContainsString('widerspricht der Schablone', implode(' ', $problems)); + + // Offer without early reservation: no hold at an incomplete request, the offer itself holds later. + $this->configure($website, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer'], 'settings' => ['pre_reservation' => '0']]); + $incomplete = $this->request($website->fresh(), false, '2026-11-07', street: ''); + $this->assertNull($incomplete->hold_expires_at, 'no reservation at the request'); + $this->assertSame(InquiryAnswer::Offer, $incomplete->process()->inquiryAnswer()); + $this->assertFalse(Booking::query()->occupying()->whereKey($incomplete->id)->exists()); + + $this->configure($website->fresh(), ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer'], 'settings' => ['pre_reservation' => null]]); + $held = $this->request($website->fresh(), false, '2026-12-07', street: ''); + $this->assertNotNull($held->hold_expires_at, 'the suggested strategy: clarification hold at the request'); + } + + public function test_switching_the_answer_keeps_explicit_module_parameters_and_asks_before_dropping_a_contradicting_one(): void + { + $website = Channel::websiteOf($this->property); + $this->configure($website, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer'], 'settings' => ['hold_hours' => '24', 'processing' => 'automatic', 'guest_link_valid_days' => '7']]); + + $this->configure($website->fresh(), ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.information'], 'settings' => ['hold_hours' => '24', 'processing' => 'automatic', 'guest_link_valid_days' => '7']]); + $saved = $website->fresh()->process_overrides['inquiry']; + $this->assertEquals(['24', 'automatic'], [(string) $saved['hold_hours'], $saved['processing']], 'explicit parameters survive the switch'); + $this->assertSame('inquiry.information', $saved['templates']['inquiry_answer']); + + // An explicitly stored reservation contradicts the information: it must be confirmed before it goes. + $website->fresh()->update(['process_overrides' => ['inquiry' => [...$saved, 'pre_reservation' => true]]]); + $conflicts = app(ChannelProcessConfiguration::class)->conflicts($website->fresh(), IntakeKind::Inquiry, 'inquiry.request', ['inquiry_answer' => 'inquiry.information']); + $this->assertSame([ProcessSetting::PreReservation], array_column($conflicts, 'setting')); + $this->expectException(ValidationException::class); + app(ConfigureChannelProcess::class)->handle($website->fresh(), IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.information']]); + } + + public function test_requests_take_no_portal_collection_and_no_external_documents(): void + { + $website = Channel::websiteOf($this->property); + $configuration = app(ChannelProcessConfiguration::class); + $options = $configuration->templateOptions($website, app(ProcessCatalogue::class)->model('inquiry.request')); + + $this->assertFalse($options['collection']['collection.portal']['admissible']); + $this->assertStringContainsString('Annahme des Angebots', $options['collection']['collection.portal']['restrictions'][0]->reason); + $this->assertFalse($options['contract_documents']['contract_docs.external']['admissible']); + $this->assertFalse($options['guest_communication']['guest_comm.portal']['admissible'], 'the own website has no portal'); + $this->assertNotSame([], $configuration->problems($website, IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['collection' => 'collection.portal']])); + } + + public function test_guest_communication_is_assigned_per_occasion_without_touching_other_tasks(): void + { + $channel = $this->bookingPortal(); + $this->configure($channel, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']], IntakeKind::Booking); + $baseline = $this->takeOver($channel->fresh(), 'KOM-1', '2027-07-10'); + + $this->configure($channel->fresh(), ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], 'settings' => ['arrival_info_sender' => 'portal']], IntakeKind::Booking); + $changed = $this->takeOver($channel->fresh(), 'KOM-2', '2027-08-10'); + + $activities = fn (Booking $booking): array => collect(CaseActivities::for($booking->fresh()))->keyBy('key')->all(); + [$before, $after] = [$activities($baseline), $activities($changed)]; + $this->assertSame(ActivityState::External, $after['arrival_info']->state, 'the arrival information is now the portal’s'); + $this->assertNotSame(ActivityState::External, $before['arrival_info']->state); + $this->assertArrayHasKey('review', $after, 'the review request stays with us'); + $this->assertSame(array_keys($before), array_keys($after), 'no other task appears or disappears'); + foreach (array_diff(array_keys($before), ['arrival_info']) as $key) { + $this->assertSame($before[$key]->state, $after[$key]->state, $key.' is unchanged'); + } + $profile = $changed->process(); + $this->assertSame([Responsibility::Portal, Responsibility::Landlord, Responsibility::Landlord], [$profile->arrivalInfoSender(), $profile->reviewRequestSender(), $profile->payments()]); + $this->assertSame(Responsibility::Landlord, $profile->guestMessages(), 'the umbrella setting is untouched'); + + // And the other way round: the review request goes to the portal, the arrival information stays ours. + $this->configure($channel->fresh(), ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], 'settings' => ['arrival_info_sender' => null, 'review_request_sender' => 'portal']], IntakeKind::Booking); + $other = $this->takeOver($channel->fresh(), 'KOM-3', '2027-09-10'); + $this->assertArrayNotHasKey('review', $activities($other)); + $this->assertNotSame(ActivityState::External, $activities($other)['arrival_info']->state); + } + + public function test_a_portal_inquiry_gets_the_portal_as_standard_sender_that_each_occasion_can_take_back(): void + { + $portal = $this->portal(); + $this->configure($portal, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer', 'guest_communication' => 'guest_comm.portal']]); + $case = $this->request($portal->fresh(), true, '2027-01-12'); + $this->assertEquals(['guest_communication' => 'guest_comm.portal@1'], array_intersect_key(ProcessPlan::of($case)->templates, ['guest_communication' => 1])); + $this->assertSame([Responsibility::Portal, Responsibility::Portal], [$case->process()->arrivalInfoSender(), $case->process()->reviewRequestSender()]); + $this->assertSame(ProcessProfile::TEMPLATE_DEFAULT, $case->process()->source(ProcessSetting::ArrivalInfoSender)); + + $this->configure($portal->fresh(), ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer', 'guest_communication' => 'guest_comm.portal'], 'settings' => ['review_request_sender' => 'landlord']]); + $mixed = $this->request($portal->fresh(), true, '2027-02-12'); + $this->assertSame([Responsibility::Portal, Responsibility::Landlord], [$mixed->process()->arrivalInfoSender(), $mixed->process()->reviewRequestSender()], 'the explicit value wins over the template suggestion'); + } + + public function test_cases_frozen_before_the_new_settings_read_exactly_as_before(): void + { + $website = Channel::websiteOf($this->property); + $this->configure($website, ['model' => 'a1.information']); + $case = $this->request($website->fresh(), false, '2026-11-07'); + $profile = $case->profile; + foreach (['inquiry_answer', 'arrival_info_sender', 'review_request_sender'] as $key) { + unset($profile['values'][$key], $profile['sources'][$key]); + } + $case->forceFill(['profile' => $profile])->saveQuietly(); + + $old = $case->fresh()->process(); + $this->assertSame(InquiryAnswer::Information, $old->inquiryAnswer(), 'derived from the reservation, as before'); + $this->assertSame([$old->guestMessages(), $old->guestMessages()], [$old->arrivalInfoSender(), $old->reviewRequestSender()]); + $this->assertSame('a1.information', ProcessPlan::of($case->fresh())->model); + } + + public function test_the_displayed_dependencies_are_the_executed_ones(): void + { + $website = Channel::websiteOf($this->property); + $this->configure($website, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']]); + $draft = ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']]; + + $lanes = app(ProcessLanes::class)->of(app(ChannelProcessConfiguration::class)->preview($website->fresh(), IntakeKind::Inquiry, $draft)); + $labels = fn (string $lane): array => array_column($lanes[$lane], 'module'); + $this->assertContains('hold', $labels('parallel'), 'the reservation runs at once'); + $this->assertContains('guest.data_request', $labels('parallel'), 'so does the data collection – independent of each other'); + $this->assertContains('offer.binding', $labels('waiting')); + $this->assertContains('documents.send', $labels('waiting')); + $this->assertContains('case.tasks', $labels('event')); + $this->assertContains('arrival.info', $labels('later')); + $this->assertNotContains('offer.information', array_merge(...array_values(array_map(fn (array $lane): array => array_column($lane, 'module'), $lanes))), 'an offer needs no information step: it is not in the plan at all'); + + // The runner agrees: with missing details the offer is held back, the hold and the data request are not. + $case = $this->request($website->fresh(), false, '2026-11-07', street: ''); + $context = CaseContext::of($case); + $runner = app(ProcessRunner::class); + $catalogue = app(ProcessCatalogue::class); + foreach (array_column($lanes['waiting'], 'module') as $module) { + if (in_array($module, ['offer.binding', 'offer.acceptance'], true) && $context->plan->enabled($module)) { + $this->assertNotSame([], $runner->unmetHardDependencies($catalogue->module($module), $context), $module.' waits in the plan as shown'); + } + } + foreach (['hold', 'guest.data_request'] as $module) { + $this->assertSame([], $runner->unmetHardDependencies($catalogue->module($module), $context), $module.' does not wait'); + } + $waitingFor = collect($lanes['waiting'])->firstWhere('module', 'offer.binding')['after']; + $this->assertContains('Angaben des Gastes', $waitingFor); + } + + /** + * @param array $draft + */ + private function configure(Channel $channel, array $draft, IntakeKind $intake = IntakeKind::Inquiry): void + { + app(ConfigureChannelProcess::class)->handle($channel, $intake, $draft, acknowledgeConflicts: true); + } + + private function request(Channel $channel, bool $viaPortal, string $arrival, string $street = 'Weg 1'): Booking + { + $arrival = CarbonImmutable::parse($arrival); + if ($viaPortal) { + return app(TakeOverPortalInquiry::class)->handle($channel, $arrival, $arrival->addDays(3), 'ANF-'.$arrival->format('md'))->fresh(); + } + + return app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest($arrival, $arrival->addDays(3), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => $street, 'postal_code' => '10115', 'city' => 'Berlin', 'country' => 'DE'])->fresh(); + } + + private function takeOver(Channel $channel, string $reference, string $arrival): Booking + { + $arrival = CarbonImmutable::parse($arrival); + + return app(TakeOverExternalBooking::class)->handle($this->property, $channel, $arrival, $arrival->addDays(7), ['portal_reference' => $reference]); + } + + private function portal(): Channel + { + return Channel::factory()->for($this->property)->create(['name' => 'Anfrageportal', 'booking_model' => 'inquiry', 'import_enabled' => false, 'settings' => ['import_url' => 'https://anfrage.example/a.ics', 'portal_profile' => 'generic']]); + } + + private function bookingPortal(): Channel + { + return Channel::factory()->for($this->property)->create(['name' => 'Buchungsportal', 'booking_model' => 'portal_booking', 'import_enabled' => false, 'settings' => ['import_url' => 'https://buchung.example/a.ics', 'portal_profile' => 'generic']]); + } +}