diff --git a/app/Filament/Resources/Channels/Pages/ChannelProcess.php b/app/Filament/Resources/Channels/Pages/ChannelProcess.php index eacbe8c..78cfee8 100644 --- a/app/Filament/Resources/Channels/Pages/ChannelProcess.php +++ b/app/Filament/Resources/Channels/Pages/ChannelProcess.php @@ -20,6 +20,7 @@ use App\Process\ChannelProcessConfiguration; use App\Process\ConfigurationImpact; use App\Process\Models\ProcessModel; +use App\Process\ProcessBlocks; use App\Process\ProcessCatalogue; use App\Process\ProcessLanes; use App\Process\ProcessProfile; @@ -27,6 +28,7 @@ use App\Process\Restriction; use App\Process\Templates\FunctionTemplate; use App\Process\Templates\TemplateArea; +use App\Process\Templates\TemplateComposer; use Filament\Actions\Action; use Filament\Notifications\Notification; use Filament\Resources\Pages\Concerns\InteractsWithRecord; @@ -62,30 +64,90 @@ class ChannelProcess extends Page /** The landlord confirmed that stored settings the chosen model overrides are removed. */ public bool $acknowledge = false; + /** The business block opened in the detail panel ('' = none). */ + public string $block = ''; + public function mount(int|string $record): void { $this->record = $this->resolveRecord($record); $configuration = app(ChannelProcessConfiguration::class); foreach ($configuration->intakes($this->record) as $intake) { - $current = $configuration->current($this->record, $intake); - $stored = (array) (($this->record->process_overrides ?? [])[$intake->value] ?? []); - // The current (saved or derived) model stays selected even if it is not admissible: the page explains why instead of - // switching silently to another one. - $model = $current['model']; - $this->drafts[$intake->value] = [ - 'model' => $model, - 'variant' => $current['variant'], - 'steps' => (array) ($stored['steps'] ?? []), - 'templates' => (array) ($stored['templates'] ?? []), - 'settings' => array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, array_intersect_key($stored, array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, ProcessSetting::cases())))), - 'derived' => $current['derived'], - ]; + $this->drafts[$intake->value] = $this->storedDraft($intake); } $this->intake = (string) array_key_first($this->drafts); - $this->capabilityDraft = $this->record->isWebsite() ? [] : collect(app(ChannelCapabilities::class)->resolve($this->record)) + $this->block = ''; + $this->capabilityDraft = $this->storedCapabilities(); + } + + /** + * The draft as it is stored (or derived) now – the reference for "unsaved changes" and for discarding them. + * The current (saved or derived) model stays selected even if it is not admissible: the page explains why instead of + * switching silently to another one. + * + * @return array + */ + private function storedDraft(IntakeKind $intake): array + { + $current = app(ChannelProcessConfiguration::class)->current($this->record, $intake); + $stored = (array) (($this->record->process_overrides ?? [])[$intake->value] ?? []); + + return [ + 'model' => $current['model'], + 'variant' => $current['variant'], + 'steps' => (array) ($stored['steps'] ?? []), + 'templates' => (array) ($stored['templates'] ?? []), + 'settings' => array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, array_intersect_key($stored, array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, ProcessSetting::cases())))), + 'derived' => $current['derived'], + ]; + } + + /** + * @return array + */ + private function storedCapabilities(): array + { + return $this->record->isWebsite() ? [] : collect(app(ChannelCapabilities::class)->resolve($this->record)) ->map(fn (Capability $capability): string => $capability->value === null ? '' : ($capability->value ? '1' : '0'))->all(); } + /** + * Whether the draft of the current intake kind differs from what is stored (nothing is saved by looking or selecting). + */ + public function dirty(): bool + { + $normalise = fn (array $draft): array => [ + 'model' => $draft['model'], + 'variant' => $draft['variant'], + 'steps' => array_filter((array) $draft['steps']), + 'templates' => (array) $draft['templates'], + 'settings' => array_filter((array) $draft['settings'], fn (mixed $value): bool => $value !== null && $value !== ''), + ]; + + return $normalise($this->drafts[$this->intake]) != $normalise($this->storedDraft(IntakeKind::from($this->intake))) + || $this->capabilityDraft != $this->storedCapabilities(); + } + + /** + * Throws the unsaved changes away and shows the stored configuration again. + */ + public function discard(): void + { + $intake = $this->intake; + $this->acknowledge = false; + $this->mount($this->record->getKey()); + $this->intake = $intake; + } + + public function selectBlock(string $block): void + { + $this->block = $this->block === $block ? '' : $block; + } + + public function updatedIntake(): void + { + $this->block = ''; + } + /** * The draft of the current intake kind including the capabilities shown (they decide which models fit). * @@ -338,6 +400,74 @@ public function profile(): ProcessProfile return app(ChannelProcessConfiguration::class)->profileWith($this->record, IntakeKind::from($this->intake), $this->draft()); } + /** + * The business blocks of the course with what is effective in each: values and their origin, the template chosen for + * its decision, what depends on what (derived from the resolved plan, see {@see ProcessBlocks}), the steps that can + * be configured here and the fixed ones (no controls, shown as one line), gaps the template names, open problems. + * + * @return array> + */ + public function blocks(): array + { + $intake = IntakeKind::from($this->intake); + $configuration = app(ChannelProcessConfiguration::class); + $profile = $this->profile(); + $model = $this->model(); + $rows = $configuration->preview($this->record, $intake, $this->draft()); + $templates = app(TemplateComposer::class)->classes($configuration->templatesOf($model, $this->draft())); + $steps = collect($this->steps())->keyBy('module'); + $conflicts = collect($this->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all(); + $problems = $this->problems(); + + $blocks = []; + foreach (app(ProcessBlocks::class)->of($rows) as $key => $block) { + $template = $block['area'] === null ? null : ($templates[$block['area']->value] ?? null); + $settings = array_values(array_filter($block['settings'], fn (ProcessSetting $setting): bool => in_array($intake, $setting->channelIntakes(), true))); + $blockSteps = array_values(array_filter(array_map(fn (array $row): ?array => $steps[$row['module']] ?? null, $block['modules']))); + $configurable = array_values(array_filter($blockSteps, fn (array $step): bool => $step['on'] && ($step['optional'] || $step['mode_setting'] || ($step['performer_setting'] && count($step['performer_options']) > 1) || $step['parameters'] !== []) + || (! $step['on'] && $step['optional']))); + $fixed = array_values(array_filter($blockSteps, fn (array $step): bool => $step['on'] && ! in_array($step, $configurable, true))); + $blocks[$key] = [...$block, + 'facts' => array_map(fn (ProcessSetting $setting): array => $this->setting($setting, $profile), $settings), + 'template' => $template, + 'extensions' => $template === null ? [] : $template::extensions(), + 'configurable' => $configurable, + 'fixed' => $fixed, + 'off' => array_values(array_filter($blockSteps, fn (array $step): bool => ! $step['on'])), + 'attention' => count(array_filter($settings, fn (ProcessSetting $setting): bool => in_array($setting->value, $conflicts, true))), + 'problems' => $this->blockProblems($problems, $block['label'], $template, $settings), + ]; + } + + return $blocks; + } + + /** + * The problems of the draft that concern a block: they name its template or one of its settings. + * + * @param list $problems + * @param class-string|null $template + * @param list $settings + * @return list + */ + private function blockProblems(array $problems, string $label, ?string $template, array $settings): array + { + return array_values(array_filter($problems, fn (string $problem): bool => ($template !== null && str_contains($problem, $template::label())) + || collect($settings)->contains(fn (ProcessSetting $setting): bool => str_contains($problem, $setting->question())))); + } + + /** + * Problems of the draft that belong to no block (shown above the blocks). + * + * @return list + */ + public function problemsOutsideBlocks(): array + { + $inBlocks = collect($this->blocks())->flatMap(fn (array $block): array => $block['problems'])->all(); + + return array_values(array_diff($this->problems(), $inBlocks)); + } + /** * The step cards: preview row + controls of each step. * diff --git a/app/Process/ProcessBlocks.php b/app/Process/ProcessBlocks.php new file mode 100644 index 0000000..fd033f8 --- /dev/null +++ b/app/Process/ProcessBlocks.php @@ -0,0 +1,125 @@ +, settings: list}> + */ + public const BLOCKS = [ + 'intake' => ['label' => 'Eingang und Gastdaten', 'phase' => 'P01', 'area' => null, + 'modules' => ['intake.record', 'guest.details', 'guest.data_request', 'guest.address_check', 'guest.loyalty_status', 'pricing.loyalty_discount'], + 'settings' => [ProcessSetting::FormRequiresAddress, ProcessSetting::DataRequest, ProcessSetting::DataRequestReminderHours]], + 'availability' => ['label' => 'Verfügbarkeit und Reservierung', 'phase' => 'P01', 'area' => null, + 'modules' => ['availability.check', 'hold', 'binding.portal', 'channels.block'], + 'settings' => [ProcessSetting::PreReservation, ProcessSetting::HoldHours, ProcessSetting::ClarificationHoldAutoMinutes]], + 'answer' => ['label' => 'Antwort und Angebot', 'phase' => 'P02', 'area' => TemplateArea::InquiryAnswer, + 'modules' => ['offer.information', 'offer.binding', 'offer.acceptance'], + 'settings' => [ProcessSetting::InquiryAnswer, ProcessSetting::Processing, ProcessSetting::GuestLinkValidDays]], + 'portal_wait' => ['label' => 'Bestätigung des Portals', 'phase' => 'P02', 'area' => null, + 'modules' => ['portal.confirmation'], + 'settings' => [ProcessSetting::AwaitPortalConfirmation, ProcessSetting::PortalConfirmationWaitHours]], + 'documents' => ['label' => 'Dokumentation', 'phase' => 'P03', 'area' => TemplateArea::ContractDocuments, + 'modules' => ['documents.send', 'documents.booking_notice', 'documents.stay_confirmation'], + 'settings' => [ProcessSetting::Documents, ProcessSetting::ContractDelivery, ProcessSetting::BookingNotice, ProcessSetting::ContractTemplate]], + 'finance' => ['label' => 'Finanzabwicklung', 'phase' => 'P03', 'area' => TemplateArea::Collection, + 'modules' => ['payments.monitor', 'payments.internal', 'portal.payout'], + 'settings' => [ProcessSetting::Payments]], + 'communication' => ['label' => 'Gastkommunikation und Aufenthalt', 'phase' => 'P04', 'area' => TemplateArea::GuestCommunication, + 'modules' => ['arrival.details', 'arrival.info', 'stay', 'review.request'], + 'settings' => [ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoSender, ProcessSetting::ArrivalInfoDaysBefore, ProcessSetting::ReviewRequestSender]], + 'closure' => ['label' => 'Aufgaben und Abschluss', 'phase' => 'P05', 'area' => null, + 'modules' => ['case.tasks', 'change.proposal', 'case.closure', 'case.settlement'], + 'settings' => []], + ]; + + public const OTHER = 'other'; + + public function __construct(private ProcessCatalogue $catalogue) {} + + /** + * The blocks of the course the preview rows describe. A block without a step in the plan is left out. + * + * @param list $rows ChannelProcessConfiguration::preview + * @return array, modules: list, active: bool, waits_for: list}>, after: list, independent: bool, events: list, scheduled: list, conditional: list, may_wait: list}> + */ + public function of(array $rows): array + { + $blockOf = []; + foreach (self::BLOCKS as $key => $block) { + foreach ($block['modules'] as $module) { + $blockOf[$module] = $key; + } + } + $other = ['label' => 'Weitere Schritte', 'phase' => 'P03', 'area' => null, 'modules' => [], 'settings' => []]; + $blocks = []; + foreach ($rows as $row) { + $key = $blockOf[$row['module']] ?? self::OTHER; + $blocks[$key] ??= [...(self::BLOCKS[$key] ?? $other), 'key' => $key, 'modules' => []]; + $blocks[$key]['modules'][] = $row; + } + // Presentation order is the table's, the plan decides which blocks exist. + $blocks = array_merge(array_intersect_key(array_flip([...array_keys(self::BLOCKS), self::OTHER]), $blocks), $blocks); + + $active = []; + foreach ($rows as $row) { + if ($row['on']) { + $active[$row['module']] = $row; + } + } + foreach ($blocks as $key => &$block) { + $block['active'] = collect($block['modules'])->contains('on', true); + $block = [...$block, 'waits_for' => [], 'after' => [], 'events' => [], 'scheduled' => [], 'conditional' => [], 'may_wait' => []]; + foreach ($block['modules'] as $row) { + $definition = $this->catalogue->modules()[$row['module']]::definition(); + if (! $row['on']) { + continue; + } + foreach ($definition->requires as $dependency) { + $targetBlock = $blockOf[$dependency->module] ?? self::OTHER; + if ($dependency->module === 'intake.record' || ! isset($active[$dependency->module]) || $targetBlock === $key) { + continue; + } + $list = $dependency->hard ? 'waits_for' : 'after'; + $label = $blocks[$targetBlock]['label'] ?? self::BLOCKS[$targetBlock]['label'] ?? $other['label']; + $entry = $block[$list][$targetBlock] ?? ['block' => $targetBlock, 'label' => $label, 'steps' => []]; + $entry['steps'][] = $active[$dependency->module]['label']; + $block[$list][$targetBlock] = $entry; + } + if ($definition->toggle === ModuleDefinition::TOGGLE_EVENT_DRIVEN) { + $block['events'][] = $row['label']; + } elseif ($definition->triggers !== [] && collect($definition->triggers)->every(fn (string $trigger): bool => str_starts_with($trigger, 'schedule:'))) { + $block['scheduled'][] = $row['label']; + } + if ($definition->toggle === ModuleDefinition::TOGGLE_CONDITIONAL) { + $block['conditional'][] = ['label' => $row['label'], 'reason' => $definition->condition]; + } + foreach ($definition->waits as $wait) { + $block['may_wait'][] = ['guest' => 'den Gast', 'portal' => 'das Portal', 'landlord' => 'Sie', 'time' => 'eine Frist'][$wait] ?? $wait; + } + } + $block['waits_for'] = array_values($block['waits_for']); + $block['after'] = array_values($block['after']); + $block['may_wait'] = array_values(array_unique($block['may_wait'])); + $block['independent'] = $block['active'] && $block['waits_for'] === []; + } + unset($block); + + return $blocks; + } +} diff --git a/docs/STATUS.md b/docs/STATUS.md index b94b17f..08b3f1a 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -1,5 +1,12 @@ # Projektstand +## Nachtrag (05.11.2026): Visueller Prozesskonfigurator (Branch `feature/prozess-konfigurator`) + +- **Befund Steuerung:** Für neue Vorgänge gibt es eine maßgebliche Definition: den beim Eingang eingefrorenen `ProcessPlan` (`CaseRecorder` → `ProcessPlan::freeze`), den der `ProcessRunner` liest. Die Modelle A1–A5 wirken nur (a) in alten Fällen mit eingefrorenem oder abgeleitetem Plan und (b) als Adapter `ProcessCatalogue::derivedModel` für Kanäle, in denen noch kein Modell gewählt wurde; dort ist der Plan eine reine Funktion des aufgelösten Profils. Ein gewähltes Modell wird nie durch das abgeleitete ersetzt. Scheduler, Actions und Ereignisse führen aus, entscheiden aber über `ProcessPlan::of($booking)`. Nachweis: `VisualProcessConfiguratorTest::test_the_derived_legacy_model_is_only_used_where_nothing_is_chosen`. +- **Konfiguratorseite (Kanal › Ablauf):** Hauptansicht sind fachliche Prozessblöcke (`App\Process\ProcessBlocks`; die Zuordnung der Module zu Blöcken dient nur der Darstellung, ein Test hält Katalog und Tabelle gleich). Je Block: gewählte Schablone, wirksame Werte mit Herkunft, harte/weiche Abhängigkeiten zu anderen Blöcken, ereignis-/zeitgesteuert, bedingt – abgeleitet aus denselben Abhängigkeiten wie im Runner. Klick öffnet das Detailpanel: Schablonenwahl mit Folgenanalyse, Verbindungen, einstellbare Schritte (Schalter, Ausführung, Zuständigkeit, Parameter), feste Schritte nur als eine Zeile, „noch nicht vorhanden“ aus den Erweiterungen der Schablone. +- **Entwurf:** Auswählen/Öffnen speichert nichts; `dirty()` zeigt ungespeicherte Änderungen, „Änderungen verwerfen“ (`discard`), der Tester bekommt denselben Entwurf. Die endlose Einzelschrittliste ist entfernt; die Basisprozess-Auswahl ist eingeklappt, sobald das Modell Schablonen hat. Widersprüche zu gespeicherten Altwerten bleiben bestätigungspflichtige Konflikte (Test C). +- Tests: `VisualProcessConfiguratorTest` (A Webseite, B Destination Solutions inkl. Vergleich Blöcke = eingefrorener Plan, C Konflikt, D Bestandsfall, E Blockzuordnung/Erreichbarkeit); Feature-Suite 946/946. Nicht auf dem Testsystem geprüft, nicht gepusht. + ## Nachtrag (05.11.2026): Anfrage-Basisprozess und Schablonen für alle Vorfälle **Branch `feature/anfrage-basisprozess`** – [SCHABLONENKATALOG.md](Prozessarchitektur/SCHABLONENKATALOG.md) §9–10. diff --git a/resources/views/filament/resources/channels/channel-process-block.blade.php b/resources/views/filament/resources/channels/channel-process-block.blade.php new file mode 100644 index 0000000..9d25e43 --- /dev/null +++ b/resources/views/filament/resources/channels/channel-process-block.blade.php @@ -0,0 +1,80 @@ +@php + $muted = 'color:#6b7280;font-size:.8rem'; + $card = 'border:1px solid rgba(128,128,128,.3);border-radius:.5rem;padding:.75rem 1rem;margin-bottom:.6rem'; + $decision = collect($this->decisions())->first(fn (array $candidate): bool => $block['area'] !== null && $candidate['area'] === $block['area']); + $areaImpacts = $block['area'] === null ? [] : array_values(array_filter($this->templateImpacts(), fn (array $impact): bool => $impact['area'] === $block['area']->label())); +@endphp + + @foreach ($block['problems'] as $problem) +

{{ $problem }}

+ @endforeach + + @if ($decision) +

{{ $decision['area']->label() }} – {{ $decision['area']->question() }}

+
+ @foreach ($decision['options'] as $option) + @php($template = $option['template']) +
+ +
    + @foreach ($template::dimensions() as $dimension => $statement)
  • {{ $dimension }}: {{ $statement }}
  • @endforeach +
+ @foreach ($option['restrictions'] as $restriction) +

Passt gerade nicht ({{ $restriction->kind }}): {{ $restriction->reason }}@if ($restriction->alternative)
Zulässig ist stattdessen: {{ $restriction->alternative }}.@endif @if ($restriction->change)
{{ $restriction->change }}.@endif

+ @endforeach + @foreach ($option['hints'] as $hint)

{{ $hint }}

@endforeach +
+ @endforeach +
+ @foreach ($areaImpacts as $impact) +
+ Was der Wechsel bedeutet: {{ $impact['from'] ?? 'bisher keine Schablone' }} → {{ $impact['to'] }} + @if ($impact['responsibility'])
Verantwortung: {{ $impact['responsibility']['from'] }} → {{ $impact['responsibility']['to'] }}
@endif + @if ($impact['removed'] !== [])
Entfällt: {{ implode(', ', $impact['removed']) }}
@endif + @if ($impact['added'] !== [])
Kommt hinzu: {{ implode(', ', $impact['added']) }}
@endif + @if ($impact['kept'] !== [])
Bleibt mit allen Einstellungen: {{ implode(', ', $impact['kept']) }}
@endif + @foreach ($impact['switches_lost'] as $lost)
Ihr gespeicherter Schalter für „{{ $lost }}“ hat dann keinen Bezug mehr.
@endforeach + @foreach ($impact['settings_replaced'] as $text)
{{ $text }}
@endforeach + @foreach ($impact['needs'] as $need)
{{ $need }}
@endforeach +
+ @endforeach + @endif + + @if ($block['extensions'] !== []) +

Noch nicht vorhanden (hier gibt es dafür keine Einstellung): {{ implode('; ', $block['extensions']) }}.

+ @endif + +

Verbindungen

+
    + @forelse ($block['waits_for'] as $dependency) +
  • Wartet auf {{ $dependency['label'] }} ({{ implode(', ', array_unique($dependency['steps'])) }}) – harte Abhängigkeit
  • + @empty +
  • Wartet auf keinen anderen Block – läuft unabhängig.
  • + @endforelse + @foreach ($block['after'] as $dependency)
  • Soll nach {{ $dependency['label'] }} ({{ implode(', ', array_unique($dependency['steps'])) }}) – weiche Abhängigkeit, blockiert nicht
  • @endforeach + @if ($block['may_wait'] !== [])
  • Kann warten auf: {{ implode(', ', $block['may_wait']) }}
  • @endif + @if ($block['events'] !== [])
  • Reagiert auf Ereignisse: {{ implode(', ', $block['events']) }}
  • @endif + @if ($block['scheduled'] !== [])
  • Zeitgesteuert: {{ implode(', ', $block['scheduled']) }}
  • @endif + @foreach ($block['conditional'] as $conditional)
  • Bedingt: {{ $conditional['label'] }}@if ($conditional['reason']) – nur wenn {{ $conditional['reason'] }}@endif
  • @endforeach +
+ + @if ($block['configurable'] !== []) +

Einstellbare Schritte

+ @foreach ($block['configurable'] as $step) + @include('filament.resources.channels.channel-process-step', ['step' => $step]) + @endforeach + @endif + + @if ($block['fixed'] !== []) +

Feste Schritte ohne eigene Einstellung: {{ implode(', ', array_column($block['fixed'], 'label')) }}.

+ @endif + @if ($block['off'] !== []) +

Entfällt hier: {{ implode('; ', array_map(fn (array $step): string => $step['label'].($step['reason'] ? ' ('.$step['reason'].')' : ''), $block['off'])) }}.

+ @endif + @if ($block['configurable'] === [] && $block['facts'] === [] && $decision === null) +

Dieser Block hat keine eigenen Einstellungen.

+ @endif +
diff --git a/resources/views/filament/resources/channels/channel-process-step.blade.php b/resources/views/filament/resources/channels/channel-process-step.blade.php new file mode 100644 index 0000000..69b5c97 --- /dev/null +++ b/resources/views/filament/resources/channels/channel-process-step.blade.php @@ -0,0 +1,67 @@ +@php + $muted = 'color:#6b7280;font-size:.8rem'; + $input = 'border:1px solid rgba(128,128,128,.4);border-radius:.375rem;padding:.3rem .45rem;background:transparent'; + $performers = ['system' => 'System', 'landlord' => 'Sie', 'guest' => 'Gast', 'portal' => 'Portal', 'service_provider' => 'Dienstleister', 'none' => 'niemand']; + $waitLabels = ['guest' => 'Gast', 'portal' => 'Portal', 'landlord' => 'Sie', 'time' => 'Frist']; +@endphp +
+
+ {{ $step['label'] }} + @if ($step['tester_only']) · nur im Prozess-Tester@endif + @if ($step['inserted']) · Zusatzschritt der Variante@endif + + @if ($step['optional']) + + {{ ($this->drafts[$this->intake]['steps'][$step['module']]['on'] ?? true) === false ? 'aus' : 'an' }} + + @endif +
+
{{ $step['purpose'] }}
+
+ @if ($step['needs'] !== []) wartet auf: {{ implode(', ', $step['needs']) }} · @elseif ($step['on']) läuft unabhängig · @endif + @if ($step['after'] !== []) soll nach: {{ implode(', ', $step['after']) }} · @endif + @if ($step['condition']) nur wenn: {{ $step['condition'] }} · @endif + Wer: {{ $performers[$step['performer']] ?? $step['performer'] ?? '–' }} + @if ($step['waits'] !== []) · kann warten auf: {{ implode(', ', array_map(fn ($wait) => $waitLabels[$wait] ?? $wait, $step['waits'])) }}@endif + @if ($step['triggers'] !== [] && $this->expert()) · Auslöser: {{ implode(', ', $step['triggers']) }}@endif + @if (! $step['on'] && $step['reason']) · übersprungen: {{ $step['reason'] }}@endif + @if ($this->expert()) · {{ $step['module'] }} v{{ $step['version'] }}@endif +
+ + @if ($step['mode_setting'] && $step['mode_options'] !== []) + + @endif + + @if ($step['performer_setting'] && count($step['performer_options']) > 1) + + @endif + + @foreach ($step['parameters'] as $parameter) + + @endforeach +
diff --git a/resources/views/filament/resources/channels/channel-process.blade.php b/resources/views/filament/resources/channels/channel-process.blade.php index acedb82..11e3048 100644 --- a/resources/views/filament/resources/channels/channel-process.blade.php +++ b/resources/views/filament/resources/channels/channel-process.blade.php @@ -52,6 +52,15 @@ @endif + @if ($conflicts = $this->conflicts()) +
+ Bisherige Einstellungen widersprechen dem gewählten Ablauf +
    @foreach ($conflicts as $conflict)
  • {{ $conflict['text'] }}
  • @endforeach
+ +
+ @endif + +
Basisprozess: {{ $model::label() }} @if ($models === [])

Für diese Eingangsart gibt es keine Ablaufmodelle.

@@ -78,11 +87,12 @@ @endforeach - @if ($conflicts = $this->conflicts()) -
- Bisherige Einstellungen widersprechen diesem Modell -
    @foreach ($conflicts as $conflict)
  • {{ $conflict['text'] }}
  • @endforeach
- + + @if ($composable && ($presets = $this->presets()) !== []) +
Bekannte Kombinationen als Ausgangspunkt: + @foreach ($presets as $archetype => $preset) + + @endforeach
@endif @@ -101,67 +111,66 @@
@endif
+
- @if ($composable) - @php($decisions = $this->decisions()) - - @if (($presets = $this->presets()) !== []) -
Bekannte Kombinationen als Ausgangspunkt: - @foreach ($presets as $archetype => $preset) - - @endforeach -
- @endif - @foreach ($decisions as $decision) -

{{ $decision['area']->label() }} – {{ $decision['area']->question() }}

-
- @foreach ($decision['options'] as $option) - @php($template = $option['template']) -
- -
    - @foreach ($template::dimensions() as $dimension => $statement)
  • {{ $dimension }}: {{ $statement }}
  • @endforeach -
-
Schritte: {{ implode(', ', $option['modules']) }}@if ($template::extensions() !== []) · noch nicht vorhanden: {{ implode('; ', $template::extensions()) }}@endif
- @foreach ($option['restrictions'] as $restriction) -

Passt gerade nicht ({{ $restriction->kind }}): {{ $restriction->reason }}@if ($restriction->alternative)
Zulässig ist stattdessen: {{ $restriction->alternative }}.@endif @if ($restriction->change)
{{ $restriction->change }}.@endif

- @endforeach - @foreach ($option['hints'] as $hint)

{{ $hint }}

@endforeach -
- @endforeach -
- @endforeach -
- - @if ($templateImpacts = $this->templateImpacts()) - - @foreach ($templateImpacts as $impact) -
- {{ $impact['area'] }}: {{ $impact['from'] ?? 'bisher keine Schablone' }} → {{ $impact['to'] }} - @if ($impact['responsibility'])
Verantwortung: {{ $impact['responsibility']['from'] }} → {{ $impact['responsibility']['to'] }}
@endif - @if ($impact['removed'] !== [])
Entfällt: {{ implode(', ', $impact['removed']) }}
@endif - @if ($impact['added'] !== [])
Kommt hinzu: {{ implode(', ', $impact['added']) }}
@endif - @if ($impact['kept'] !== [])
Bleibt mit allen Einstellungen: {{ implode(', ', $impact['kept']) }}
@endif - @foreach ($impact['switches_lost'] as $lost)
Ihr gespeicherter Schalter für „{{ $lost }}“ hat dann keinen Bezug mehr.
@endforeach - @foreach ($impact['settings_replaced'] as $text)
{{ $text }}
@endforeach - @foreach ($impact['needs'] as $need)
{{ $need }}
@endforeach -
- @endforeach -
- @endif + @if ($this->dirty()) +
+ Ungespeicherte Änderungen. Der Prozess unten zeigt Ihren Entwurf; der Tester verwendet ihn ebenfalls. Gespeichert wird erst mit „Speichern“. + Änderungen verwerfen +
@endif - @if ($problems !== []) + @if (($loose = $this->problemsOutsideBlocks()) !== [])
    - @foreach ($problems as $problem)
  • {{ $problem }}
  • @endforeach + @foreach ($loose as $problem)
  • {{ $problem }}
  • @endforeach
@endif + @php($blocks = $this->blocks()) + +
+ @foreach ($blocks as $key => $block) +
+ +
+ @endforeach +
+

Gilt für neue Vorgänge. Laufende Vorgänge dieses Kanals ({{ $this->runningCases() }}) behalten ihren bisherigen Ablauf.

+
+ +
+ @if ($this->block !== '' && isset($blocks[$this->block])) + @include('filament.resources.channels.channel-process-block', ['block' => $blocks[$this->block]]) + @endif +
+ @if ($impacts = $this->impacts()) @foreach ($impacts as $impact) @@ -174,111 +183,19 @@ @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 -
+ + Ablauf testen + @if ($this->expert()) +
Alle Schritte dieses Ablaufs ({{ count($steps) }}) +
    + @foreach ($steps as $step) +
  • + {{ $step['label'] }} + – {{ $step['on'] ? ($performers[$step['performer']] ?? $step['performer'] ?? '').($step['mode'] ? ', '.(\App\Enums\ProcessingMode::tryFrom($step['mode'])?->getLabel() ?? \App\Enums\DataRequestMode::tryFrom($step['mode'])?->getLabel() ?? $step['mode']) : '') : 'übersprungen: '.$step['reason'] }} +
  • + @endforeach +
+
+ @endif
- -
-
- Einzelschritte einstellen ({{ count($steps) }} Schritte) - @foreach (collect($steps)->groupBy('phase') as $phase => $group) -

{{ $phases[$phase] ?? $phase }}

- @foreach ($group as $index => $step) -
-
- {{ $step['label'] }} - @if ($step['tester_only']) · nur im Prozess-Tester@endif - @if ($step['inserted']) · Zusatzschritt der Variante@endif - @if ($step['template'] ?? null) · Schablone: {{ $step['template'] }}@endif - - @if ($step['optional']) - - {{ ($draft['steps'][$step['module']]['on'] ?? true) === false ? 'aus' : 'an' }} - - @else - 🔒 Pflicht - @endif -
-
{{ $step['purpose'] }}
-
- @if ($step['needs'] !== []) braucht zuerst: {{ implode(', ', $step['needs']) }} · @elseif ($step['on']) läuft unabhängig · @endif - @if ($step['after'] !== []) soll nach: {{ implode(', ', $step['after']) }} · @endif - @if ($step['condition']) nur wenn: {{ $step['condition'] }} · @endif - @if ($step['executions'] !== [] && ! $step['optional']) So darf das erfüllt werden: {{ implode(', ', $step['executions']) }}@if ($step['why']) – {{ $step['why'] }}@endif · @endif - Wer: {{ $performers[$step['performer']] ?? $step['performer'] ?? '–' }} - @if ($step['waits'] !== []) · kann warten auf: {{ implode(', ', array_map(fn ($wait) => ['guest' => 'Gast', 'portal' => 'Portal', 'landlord' => 'Sie', 'time' => 'Frist'][$wait] ?? $wait, $step['waits'])) }}@endif - @if (! $step['on'] && $step['reason']) · übersprungen: {{ $step['reason'] }}@endif - @if ($this->expert()) · {{ $step['module'] }} v{{ $step['version'] }}@endif -
- - @if ($step['mode_setting'] && $step['mode_options'] !== []) - - @endif - - @if ($step['performer_setting'] && count($step['performer_options']) > 1) - - @endif - - @foreach ($step['parameters'] as $parameter) - - @endforeach -
- @endforeach - @endforeach -
- - -
    - @foreach ($steps as $step) -
  • - {{ $step['label'] }} - – {{ $step['on'] ? ($performers[$step['performer']] ?? $step['performer'] ?? '').($step['mode'] ? ', '.(\App\Enums\ProcessingMode::tryFrom($step['mode'])?->getLabel() ?? \App\Enums\DataRequestMode::tryFrom($step['mode'])?->getLabel() ?? $step['mode']) : '') : 'übersprungen: '.$step['reason'] }} -
  • - @endforeach -
-

Gilt für neue Vorgänge. Laufende Vorgänge dieses Kanals ({{ $this->runningCases() }}) behalten ihren bisherigen Ablauf.

- Ablauf testen -

Spielt einen ausgedachten Vorgang mit genau dieser Einstellung durch – ohne Wirkung auf echte Daten.

-
-
diff --git a/tests/Feature/Process/ChannelProcessConfiguratorTest.php b/tests/Feature/Process/ChannelProcessConfiguratorTest.php index 4432cec..96fc875 100644 --- a/tests/Feature/Process/ChannelProcessConfiguratorTest.php +++ b/tests/Feature/Process/ChannelProcessConfiguratorTest.php @@ -193,9 +193,9 @@ public function test_the_page_shows_the_steps_with_their_settings_and_saves(): v Livewire::test(ChannelProcess::class, ['record' => $website->getRouteKey()]) ->assertSee('Wie wird eine Anfrage über') ->assertSee('Angebot mit Vorreservierung') + ->assertSee('Der Geschäftsprozess') + ->call('selectBlock', 'intake') ->assertSee('Fehlende Angaben beim Gast anfragen') - ->assertSee('Pflicht') - ->assertSee('Vorschau: ein neuer Vorgang') ->set('drafts.inquiry.settings.hold_hours', '24') ->assertSee('hier gesetzt') ->call('save') diff --git a/tests/Feature/Process/TemplateConfiguratorTest.php b/tests/Feature/Process/TemplateConfiguratorTest.php index 425e24c..aa66024 100644 --- a/tests/Feature/Process/TemplateConfiguratorTest.php +++ b/tests/Feature/Process/TemplateConfiguratorTest.php @@ -65,15 +65,16 @@ public function test_the_page_shows_the_business_decisions_first_and_keeps_the_s Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()]) ->call('chooseModel', 'external.booking') - ->assertSee('Geschäftsentscheidungen') + ->assertSee('Der Geschäftsprozess') + ->call('selectBlock', 'finance') ->assertSee('Wer zieht das Geld des Gastes ein?') ->assertSee('Eigenes Inkasso') ->assertSee('Portal-Inkasso') - ->assertSee('Eigene Vertragsdokumentation') - ->assertSee('Externe Vertragsunterlagen') ->assertSee('Mehrstufige Mahnungen', escape: false) - ->assertSee('Einzelschritte einstellen') - ->assertSee('Zahlungen des Gastes'); + ->assertSee('Zahlungen des Gastes') + ->call('selectBlock', 'documents') + ->assertSee('Eigene Vertragsdokumentation') + ->assertSee('Externe Vertragsunterlagen'); } public function test_an_archetype_moves_to_the_base_process_with_the_same_combination_and_saves(): void @@ -101,7 +102,7 @@ public function test_a_template_the_portal_cannot_support_cannot_be_chosen_and_s $page->call('chooseTemplate', 'collection', 'collection.own'); $this->assertSame('collection.portal', $page->get('drafts')['booking']['templates']['collection'], 'refused: FeWo-direkt collects the money'); - $page->assertSee('Passt gerade nicht')->assertSee('Zieht das Portal das Geld des Gastes ein?'); + $page->call('selectBlock', 'finance')->assertSee('Passt gerade nicht')->assertSee('Zieht das Portal das Geld des Gastes ein?'); // The landlord corrects the capability first: now the template fits. $page->set('capabilityDraft.collects_payment', '0')->call('chooseTemplate', 'collection', 'collection.own'); diff --git a/tests/Feature/Process/VisualProcessConfiguratorTest.php b/tests/Feature/Process/VisualProcessConfiguratorTest.php new file mode 100644 index 0000000..18098d9 --- /dev/null +++ b/tests/Feature/Process/VisualProcessConfiguratorTest.php @@ -0,0 +1,261 @@ +travelTo(CarbonImmutable::parse('2026-10-23 18: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(); + $this->actingAs(User::factory()->create()); + } + + /** Test A: own website – answer and reservation changed in the blocks, overview follows, draft is tested, then saved */ + public function test_a_website_request_is_configured_in_the_blocks_and_the_overview_follows(): void + { + $website = Channel::websiteOf($this->property); + $page = Livewire::test(ChannelProcess::class, ['record' => $website->getRouteKey()]) + ->call('chooseModel', 'inquiry.request') + ->call('selectBlock', 'answer') + ->assertSee('Verbindliches Angebot') + ->call('chooseTemplate', 'inquiry_answer', 'inquiry.binding_offer'); + + $blocks = $page->instance()->blocks(); + $this->assertSame('Verbindliches Angebot', $blocks['answer']['template']::label()); + $this->assertTrue($page->instance()->dirty(), 'a changed draft is shown as unsaved'); + $this->assertNull($website->fresh()->process_overrides['inquiry']['model'] ?? null, 'nothing is saved by choosing'); + + // The offer waits for exactly what it needs; data collection and availability do not wait for it. + $this->assertContains('Eingang und Gastdaten', array_column($blocks['answer']['waits_for'], 'label')); + $this->assertContains('Verfügbarkeit und Reservierung', array_column($blocks['answer']['waits_for'], 'label')); + $this->assertTrue($blocks['intake']['independent']); + $this->assertTrue($blocks['availability']['independent']); + $this->assertSame([], $blocks['availability']['waits_for']); + + $reserving = collect($blocks['availability']['facts'])->firstWhere('key', 'pre_reservation'); + $this->assertSame('ja', mb_strtolower(substr($reserving['value'], 0, 2)), 'the offer suggests holding the dates at the request'); + + $page->call('selectBlock', 'availability')->set('drafts.inquiry.settings.pre_reservation', '0')->set('drafts.inquiry.settings.data_request_mode', 'manual'); + $blocks = $page->instance()->blocks(); + $this->assertContains('Reservierung des Zeitraums', array_column($blocks['availability']['off'], 'label'), 'the hold step drops out of the overview at once'); + $this->assertSame('hier gesetzt', collect($blocks['availability']['facts'])->firstWhere('key', 'pre_reservation')['source']); + $this->assertStringContainsString('selbst nach', mb_strtolower(collect($blocks['intake']['facts'])->firstWhere('key', 'data_request_mode')['value']), 'the data request mode is shown in its block'); + + // The tester gets the very same unsaved draft. + $page->call('test'); + $draft = session('process-tester.draft.'.$website->id.'.inquiry'); + $this->assertSame('inquiry.request', $draft['model']); + $this->assertSame('inquiry.binding_offer', $draft['templates']['inquiry_answer']); + $this->assertSame('0', $draft['settings']['pre_reservation']); + + $page->call('save')->assertNotified('Ablauf gespeichert'); + $saved = $website->fresh()->process_overrides['inquiry']; + $this->assertSame(['inquiry.request', 'inquiry.binding_offer'], [$saved['model'], $saved['templates']['inquiry_answer']]); + $this->assertFalse($saved['pre_reservation']); + $this->assertFalse($page->instance()->dirty(), 'after saving the stored configuration is shown'); + } + + public function test_selecting_never_saves_and_changes_can_be_discarded(): void + { + $website = Channel::websiteOf($this->property); + $page = Livewire::test(ChannelProcess::class, ['record' => $website->getRouteKey()])->call('selectBlock', 'availability'); + $this->assertFalse($page->instance()->dirty(), 'opening a block changes nothing'); + + $page->set('drafts.inquiry.settings.hold_hours', '12'); + $this->assertTrue($page->instance()->dirty()); + $this->assertNull(($website->fresh()->process_overrides['inquiry'] ?? [])['hold_hours'] ?? null); + + $page->call('discard'); + $this->assertFalse($page->instance()->dirty()); + $this->assertArrayNotHasKey('hold_hours', $page->get('drafts')['inquiry']['settings']); + } + + /** Test B: Destination Solutions – own collection, external contract documents, own booking notice, waiting for the portal */ + public function test_destination_solutions_blocks_templates_modules_and_the_frozen_plan_agree(): void + { + $ds = $this->portal('Destination Solution'); + app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, [ + 'model' => 'external.booking', + 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.external'], + 'settings' => ['await_portal_confirmation' => '1', 'booking_notice' => 'automatic'], + 'capabilities' => ['collects_payment' => '0', 'provides_contract_documents' => '1'], + ]); + + $page = Livewire::test(ChannelProcess::class, ['record' => $ds->fresh()->getRouteKey()])->set('intake', 'booking'); + $blocks = $page->instance()->blocks(); + + $this->assertSame('Eigenes Inkasso', $blocks['finance']['template']::label()); + $this->assertSame('Externe Vertragsunterlagen', $blocks['documents']['template']::label()); + $this->assertContains('Bestätigung des Portals', array_column($blocks['documents']['waits_for'], 'label'), 'the documents wait for the portal confirmation'); + $this->assertTrue($blocks['finance']['independent'], 'collecting the money does not wait for it'); + $this->assertTrue($blocks['communication']['independent'], 'neither does the guest communication'); + $this->assertContains('Zahlungen des Gastes', array_column($blocks['finance']['fixed'], 'label')); + $this->assertContains('Mehrstufige Mahnungen (rechtliche Ausgestaltung offen)', $blocks['finance']['extensions']); + $this->assertSame('automatic', collect($blocks['documents']['facts'])->firstWhere('key', 'booking_notice') ? 'automatic' : null); + + // What the overview shows is what a new case gets. + $booking = $this->takeOver($ds->fresh(), 'DS-1'); + $plan = ProcessPlan::of($booking); + $shown = collect($blocks)->flatMap(fn (array $block): array => collect($block['modules'])->where('on', true)->pluck('module')->all())->sort()->values()->all(); + $this->assertSame(collect(array_keys($plan->modules))->sort()->values()->all(), $shown); + $this->assertEqualsCanonicalizing(['collection' => 'collection.own@1', 'contract_documents' => 'contract_docs.external@1'], array_intersect_key($plan->templates, ['collection' => 1, 'contract_documents' => 1])); + $this->assertSame('landlord', $booking->process()->payments()->value); + $this->assertSame('portal', $booking->process()->documents()->value); + } + + /** Test C: a stored legacy setting contradicts the chosen template – one definition, controlled adoption */ + public function test_a_contradicting_legacy_setting_becomes_a_conflict_and_never_a_second_definition(): void + { + $website = Channel::websiteOf($this->property); + $website->update(['process_overrides' => ['inquiry' => ['model' => 'a1.offer', 'pre_reservation' => true]]]); + + $page = Livewire::test(ChannelProcess::class, ['record' => $website->fresh()->getRouteKey()]) + ->call('chooseModel', 'inquiry.request') + ->call('chooseTemplate', 'inquiry_answer', 'inquiry.information'); + + $conflicts = collect($page->instance()->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all(); + $this->assertContains('pre_reservation', $conflicts); + $this->assertGreaterThan(0, $page->instance()->blocks()['availability']['attention'], 'the block that is affected is marked'); + $page->assertSee('Bisherige Einstellungen widersprechen'); + + $page->call('save')->assertNotified('Nicht gespeichert'); + $this->assertSame('a1.offer', $website->fresh()->process_overrides['inquiry']['model'], 'refused: still exactly the old definition'); + + $page->set('acknowledge', true)->call('save')->assertNotified('Ablauf gespeichert'); + $saved = $website->fresh()->process_overrides['inquiry']; + $this->assertSame('inquiry.request', $saved['model']); + $this->assertArrayNotHasKey('pre_reservation', $saved, 'the stale legacy value is gone, not hidden behind the template'); + + $plan = ProcessPlan::freeze(app(ProcessSettings::class)->forWebsite($this->property), ProcessPlan::configurationOf($website->fresh(), IntakeKind::Inquiry)); + $this->assertSame([ProcessPlan::CONFIGURED, 'inquiry.request', 'inquiry.information@1'], [$plan->source, $plan->model, $plan->templates['inquiry_answer']]); + $this->assertFalse(app(ProcessSettings::class)->forWebsite($this->property)->preReservation()); + } + + /** Test D: cases of the historical models keep their frozen plan when the channel is reconfigured */ + public function test_historical_cases_keep_their_frozen_plan(): void + { + $fewo = $this->portal('FeWo-direkt', 'mixed'); + app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Booking, ['model' => 'a4.portal_booking', 'capabilities' => ['collects_payment' => '1']]); + $old = $this->takeOver($fewo->fresh(), 'FD-ALT'); + $frozen = $old->fresh()->profile; + $this->assertSame('a4.portal_booking', ProcessPlan::of($old)->model); + + $page = Livewire::test(ChannelProcess::class, ['record' => $fewo->fresh()->getRouteKey()])->set('intake', 'booking')->call('applyPreset', 'a4.portal_booking'); + $page->call('save')->assertNotified('Ablauf gespeichert'); + + $this->assertSame($frozen, $old->fresh()->profile); + $this->assertSame('a4.portal_booking', ProcessPlan::of($old->fresh())->model); + $this->assertSame('external.booking', ProcessPlan::of($this->takeOver($fewo->fresh(), 'FD-NEU', '2027-09-10'))->model); + } + + /** Test E: the main view has few blocks, every module sits in exactly one of them, every control is reachable */ + public function test_every_module_is_in_a_block_and_every_control_is_reachable_there(): void + { + $catalogue = app(ProcessCatalogue::class); + $grouped = collect(ProcessBlocks::BLOCKS)->flatMap(fn (array $block): array => $block['modules'])->all(); + $this->assertSame([], array_values(array_diff(array_keys($catalogue->modules()), $grouped)), 'a new module needs a block'); + $this->assertSame($grouped, array_values(array_unique($grouped)), 'no module is in two blocks'); + + $ds = $this->portal('Destination Solution'); + $page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking')->call('chooseModel', 'external.booking'); + $blocks = $page->instance()->blocks(); + $this->assertLessThanOrEqual(8, count($blocks), 'a handful of blocks, not 28 modules'); + $this->assertNotContains(ProcessBlocks::OTHER, array_keys($blocks)); + + $reachable = []; + foreach ($blocks as $block) { + foreach ($block['configurable'] as $step) { + foreach ([$step['mode_setting'], $step['performer_setting'], ...array_map(fn (array $parameter) => ProcessSetting::from($parameter['key']), $step['parameters'])] as $setting) { + if ($setting !== null) { + $reachable[$step['module']][$setting->value] = true; + } + } + } + } + // Whatever the configurator can save for a step is offered inside the block of that step. + foreach ($page->instance()->steps() as $step) { + if (! $step['on']) { + continue; + } + $offered = array_filter([$step['mode_setting']?->value, ...(count($step['performer_options']) > 1 ? [$step['performer_setting']?->value] : []), ...array_column($step['parameters'], 'key')]); + foreach ($offered as $setting) { + $this->assertArrayHasKey($setting, $reachable[$step['module']] ?? [], $step['module'].' / '.$setting.' is not reachable in its block'); + } + } + } + + /** One authoritative definition: the derived legacy model is only an adapter for channels without a chosen model */ + public function test_the_derived_legacy_model_is_only_used_where_nothing_is_chosen(): void + { + $users = collect(['app/Process', 'app/Actions', 'app/Filament', 'app/Console']) + ->flatMap(fn (string $directory): array => collect(app('files')->allFiles(base_path($directory)))->map(fn ($file) => $file->getPathname())->all()) + ->filter(fn (string $path): bool => str_contains(file_get_contents($path), 'derivedModel(')) + ->map(fn (string $path): string => basename($path))->sort()->values()->all(); + + $this->assertSame(['ChannelProcessConfiguration.php', 'ProcessCatalogue.php', 'ProcessPlan.php'], $users, 'only plan resolution and the configurator show the adapter'); + + $website = Channel::websiteOf($this->property); + app(ConfigureChannelProcess::class)->handle($website, IntakeKind::Inquiry, ['model' => 'inquiry.request', 'templates' => ['inquiry_answer' => 'inquiry.binding_offer']]); + $profile = app(ProcessSettings::class)->forWebsite($this->property); + $plan = ProcessPlan::freeze($profile, ProcessPlan::configurationOf($website->fresh(), IntakeKind::Inquiry)); + $this->assertSame([ProcessPlan::CONFIGURED, 'inquiry.request'], [$plan->source, $plan->model], 'a chosen model is never replaced by the derived one'); + } + + private function portal(string $name, string $model = 'portal_booking'): Channel + { + return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => $model, 'import_enabled' => false, 'settings' => ['import_url' => 'https://portal.example/'.md5($name).'.ics']]); + } + + private function takeOver(Channel $channel, string $reference, string $arrival = '2027-07-10'): Booking + { + $arrival = CarbonImmutable::parse($arrival); + + return app(TakeOverExternalBooking::class)->handle($this->property, $channel, $arrival, $arrival->addDays(7), ['portal_reference' => $reference]); + } +}