Merge feature/schablonenkomposition: Funktionsschablonen für extern verbindliche Buchungen
Deploy FeWo mit PipelineManager / deploy (push) Failing after 5m14s
Deploy FeWo mit PipelineManager / deploy (push) Failing after 5m14s
This commit is contained in:
commit
e1d0f6b023
35 files changed
+2508
-47
No files matched your search
@@ -7,6 +7,7 @@
|
||||
use App\Models\Channel;
|
||||
use App\Process\ChannelCapabilities;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@@ -23,10 +24,10 @@ class ConfigureChannelProcess
|
||||
{
|
||||
public const HISTORY_LIMIT = 20;
|
||||
|
||||
public function __construct(private ChannelProcessConfiguration $configuration, private ChannelCapabilities $capabilities) {}
|
||||
public function __construct(private ChannelProcessConfiguration $configuration, private ChannelCapabilities $capabilities, private ProcessCatalogue $catalogue) {}
|
||||
|
||||
/**
|
||||
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>, capabilities?: array<string, bool|string|null>} $draft
|
||||
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>, templates?: array<string, string>, capabilities?: array<string, bool|string|null>} $draft
|
||||
* @param bool $acknowledgeConflicts the landlord confirmed that stored settings the model overrides are removed
|
||||
*
|
||||
* @throws ValidationException
|
||||
@@ -38,7 +39,7 @@ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?stri
|
||||
throw ValidationException::withMessages(['process' => $problems]);
|
||||
}
|
||||
|
||||
$conflicts = $this->configuration->conflicts($channel, $intake, (string) $draft['model']);
|
||||
$conflicts = $this->configuration->conflicts($channel, $intake, (string) $draft['model'], (array) ($draft['templates'] ?? []));
|
||||
if ($conflicts !== [] && ! $acknowledgeConflicts) {
|
||||
throw ValidationException::withMessages(['process' => [
|
||||
'Bisherige Einstellungen widersprechen dem gewählten Modell und würden still überstimmt. Bitte ausdrücklich bestätigen, dass sie entfernt werden:',
|
||||
@@ -71,11 +72,19 @@ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?stri
|
||||
}
|
||||
}
|
||||
|
||||
// A model with slots always stores its explicit template choice (keys; the version is frozen with each new case).
|
||||
$model = $this->catalogue->model((string) $draft['model']);
|
||||
$templates = array_map(fn (string $reference): string => explode('@', $reference)[0], $this->configuration->templatesOf($model, $draft));
|
||||
if ($model->slots() === []) {
|
||||
$templates = [];
|
||||
}
|
||||
|
||||
$overrides[$intake->value] = [
|
||||
...$settings,
|
||||
'model' => $draft['model'],
|
||||
'variant' => $draft['variant'] ?? 'standard',
|
||||
'steps' => $steps,
|
||||
'templates' => $templates,
|
||||
'configured_at' => now()->toIso8601String(),
|
||||
'configured_by' => $by,
|
||||
];
|
||||
@@ -88,7 +97,7 @@ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?stri
|
||||
$changes = $confirmed['changes'];
|
||||
}
|
||||
$channelSettings['process_history'] = array_slice([...(array) ($channelSettings['process_history'] ?? []), [
|
||||
'at' => now()->toIso8601String(), 'by' => $by, 'intake' => $intake->value, 'model' => $draft['model'], 'variant' => $draft['variant'] ?? 'standard',
|
||||
'at' => now()->toIso8601String(), 'by' => $by, 'intake' => $intake->value, 'model' => $draft['model'], 'variant' => $draft['variant'] ?? 'standard', 'templates' => $templates,
|
||||
'capabilities' => $changes, 'removed_settings' => array_map(fn (array $conflict): string => $conflict['text'], $conflicts),
|
||||
]], -self::HISTORY_LIMIT);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
use App\Pricing\CaseMoney;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
@@ -121,6 +123,7 @@ public static function configure(Schema $schema): Schema
|
||||
->schema([
|
||||
TextEntry::make('status')->label('Status')->badge(),
|
||||
TextEntry::make('case_type')->label('Vorgangsart')->state(fn (Booking $record): string => strtoupper($record->caseType()->value).' – '.$record->caseType()->getLabel()),
|
||||
TextEntry::make('templates')->label('Funktionsschablonen')->state(fn (Booking $record): ?string => self::templates($record))->placeholder('– (fester Ablauf)'),
|
||||
TextEntry::make('intake')->label('Eingangsart')->state(fn (Booking $record): string => $record->intake?->getLabel() ?? '–'),
|
||||
TextEntry::make('sources')->label('Quellen und Kalenderdarstellungen')->state(fn (Booking $record): HtmlString => self::sources($record))->html()->columnSpanFull(),
|
||||
TextEntry::make('profile')->label('Abwicklungsprofil (eingefroren)')->state(fn (Booking $record): HtmlString => self::profile($record))->html()->columnSpanFull(),
|
||||
@@ -238,6 +241,17 @@ private static function history(Booking $booking): HtmlString
|
||||
return new HtmlString($rows === '' ? 'Noch keine Einträge.' : '<ul style="list-style:none;padding:0;margin:0;font-size:.9rem">'.$rows.'</ul>');
|
||||
}
|
||||
|
||||
/**
|
||||
* The function templates the case was composed with, as frozen in its plan (null for the fixed models).
|
||||
*/
|
||||
private static function templates(Booking $record): ?string
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$labels = array_map(fn (string $reference): string => ($class = $catalogue->templateClass($reference)) !== null ? $class::label().' ('.$reference.')' : $reference, ProcessPlan::of($record)->templates);
|
||||
|
||||
return $labels === [] ? null : implode(' · ', $labels);
|
||||
}
|
||||
|
||||
private static function profile(Booking $booking): HtmlString
|
||||
{
|
||||
$profile = $booking->process();
|
||||
|
||||
@@ -15,11 +15,14 @@
|
||||
use App\Process\ChannelCapabilities;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\ConfigurationImpact;
|
||||
use App\Process\Models\ExternalBookingModel;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Process\ProcessSettings;
|
||||
use App\Process\Restriction;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\Concerns\InteractsWithRecord;
|
||||
@@ -46,7 +49,7 @@ class ChannelProcess extends Page
|
||||
|
||||
public string $intake = 'inquiry';
|
||||
|
||||
/** @var array<string, array{model: string, variant: string, steps: array<string, array{on?: bool}>, settings: array<string, mixed>}> */
|
||||
/** @var array<string, array{model: string, variant: string, steps: array<string, array{on?: bool}>, settings: array<string, mixed>, templates: array<string, string>}> */
|
||||
public array $drafts = [];
|
||||
|
||||
/** @var array<string, string> capability key => '1' | '0' | '' (unknown); saving confirms what is shown */
|
||||
@@ -69,6 +72,7 @@ public function mount(int|string $record): void
|
||||
'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'],
|
||||
];
|
||||
@@ -140,7 +144,124 @@ public function models(): array
|
||||
*/
|
||||
public function conflicts(): array
|
||||
{
|
||||
return app(ChannelProcessConfiguration::class)->conflicts($this->record, IntakeKind::from($this->intake), $this->drafts[$this->intake]['model']);
|
||||
return app(ChannelProcessConfiguration::class)->conflicts($this->record, IntakeKind::from($this->intake), $this->drafts[$this->intake]['model'], $this->drafts[$this->intake]['templates']);
|
||||
}
|
||||
|
||||
/**
|
||||
* The models offered as a choice: the archetypes A3–A5 are presets of the base process, so they only appear while one
|
||||
* of them is the current choice (then with the hint to move to the templates).
|
||||
*
|
||||
* @param array<string, array{model: ProcessModel, admissible: bool, restrictions: list<Restriction>, hints: list<string>}> $models
|
||||
* @return array<string, array{model: ProcessModel, admissible: bool, restrictions: list<Restriction>, hints: list<string>}>
|
||||
*/
|
||||
public function visibleModels(array $models): array
|
||||
{
|
||||
return array_filter($models, fn (array $option, string $key): bool => ! $option['model']::isLegacy() || $key === $this->drafts[$this->intake]['model'], ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the chosen model composes function templates (otherwise its course is fixed).
|
||||
*/
|
||||
public function composable(): bool
|
||||
{
|
||||
return $this->model()->slots() !== [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The business decisions of the chosen base process: per slot the templates with fit, selection and what each stands
|
||||
* for. The first view of the configurator; the single steps stay below.
|
||||
*
|
||||
* @return list<array{area: TemplateArea, selected: ?string, options: list<array{key: string, template: class-string<FunctionTemplate>, admissible: bool, selected: bool, restrictions: list<Restriction>, hints: list<string>, unconfirmed: list<string>, modules: list<string>}>}>
|
||||
*/
|
||||
public function decisions(): array
|
||||
{
|
||||
$model = $this->model();
|
||||
if ($model->slots() === []) {
|
||||
return [];
|
||||
}
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$resolved = $configuration->templatesOf($model, $this->draft());
|
||||
$options = $configuration->templateOptions($this->record, $model, $this->capabilityDraft);
|
||||
$decisions = [];
|
||||
foreach ($model->slots() as $area) {
|
||||
$selected = isset($resolved[$area->value]) ? explode('@', $resolved[$area->value])[0] : null;
|
||||
$decisions[] = [
|
||||
'area' => $area,
|
||||
'selected' => $selected,
|
||||
'options' => array_values(array_map(fn (array $option, string $key): array => [
|
||||
...$option,
|
||||
'key' => $key,
|
||||
'selected' => $key === $selected,
|
||||
'modules' => array_map(fn (string $module): string => $catalogue->modules()[$module]::definition()->label, $option['template']::modules()),
|
||||
], $options[$area->value] ?? [], array_keys($options[$area->value] ?? []))),
|
||||
];
|
||||
}
|
||||
|
||||
return $decisions;
|
||||
}
|
||||
|
||||
/**
|
||||
* The archetypes as known combinations (presets) the landlord can start from.
|
||||
*
|
||||
* @return array<string, array{label: string, templates: array<string, string>}>
|
||||
*/
|
||||
public function presets(): array
|
||||
{
|
||||
$presets = [];
|
||||
foreach (app(ProcessCatalogue::class)->models() as $key => $candidate) {
|
||||
if ($candidate::isLegacy() && in_array(IntakeKind::from($this->intake), $candidate::intakes(), true)) {
|
||||
$presets[$key] = ['label' => $candidate::label(), 'templates' => $candidate::presetTemplates()];
|
||||
}
|
||||
}
|
||||
|
||||
return $presets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses the template of an area. Switches of steps that drop out of the course are removed from the draft; the
|
||||
* consequences are listed by templateImpacts() before anything is saved.
|
||||
*/
|
||||
public function chooseTemplate(string $area, string $key): void
|
||||
{
|
||||
$model = $this->model();
|
||||
$option = app(ChannelProcessConfiguration::class)->templateOptions($this->record, $model, $this->capabilityDraft)[$area][$key] ?? null;
|
||||
if ($option === null || ! $option['admissible']) {
|
||||
return;
|
||||
}
|
||||
$this->acknowledge = false;
|
||||
$this->drafts[$this->intake]['templates'] = [...app(ChannelProcessConfiguration::class)->templatesOf($model, $this->draft()), $area => $key];
|
||||
$this->drafts[$this->intake]['templates'] = array_map(fn (string $reference): string => explode('@', $reference)[0], $this->drafts[$this->intake]['templates']);
|
||||
$modules = $model->modules($this->drafts[$this->intake]['variant'], $this->drafts[$this->intake]['templates']);
|
||||
$this->drafts[$this->intake]['steps'] = array_intersect_key($this->drafts[$this->intake]['steps'], array_flip($modules));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves from a fixed archetype to the base process with the combination the archetype stands for. Switches and settings
|
||||
* stay as they are; what contradicts the templates shows as a conflict that has to be confirmed.
|
||||
*/
|
||||
public function applyPreset(string $archetype): void
|
||||
{
|
||||
$presets = $this->presets();
|
||||
$base = app(ProcessCatalogue::class)->model(ExternalBookingModel::key());
|
||||
if (! isset($presets[$archetype]) || ! in_array(IntakeKind::from($this->intake), $base::intakes(), true)) {
|
||||
return;
|
||||
}
|
||||
$this->acknowledge = false;
|
||||
$this->drafts[$this->intake]['model'] = $base::key();
|
||||
$this->drafts[$this->intake]['variant'] = 'standard';
|
||||
$this->drafts[$this->intake]['templates'] = $presets[$archetype]['templates'];
|
||||
$this->drafts[$this->intake]['steps'] = array_intersect_key($this->drafts[$this->intake]['steps'], array_flip($base->modules('standard', $presets[$archetype]['templates'])));
|
||||
}
|
||||
|
||||
/**
|
||||
* What the draft's change of templates means (modules, responsibilities, stored switches and settings).
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function templateImpacts(): array
|
||||
{
|
||||
return app(ConfigurationImpact::class)->ofTemplates($this->record, IntakeKind::from($this->intake), $this->draft());
|
||||
}
|
||||
|
||||
public function chooseModel(string $model): void
|
||||
@@ -149,9 +270,13 @@ public function chooseModel(string $model): void
|
||||
return;
|
||||
}
|
||||
$this->acknowledge = false;
|
||||
// Leaving an archetype for a model with slots keeps its combination as the starting point of the templates.
|
||||
$previous = app(ProcessCatalogue::class)->model($this->drafts[$this->intake]['model']);
|
||||
$this->drafts[$this->intake]['model'] = $model;
|
||||
$this->drafts[$this->intake]['variant'] = 'standard';
|
||||
$this->drafts[$this->intake]['steps'] = [];
|
||||
$this->drafts[$this->intake]['templates'] = $this->model()->slots() === [] ? [] : $previous::presetTemplates();
|
||||
// Switches of steps the new course still has stay; only those that have no counterpart there drop out.
|
||||
$this->drafts[$this->intake]['steps'] = array_intersect_key($this->drafts[$this->intake]['steps'], array_flip($this->model()->modules('standard', $this->drafts[$this->intake]['templates'])));
|
||||
}
|
||||
|
||||
public function model(): ProcessModel
|
||||
|
||||
@@ -67,7 +67,7 @@ public function mount(int|string $record): void
|
||||
if ($this->draft === []) {
|
||||
$current = app(ChannelProcessConfiguration::class)->current($this->record, IntakeKind::from($this->intake));
|
||||
$stored = (array) (($this->record->process_overrides ?? [])[$this->intake] ?? []);
|
||||
$this->draft = ['model' => $current['model'], 'variant' => $current['variant'], 'steps' => (array) ($stored['steps'] ?? []), 'settings' => []];
|
||||
$this->draft = ['model' => $current['model'], 'variant' => $current['variant'], 'steps' => (array) ($stored['steps'] ?? []), 'templates' => $current['templates'], 'settings' => []];
|
||||
}
|
||||
$this->scenario = (string) array_key_first($this->scenarios());
|
||||
$this->resetInputs();
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Models\Channel;
|
||||
use App\Process\Models\ExternalBookingModel;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Models\Responsibilities;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
|
||||
/**
|
||||
* What the channel configurator offers and checks (docs/Prozessarchitektur/Architektur/03): per channel and intake
|
||||
@@ -39,7 +43,7 @@ final class ChannelProcessConfiguration
|
||||
'arrival.info' => ['performer' => ['field' => 'guest_messages', 'setting' => ProcessSetting::GuestMessages], 'parameters' => [ProcessSetting::ArrivalInfoDaysBefore]],
|
||||
];
|
||||
|
||||
public function __construct(private ProcessCatalogue $catalogue) {}
|
||||
public function __construct(private ProcessCatalogue $catalogue, private TemplateComposer $composer) {}
|
||||
|
||||
/**
|
||||
* The intake kinds the channel delivers.
|
||||
@@ -134,20 +138,103 @@ public function admissibleModels(Channel $channel, IntakeKind $intake, ?array $c
|
||||
return array_map(fn (array $option): ProcessModel => $option['model'], array_filter($this->modelOptions($channel, $intake, $capabilityDraft), fn (array $option): bool => $option['admissible']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Every function template of each slot of the model with whether this channel fits it and – if not – why. The
|
||||
* portal's confirmed capabilities decide; an unknown capability is never taken as proven (shown as "please confirm").
|
||||
*
|
||||
* @param array<string, bool|string|null>|null $capabilityDraft
|
||||
* @return array<string, array<string, array{template: class-string<FunctionTemplate>, admissible: bool, restrictions: list<Restriction>, hints: list<string>, unconfirmed: list<string>}>> area value => template key => option
|
||||
*/
|
||||
public function templateOptions(Channel $channel, ProcessModel $model, ?array $capabilityDraft = null): array
|
||||
{
|
||||
$capabilities = app(ChannelCapabilities::class)->resolve($channel, $capabilityDraft);
|
||||
$options = [];
|
||||
foreach ($model->slots() as $area) {
|
||||
foreach ($this->catalogue->templates($area) as $key => $class) {
|
||||
$restrictions = $hints = $unconfirmed = [];
|
||||
foreach ($class::capabilityRequirements() as $capability => $required) {
|
||||
$actual = $capabilities[$capability] ?? null;
|
||||
$definition = ChannelCapabilities::definitions()[$capability];
|
||||
if ($actual === null || ! $actual->isKnown()) {
|
||||
$hints[] = $definition['label'].' ist noch nicht bekannt – bitte bestätigen.';
|
||||
$unconfirmed[] = $capability;
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($actual->source !== Capability::CONFIRMED) {
|
||||
$unconfirmed[] = $capability;
|
||||
$hints[] = $definition['label'].' gilt nur als „'.($actual->source === Capability::SUGGESTED ? 'Vorschlag des Kanalprofils' : 'abgeleitet').'“, nicht als bestätigt.';
|
||||
}
|
||||
if ($actual->value !== $required) {
|
||||
$other = collect($this->catalogue->templates($area))->first(fn (string $candidate): bool => $candidate !== $class && collect($candidate::capabilityRequirements())->every(fn (bool $value, string $name): bool => ($capabilities[$name] ?? null)?->value === $value));
|
||||
$restrictions[] = new Restriction(
|
||||
Restriction::CAPABILITY,
|
||||
'„'.$class::label().'“ setzt voraus: „'.$definition['question'].'“ – '.($required ? 'ja' : 'nein').'. Für diesen Kanal gilt aber '.($actual->value ? 'ja' : 'nein').' ('.$actual->sourceLabel().').',
|
||||
$other ? $other::label() : null,
|
||||
'Wenn das nicht stimmt: oben bei „Was kann dieses Portal?“ „'.$definition['label'].'“ auf '.($required ? 'ja' : 'nein').' stellen und bestätigen.',
|
||||
);
|
||||
}
|
||||
}
|
||||
$options[$area->value][$key] = ['template' => $class, 'admissible' => $restrictions === [], 'restrictions' => $restrictions, 'hints' => $hints, 'unconfirmed' => $unconfirmed];
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* The templates in force for new cases of the channel and intake kind (key@version per area): the saved choice of a
|
||||
* model with slots, otherwise the combination a legacy archetype reproduces (empty when there is none).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function currentTemplates(Channel $channel, IntakeKind $intake): array
|
||||
{
|
||||
$current = $this->current($channel, $intake);
|
||||
$model = $this->catalogue->model($current['model']);
|
||||
|
||||
if ($model->slots() !== []) {
|
||||
return $this->composer->resolve($model, $current['templates']);
|
||||
}
|
||||
|
||||
return $model::presetTemplates() === [] ? [] : $this->composer->resolve($this->catalogue->model(ExternalBookingModel::key()), $model::presetTemplates());
|
||||
}
|
||||
|
||||
/**
|
||||
* The templates a draft uses for the model slots (chosen ones, otherwise the model defaults) as key@version.
|
||||
*
|
||||
* @param array<string, mixed> $draft
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function templatesOf(ProcessModel $model, array $draft): array
|
||||
{
|
||||
return $this->composer->resolve($model, (array) ($draft['templates'] ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stored settings of the channel that the chosen model fixes differently: saving the model would silently override
|
||||
* them (they would stay stored but not take effect). They are listed so that the landlord confirms their removal.
|
||||
*
|
||||
* @param array<string, string> $templates area => template key chosen in the draft (templates fix responsibilities just like models)
|
||||
* @return list<array{setting: ProcessSetting, stored: string, fixed: string, text: string}>
|
||||
*/
|
||||
public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey): array
|
||||
public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey, array $templates = []): array
|
||||
{
|
||||
if (! $this->catalogue->hasModel($modelKey)) {
|
||||
return [];
|
||||
}
|
||||
$stored = (array) (($channel->process_overrides ?? [])[$intake->value] ?? []);
|
||||
$conflicts = [];
|
||||
foreach ($this->catalogue->model($modelKey)::fixes() as $key => $fixed) {
|
||||
$model = $this->catalogue->model($modelKey);
|
||||
$fixes = $model::fixes();
|
||||
$fixedBy = array_fill_keys(array_keys($fixes), 'Das Modell „'.$modelKey.'“');
|
||||
foreach ($this->composer->classes($this->composer->resolve($model, $templates)) as $class) {
|
||||
foreach ($class::fixes() as $key => $fixed) {
|
||||
$fixes[$key] = $fixed;
|
||||
$fixedBy[$key] = 'Die Schablone „'.$class::label().'“';
|
||||
}
|
||||
}
|
||||
foreach ($fixes as $key => $fixed) {
|
||||
$setting = ProcessSetting::tryFrom($key);
|
||||
$value = $setting?->normalize($stored[$key] ?? null);
|
||||
$fixedValue = $setting?->normalize($fixed) ?? $fixed;
|
||||
@@ -155,7 +242,7 @@ public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey
|
||||
continue;
|
||||
}
|
||||
$conflicts[] = ['setting' => $setting, 'stored' => $setting->describe($value), 'fixed' => $setting->describe($fixedValue),
|
||||
'text' => $setting->question().' Bisher eingestellt: „'.$setting->describe($value).'“. Das Modell „'.$modelKey.'“ legt fest: „'.$setting->describe($fixedValue).'“.'];
|
||||
'text' => $setting->question().' Bisher eingestellt: „'.$setting->describe($value).'“. '.$fixedBy[$key].' legt fest: „'.$setting->describe($fixedValue).'“.'];
|
||||
}
|
||||
|
||||
// Stored responsibilities the model does not allow (variable ones, not fixed through fixes()) are just as stale.
|
||||
@@ -171,6 +258,14 @@ public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey
|
||||
'text' => $setting->question().' Bisher eingestellt: „'.$setting->describe($value).'“. Das Modell „'.$modelKey.'“ erlaubt: „'.$allowed.'“.'];
|
||||
}
|
||||
|
||||
// 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).'“.'];
|
||||
}
|
||||
|
||||
return $conflicts;
|
||||
}
|
||||
|
||||
@@ -184,7 +279,7 @@ public function conflicts(Channel $channel, IntakeKind $intake, string $modelKey
|
||||
public function withoutOverriddenSettings(Channel $channel, IntakeKind $intake, array $draft): array
|
||||
{
|
||||
$stored = (array) (($channel->process_overrides ?? [])[$intake->value] ?? []);
|
||||
foreach ($this->conflicts($channel, $intake, (string) ($draft['model'] ?? '')) as $conflict) {
|
||||
foreach ($this->conflicts($channel, $intake, (string) ($draft['model'] ?? ''), (array) ($draft['templates'] ?? [])) as $conflict) {
|
||||
$key = $conflict['setting']->value;
|
||||
$value = $draft['settings'][$key] ?? null;
|
||||
if (array_key_exists($key, (array) ($draft['settings'] ?? [])) && (string) $conflict['setting']->normalize($value) === (string) $conflict['setting']->normalize($stored[$key] ?? null)) {
|
||||
@@ -199,19 +294,19 @@ public function withoutOverriddenSettings(Channel $channel, IntakeKind $intake,
|
||||
* The model a new case of this channel and intake would follow now: the chosen one, or the one derived from the
|
||||
* settings as before (marked as derived).
|
||||
*
|
||||
* @return array{model: string, variant: string, derived: bool}
|
||||
* @return array{model: string, variant: string, derived: bool, templates: array<string, string>}
|
||||
*/
|
||||
public function current(Channel $channel, IntakeKind $intake): array
|
||||
{
|
||||
$config = ProcessPlan::configurationOf($channel, $intake);
|
||||
if (filled($config['model'] ?? null) && $this->catalogue->hasModel((string) $config['model'])) {
|
||||
return ['model' => (string) $config['model'], 'variant' => (string) ($config['variant'] ?? 'standard'), 'derived' => false];
|
||||
return ['model' => (string) $config['model'], 'variant' => (string) ($config['variant'] ?? 'standard'), 'derived' => false, 'templates' => (array) ($config['templates'] ?? [])];
|
||||
}
|
||||
|
||||
$property = $channel->property;
|
||||
$profile = app(ProcessSettings::class)->resolve($property, $channel, $intake);
|
||||
|
||||
return ['model' => $this->catalogue->derivedModel($profile), 'variant' => 'standard', 'derived' => true];
|
||||
return ['model' => $this->catalogue->derivedModel($profile), 'variant' => 'standard', 'derived' => true, 'templates' => []];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,16 +360,23 @@ public function modeOptions(string $module): array
|
||||
* with whether it takes part and why not, who carries it out and how.
|
||||
*
|
||||
* @param array<string, mixed> $draft model, variant, steps, settings of channels.process_overrides[intake]
|
||||
* @return list<array{module: string, label: string, phase: string, on: bool, reason: ?string, performer: ?string, mode: ?string, toggle: string, tester_only: bool, inserted: bool}>
|
||||
* @return list<array{module: string, label: string, phase: string, on: bool, reason: ?string, performer: ?string, mode: ?string, toggle: string, tester_only: bool, inserted: bool, template: ?string}>
|
||||
*/
|
||||
public function preview(Channel $channel, IntakeKind $intake, array $draft): array
|
||||
{
|
||||
$model = $this->catalogue->model((string) ($draft['model'] ?? $this->current($channel, $intake)['model']));
|
||||
$variant = (string) ($draft['variant'] ?? 'standard');
|
||||
$profile = $this->profileWith($channel, $intake, $draft);
|
||||
$standard = $model->modules('standard');
|
||||
$templates = $this->templatesOf($model, $draft);
|
||||
$standard = $model->modules('standard', $templates);
|
||||
$owners = [];
|
||||
foreach ($this->composer->classes($templates) as $class) {
|
||||
foreach ($class::modules() as $module) {
|
||||
$owners[$module] = $class::label();
|
||||
}
|
||||
}
|
||||
$rows = [];
|
||||
foreach ($model->modules($variant) as $key) {
|
||||
foreach ($model->modules($variant, $templates) as $key) {
|
||||
$class = $this->catalogue->modules()[$key];
|
||||
$definition = $class::definition();
|
||||
$on = ($draft['steps'][$key]['on'] ?? true) !== false || ! $definition->isOptional();
|
||||
@@ -296,7 +398,7 @@ public function preview(Channel $channel, IntakeKind $intake, array $draft): arr
|
||||
default => $definition->performers[0] ?? null,
|
||||
};
|
||||
$rows[] = ['module' => $key, 'label' => $definition->label, 'phase' => $definition->phase, 'on' => $on && $reason === null, 'reason' => $reason,
|
||||
'performer' => $performer, 'mode' => $mode, 'toggle' => $definition->toggle, 'tester_only' => $definition->isTesterOnly(), 'inserted' => ! in_array($key, $standard, true)];
|
||||
'performer' => $performer, 'mode' => $mode, 'toggle' => $definition->toggle, 'tester_only' => $definition->isTesterOnly(), 'inserted' => ! in_array($key, $standard, true), 'template' => $owners[$key] ?? null];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
@@ -332,8 +434,9 @@ public function problems(Channel $channel, IntakeKind $intake, array $draft, boo
|
||||
$problems[] = 'Die Variante „'.$variant->label.'“ ist nur im Prozess-Tester verwendbar und kann nicht gespeichert werden.';
|
||||
}
|
||||
|
||||
$templates = $this->templatesOf($model, $draft);
|
||||
foreach ((array) ($draft['steps'] ?? []) as $module => $step) {
|
||||
if (! $this->catalogue->hasModule($module) || ! in_array($module, $model->modules($variant->key), true)) {
|
||||
if (! $this->catalogue->hasModule($module) || ! in_array($module, $model->modules($variant->key, $templates), true)) {
|
||||
$problems[] = "Der Schritt {$module} gehört nicht zu diesem Modell.";
|
||||
|
||||
continue;
|
||||
@@ -360,7 +463,41 @@ public function problems(Channel $channel, IntakeKind $intake, array $draft, boo
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($problems));
|
||||
return array_values(array_unique([...$problems, ...$this->templateProblems($channel, $model, $draft)]));
|
||||
}
|
||||
|
||||
/**
|
||||
* What is wrong with the function templates of a draft: composition, the confirmed capabilities of the portal and
|
||||
* responsibilities set by hand that contradict a template.
|
||||
*
|
||||
* @param array<string, mixed> $draft
|
||||
* @return list<string>
|
||||
*/
|
||||
private function templateProblems(Channel $channel, ProcessModel $model, array $draft): array
|
||||
{
|
||||
$variant = (string) ($draft['variant'] ?? 'standard');
|
||||
$problems = $this->composer->problems($model, (array) ($draft['templates'] ?? []), $variant);
|
||||
if ($model->slots() === []) {
|
||||
return $problems;
|
||||
}
|
||||
$capabilities = (array) ($draft['capabilities'] ?? []) ?: null;
|
||||
$options = $this->templateOptions($channel, $model, $capabilities);
|
||||
foreach ($this->composer->classes($this->templatesOf($model, $draft)) as $area => $class) {
|
||||
foreach ($options[$area][$class::key()]['restrictions'] ?? [] as $restriction) {
|
||||
$problems[] = $restriction->text();
|
||||
}
|
||||
$setting = TemplateArea::from($area)->setting();
|
||||
$value = $setting->normalize($draft['settings'][$setting->value] ?? null);
|
||||
if ($value !== null && (string) $value !== $class::responsibility()->value) {
|
||||
$problems[] = $setting->question().' „'.$setting->describe($value).'“ widerspricht der Schablone „'.$class::label().'“ ('.$setting->describe($class::responsibility()->value).').';
|
||||
}
|
||||
}
|
||||
$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.';
|
||||
}
|
||||
|
||||
return $problems;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,7 +510,7 @@ public function profileWith(Channel $channel, IntakeKind $intake, array $draft):
|
||||
$draft = $this->withoutOverriddenSettings($channel, $intake, $draft);
|
||||
$preview = clone $channel;
|
||||
$overrides = (array) ($channel->process_overrides ?? []);
|
||||
$overrides[$intake->value] = [...array_filter((array) ($draft['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== ''), 'model' => $draft['model'] ?? null, 'variant' => $draft['variant'] ?? 'standard', 'steps' => (array) ($draft['steps'] ?? [])];
|
||||
$overrides[$intake->value] = [...array_filter((array) ($draft['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== ''), 'model' => $draft['model'] ?? null, 'variant' => $draft['variant'] ?? 'standard', 'steps' => (array) ($draft['steps'] ?? []), 'templates' => (array) ($draft['templates'] ?? [])];
|
||||
$preview->setAttribute('process_overrides', $overrides);
|
||||
|
||||
return app(ProcessSettings::class)->resolve($channel->property, $preview, $intake);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Models\Channel;
|
||||
use App\Process\Modules\ModuleDefinition;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
|
||||
/**
|
||||
* Rule-based comparison of a configuration draft (docs/Prozessarchitektur/MODUL_KONFIGURATIONSMATRIX.md §5): for every
|
||||
@@ -15,7 +16,7 @@
|
||||
*/
|
||||
final class ConfigurationImpact
|
||||
{
|
||||
public function __construct(private ProcessCatalogue $catalogue, private ChannelProcessConfiguration $configuration) {}
|
||||
public function __construct(private ProcessCatalogue $catalogue, private ChannelProcessConfiguration $configuration, private TemplateComposer $composer) {}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $draft
|
||||
@@ -61,6 +62,63 @@ public function of(Channel $channel, IntakeKind $intake, array $draft): array
|
||||
return $impacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a change of function templates means (docs/Prozessarchitektur/SCHABLONEN.md): per changed area the modules that
|
||||
* drop out, join or stay, the responsibility that changes, the stored switches and settings that no longer apply and
|
||||
* what the new template still needs or does not build yet. Compared with the templates in force for new cases. Pure:
|
||||
* nothing is changed, nothing is dropped silently – the landlord sees every consequence before saving.
|
||||
*
|
||||
* @param array<string, mixed> $draft
|
||||
* @return list<array{area: string, from: ?string, to: string, removed: list<string>, added: list<string>, kept: list<string>, responsibility: ?array{from: string, to: string}, switches_lost: list<string>, settings_replaced: list<string>, needs: list<string>, extensions: list<string>}>
|
||||
*/
|
||||
public function ofTemplates(Channel $channel, IntakeKind $intake, array $draft): array
|
||||
{
|
||||
$model = $this->catalogue->model((string) ($draft['model'] ?? ''));
|
||||
if ($model->slots() === []) {
|
||||
return [];
|
||||
}
|
||||
$current = $this->configuration->currentTemplates($channel, $intake);
|
||||
$target = $this->composer->resolve($model, (array) ($draft['templates'] ?? []));
|
||||
$stored = (array) (($channel->process_overrides ?? [])[$intake->value] ?? []);
|
||||
$labelOf = fn (string $module): string => ($this->catalogue->hasModule($module) ? $this->catalogue->modules()[$module]::definition()->label : $module);
|
||||
$impacts = [];
|
||||
|
||||
foreach ($model->slots() as $area) {
|
||||
$from = $current[$area->value] ?? null;
|
||||
$to = $target[$area->value] ?? null;
|
||||
$toClass = $to === null ? null : $this->catalogue->templateClass($to);
|
||||
if ($toClass === null || $from === $to) {
|
||||
continue;
|
||||
}
|
||||
$fromClass = $from === null ? null : $this->catalogue->templateClass($from);
|
||||
$before = $fromClass === null ? [] : $fromClass::modules();
|
||||
$after = $toClass::modules();
|
||||
$removed = array_values(array_diff($before, $after));
|
||||
$setting = $area->setting();
|
||||
$storedValue = $setting->normalize($stored[$setting->value] ?? null);
|
||||
|
||||
$impacts[] = [
|
||||
'area' => $area->label(),
|
||||
'from' => $fromClass === null ? null : $fromClass::label(),
|
||||
'to' => $toClass::label(),
|
||||
'removed' => array_map($labelOf, $removed),
|
||||
'added' => array_map($labelOf, array_values(array_diff($after, $before))),
|
||||
'kept' => array_map($labelOf, array_values(array_intersect($after, $before))),
|
||||
'responsibility' => $fromClass !== null && $fromClass::responsibility() !== $toClass::responsibility()
|
||||
? ['from' => $setting->describe($fromClass::responsibility()->value), 'to' => $setting->describe($toClass::responsibility()->value)]
|
||||
: null,
|
||||
'switches_lost' => array_map($labelOf, array_values(array_filter($removed, fn (string $module): bool => ($stored['steps'][$module]['on'] ?? true) === false))),
|
||||
'settings_replaced' => $storedValue !== null && (string) $storedValue !== $toClass::responsibility()->value
|
||||
? [$setting->question().' Bisher gespeichert: „'.$setting->describe($storedValue).'“, künftig durch die Schablone: „'.$setting->describe($toClass::responsibility()->value).'“. Der gespeicherte Wert muss beim Speichern ausdrücklich entfernt werden.']
|
||||
: [],
|
||||
'needs' => array_map(fn (string $result): string => 'Voraussetzung: '.$result, $toClass::requires()),
|
||||
'extensions' => $toClass::extensions(),
|
||||
];
|
||||
}
|
||||
|
||||
return $impacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* The results that stay necessary although the step is off: what the steps depending on it still need.
|
||||
*
|
||||
|
||||
@@ -48,6 +48,16 @@ public static function responsibilities(): Responsibilities
|
||||
);
|
||||
}
|
||||
|
||||
public static function isLegacy(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function presetTemplates(): array
|
||||
{
|
||||
return ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'];
|
||||
}
|
||||
|
||||
public static function fixes(): array
|
||||
{
|
||||
return ['payments' => 'landlord', 'documents' => 'landlord'];
|
||||
|
||||
@@ -48,6 +48,16 @@ public static function responsibilities(): Responsibilities
|
||||
);
|
||||
}
|
||||
|
||||
public static function isLegacy(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function presetTemplates(): array
|
||||
{
|
||||
return ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own'];
|
||||
}
|
||||
|
||||
public static function fixes(): array
|
||||
{
|
||||
return ['payments' => 'portal', 'documents' => 'landlord'];
|
||||
|
||||
@@ -48,6 +48,16 @@ public static function responsibilities(): Responsibilities
|
||||
);
|
||||
}
|
||||
|
||||
public static function isLegacy(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function presetTemplates(): array
|
||||
{
|
||||
return ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.external'];
|
||||
}
|
||||
|
||||
public static function fixes(): array
|
||||
{
|
||||
return ['payments' => 'portal', 'documents' => 'portal'];
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Models;
|
||||
|
||||
use App\Enums\CaseType;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
|
||||
/**
|
||||
* The base process of a booking that is already binding at a portal (E-036), with slots for the function templates
|
||||
* of collection and contract documentation. It replaces the fixed combinations A3/A4/A5: who collects and who provides
|
||||
* the contract documents are chosen independently (docs/Prozessarchitektur/SCHABLONEN.md); the case type stays a derived
|
||||
* classification. The course is the one A3–A5 share, with the slots at the positions of the modules they replace.
|
||||
*/
|
||||
class ExternalBookingModel extends ProcessModel
|
||||
{
|
||||
/** Results the base process provides to the templates. */
|
||||
public const PROVIDES = ['case.recorded', 'guest.identified', 'binding.portal_total'];
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'external.booking';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Extern verbindliche Portalbuchung';
|
||||
}
|
||||
|
||||
public static function description(): string
|
||||
{
|
||||
return 'Das Portal bestätigt verbindlich. Wer das Geld einzieht und wer die Vertragsunterlagen bereitstellt, wählen Sie unabhängig voneinander; die Einzelschritte bleiben einstellbar.';
|
||||
}
|
||||
|
||||
public static function caseTypes(): array
|
||||
{
|
||||
return [CaseType::A3, CaseType::A4, CaseType::A5];
|
||||
}
|
||||
|
||||
public static function intakes(): array
|
||||
{
|
||||
return [IntakeKind::Booking];
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection and contract documentation are chosen by template; guest communication is limited by the portal's
|
||||
* confirmed capability, not by a fixed model.
|
||||
*/
|
||||
public static function responsibilities(): Responsibilities
|
||||
{
|
||||
return Responsibilities::of(
|
||||
fixed: ['contract' => Responsibility::Portal],
|
||||
variable: [
|
||||
'collection' => [Responsibility::Landlord, Responsibility::Portal],
|
||||
'contract_documents' => [Responsibility::Landlord, Responsibility::Portal],
|
||||
'guest_messages' => [Responsibility::Landlord, Responsibility::Portal],
|
||||
'supplementary_documents' => [Responsibility::Landlord, Responsibility::Nobody],
|
||||
'local_services' => [Responsibility::Landlord],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public static function providedResults(): array
|
||||
{
|
||||
return self::PROVIDES;
|
||||
}
|
||||
|
||||
public static function defaultTemplates(): array
|
||||
{
|
||||
return [
|
||||
TemplateArea::Collection->value => 'collection.own',
|
||||
TemplateArea::ContractDocuments->value => 'contract_docs.own',
|
||||
];
|
||||
}
|
||||
|
||||
public function steps(): array
|
||||
{
|
||||
return [
|
||||
Step::module('intake.record'),
|
||||
Step::module('guest.details'),
|
||||
Step::point(Point::AfterGuestIdentified),
|
||||
Step::module('binding.portal'),
|
||||
Step::module('portal.confirmation'),
|
||||
Step::point(Point::AfterBinding),
|
||||
Step::slot(TemplateArea::ContractDocuments),
|
||||
Step::module('channels.block'),
|
||||
Step::slot(TemplateArea::Collection),
|
||||
Step::module('case.tasks'),
|
||||
Step::module('change.proposal'),
|
||||
Step::module('arrival.details'),
|
||||
Step::module('arrival.info'),
|
||||
Step::module('guest.data_request'),
|
||||
Step::point(Point::BeforeStay),
|
||||
Step::module('stay'),
|
||||
Step::module('review.request'),
|
||||
Step::point(Point::BeforeSettlement),
|
||||
Step::module('case.closure'),
|
||||
Step::module('case.settlement'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
use App\Enums\CaseType;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
|
||||
/**
|
||||
* A centrally defined, versioned process model (docs/Prozessarchitektur/Architektur/02 §5): its course of steps with
|
||||
@@ -74,17 +76,74 @@ public function variant(string $key): ?Variant
|
||||
}
|
||||
|
||||
/**
|
||||
* The modules of the course in order, with the variant's modules at their points.
|
||||
* The function template areas this model offers a slot for (empty: the model's course is fixed).
|
||||
*
|
||||
* @return list<TemplateArea>
|
||||
*/
|
||||
public function slots(): array
|
||||
{
|
||||
return array_values(array_map(fn (Step $step): TemplateArea => $step->slot, array_filter($this->steps(), fn (Step $step): bool => $step->isSlot())));
|
||||
}
|
||||
|
||||
/**
|
||||
* The results the base course provides to the templates of its slots (see FunctionTemplate::requires()).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public function modules(?string $variant = 'standard'): array
|
||||
public static function providedResults(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The template (key) every slot gets when none was chosen: area value => template key.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function defaultTemplates(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the model is kept for compatibility (existing channels and frozen plans) and no longer offered as a
|
||||
* choice: its combination is a preset of a composable model.
|
||||
*/
|
||||
public static function isLegacy(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The template combination that reproduces this legacy model (area value => template key), or empty.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function presetTemplates(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The modules of the course in order, with the variant's modules at their points and the chosen templates' modules
|
||||
* at their slots.
|
||||
*
|
||||
* @param array<string, string> $templates area value => template key or key@version (missing areas: the default)
|
||||
* @return list<string>
|
||||
*/
|
||||
public function modules(?string $variant = 'standard', array $templates = []): array
|
||||
{
|
||||
$chosen = $this->variant($variant ?? 'standard');
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$modules = [];
|
||||
foreach ($this->steps() as $step) {
|
||||
if ($step->isPoint()) {
|
||||
array_push($modules, ...($chosen?->modulesAt($step->point) ?? []));
|
||||
} elseif ($step->isSlot()) {
|
||||
$reference = $templates[$step->slot->value] ?? static::defaultTemplates()[$step->slot->value] ?? null;
|
||||
if ($reference !== null && ($class = $catalogue->templateClass($reference)) !== null) {
|
||||
array_push($modules, ...$class::modules());
|
||||
}
|
||||
} else {
|
||||
$modules[] = $step->module;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Process\Models;
|
||||
|
||||
use App\Process\Templates\TemplateArea;
|
||||
|
||||
/**
|
||||
* One entry of a model's course: a module or an extension point where variants insert modules.
|
||||
* One entry of a model's course: a module, an extension point where variants insert modules, or a slot where the
|
||||
* function template chosen for its area puts its modules.
|
||||
*/
|
||||
final readonly class Step
|
||||
{
|
||||
private function __construct(public ?string $module, public ?Point $point) {}
|
||||
private function __construct(public ?string $module, public ?Point $point, public ?TemplateArea $slot = null) {}
|
||||
|
||||
public static function module(string $key): self
|
||||
{
|
||||
@@ -19,8 +22,18 @@ public static function point(Point $point): self
|
||||
return new self(null, $point);
|
||||
}
|
||||
|
||||
public static function slot(TemplateArea $area): self
|
||||
{
|
||||
return new self(null, null, $area);
|
||||
}
|
||||
|
||||
public function isPoint(): bool
|
||||
{
|
||||
return $this->point !== null;
|
||||
}
|
||||
|
||||
public function isSlot(): bool
|
||||
{
|
||||
return $this->slot !== null;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Modules\ProcessModule;
|
||||
use App\Process\Modules\RunsAutomatically;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
@@ -97,6 +99,53 @@ public function models(): array
|
||||
return $models;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, class-string<FunctionTemplate>>>
|
||||
*/
|
||||
public function templateVersions(): array
|
||||
{
|
||||
return (array) config('process.templates', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* The class of a template named by key (latest version) or key@version; null when it is not registered.
|
||||
*
|
||||
* @return class-string<FunctionTemplate>|null
|
||||
*/
|
||||
public function templateClass(string $reference): ?string
|
||||
{
|
||||
[$key, $version] = array_pad(explode('@', $reference, 2), 2, null);
|
||||
$versions = $this->templateVersions()[$key] ?? [];
|
||||
if ($versions === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $versions[$version === null ? max(array_keys($versions)) : (int) $version] ?? null;
|
||||
}
|
||||
|
||||
public function hasTemplate(string $reference): bool
|
||||
{
|
||||
return $this->templateClass($reference) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The latest version of every template, optionally of one area.
|
||||
*
|
||||
* @return array<string, class-string<FunctionTemplate>>
|
||||
*/
|
||||
public function templates(?TemplateArea $area = null): array
|
||||
{
|
||||
$templates = [];
|
||||
foreach (array_keys($this->templateVersions()) as $key) {
|
||||
$class = $this->templateClass($key);
|
||||
if ($area === null || $class::area() === $area) {
|
||||
$templates[$key] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* The model a case follows when nobody chose one: derived from its frozen profile exactly as the v0.11 course
|
||||
* branched (legacy mapping, docs/Prozessarchitektur/Architektur/06 §4).
|
||||
@@ -151,12 +200,42 @@ public function problems(): array
|
||||
$problems[] = 'Zyklische harte Abhängigkeit: '.implode(' → ', $cycle);
|
||||
}
|
||||
|
||||
foreach ($this->templateVersions() as $key => $versions) {
|
||||
foreach ($versions as $version => $class) {
|
||||
if ($class::key() !== $key || $class::version() !== $version) {
|
||||
$problems[] = "Schablone {$key}@{$version}: Klasse {$class} meldet ".$class::reference().'.';
|
||||
}
|
||||
foreach ($class::modules() as $module) {
|
||||
if (! $this->hasModule($module)) {
|
||||
$problems[] = "Schablone {$class::reference()}: Modul {$module} ist nicht registriert.";
|
||||
}
|
||||
}
|
||||
if (! in_array($class::area()->result(), $class::provides(), true)) {
|
||||
$problems[] = "Schablone {$class::reference()}: liefert das Ergebnis ihres Bereichs ({$class::area()->result()}) nicht.";
|
||||
}
|
||||
if ($class::fixes() === [] || array_keys($class::fixes()) !== [$class::area()->setting()->value]) {
|
||||
$problems[] = "Schablone {$class::reference()}: darf nur die Verantwortlichkeit ihres Bereichs festlegen.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->modelVersions() as $key => $versions) {
|
||||
foreach ($versions as $version => $class) {
|
||||
if ($class::key() !== $key || $class::version() !== $version) {
|
||||
$problems[] = "Modell {$key}@{$version}: Klasse {$class} meldet ".$class::key().'@'.$class::version().'.';
|
||||
}
|
||||
$model = app($class);
|
||||
foreach ($model->slots() as $area) {
|
||||
$default = $class::defaultTemplates()[$area->value] ?? null;
|
||||
if ($default === null || ! $this->hasTemplate($default) || $this->templateClass($default)::area() !== $area) {
|
||||
$problems[] = "Modell {$key}@{$version}: Platz {$area->value} hat keine gültige Standardschablone.";
|
||||
}
|
||||
}
|
||||
foreach ($class::presetTemplates() as $area => $reference) {
|
||||
if (! $this->hasTemplate($reference) || $this->templateClass($reference)::area()->value !== $area) {
|
||||
$problems[] = "Modell {$key}@{$version}: Voreinstellung {$area} nennt die Schablone {$reference} nicht (richtig).";
|
||||
}
|
||||
}
|
||||
foreach ($model->variants() as $variant) {
|
||||
foreach ($model->modules($variant->key) as $module) {
|
||||
if (! $this->hasModule($module)) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Models\Booking;
|
||||
use App\Models\Channel;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
use DomainException;
|
||||
|
||||
/**
|
||||
@@ -27,6 +28,7 @@ final class ProcessPlan
|
||||
* @param array<string, int> $modules module key => frozen version
|
||||
* @param array<string, array{on?: bool, mode?: ?string, performer?: ?string, params?: array<string, mixed>}> $steps
|
||||
* @param array<string, string> $labels module key => label at the time of freezing
|
||||
* @param array<string, string> $templates area => function template key@version the plan was composed with
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $model,
|
||||
@@ -37,6 +39,7 @@ public function __construct(
|
||||
public readonly string $source = self::DERIVED,
|
||||
public readonly array $labels = [],
|
||||
public readonly ?string $notice = null,
|
||||
public readonly array $templates = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -64,7 +67,7 @@ public static function derive(ProcessProfile $profile): self
|
||||
* Ablauf), when admissible for the case's type; otherwise the derived one with a notice. Tester-only variants or
|
||||
* modules are refused outside the process tester (decision E7).
|
||||
*
|
||||
* @param array<string, mixed> $configuration model, variant, steps of channels.process_overrides[intake]
|
||||
* @param array<string, mixed> $configuration model, variant, steps, templates of channels.process_overrides[intake]
|
||||
*/
|
||||
public static function freeze(ProcessProfile $profile, array $configuration, bool $sandbox = false): self
|
||||
{
|
||||
@@ -96,7 +99,16 @@ public static function freeze(ProcessProfile $profile, array $configuration, boo
|
||||
}
|
||||
}
|
||||
|
||||
return self::build($model, $variant, (array) ($configuration['steps'] ?? []), $sandbox ? self::TESTER : self::CONFIGURED);
|
||||
$templates = [];
|
||||
if ($model->slots() !== []) {
|
||||
$composer = app(TemplateComposer::class);
|
||||
$templates = $composer->resolve($model, (array) ($configuration['templates'] ?? []));
|
||||
if (($problems = $composer->problems($model, $templates, $variant)) !== []) {
|
||||
return self::derive($profile)->withNotice("Schablonen von {$chosen} nicht zulässig (".implode(' ', $problems).') – abgeleitetes Modell verwendet.');
|
||||
}
|
||||
}
|
||||
|
||||
return self::build($model, $variant, (array) ($configuration['steps'] ?? []), $sandbox ? self::TESTER : self::CONFIGURED, $templates);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,29 +122,30 @@ public static function configurationOf(?Channel $channel, IntakeKind $intake): a
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_intersect_key((array) (($channel->process_overrides ?? [])[$intake->value] ?? []), array_flip(['model', 'variant', 'steps']));
|
||||
return array_intersect_key((array) (($channel->process_overrides ?? [])[$intake->value] ?? []), array_flip(['model', 'variant', 'steps', 'templates']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $steps
|
||||
* @param array<string, string> $templates area => key@version
|
||||
*/
|
||||
private static function build(ProcessModel $model, string $variant, array $steps, string $source): self
|
||||
private static function build(ProcessModel $model, string $variant, array $steps, string $source, array $templates = []): self
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$modules = [];
|
||||
$labels = [];
|
||||
foreach ($model->modules($variant) as $key) {
|
||||
foreach ($model->modules($variant, $templates) as $key) {
|
||||
$class = $catalogue->modules()[$key];
|
||||
$modules[$key] = $class::version();
|
||||
$labels[$key] = $class::definition()->label;
|
||||
}
|
||||
|
||||
return new self($model::key(), $model::version(), $variant, $modules, array_intersect_key($steps, $modules), $source, $labels);
|
||||
return new self($model::key(), $model::version(), $variant, $modules, array_intersect_key($steps, $modules), $source, $labels, null, $templates);
|
||||
}
|
||||
|
||||
private function withNotice(string $notice): self
|
||||
{
|
||||
return new self($this->model, $this->modelVersion, $this->variant, $this->modules, $this->steps, $this->source, $this->labels, $notice);
|
||||
return new self($this->model, $this->modelVersion, $this->variant, $this->modules, $this->steps, $this->source, $this->labels, $notice, $this->templates);
|
||||
}
|
||||
|
||||
public function modelDefinition(): ProcessModel
|
||||
@@ -204,6 +217,7 @@ public function toArray(): array
|
||||
'source' => $this->source,
|
||||
'labels' => $this->labels,
|
||||
'notice' => $this->notice,
|
||||
'templates' => $this->templates === [] ? null : $this->templates,
|
||||
], fn (mixed $value): bool => $value !== null);
|
||||
}
|
||||
|
||||
@@ -221,6 +235,7 @@ public static function fromArray(array $data): self
|
||||
(string) ($data['source'] ?? self::DERIVED),
|
||||
(array) ($data['labels'] ?? []),
|
||||
isset($data['notice']) ? (string) $data['notice'] : null,
|
||||
array_map('strval', (array) ($data['templates'] ?? [])),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ final class ProcessProfile
|
||||
/** Fixed by the process model chosen for the channel (Architektur V2). */
|
||||
public const MODEL = 'model';
|
||||
|
||||
/** Fixed by a function template chosen for the channel (Schablonenkomposition). */
|
||||
public const TEMPLATE = 'template';
|
||||
|
||||
/** Fixed by the case type (A6), not settable. */
|
||||
public const CASE_TYPE = 'case_type';
|
||||
|
||||
@@ -53,7 +56,9 @@ public function __construct(
|
||||
|
||||
/**
|
||||
* The case type of a constellation: internal occasions are A6; requests are A1 (own way) or A2 (intermediary);
|
||||
* binding external bookings are A3–A5 by who handles documents and payments.
|
||||
* binding external bookings are A3–A5 by who handles documents and payments. Only a classification (labels, reports,
|
||||
* compatibility): the course follows the composed plan, and a combination without an archetype of its own –
|
||||
* collection by us, contract documents by the portal – is classified A3 (we collect), never by a new case type.
|
||||
*/
|
||||
public static function caseTypeFor(IntakeKind $intake, bool $viaChannel, Responsibility $documents, Responsibility $payments): CaseType
|
||||
{
|
||||
@@ -61,7 +66,7 @@ public static function caseTypeFor(IntakeKind $intake, bool $viaChannel, Respons
|
||||
IntakeKind::Internal => CaseType::A6,
|
||||
IntakeKind::Inquiry => $viaChannel ? CaseType::A2 : CaseType::A1,
|
||||
IntakeKind::Booking => match (true) {
|
||||
$documents === Responsibility::Portal => CaseType::A5,
|
||||
$documents === Responsibility::Portal && $payments === Responsibility::Portal => CaseType::A5,
|
||||
$payments === Responsibility::Portal => CaseType::A4,
|
||||
default => CaseType::A3,
|
||||
},
|
||||
@@ -193,6 +198,7 @@ public static function sourceLabel(string $source): string
|
||||
self::WEBSITE => 'Einstellung der eigenen Webseite',
|
||||
self::CASE_TYPE => 'fest für diese Vorgangsart',
|
||||
self::MODEL => 'festgelegt durch das gewählte Ablaufmodell',
|
||||
self::TEMPLATE => 'festgelegt durch die gewählte Funktionsschablone',
|
||||
'migration' => 'aus dem bisherigen Stand übernommen',
|
||||
default => 'Grundeinstellung',
|
||||
};
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
use App\Models\Property;
|
||||
use App\Models\Tenant;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
|
||||
/**
|
||||
* Resolves the effective process settings: built-in default → landlord default (tenant) → deviation of the property
|
||||
@@ -61,6 +63,14 @@ public function resolve(Property $property, ?Channel $channel, IntakeKind $intak
|
||||
}
|
||||
}
|
||||
|
||||
// Function templates chosen for the model's slots fix the responsibility of their area.
|
||||
foreach ($this->chosenTemplates($channel, $intake, $model) as $class) {
|
||||
foreach ($class::fixes() as $key => $fixed) {
|
||||
$values[$key] = $fixed;
|
||||
$sources[$key] = ProcessProfile::TEMPLATE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($intake === IntakeKind::Internal) {
|
||||
// Own use, private stays and blocks (A6): no rental documents, no payment reminders, no guest mails – fixed by
|
||||
// the case type, not by a setting.
|
||||
@@ -80,6 +90,21 @@ public function resolve(Property $property, ?Channel $channel, IntakeKind $intak
|
||||
return new ProcessProfile($intake, ProcessProfile::caseTypeFor($intake, $channel?->isPortal() ?? false, $documents, $payments), $values, $sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* The function templates in force for the chosen model's slots (chosen ones, otherwise the model's defaults).
|
||||
*
|
||||
* @return array<string, class-string<FunctionTemplate>>
|
||||
*/
|
||||
private function chosenTemplates(?Channel $channel, IntakeKind $intake, ?ProcessModel $model): array
|
||||
{
|
||||
if ($model === null || $model->slots() === []) {
|
||||
return [];
|
||||
}
|
||||
$composer = app(TemplateComposer::class);
|
||||
|
||||
return $composer->classes($composer->resolve($model, (array) (ProcessPlan::configurationOf($channel, $intake)['templates'] ?? [])));
|
||||
}
|
||||
|
||||
/**
|
||||
* The model chosen for the channel and intake kind (Kanal › Ablauf), when it is registered and fits the intake.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\Responsibility;
|
||||
|
||||
/**
|
||||
* The portal provides the binding contract documents to the guest. We create and send no contract of our own; the
|
||||
* evidence is the portal's confirmation. Whatever the portal's documents say about payments, our payment handling
|
||||
* follows the collection template – the two areas are independent.
|
||||
*/
|
||||
final class ExternalContractDocuments extends FunctionTemplate
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'contract_docs.external';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Externe Vertragsunterlagen';
|
||||
}
|
||||
|
||||
public static function purpose(): string
|
||||
{
|
||||
return 'Das Portal stellt dem Gast die verbindlichen Vertragsunterlagen bereit. Wir halten Buchungsdaten und den Nachweis der Portalbestätigung fest und versenden keinen eigenen Vertrag.';
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send', 'documents.booking_notice'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Portal;
|
||||
}
|
||||
|
||||
public static function capabilityRequirements(): array
|
||||
{
|
||||
return ['provides_contract_documents' => true];
|
||||
}
|
||||
|
||||
public static function provides(): array
|
||||
{
|
||||
return [TemplateArea::ContractDocuments->result(), 'contract.documents_by_portal'];
|
||||
}
|
||||
|
||||
public static function dimensions(): array
|
||||
{
|
||||
return [
|
||||
'Vertragsbedingungen' => 'Das Portal verantwortet Abschluss und Bedingungen.',
|
||||
'Erstellung' => 'Durch das Portal.',
|
||||
'Bereitstellung / Versand' => 'Durch das Portal; wir senden keinen Vertrag. Die Buchungsinformation bleibt einzeln einstellbar.',
|
||||
'Nachweis' => 'Bestätigung des Portals (E-Mail oder Vermerk des Vermieters).',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\Responsibility;
|
||||
|
||||
/**
|
||||
* A centrally defined, versioned function template (docs/Prozessarchitektur/SCHABLONEN.md): a business combination of
|
||||
* already existing modules for one slot of a process model. A template is no second process engine – it only names
|
||||
* the modules the plan gets at its slot, what it needs, what it provides, who answers for the result and which
|
||||
* portal capability it presupposes. The modules stay individually configurable (MODUL_KONFIGURATIONSMATRIX).
|
||||
*/
|
||||
abstract class FunctionTemplate
|
||||
{
|
||||
abstract public static function key(): string;
|
||||
|
||||
abstract public static function version(): int;
|
||||
|
||||
abstract public static function area(): TemplateArea;
|
||||
|
||||
abstract public static function label(): string;
|
||||
|
||||
/** The business purpose in plain words. */
|
||||
abstract public static function purpose(): string;
|
||||
|
||||
/**
|
||||
* The modules this template puts at its slot, in order.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
abstract public static function modules(): array;
|
||||
|
||||
/** Who answers for the result of the area. It becomes the value of the area's responsibility setting. */
|
||||
abstract public static function responsibility(): Responsibility;
|
||||
|
||||
/**
|
||||
* The portal capability that must hold for the template to fit: capability key => required value (the channel's
|
||||
* confirmed capabilities decide; an unknown one is a hint, never taken as proven).
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*/
|
||||
public static function capabilityRequirements(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Results of the process this template needs (provided by the base process or another template).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function requires(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Results this template provides. The result of its area is always among them.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function provides(): array
|
||||
{
|
||||
return [static::area()->result()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Templates (keys) that must not be combined with this one, with the reason.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function incompatibleWith(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* What the template stands for along the business dimensions of its area (shown in the configurator):
|
||||
* dimension label => statement.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function dimensions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Capabilities that are not built yet; they appear as extensions, never as promises.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function extensions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings the template fixes for the cases that follow it (setting key => value).
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function fixes(): array
|
||||
{
|
||||
return [static::area()->setting()->value => static::responsibility()->value];
|
||||
}
|
||||
|
||||
public static function reference(): string
|
||||
{
|
||||
return static::key().'@'.static::version();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\Responsibility;
|
||||
|
||||
/**
|
||||
* We collect the guest's money (e.g. Destination Solutions): payment monitoring on our side. Multi-stage dunning is
|
||||
* not built – it is listed as an extension, not promised.
|
||||
*/
|
||||
final class OwnCollection extends FunctionTemplate
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'collection.own';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::Collection;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Eigenes Inkasso';
|
||||
}
|
||||
|
||||
public static function purpose(): string
|
||||
{
|
||||
return 'Wir fordern Anzahlung und Restzahlung vom Gast an, überwachen die Zahlungseingänge, erinnern an offene Beträge und schließen die Forderung kaufmännisch ab.';
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['payments.monitor'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function capabilityRequirements(): array
|
||||
{
|
||||
return ['collects_payment' => false];
|
||||
}
|
||||
|
||||
public static function requires(): array
|
||||
{
|
||||
return ['binding.portal_total'];
|
||||
}
|
||||
|
||||
public static function provides(): array
|
||||
{
|
||||
return [TemplateArea::Collection->result(), 'money.guest_payments_monitored'];
|
||||
}
|
||||
|
||||
public static function dimensions(): array
|
||||
{
|
||||
return [
|
||||
'Zahlungsplan' => 'Anzahlung und Restzahlung nach den Zahlungsfristen des Vermieters.',
|
||||
'Zahlungsanforderung' => 'Aufgabe vor Fälligkeit; Versand durch uns.',
|
||||
'Zahlungseingang' => 'Wir erfassen die Zahlungen des Gastes.',
|
||||
'Erinnerung' => 'Aufgabe mit Versand per Klick (nicht automatisch).',
|
||||
'Abschluss' => 'Kaufmännischer Abschluss mit tatsächlichen Nachweisen.',
|
||||
];
|
||||
}
|
||||
|
||||
public static function extensions(): array
|
||||
{
|
||||
return ['Mehrstufige Mahnungen (rechtliche Ausgestaltung offen)', 'Bank-Abgleich der Zahlungseingänge'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\Responsibility;
|
||||
|
||||
/**
|
||||
* We create and send the contract documentation (booking record with our terms). Creation, filing, provision and
|
||||
* dispatch remain configurable at the module (processing, contract_delivery, template).
|
||||
*/
|
||||
final class OwnContractDocumentation extends FunctionTemplate
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'contract_docs.own';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Eigene Vertragsdokumentation';
|
||||
}
|
||||
|
||||
public static function purpose(): string
|
||||
{
|
||||
return 'Wir erstellen die Vertragsunterlagen aus Buchungsdaten und unseren Bedingungen, legen sie ab und stellen sie dem Gast bereit.';
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send', 'documents.booking_notice'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function capabilityRequirements(): array
|
||||
{
|
||||
return ['provides_contract_documents' => false];
|
||||
}
|
||||
|
||||
public static function requires(): array
|
||||
{
|
||||
return ['guest.identified'];
|
||||
}
|
||||
|
||||
public static function provides(): array
|
||||
{
|
||||
return [TemplateArea::ContractDocuments->result(), 'contract.documents_by_us'];
|
||||
}
|
||||
|
||||
public static function dimensions(): array
|
||||
{
|
||||
return [
|
||||
'Vertragsbedingungen' => 'Das Portal verantwortet den Vertragsabschluss; die Bedingungen der Unterlagen sind unsere.',
|
||||
'Erstellung' => 'Durch uns (Vorlage der Wohnung oder des Kanals).',
|
||||
'Bereitstellung / Versand' => 'Durch uns; automatisch, nach Freigabe oder von Hand, per E-Mail oder nur intern abgelegt.',
|
||||
'Nachweis' => 'Gespeichertes Dokument und Versandvermerk am Vorgang.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\Responsibility;
|
||||
|
||||
/**
|
||||
* The portal collects the guest's money (e.g. FeWo-direkt): we record what the portal reports and check the payout.
|
||||
* No payment request towards the guest arises from this template.
|
||||
*/
|
||||
final class PortalCollection extends FunctionTemplate
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'collection.portal';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::Collection;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Portal-Inkasso';
|
||||
}
|
||||
|
||||
public static function purpose(): string
|
||||
{
|
||||
return 'Das Portal zieht das Geld des Gastes ein. Wir erfassen die gemeldeten Beträge, kontrollieren die Auszahlung gegen Nachweise, bearbeiten Differenzen und schließen kaufmännisch ab.';
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['payments.monitor', 'portal.payout'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Portal;
|
||||
}
|
||||
|
||||
public static function capabilityRequirements(): array
|
||||
{
|
||||
return ['collects_payment' => true];
|
||||
}
|
||||
|
||||
public static function requires(): array
|
||||
{
|
||||
return ['binding.portal_total'];
|
||||
}
|
||||
|
||||
public static function provides(): array
|
||||
{
|
||||
return [TemplateArea::Collection->result(), 'money.portal_payout_checked'];
|
||||
}
|
||||
|
||||
public static function dimensions(): array
|
||||
{
|
||||
return [
|
||||
'Zahlungsplan' => 'Beim Portal; wir zeigen nur „laut Portal“.',
|
||||
'Zahlungsanforderung' => 'Keine eigene gegenüber dem Gast.',
|
||||
'Zahlungseingang' => 'Angaben des Portals werden erfasst (kein Geld auf unserem Konto).',
|
||||
'Auszahlung' => 'Kontrolle gegen Nachweis; Differenzen werden bearbeitet.',
|
||||
'Abschluss' => 'Kaufmännischer Abschluss erst mit tatsächlichem Nachweis der Auszahlung.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Enums\ProcessSetting;
|
||||
|
||||
/**
|
||||
* A functional area of a process where a model offers a slot for a function template. Each area answers one business
|
||||
* decision and stands for exactly one result of the process (so the same result is never produced twice).
|
||||
*/
|
||||
enum TemplateArea: string
|
||||
{
|
||||
case Collection = 'collection';
|
||||
case ContractDocuments = 'contract_documents';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Collection => 'Finanzabwicklung (Inkasso)',
|
||||
self::ContractDocuments => 'Vertragsdokumentation',
|
||||
};
|
||||
}
|
||||
|
||||
public function question(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Collection => 'Wer zieht das Geld des Gastes ein?',
|
||||
self::ContractDocuments => 'Wer stellt dem Gast die Vertragsunterlagen bereit?',
|
||||
};
|
||||
}
|
||||
|
||||
/** The process result every template of this area provides – exactly once per process. */
|
||||
public function result(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Collection => 'money.collection_handled',
|
||||
self::ContractDocuments => 'contract.documented',
|
||||
};
|
||||
}
|
||||
|
||||
/** The responsibility setting the chosen template fixes. */
|
||||
public function setting(): ProcessSetting
|
||||
{
|
||||
return match ($this) {
|
||||
self::Collection => ProcessSetting::Payments,
|
||||
self::ContractDocuments => ProcessSetting::Documents,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace App\Process\Templates;
|
||||
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\ProcessCatalogue;
|
||||
|
||||
/**
|
||||
* Checks and resolves a combination of function templates for the slots of a model. Pure: it reads the registered
|
||||
* definitions and returns what is wrong in plain words (empty = the combination yields a valid plan). It is no second
|
||||
* engine – the plan it leads to is run by the ProcessRunner with the dependencies the modules declare.
|
||||
*/
|
||||
final class TemplateComposer
|
||||
{
|
||||
public function __construct(private ProcessCatalogue $catalogue) {}
|
||||
|
||||
/**
|
||||
* The template reference (key@version) every slot of the model gets: the chosen one, otherwise the model's default.
|
||||
* References that are not registered are kept as given so that problems() can name them.
|
||||
*
|
||||
* @param array<string, string> $chosen area value => template key or key@version
|
||||
* @return array<string, string> area value => key@version
|
||||
*/
|
||||
public function resolve(ProcessModel $model, array $chosen): array
|
||||
{
|
||||
$resolved = [];
|
||||
foreach ($model->slots() as $area) {
|
||||
$reference = (string) ($chosen[$area->value] ?? $model::defaultTemplates()[$area->value] ?? '');
|
||||
$class = $reference === '' ? null : $this->catalogue->templateClass($reference);
|
||||
$resolved[$area->value] = $class === null ? $reference : $class::reference();
|
||||
}
|
||||
|
||||
return $resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* The template classes behind a resolved combination (unknown references are left out).
|
||||
*
|
||||
* @param array<string, string> $resolved
|
||||
* @return array<string, class-string<FunctionTemplate>>
|
||||
*/
|
||||
public function classes(array $resolved): array
|
||||
{
|
||||
$classes = [];
|
||||
foreach ($resolved as $area => $reference) {
|
||||
if (($class = $this->catalogue->templateClass($reference)) !== null) {
|
||||
$classes[$area] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $chosen area value => template key or key@version
|
||||
* @return list<string>
|
||||
*/
|
||||
public function problems(ProcessModel $model, array $chosen, string $variant = 'standard'): array
|
||||
{
|
||||
$problems = [];
|
||||
$slots = array_map(fn (TemplateArea $area): string => $area->value, $model->slots());
|
||||
foreach (array_keys($chosen) as $area) {
|
||||
if (! in_array($area, $slots, true)) {
|
||||
$problems[] = 'Das Modell „'.$model::label().'“ hat keinen Platz für „'.$area.'“.';
|
||||
}
|
||||
}
|
||||
if ($slots === []) {
|
||||
return $problems;
|
||||
}
|
||||
|
||||
$resolved = $this->resolve($model, array_intersect_key($chosen, array_flip($slots)));
|
||||
$classes = [];
|
||||
foreach ($resolved as $area => $reference) {
|
||||
$class = $this->catalogue->templateClass($reference);
|
||||
if ($class === null) {
|
||||
$problems[] = 'Die Schablone „'.$reference.'“ gibt es nicht.';
|
||||
|
||||
continue;
|
||||
}
|
||||
if ($class::area()->value !== $area) {
|
||||
$problems[] = 'Die Schablone „'.$class::label().'“ gehört zu „'.$class::area()->label().'“, nicht zu „'.TemplateArea::from($area)->label().'“.';
|
||||
|
||||
continue;
|
||||
}
|
||||
$classes[$area] = $class;
|
||||
}
|
||||
|
||||
$problems = [...$problems, ...$this->resultProblems($model, $classes), ...$this->pairProblems($classes), ...$this->planProblems($model, $classes, $variant)];
|
||||
|
||||
return array_values(array_unique($problems));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prerequisites and double effects at the level of business results.
|
||||
*
|
||||
* @param array<string, class-string<FunctionTemplate>> $classes
|
||||
* @return list<string>
|
||||
*/
|
||||
private function resultProblems(ProcessModel $model, array $classes): array
|
||||
{
|
||||
$problems = [];
|
||||
$providers = [];
|
||||
foreach ($model::providedResults() as $result) {
|
||||
$providers[$result][] = 'der Basisprozess';
|
||||
}
|
||||
foreach ($classes as $class) {
|
||||
foreach ($class::provides() as $result) {
|
||||
$providers[$result][] = '„'.$class::label().'“';
|
||||
}
|
||||
}
|
||||
foreach ($providers as $result => $by) {
|
||||
if (count($by) > 1) {
|
||||
$problems[] = 'Das Ergebnis „'.$result.'“ würde doppelt erzeugt: '.implode(' und ', $by).'.';
|
||||
}
|
||||
}
|
||||
foreach ($classes as $class) {
|
||||
foreach ($class::requires() as $needed) {
|
||||
if (! isset($providers[$needed])) {
|
||||
$problems[] = '„'.$class::label().'“ setzt das Ergebnis „'.$needed.'“ voraus, das in dieser Kombination niemand liefert.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutually exclusive templates and contradictory responsibilities.
|
||||
*
|
||||
* @param array<string, class-string<FunctionTemplate>> $classes
|
||||
* @return list<string>
|
||||
*/
|
||||
private function pairProblems(array $classes): array
|
||||
{
|
||||
$problems = [];
|
||||
$fixed = [];
|
||||
foreach ($classes as $class) {
|
||||
foreach ($class::incompatibleWith() as $other => $reason) {
|
||||
if (collect($classes)->contains(fn (string $chosen): bool => $chosen::key() === $other)) {
|
||||
$problems[] = '„'.$class::label().'“ und „'.$this->catalogue->templateClass($other)::label().'“ lassen sich nicht kombinieren: '.$reason;
|
||||
}
|
||||
}
|
||||
foreach ($class::fixes() as $setting => $value) {
|
||||
if (isset($fixed[$setting]) && $fixed[$setting]['value'] !== $value) {
|
||||
$problems[] = 'Widersprüchliche Verantwortlichkeit ('.$setting.'): „'.$fixed[$setting]['by'].'“ und „'.$class::label().'“ legen Unterschiedliches fest.';
|
||||
}
|
||||
$fixed[$setting] = ['value' => $value, 'by' => $class::label()];
|
||||
}
|
||||
}
|
||||
|
||||
return $problems;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the composed course needs from the modules: no module twice, and a hard dependency on a module that one of the
|
||||
* templates of this model's slots would have supplied must be in the plan.
|
||||
*
|
||||
* @param array<string, class-string<FunctionTemplate>> $classes
|
||||
* @return list<string>
|
||||
*/
|
||||
private function planProblems(ProcessModel $model, array $classes, string $variant): array
|
||||
{
|
||||
$problems = [];
|
||||
$modules = $model->modules($variant, array_map(fn (string $class): string => $class::reference(), $classes));
|
||||
foreach (array_count_values($modules) as $module => $count) {
|
||||
if ($count > 1) {
|
||||
$problems[] = 'Das Modul „'.$module.'“ wäre mehrfach im Ablauf.';
|
||||
}
|
||||
}
|
||||
|
||||
$templateOwned = [];
|
||||
foreach ($model->slots() as $area) {
|
||||
foreach ($this->catalogue->templates($area) as $class) {
|
||||
array_push($templateOwned, ...$class::modules());
|
||||
}
|
||||
}
|
||||
foreach (array_unique($modules) as $key) {
|
||||
if (! $this->catalogue->hasModule($key)) {
|
||||
$problems[] = 'Das Modul „'.$key.'“ ist nicht registriert.';
|
||||
|
||||
continue;
|
||||
}
|
||||
foreach ($this->catalogue->modules()[$key]::definition()->requires as $dependency) {
|
||||
if ($dependency->hard && ! in_array($dependency->module, $modules, true) && in_array($dependency->module, $templateOwned, true)) {
|
||||
$problems[] = 'Das Modul „'.$key.'“ braucht zwingend „'.$dependency->module.'“, das in dieser Kombination fehlt.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $problems;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,10 @@
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Models\Tenant;
|
||||
use App\Process\Capability;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseContext;
|
||||
use App\Process\ChannelCapabilities;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessProfile;
|
||||
@@ -37,6 +39,9 @@ final class ProcessSandboxDriver
|
||||
|
||||
private int $ledgerSeen = 0;
|
||||
|
||||
/** @var list<string> labels of the activities that were done after the previous event */
|
||||
private array $doneBefore = [];
|
||||
|
||||
/** @var list<Email> every mail of the run (simulated: the only mailer is `array`) */
|
||||
private array $sent = [];
|
||||
|
||||
@@ -98,7 +103,7 @@ public function run(array $input): array
|
||||
|
||||
return [
|
||||
'scenario' => ['key' => $scenario::key(), 'label' => $scenario::label(), 'inputs' => $context->inputs, 'available_events' => count($scenario->events($context->inputs))],
|
||||
'plan' => $booking === null ? null : $this->plan($booking),
|
||||
'plan' => $booking === null ? null : $this->plan($booking, $channel),
|
||||
'timeline' => $timeline,
|
||||
'result' => $booking === null ? null : ['status' => $booking->status->getLabel(), 'situation' => CaseActivities::situation($booking), 'next' => CaseActivities::next($booking)?->label],
|
||||
'violations' => EffectLedger::violations(),
|
||||
@@ -122,7 +127,7 @@ private function assertSandbox(): void
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function plan(Booking $booking): array
|
||||
private function plan(Booking $booking, Channel $channel): array
|
||||
{
|
||||
$plan = ProcessPlan::of($booking);
|
||||
$profile = $booking->process();
|
||||
@@ -134,10 +139,49 @@ private function plan(Booking $booking): array
|
||||
'variant' => $plan->variant,
|
||||
'modules' => $plan->modules,
|
||||
'case_type' => strtoupper($profile->caseType->value),
|
||||
'templates' => $this->templates($plan, $channel),
|
||||
'configuration' => collect(ProcessSetting::cases())->map(fn ($setting): array => ['question' => $setting->question(), 'value' => $setting->describe($profile->value($setting)), 'source' => ProcessProfile::sourceLabel($profile->source($setting))])->all(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The function templates the case follows: what each stands for, its modules and the portal capabilities it relies on
|
||||
* with their origin – a capability that is only suggested or derived is shown as not confirmed, never as proven.
|
||||
*
|
||||
* @return list<array{area: string, label: string, reference: string, responsibility: string, modules: list<string>, capabilities: list<array{label: string, required: string, source: string, confirmed: bool}>}>
|
||||
*/
|
||||
private function templates(ProcessPlan $plan, Channel $channel): array
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
$capabilities = app(ChannelCapabilities::class)->resolve($channel);
|
||||
$rows = [];
|
||||
foreach ($plan->templates as $area => $reference) {
|
||||
$class = $catalogue->templateClass($reference);
|
||||
if ($class === null) {
|
||||
continue;
|
||||
}
|
||||
$rows[] = [
|
||||
'area' => $class::area()->label(),
|
||||
'label' => $class::label(),
|
||||
'reference' => $reference,
|
||||
'responsibility' => $class::responsibility()->getLabel(),
|
||||
'modules' => array_values(array_map(fn (string $module): string => $plan->labels[$module] ?? $module, $class::modules())),
|
||||
'capabilities' => array_values(array_map(function (string $key, bool $required) use ($capabilities): array {
|
||||
$capability = $capabilities[$key] ?? null;
|
||||
|
||||
return [
|
||||
'label' => ChannelCapabilities::definitions()[$key]['question'],
|
||||
'required' => $required ? 'ja' : 'nein',
|
||||
'source' => $capability?->sourceLabel() ?? 'noch nicht bekannt',
|
||||
'confirmed' => $capability?->source === Capability::CONFIRMED,
|
||||
];
|
||||
}, array_keys($class::capabilityRequirements()), $class::capabilityRequirements())),
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* The case after one event: its course, the skipped steps, the simulated mails and effects.
|
||||
*
|
||||
@@ -172,9 +216,18 @@ private function capture(SandboxContext $context): array
|
||||
}
|
||||
}
|
||||
|
||||
$activities = CaseActivities::for($booking);
|
||||
$waiting = array_values(array_map(fn ($activity): string => $activity->label, array_filter($activities, fn ($activity): bool => $activity->state->value === 'waiting')));
|
||||
$done = array_values(array_map(fn ($activity): string => $activity->label, array_filter($activities, fn ($activity): bool => in_array($activity->state->value, ['done', 'external'], true))));
|
||||
// Steps that came to an end in this event while others wait: they do not hold each other up.
|
||||
$independent = $waiting === [] ? [] : array_values(array_diff($done, $this->doneBefore));
|
||||
$this->doneBefore = $done;
|
||||
|
||||
return [
|
||||
'status' => $booking->status->getLabel(),
|
||||
'situation' => CaseActivities::situation($booking),
|
||||
'waiting' => $waiting,
|
||||
'independent' => $independent,
|
||||
'activities' => array_map(fn ($activity): array => ['label' => $activity->label, 'state' => $activity->state->getLabel(), 'state_key' => $activity->state->value, 'detail' => $activity->detail], CaseActivities::for($booking)),
|
||||
'skipped' => $skipped,
|
||||
'calendar' => ['occupying' => Booking::query()->occupying()->whereKey($booking->id)->exists(), 'hold_until' => $booking->isHoldActive() ? $booking->hold_expires_at->format('d.m.Y H:i') : null],
|
||||
|
||||
@@ -63,7 +63,7 @@ public static function build(Channel $channel, IntakeKind $intake, array $draft)
|
||||
foreach ($tables['channels'] ?? [] as $index => $row) {
|
||||
if ((int) $row['id'] === $channel->id) {
|
||||
$overrides = (array) json_decode((string) ($row['process_overrides'] ?? '[]'), true);
|
||||
$overrides[$intake->value] = [...array_filter((array) ($draft['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== ''), 'model' => $draft['model'] ?? null, 'variant' => $draft['variant'] ?? 'standard', 'steps' => (array) ($draft['steps'] ?? [])];
|
||||
$overrides[$intake->value] = [...array_filter((array) ($draft['settings'] ?? []), fn (mixed $value): bool => $value !== null && $value !== ''), 'model' => $draft['model'] ?? null, 'variant' => $draft['variant'] ?? 'standard', 'steps' => (array) ($draft['steps'] ?? []), 'templates' => (array) ($draft['templates'] ?? [])];
|
||||
$tables['channels'][$index]['process_overrides'] = json_encode($overrides);
|
||||
$tables['channels'][$index]['case_intake'] = 'create';
|
||||
// In the run the tested portal is active, so its (synthetic) booking mails are recognised.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
use App\Process\Modules\Offer;
|
||||
use App\Process\Modules\Settlement;
|
||||
use App\Process\Modules\Stay;
|
||||
use App\Process\Templates;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -72,5 +73,18 @@
|
||||
'a4.portal_booking' => [1 => Models\A4PortalBookingModelV1::class, 2 => Models\A4PortalBookingModel::class],
|
||||
'a5.portal_booking' => [1 => Models\A5PortalBookingModelV1::class, 2 => Models\A5PortalBookingModel::class],
|
||||
'a6.internal' => [1 => Models\A6InternalModel::class],
|
||||
// Base process with slots for function templates; A3–A5 above are its presets (compatibility).
|
||||
'external.booking' => [1 => Models\ExternalBookingModel::class],
|
||||
],
|
||||
|
||||
/*
|
||||
| Function templates (docs/Prozessarchitektur/SCHABLONEN.md): versioned combinations of the modules above for the slots
|
||||
| of a model. A plan freezes the template versions it was built with.
|
||||
*/
|
||||
'templates' => [
|
||||
'collection.own' => [1 => Templates\OwnCollection::class],
|
||||
'collection.portal' => [1 => Templates\PortalCollection::class],
|
||||
'contract_docs.own' => [1 => Templates\OwnContractDocumentation::class],
|
||||
'contract_docs.external' => [1 => Templates\ExternalContractDocuments::class],
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,74 @@
|
||||
# Funktionsschablonen und Basisprozess „Extern verbindliche Portalbuchung“
|
||||
|
||||
Stand: 05.11.2026 · Branch `feature/schablonenkomposition` · kurze technische Umsetzungsgrundlage, keine neue Architekturstudie.
|
||||
|
||||
## 1. Prinzip
|
||||
|
||||
Der Basisprozess bleibt (P01–P05, `ProcessRunner`, Moduldefinitionen, harte/weiche Abhängigkeiten). Neu ist nur:
|
||||
|
||||
- **Platz (Slot)** im Modell (`Step::slot(TemplateArea)`), an dem die gewählte **Funktionsschablone** ihre bereits vorhandenen Module einsetzt.
|
||||
- **Schablone** (`App\Process\Templates\FunctionTemplate`, versioniert, in `config/process.php › templates`): Zweck, Module, benötigte/gelieferte Ergebnisse, Verantwortlichkeit, Portal-Fähigkeit, Ausschlüsse, Dimensionen, noch nicht gebaute Erweiterungen.
|
||||
- **`TemplateComposer`** (rein lesend): löst die Wahl auf, prüft Plätze/Bereiche, Voraussetzungen, doppelte Ergebnisse, Ausschlüsse, widersprüchliche Verantwortlichkeiten, doppelte Module und harte Modulabhängigkeiten. Keine Regelsprache, keine zweite Engine.
|
||||
- Der **Plan** (`ProcessPlan`) friert Schablonen mit Version ein (`bookings.profile.plan.templates`, optional – alte Pläne bleiben lesbar). Die Schablone legt die Verantwortlichkeit ihres Bereichs fest (`ProcessSettings`, Quelle `template`); alle anderen Parameter laufen weiter über Systemstandard → Vermieter → Wohnung → Kanal × Eingangsart → eingefroren.
|
||||
- `CaseType` A1–A6 bleibt **abgeleitete Klassifikation** (Berichte, Altfälle). Die vierte Kombination (eigenes Inkasso + externe Unterlagen) wird als A3 klassifiziert („wir kassieren“); es gibt kein A7.
|
||||
|
||||
## 2. Zuordnung: bisheriger Funktionsblock → Module → Schablone
|
||||
|
||||
| Funktionsblock (Prozesslandkarte) | Module | Zuordnung |
|
||||
|---|---|---|
|
||||
| Eingang, Gastangaben, Verbindlichkeit beim Portal, Bestätigung abwarten, Kalender sperren | `intake.record`, `guest.details`, `binding.portal`, `portal.confirmation`, `channels.block` | fester Bestandteil des Basisprozesses |
|
||||
| Datenbeschaffung | `guest.data_request` | fest, Ausführung am Modul wählbar (automatisch/Freigabe/von Hand/nicht erforderlich) – eigene Schablone erst bei echten Alternativen |
|
||||
| **Vertragsdokumentation** | `documents.send`, `documents.booking_notice` | **Schablonen** `contract_docs.own` / `contract_docs.external` |
|
||||
| **Finanzabwicklung** | `payments.monitor` (+ `portal.payout`) | **Schablonen** `collection.own` (Zahlungsüberwachung) / `collection.portal` (Portalzahlungen + Auszahlungskontrolle) |
|
||||
| Aufgaben, Änderungen | `case.tasks`, `change.proposal` | fest (ereignisgesteuert) |
|
||||
| Anreise, Aufenthalt, Bewertung | `arrival.details`, `arrival.info`, `stay`, `review.request` | fest, Absender am Modul wählbar (Gastkommunikation) |
|
||||
| Abschluss | `case.closure`, `case.settlement` | fest (Pflicht, Nachweise nach O5) |
|
||||
| Angebot/Annahme (A1/A2), interne Belegung (A6), Tester-Module | `offer.*`, `hold`, `availability.check`, `payments.internal`, `documents.stay_confirmation`, `guest.*`/`pricing.*` (Tester) | nicht Teil dieses Umbaus; spätere Schablonen nutzen dasselbe Prinzip |
|
||||
|
||||
Es wurden bewusst **nur zwei Bereiche** zu Schablonen: dort liegen die unterschiedlichen Verantwortlichkeiten. Module wurden nicht zusammengefasst.
|
||||
|
||||
## 3. Die vier Schablonen
|
||||
|
||||
| Schablone | Module | Verantwortung | Portal-Fähigkeit | Liefert | Braucht |
|
||||
|---|---|---|---|---|---|
|
||||
| `collection.own@1` Eigenes Inkasso | `payments.monitor` | wir | Portal zieht **nicht** ein | `money.collection_handled`, `money.guest_payments_monitored` | `binding.portal_total` |
|
||||
| `collection.portal@1` Portal-Inkasso | `payments.monitor`, `portal.payout` | Portal | Portal zieht ein | `money.collection_handled`, `money.portal_payout_checked` | `binding.portal_total` |
|
||||
| `contract_docs.own@1` Eigene Vertragsdokumentation | `documents.send`, `documents.booking_notice` | wir | Portal stellt **keine** Unterlagen bereit | `contract.documented`, `contract.documents_by_us` | `guest.identified` |
|
||||
| `contract_docs.external@1` Externe Vertragsunterlagen | dieselben Module | Portal | Portal stellt Unterlagen bereit | `contract.documented`, `contract.documents_by_portal` | – |
|
||||
|
||||
Die Schablonen der Dokumente unterscheiden sich nicht in den Modulen, sondern in **Verantwortung, Ausführungsart (Portal statt wir) und Nachweis** (§4.2 des Auftrags): Vertragsbedingungen – Erstellung – Bereitstellung/Versand – Nachweis stehen als `dimensions()` an der Schablone; Erstellung, Ablage, Bereitstellung und Versand bleiben am Modul einzeln einstellbar (`processing`, `contract_delivery`, Vorlage). Was die Unterlagen des Portals über Zahlungen sagen, ändert nichts an der Zahlungsüberwachung: sie folgt allein der Finanzschablone.
|
||||
|
||||
## 4. Die vier Pflichtkombinationen
|
||||
|
||||
| # | Inkasso | Dokumente | Klassifikation | Entspricht |
|
||||
|---|---|---|---|---|
|
||||
| 1 | eigenes | eigene | A3 | A3 v2 |
|
||||
| 2 | Portal | eigene | A4 | A4 v2 |
|
||||
| 3 | Portal | externe | A5 | A5 v2 |
|
||||
| 4 | eigenes | externe | A3 | – (bisher nicht darstellbar) |
|
||||
|
||||
`TemplateCompositionTest` beweist: Kombinationen 1–3 haben dasselbe wirksame Profil, dieselben Aktivitäten/Zustände und denselben Ablauf wie A3–A5 (nur `portal.payout` entfällt, wo wir selbst kassieren). `TemplateProcessTesterTest` spielt alle vier im isolierten Prozess-Tester durch.
|
||||
|
||||
## 5. Unbestätigte Portal-Fähigkeiten
|
||||
|
||||
Die Schablonenwahl prüft die **bestätigten** Fähigkeiten des Kanals. Widerspruch → Schablone nicht wählbar, mit Begründung und Weg. Unbekannt oder nur vorgeschlagen/abgeleitet → nicht gesperrt, aber überall als „nicht bestätigt“ gekennzeichnet (Konfigurator, Tester-Bericht); sie gilt nie als nachgewiesen.
|
||||
|
||||
## 6. Umgang mit A3–A5
|
||||
|
||||
`external.booking@1` ist der Basisprozess für neue Konfigurationen. A3/A4/A5 (v1/v2) bleiben registriert (eingefrorene Pläne, Altkanäle) und sind im Konfigurator **Voreinstellungen** („Auf Schablonen umstellen“ / „Bekannte Kombinationen“). Gespeicherte Kanäle ändern sich nicht, bis jemand ausdrücklich speichert. `ProcessCatalogue::derivedModel` und die Altfall-Ableitung bleiben unverändert.
|
||||
|
||||
Stellen, an denen `CaseType`/A3–A5 vorher etwas entschieden, und was jetzt gilt:
|
||||
|
||||
| Stelle | Vorher | Jetzt |
|
||||
|---|---|---|
|
||||
| `ProcessProfile::caseTypeFor` | Dokumente = Portal ⇒ immer A5 | A5 nur, wenn Portal Dokumente **und** Inkasso hat; sonst A4 (Inkasso Portal) bzw. A3 – reine Klassifikation |
|
||||
| `ProcessPlan::freeze` (Modell zulässig für Vorgangsart) | Modell nennt genau eine Art | `external.booking` nennt A3–A5; die Schablonenwahl bestimmt den Ablauf |
|
||||
| `ProcessCatalogue::derivedModel` | Altfall-/Ableitungspfad nach Vorgangsart | unverändert (Altfälle, Kanäle ohne gewähltes Modell) |
|
||||
| `isExternallyBinding()` (Änderung/Storno/Anzeige) | A3–A5 | unverändert, gilt für alle vier Kombinationen |
|
||||
| `payments()` / `documents()` (Zahlungsaufgaben, Dokumentenart, Abschluss, Auszahlung) | Wert aus Modell-`fixes()` | Wert aus der Schablone (Quelle `template`); die Module selbst blieben unverändert |
|
||||
|
||||
## 7. Bewusste Grenzen / offen
|
||||
|
||||
- Mahnstufen, Zahlungsplan je Kanal, Bank-Abgleich: Erweiterungen (`OwnCollection::extensions()`), nicht erfunden.
|
||||
- Weitere Bereiche (Gastkommunikation, Datenbeschaffung, Aufenthalt) nutzen später dasselbe Prinzip (`TemplateArea` um einen Fall und einen Platz im Modell erweitern).
|
||||
- A1/A2 und A6 haben noch keine Plätze.
|
||||
@@ -1,5 +1,15 @@
|
||||
# Projektstand
|
||||
|
||||
## Nachtrag (05.11.2026): Schablonenkomposition für extern verbindliche Buchungen
|
||||
|
||||
**Branch `feature/schablonenkomposition`** – Details, Zuordnung und Grenzen: [SCHABLONEN.md](Prozessarchitektur/SCHABLONEN.md).
|
||||
|
||||
- Basisprozess `external.booking@1` mit Plätzen für **Finanzabwicklung** (`collection.own` / `collection.portal`) und **Vertragsdokumentation** (`contract_docs.own` / `contract_docs.external`). Alle vier Kombinationen laufen im Prozesskern und im Prozess-Tester; die vierte (eigenes Inkasso + externe Unterlagen) war mit A3–A5 nicht darstellbar.
|
||||
- A3–A5 bleiben als Voreinstellungen/Altfassungen erhalten (Äquivalenz mit den Archetypen ist getestet); `CaseType` ist nur noch Klassifikation, kein A7.
|
||||
- Der Plan friert die Schablonenversionen ein; laufende Vorgänge und Altpläne bleiben unverändert. Keine Migration.
|
||||
- Kanalkonfigurator: Geschäftsentscheidungen zuerst, Einzelschritte eingeklappt, Auswirkungsanalyse beim Schablonenwechsel, Konflikte (A4→A3-Fall) bleiben bestätigungspflichtig. Tester-Bericht nennt Schablonen, unabhängig laufende Schritte, fehlende Nachweise und nicht bestätigte Portal-Fähigkeiten.
|
||||
- Offen: Bereitstellung auf `develop`/stommer.info (siehe Abschnitt unten, sobald erfolgt).
|
||||
|
||||
## Nachtrag (05.11.2026): Konfigurierbarkeit der Fachmodule
|
||||
|
||||
- **Speicherkonflikt behoben:** Ein bestätigter Wechsel A4 → A3 (Destination Solutions mit `payments = portal`) scheiterte an „Inkasso … nicht zulässig“, weil der Entwurf den Altwert vor der bestätigten Entfernung gegen das neue Modell prüfte; nicht mehr erlaubte variable Verantwortlichkeiten zählten zudem nicht als Konflikt. Jetzt: `ChannelProcessConfiguration::conflicts()` + `withoutOverriddenSettings()`, Regressionstests in `ChannelCapabilityTest`.
|
||||
|
||||
@@ -65,6 +65,20 @@
|
||||
@endif
|
||||
@if ($plan = $report['plan'] ?? null)
|
||||
<p style="font-size:.9rem"><strong>{{ $plan['label'] }}</strong> ({{ $plan['model'] }} Version {{ $plan['version'] }}{{ $plan['variant'] !== 'standard' ? ', Variante '.$plan['variant'] : '' }}) · Vorgangsart {{ $plan['case_type'] }}</p>
|
||||
@if (($plan['templates'] ?? []) !== [])
|
||||
<div style="font-size:.85rem;margin:.4rem 0">
|
||||
<strong>Verwendete Funktionsschablonen</strong>
|
||||
<ul style="padding-left:1.2rem;list-style:disc">
|
||||
@foreach ($plan['templates'] as $template)
|
||||
<li>{{ $template['area'] }}: <strong>{{ $template['label'] }}</strong> <span style="{{ $muted }}">({{ $template['reference'] }}, Verantwortung: {{ $template['responsibility'] }}; Schritte: {{ implode(', ', $template['modules']) }})</span>
|
||||
@foreach ($template['capabilities'] as $capability)
|
||||
<div style="{{ $capability['confirmed'] ? $muted : 'color:#b45309;font-size:.8rem' }}">Voraussetzung „{{ $capability['label'] }}“ = {{ $capability['required'] }} – {{ $capability['confirmed'] ? 'bestätigt' : 'NICHT bestätigt, wird nicht als nachgewiesen behandelt' }} ({{ $capability['source'] }})</div>
|
||||
@endforeach
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
<details style="font-size:.85rem;margin:.4rem 0"><summary>Wirksame Einstellungen</summary>
|
||||
<ul style="padding-left:1.2rem;list-style:disc">
|
||||
@foreach ($plan['configuration'] as $row)<li>{{ $row['question'] }}: <strong>{{ $row['value'] }}</strong> <span style="{{ $muted }}">({{ $row['source'] }})</span></li>@endforeach
|
||||
@@ -77,6 +91,12 @@
|
||||
<div style="display:flex;justify-content:space-between"><strong>{{ $index + 1 }}. {{ $event['label'] }}</strong><span style="{{ $muted }}">{{ $event['at'] }} (simuliert)</span></div>
|
||||
@if ($event['error'])<p style="color:#b91c1c;font-size:.85rem">Fehler: {{ $event['error'] }}</p>@endif
|
||||
@isset($event['situation'])<p style="font-size:.85rem;margin:.3rem 0">{{ $event['status'] }} · {{ $event['situation'] }}</p>@endisset
|
||||
@if (($event['independent'] ?? []) !== [])
|
||||
<p style="font-size:.85rem;color:#15803d">Läuft unabhängig weiter, obwohl anderes wartet: {{ implode(', ', $event['independent']) }}</p>
|
||||
@endif
|
||||
@if (($event['waiting'] ?? []) !== [])
|
||||
<p style="font-size:.85rem;color:#6d28d9">Wartet / Nachweis fehlt: {{ implode(', ', $event['waiting']) }}</p>
|
||||
@endif
|
||||
<ul style="font-size:.85rem;list-style:none;padding:0">
|
||||
@foreach ($event['activities'] as $activity)
|
||||
<li><span style="color:{{ $stateColor[$activity['state_key']] ?? '#6b7280' }};font-weight:600">{{ $activity['state'] }}</span> – {{ $activity['label'] }}@if ($activity['detail'])<span style="{{ $muted }}"> · {{ $activity['detail'] }}</span>@endif</li>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
$model = $this->model();
|
||||
$steps = $this->steps();
|
||||
$problems = $this->problems();
|
||||
$composable = $this->composable();
|
||||
@endphp
|
||||
|
||||
@if (count($this->tabs()) > 1)
|
||||
@@ -42,7 +43,7 @@
|
||||
<p>Für diese Eingangsart gibt es keine Ablaufmodelle.</p>
|
||||
@endif
|
||||
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(18rem,1fr));gap:.6rem" role="radiogroup" aria-label="Ablaufmodell">
|
||||
@foreach ($models as $key => $option)
|
||||
@foreach ($this->visibleModels($models) as $key => $option)
|
||||
@php($candidate = $option['model'])
|
||||
<div style="{{ $card }};{{ $draft['model'] === $key ? 'border-color:rgb(var(--primary-600));box-shadow:0 0 0 1px rgb(var(--primary-600))' : '' }};{{ $option['admissible'] ? '' : 'opacity:.85;background:rgba(128,128,128,.07)' }}">
|
||||
<button type="button" role="radio" aria-checked="{{ $draft['model'] === $key ? 'true' : 'false' }}" @disabled(! $option['admissible']) wire:click="chooseModel('{{ $key }}')" style="text-align:left;width:100%">
|
||||
@@ -55,6 +56,10 @@
|
||||
@endforeach
|
||||
@foreach ($option['hints'] as $hint)<p style="{{ $muted }};margin-top:.3rem">{{ $hint }}</p>@endforeach
|
||||
@if ($draft['model'] === $key && ! $option['admissible'])<p style="color:#b91c1c;font-size:.8rem;margin-top:.3rem">Dies ist Ihr bisheriger Ablauf. Er bleibt wirksam, bis Sie ein passendes Modell wählen oder die Fähigkeit oben ändern.</p>@endif
|
||||
@if ($candidate::isLegacy() && $draft['model'] === $key)
|
||||
<p style="{{ $muted }};margin-top:.4rem">Festes Modell (bisherige Vorgangsart). Sie können es in die frei kombinierbaren Schablonen übernehmen – die Kombination bleibt dabei gleich.</p>
|
||||
<x-filament::button size="xs" color="gray" wire:click="applyPreset('{{ $key }}')" style="margin-top:.3rem">Auf Schablonen umstellen</x-filament::button>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@@ -83,6 +88,58 @@
|
||||
@endif
|
||||
</x-filament::section>
|
||||
|
||||
@if ($composable)
|
||||
@php($decisions = $this->decisions())
|
||||
<x-filament::section heading="Geschäftsentscheidungen" description="Wählen Sie je Bereich die passende Funktionsschablone. Die Einzelschritte jeder Schablone bleiben darunter einzeln einstellbar.">
|
||||
@if (($presets = $this->presets()) !== [])
|
||||
<div style="{{ $muted }};margin-bottom:.6rem">Bekannte Kombinationen als Ausgangspunkt:
|
||||
@foreach ($presets as $archetype => $preset)
|
||||
<button type="button" wire:click="applyPreset('{{ $archetype }}')" style="text-decoration:underline;margin-left:.4rem">{{ $preset['label'] }}</button>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
@foreach ($decisions as $decision)
|
||||
<h3 style="font-weight:600;margin:.6rem 0 .3rem">{{ $decision['area']->label() }} <span style="{{ $muted }}">– {{ $decision['area']->question() }}</span></h3>
|
||||
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(20rem,1fr));gap:.6rem" role="radiogroup" aria-label="{{ $decision['area']->label() }}">
|
||||
@foreach ($decision['options'] as $option)
|
||||
@php($template = $option['template'])
|
||||
<div style="{{ $card }};{{ $option['selected'] ? 'border-color:rgb(var(--primary-600));box-shadow:0 0 0 1px rgb(var(--primary-600))' : '' }};{{ $option['admissible'] ? '' : 'opacity:.85;background:rgba(128,128,128,.07)' }}" wire:key="template-{{ $this->intake }}-{{ $option['key'] }}">
|
||||
<button type="button" role="radio" aria-checked="{{ $option['selected'] ? 'true' : 'false' }}" @disabled(! $option['admissible']) wire:click="chooseTemplate('{{ $decision['area']->value }}', '{{ $option['key'] }}')" style="text-align:left;width:100%">
|
||||
<strong>{{ $template::label() }}</strong>
|
||||
<div style="font-size:.85rem;margin-top:.3rem">{{ $template::purpose() }}</div>
|
||||
</button>
|
||||
<ul style="{{ $muted }};margin-top:.4rem;list-style:disc;padding-left:1.1rem">
|
||||
@foreach ($template::dimensions() as $dimension => $statement)<li><strong>{{ $dimension }}:</strong> {{ $statement }}</li>@endforeach
|
||||
</ul>
|
||||
<div style="{{ $muted }};margin-top:.3rem">Schritte: {{ implode(', ', $option['modules']) }}@if ($template::extensions() !== []) · noch nicht vorhanden: {{ implode('; ', $template::extensions()) }}@endif</div>
|
||||
@foreach ($option['restrictions'] as $restriction)
|
||||
<p style="color:#b45309;font-size:.8rem;margin-top:.4rem"><strong>Passt gerade nicht ({{ $restriction->kind }}):</strong> {{ $restriction->reason }}@if ($restriction->alternative) <br>Zulässig ist stattdessen: {{ $restriction->alternative }}.@endif @if ($restriction->change) <br>{{ $restriction->change }}.@endif</p>
|
||||
@endforeach
|
||||
@foreach ($option['hints'] as $hint)<p style="{{ $muted }};margin-top:.3rem">{{ $hint }}</p>@endforeach
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endforeach
|
||||
</x-filament::section>
|
||||
|
||||
@if ($templateImpacts = $this->templateImpacts())
|
||||
<x-filament::section heading="Was der Wechsel bedeutet" description="Nichts davon wird still geändert – Sie sehen jede Folge, bevor Sie speichern.">
|
||||
@foreach ($templateImpacts as $impact)
|
||||
<div style="font-size:.9rem;margin-bottom:.8rem">
|
||||
<strong>{{ $impact['area'] }}:</strong> {{ $impact['from'] ?? 'bisher keine Schablone' }} → <strong>{{ $impact['to'] }}</strong>
|
||||
@if ($impact['responsibility'])<div>Verantwortung: {{ $impact['responsibility']['from'] }} → {{ $impact['responsibility']['to'] }}</div>@endif
|
||||
@if ($impact['removed'] !== [])<div>Entfällt: {{ implode(', ', $impact['removed']) }}</div>@endif
|
||||
@if ($impact['added'] !== [])<div>Kommt hinzu: {{ implode(', ', $impact['added']) }}</div>@endif
|
||||
@if ($impact['kept'] !== [])<div style="{{ $muted }}">Bleibt mit allen Einstellungen: {{ implode(', ', $impact['kept']) }}</div>@endif
|
||||
@foreach ($impact['switches_lost'] as $lost)<div style="color:#b45309">Ihr gespeicherter Schalter für „{{ $lost }}“ hat dann keinen Bezug mehr.</div>@endforeach
|
||||
@foreach ($impact['settings_replaced'] as $text)<div style="color:#b45309">{{ $text }}</div>@endforeach
|
||||
@foreach ($impact['needs'] as $need)<div style="{{ $muted }}">{{ $need }}</div>@endforeach
|
||||
</div>
|
||||
@endforeach
|
||||
</x-filament::section>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
@if ($problems !== [])
|
||||
<x-filament::section heading="Nicht zulässig">
|
||||
<ul style="color:#b91c1c;font-size:.9rem;list-style:disc;padding-left:1.2rem">
|
||||
@@ -104,7 +161,8 @@
|
||||
@endif
|
||||
|
||||
<div style="display:grid;grid-template-columns:minmax(0,2fr) minmax(0,1fr);gap:1rem;align-items:start">
|
||||
<div>
|
||||
<details @if (! $composable) open @endif>
|
||||
<summary style="cursor:pointer;font-weight:600;margin-bottom:.4rem">Einzelschritte einstellen ({{ count($steps) }} Schritte)</summary>
|
||||
@foreach (collect($steps)->groupBy('phase') as $phase => $group)
|
||||
<h3 style="font-weight:600;margin:.6rem 0 .3rem">{{ $phases[$phase] ?? $phase }}</h3>
|
||||
@foreach ($group as $index => $step)
|
||||
@@ -113,6 +171,7 @@
|
||||
<strong>{{ $step['label'] }}
|
||||
@if ($step['tester_only'])<span style="color:#b45309;font-size:.75rem"> · nur im Prozess-Tester</span>@endif
|
||||
@if ($step['inserted'])<span style="{{ $muted }}"> · Zusatzschritt der Variante</span>@endif
|
||||
@if ($step['template'] ?? null)<span style="{{ $muted }}"> · Schablone: {{ $step['template'] }}</span>@endif
|
||||
</strong>
|
||||
@if ($step['optional'])
|
||||
<x-filament::button size="xs" :color="($draft['steps'][$step['module']]['on'] ?? true) === false ? 'gray' : 'success'" wire:click="toggleStep('{{ $step['module'] }}')">
|
||||
@@ -173,7 +232,7 @@
|
||||
</div>
|
||||
@endforeach
|
||||
@endforeach
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<x-filament::section heading="Vorschau: ein neuer Vorgang" description="Mit den aktuellen, auch ungespeicherten Einstellungen. Es wird nichts gespeichert und nichts ausgeführt.">
|
||||
<ul style="font-size:.85rem;list-style:disc;padding-left:1.2rem">
|
||||
|
||||
@@ -244,7 +244,7 @@ public function test_unknown_capabilities_block_nothing_but_ask_for_confirmation
|
||||
|
||||
$options = app(ChannelProcessConfiguration::class)->modelOptions($generic, IntakeKind::Booking);
|
||||
|
||||
$this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking'], array_keys(array_filter($options, fn (array $option): bool => $option['admissible'])));
|
||||
$this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking', 'external.booking'], array_keys(array_filter($options, fn (array $option): bool => $option['admissible'])));
|
||||
$this->assertNotSame([], $options['a4.portal_booking']['hints']);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,15 +72,15 @@ public function test_only_admissible_models_per_channel_and_intake_are_offered()
|
||||
$website = Channel::websiteOf($this->property);
|
||||
|
||||
$this->assertSame(['a2.offer', 'a2.information'], array_keys($configuration->admissibleModels($fewo, IntakeKind::Inquiry)));
|
||||
$this->assertSame(['a4.portal_booking'], array_keys($configuration->admissibleModels($fewo, IntakeKind::Booking)), 'O2: FeWo-direkt bookings only A4 for now');
|
||||
$this->assertSame(['a3.portal_booking'], array_keys($configuration->admissibleModels($ds, IntakeKind::Booking)));
|
||||
$this->assertSame(['a4.portal_booking', 'external.booking'], array_keys($configuration->admissibleModels($fewo, IntakeKind::Booking)), 'O2: of the archetypes only A4 fits FeWo-direkt; the base process is open and restricts per template');
|
||||
$this->assertSame(['a3.portal_booking', 'external.booking'], array_keys($configuration->admissibleModels($ds, IntakeKind::Booking)));
|
||||
$this->assertSame([IntakeKind::Booking], $configuration->intakes($ds));
|
||||
$this->assertSame(['a2.offer', 'a2.information'], array_keys($configuration->admissibleModels($listing, IntakeKind::Inquiry)));
|
||||
$this->assertSame(['a1.offer', 'a1.information'], array_keys($configuration->admissibleModels($website, IntakeKind::Inquiry)));
|
||||
|
||||
// The restriction lives in the channel profile, not in the process core: a changed profile releases more models.
|
||||
$fewo->update(['settings' => [...(array) $fewo->settings, 'portal_profile' => 'generic']]);
|
||||
$this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking'], array_keys($configuration->admissibleModels($fewo->fresh(), IntakeKind::Booking)));
|
||||
$this->assertSame(['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking', 'external.booking'], array_keys($configuration->admissibleModels($fewo->fresh(), IntakeKind::Booking)));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'a4.portal_booking']);
|
||||
|
||||
@@ -0,0 +1,540 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\ConfigureChannelProcess;
|
||||
use App\Actions\SendBookingReminders;
|
||||
use App\Actions\TakeOverExternalBooking;
|
||||
use App\Enums\ActivityState;
|
||||
use App\Enums\CaseType;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Enums\Responsibility;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\Models\ExternalBookingModel;
|
||||
use App\Process\Models\ProcessModel;
|
||||
use App\Process\Models\Responsibilities;
|
||||
use App\Process\Models\Step;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Process\Templates\FunctionTemplate;
|
||||
use App\Process\Templates\OwnCollection;
|
||||
use App\Process\Templates\TemplateArea;
|
||||
use App\Process\Templates\TemplateComposer;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Composition of function templates on the base process of externally binding bookings (docs/Prozessarchitektur/
|
||||
* SCHABLONEN.md): the four combinations of collection and contract documentation, equivalence with the archetypes
|
||||
* A3–A5, refusal of invalid combinations and versioning.
|
||||
*/
|
||||
#[Group('configurator')]
|
||||
class TemplateCompositionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
config(['mail.default' => 'array']);
|
||||
Mail::swap(new MailManager($this->app));
|
||||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'test@example.org']);
|
||||
Http::preventStrayRequests();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string, 2: CaseType, 3: bool}> collection, documents, classification, whether the payout check is part of the course
|
||||
*/
|
||||
public static function combinations(): array
|
||||
{
|
||||
return [
|
||||
'own collection + own documents (A3)' => ['collection.own', 'contract_docs.own', CaseType::A3, false],
|
||||
'portal collection + own documents (A4)' => ['collection.portal', 'contract_docs.own', CaseType::A4, true],
|
||||
'portal collection + external documents (A5)' => ['collection.portal', 'contract_docs.external', CaseType::A5, true],
|
||||
'own collection + external documents (no archetype)' => ['collection.own', 'contract_docs.external', CaseType::A3, false],
|
||||
];
|
||||
}
|
||||
|
||||
public function test_the_catalogue_with_templates_is_consistent(): void
|
||||
{
|
||||
$this->assertSame([], app(ProcessCatalogue::class)->problems());
|
||||
}
|
||||
|
||||
#[DataProvider('combinations')]
|
||||
public function test_every_combination_is_composed_into_a_valid_versioned_plan(string $collection, string $documents, CaseType $type, bool $payout): void
|
||||
{
|
||||
$model = app(ProcessCatalogue::class)->model('external.booking');
|
||||
$chosen = ['collection' => $collection, 'contract_documents' => $documents];
|
||||
|
||||
$this->assertSame([], app(TemplateComposer::class)->problems($model, $chosen));
|
||||
|
||||
$channel = $this->configured($chosen);
|
||||
$booking = $this->takeOver($channel, 'COMBO');
|
||||
$plan = ProcessPlan::of($booking);
|
||||
|
||||
$this->assertSame(['external.booking', 1], [$plan->model, $plan->modelVersion]);
|
||||
$this->assertEquals(['collection' => $collection.'@1', 'contract_documents' => $documents.'@1'], $plan->templates);
|
||||
$this->assertSame($payout, array_key_exists('portal.payout', $plan->modules));
|
||||
$this->assertArrayHasKey('payments.monitor', $plan->modules);
|
||||
$this->assertArrayHasKey('documents.send', $plan->modules);
|
||||
$this->assertSame($type, $booking->case_type, 'the case type is only a classification');
|
||||
$this->assertNull($plan->notice);
|
||||
}
|
||||
|
||||
public function test_the_fourth_combination_collects_ourselves_while_the_portal_provides_the_documents(): void
|
||||
{
|
||||
$booking = $this->takeOver($this->configured(['collection' => 'collection.own', 'contract_documents' => 'contract_docs.external']), 'VIER');
|
||||
$profile = $booking->process();
|
||||
|
||||
$this->assertSame([Responsibility::Landlord, Responsibility::Portal], [$profile->payments(), $profile->documents()]);
|
||||
$this->assertSame(ProcessProfile::TEMPLATE, $profile->source(ProcessSetting::Payments));
|
||||
$this->assertSame(ProcessProfile::TEMPLATE, $profile->source(ProcessSetting::Documents));
|
||||
|
||||
$activities = collect(CaseActivities::for($booking))->keyBy('key');
|
||||
$this->assertNotSame(ActivityState::External, $activities['payment']->state, 'we monitor the guest payments ourselves');
|
||||
$this->assertStringNotContainsString('Portal', $activities['payment']->label, 'no portal collection shown');
|
||||
$this->assertNull($activities['payout'] ?? null, 'no payout check without portal collection');
|
||||
$this->assertNull($booking->fresh()->confirmation_sent_at, 'the portal provides the contract documents: we send none');
|
||||
}
|
||||
|
||||
#[DataProvider('archetypes')]
|
||||
public function test_a_combination_behaves_like_the_archetype_it_reproduces(string $legacy, string $collection, string $documents): void
|
||||
{
|
||||
$old = $this->takeOver($this->legacyChannel($legacy), 'ALT', '2027-07-10');
|
||||
$new = $this->takeOver($this->configured(['collection' => $collection, 'contract_documents' => $documents]), 'NEU', '2027-08-10');
|
||||
|
||||
$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);
|
||||
|
||||
$summarise = fn (Booking $booking): array => collect(CaseActivities::for($booking))->map(fn ($activity): array => [$activity->key, $activity->label, $activity->state->value])->all();
|
||||
$this->assertSame($summarise($old), $summarise($new), 'identical activities and states');
|
||||
|
||||
$oldModules = array_keys(ProcessPlan::of($old)->modules);
|
||||
$newModules = array_keys(ProcessPlan::of($new)->modules);
|
||||
$this->assertSame(array_values(array_diff($oldModules, $legacy === 'a3.portal_booking' ? ['portal.payout'] : [])), $newModules, 'the course is the archetype course (the payout check only where the portal collects)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string, 2: string}>
|
||||
*/
|
||||
public static function archetypes(): array
|
||||
{
|
||||
return [
|
||||
'A3' => ['a3.portal_booking', 'collection.own', 'contract_docs.own'],
|
||||
'A4' => ['a4.portal_booking', 'collection.portal', 'contract_docs.own'],
|
||||
'A5' => ['a5.portal_booking', 'collection.portal', 'contract_docs.external'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('combinations')]
|
||||
public function test_payment_requests_arise_from_own_collection_only_and_never_twice(string $collection, string $documents): void
|
||||
{
|
||||
$channel = $this->configured(['collection' => $collection, 'contract_documents' => $documents]);
|
||||
$booking = app(TakeOverExternalBooking::class)->handle($this->property, $channel, CarbonImmutable::parse('2027-07-10'), CarbonImmutable::parse('2027-07-17'), [
|
||||
'portal_reference' => 'ZAHL', 'portal_total' => 98000, 'guests' => 2,
|
||||
'guest' => ['first_name' => 'Pia', 'last_name' => 'Portal', 'email' => 'pia@example.org', 'street' => 'Weg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
]);
|
||||
$this->travelTo(CarbonImmutable::parse('2027-06-25 10:00'));
|
||||
|
||||
app(SendBookingReminders::class)->handle();
|
||||
$first = BookingTask::query()->where('booking_id', $booking->id)->count();
|
||||
app(SendBookingReminders::class)->handle();
|
||||
$second = BookingTask::query()->where('booking_id', $booking->id)->count();
|
||||
|
||||
$this->assertSame($first, $second, 'repeated runs create no second request');
|
||||
$collection === 'collection.own' ? $this->assertGreaterThan(0, $first, 'we collect: payment tasks exist') : $this->assertSame(0, $first, 'the portal collects: no own payment request towards the guest');
|
||||
$this->assertNull($booking->fresh()->confirmation_sent_at, 'a portal event or reminder never creates or changes our contract');
|
||||
}
|
||||
|
||||
public function test_the_archetypes_are_presets_of_the_base_process(): void
|
||||
{
|
||||
$catalogue = app(ProcessCatalogue::class);
|
||||
foreach (['a3.portal_booking', 'a4.portal_booking', 'a5.portal_booking'] as $key) {
|
||||
$model = $catalogue->model($key);
|
||||
$this->assertTrue($model::isLegacy());
|
||||
$this->assertSame([], app(TemplateComposer::class)->problems($catalogue->model('external.booking'), $model::presetTemplates()));
|
||||
}
|
||||
$this->assertFalse(ExternalBookingModel::isLegacy());
|
||||
}
|
||||
|
||||
public function test_unsuitable_combinations_are_refused_with_a_reason(): void
|
||||
{
|
||||
$composer = app(TemplateComposer::class);
|
||||
$model = app(ProcessCatalogue::class)->model('external.booking');
|
||||
|
||||
$this->assertStringContainsString('gehört zu', implode(' ', $composer->problems($model, ['collection' => 'contract_docs.own'])), 'a template only fits the slot of its area');
|
||||
$this->assertStringContainsString('gibt es nicht', implode(' ', $composer->problems($model, ['collection' => 'collection.gibt-es-nicht'])));
|
||||
$this->assertStringContainsString('keinen Platz', implode(' ', $composer->problems($model, ['gastronomie' => 'collection.own'])));
|
||||
}
|
||||
|
||||
public function test_double_effects_missing_prerequisites_contradictions_and_exclusions_are_detected(): void
|
||||
{
|
||||
$this->register(DoubleCollectionTemplate::class, NeedyDocumentsTemplate::class, ContradictingDocumentsTemplate::class, ExcludingDocumentsTemplate::class, DuplicateModuleTemplate::class);
|
||||
$composer = app(TemplateComposer::class);
|
||||
$model = app(ProcessCatalogue::class)->model('external.booking');
|
||||
$problems = fn (array $chosen): string => implode(' | ', $composer->problems($model, $chosen));
|
||||
|
||||
$this->assertStringContainsString('doppelt erzeugt', $problems(['contract_documents' => DoubleCollectionTemplate::key()]), 'the collection result may come from one template only');
|
||||
$this->assertStringContainsString('voraus', $problems(['contract_documents' => NeedyDocumentsTemplate::key()]));
|
||||
$this->assertStringContainsString('Widersprüchliche Verantwortlichkeit', $problems(['contract_documents' => ContradictingDocumentsTemplate::key()]));
|
||||
$this->assertStringContainsString('nicht kombinieren', $problems(['collection' => 'collection.portal', 'contract_documents' => ExcludingDocumentsTemplate::key()]));
|
||||
$this->assertSame('', $problems(['collection' => 'collection.own', 'contract_documents' => ExcludingDocumentsTemplate::key()]), 'the exclusion only concerns portal collection');
|
||||
$this->assertStringContainsString('mehrfach', $problems(['collection' => DuplicateModuleTemplate::key()]));
|
||||
}
|
||||
|
||||
public function test_a_hard_dependency_on_a_module_the_templates_would_have_supplied_is_unmet(): void
|
||||
{
|
||||
config(['process.models' => [...config('process.models'), 'test.model' => [1 => ModelWithDependentStep::class]]]);
|
||||
$this->register(SuppliesStayTemplate::class);
|
||||
$model = app(ProcessCatalogue::class)->model('test.model');
|
||||
|
||||
$this->assertStringContainsString('braucht zwingend', implode(' ', app(TemplateComposer::class)->problems($model, ['collection' => 'collection.own'])));
|
||||
$this->assertSame([], app(TemplateComposer::class)->problems($model, ['collection' => SuppliesStayTemplate::key()]));
|
||||
}
|
||||
|
||||
public function test_a_new_template_version_applies_to_new_cases_only_and_old_plans_stay_readable(): void
|
||||
{
|
||||
$channel = $this->configured(['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']);
|
||||
$first = $this->takeOver($channel, 'V1');
|
||||
|
||||
config(['process.templates' => [...config('process.templates'), 'collection.own' => [1 => OwnCollection::class, 2 => OwnCollectionVersion2::class]]]);
|
||||
$second = $this->takeOver($channel->fresh(), 'V2', '2027-08-10');
|
||||
|
||||
$this->assertSame('collection.own@1', ProcessPlan::of($first->fresh())->templates['collection']);
|
||||
$this->assertSame('collection.own@2', ProcessPlan::of($second)->templates['collection']);
|
||||
$this->assertSame($first->profile['plan'], $first->fresh()->profile['plan'], 'the running case keeps its frozen plan');
|
||||
|
||||
$legacy = ProcessPlan::fromArray(['model' => 'a3.portal_booking', 'model_version' => 2, 'modules' => ['intake.record' => 1]]);
|
||||
$this->assertSame([], $legacy->templates, 'plans frozen before the composition have no templates');
|
||||
}
|
||||
|
||||
public function test_the_unsaved_choice_shows_in_the_preview_with_the_template_of_each_step(): void
|
||||
{
|
||||
$channel = $this->channel('Test Portal');
|
||||
$rows = collect(app(ChannelProcessConfiguration::class)->preview($channel, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.external']]));
|
||||
|
||||
$this->assertSame('Portal-Inkasso', $rows->firstWhere('module', 'portal.payout')['template']);
|
||||
$this->assertSame('Externe Vertragsunterlagen', $rows->firstWhere('module', 'documents.send')['template']);
|
||||
$this->assertNull($rows->firstWhere('module', 'stay')['template']);
|
||||
}
|
||||
|
||||
public function test_the_base_process_cannot_be_saved_with_templates_the_portal_cannot_support(): void
|
||||
{
|
||||
$channel = $this->channel('FeWo-direkt Test');
|
||||
$configure = app(ConfigureChannelProcess::class);
|
||||
$draft = ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], 'capabilities' => ['collects_payment' => '1', 'provides_contract_documents' => '0']];
|
||||
|
||||
try {
|
||||
$configure->handle($channel, IntakeKind::Booking, $draft);
|
||||
$this->fail('own collection although the portal collects');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertStringContainsString('Zieht das Portal das Geld', implode(' ', $exception->errors()['process']));
|
||||
}
|
||||
$this->assertNull(($channel->fresh()->process_overrides ?? [])['booking'] ?? null, 'nothing saved');
|
||||
|
||||
$configure->handle($channel, IntakeKind::Booking, [...$draft, 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]);
|
||||
$this->assertEquals(['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own'], $channel->fresh()->process_overrides['booking']['templates']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $templates
|
||||
*/
|
||||
private function configured(array $templates): Channel
|
||||
{
|
||||
$channel = $this->channel('Vergleichsportal', suffix: md5(json_encode($templates)));
|
||||
app(ConfigureChannelProcess::class)->handle($channel, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => $templates]);
|
||||
|
||||
return $channel->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<FunctionTemplate> ...$classes
|
||||
*/
|
||||
private function register(string ...$classes): void
|
||||
{
|
||||
$templates = config('process.templates');
|
||||
foreach ($classes as $class) {
|
||||
$templates[$class::key()] = [1 => $class];
|
||||
}
|
||||
config(['process.templates' => $templates]);
|
||||
}
|
||||
|
||||
private function legacyChannel(string $model): Channel
|
||||
{
|
||||
$channel = $this->channel('Vergleichsportal', suffix: 'alt');
|
||||
app(ConfigureChannelProcess::class)->handle($channel, IntakeKind::Booking, ['model' => $model]);
|
||||
|
||||
return $channel->fresh();
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
private function channel(string $name, string $suffix = ''): Channel
|
||||
{
|
||||
return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => 'portal_booking', 'import_enabled' => false, 'settings' => ['import_url' => 'https://portal.example/'.md5($name.$suffix).'.ics', 'portal_profile' => 'generic']]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test doubles: templates and a model that exist only to provoke the composition checks. */
|
||||
abstract class TestTemplate extends FunctionTemplate
|
||||
{
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.'.strtolower(substr(strrchr(static::class, '\\'), 1));
|
||||
}
|
||||
|
||||
public static function purpose(): string
|
||||
{
|
||||
return 'Testschablone';
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return static::key();
|
||||
}
|
||||
}
|
||||
|
||||
final class DoubleCollectionTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function provides(): array
|
||||
{
|
||||
return [TemplateArea::ContractDocuments->result(), TemplateArea::Collection->result()];
|
||||
}
|
||||
}
|
||||
|
||||
final class NeedyDocumentsTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function requires(): array
|
||||
{
|
||||
return ['signature.qualified'];
|
||||
}
|
||||
}
|
||||
|
||||
final class ContradictingDocumentsTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function fixes(): array
|
||||
{
|
||||
return ['documents' => 'landlord', 'payments' => 'portal'];
|
||||
}
|
||||
}
|
||||
|
||||
final class ExcludingDocumentsTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::ContractDocuments;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['documents.send'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
|
||||
public static function incompatibleWith(): array
|
||||
{
|
||||
return ['collection.portal' => 'Beide würden die Auszahlung dokumentieren.'];
|
||||
}
|
||||
}
|
||||
|
||||
final class DuplicateModuleTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::Collection;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['payments.monitor', 'documents.send'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
}
|
||||
|
||||
final class SuppliesStayTemplate extends TestTemplate
|
||||
{
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::Collection;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['stay'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
}
|
||||
|
||||
final class OwnCollectionVersion2 extends TestTemplate
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'collection.own';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public static function area(): TemplateArea
|
||||
{
|
||||
return TemplateArea::Collection;
|
||||
}
|
||||
|
||||
public static function modules(): array
|
||||
{
|
||||
return ['payments.monitor'];
|
||||
}
|
||||
|
||||
public static function responsibility(): Responsibility
|
||||
{
|
||||
return Responsibility::Landlord;
|
||||
}
|
||||
}
|
||||
|
||||
/** A model whose review step needs the stay, which a collection template may supply. */
|
||||
final class ModelWithDependentStep extends ProcessModel
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'test.model';
|
||||
}
|
||||
|
||||
public static function version(): int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Testmodell';
|
||||
}
|
||||
|
||||
public static function description(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function caseTypes(): array
|
||||
{
|
||||
return [CaseType::A3];
|
||||
}
|
||||
|
||||
public static function intakes(): array
|
||||
{
|
||||
return [IntakeKind::Booking];
|
||||
}
|
||||
|
||||
public static function responsibilities(): Responsibilities
|
||||
{
|
||||
return Responsibilities::of(fixed: []);
|
||||
}
|
||||
|
||||
public static function defaultTemplates(): array
|
||||
{
|
||||
return ['collection' => 'collection.own'];
|
||||
}
|
||||
|
||||
public function steps(): array
|
||||
{
|
||||
return [Step::module('intake.record'), Step::slot(TemplateArea::Collection), Step::module('review.request')];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Actions\ConfigureChannelProcess;
|
||||
use App\Actions\TakeOverExternalBooking;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessSetting;
|
||||
use App\Filament\Resources\Channels\Pages\ChannelProcess;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Models\User;
|
||||
use App\Process\ChannelProcessConfiguration;
|
||||
use App\Process\ConfigurationImpact;
|
||||
use App\Process\ProcessCatalogue;
|
||||
use App\Process\ProcessPlan;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Process\ProcessSettings;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Mail\MailManager;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Livewire;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* The channel configurator on the composition: the business decisions come first, the single steps stay reachable and
|
||||
* configurable, nothing changes silently, running cases keep their plan.
|
||||
*/
|
||||
#[Group('configurator')]
|
||||
class TemplateConfiguratorTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
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());
|
||||
}
|
||||
|
||||
public function test_the_page_shows_the_business_decisions_first_and_keeps_the_steps_reachable(): void
|
||||
{
|
||||
$ds = $this->channel('Destination Solution', []);
|
||||
|
||||
Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])
|
||||
->call('chooseModel', 'external.booking')
|
||||
->assertSee('Geschäftsentscheidungen')
|
||||
->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');
|
||||
}
|
||||
|
||||
public function test_an_archetype_moves_to_the_base_process_with_the_same_combination_and_saves(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', [], 'mixed');
|
||||
$page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking');
|
||||
|
||||
$page->assertSee('Auf Schablonen umstellen')->call('applyPreset', 'a4.portal_booking');
|
||||
$this->assertSame(['external.booking', ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']], [$page->get('drafts')['booking']['model'], $page->get('drafts')['booking']['templates']]);
|
||||
$this->assertSame([], $page->instance()->problems());
|
||||
|
||||
$page->call('save')->assertNotified('Ablauf gespeichert');
|
||||
$this->assertSame('external.booking', $fewo->fresh()->process_overrides['booking']['model']);
|
||||
$this->assertEquals(['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own'], $fewo->fresh()->process_overrides['booking']['templates']);
|
||||
|
||||
$booking = $this->takeOver($fewo->fresh(), 'FD-1');
|
||||
$this->assertEquals(['collection' => 'collection.portal@1', 'contract_documents' => 'contract_docs.own@1'], ProcessPlan::of($booking)->templates);
|
||||
$this->assertSame('A4', strtoupper($booking->case_type->value));
|
||||
}
|
||||
|
||||
public function test_a_template_the_portal_cannot_support_cannot_be_chosen_and_says_why(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', [], 'mixed');
|
||||
$page = Livewire::test(ChannelProcess::class, ['record' => $fewo->getRouteKey()])->set('intake', 'booking')->call('applyPreset', 'a4.portal_booking');
|
||||
|
||||
$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?');
|
||||
|
||||
// The landlord corrects the capability first: now the template fits.
|
||||
$page->set('capabilityDraft.collects_payment', '0')->call('chooseTemplate', 'collection', 'collection.own');
|
||||
$this->assertSame('collection.own', $page->get('drafts')['booking']['templates']['collection']);
|
||||
}
|
||||
|
||||
public function test_unconfirmed_capabilities_are_flagged_and_never_taken_as_proven(): void
|
||||
{
|
||||
$generic = $this->channel('Irgendein Portal', [], 'portal_booking');
|
||||
$options = app(ChannelProcessConfiguration::class)->templateOptions($generic, app(ProcessCatalogue::class)->model('external.booking'));
|
||||
|
||||
$this->assertTrue($options['collection']['collection.own']['admissible'], 'unknown blocks nothing');
|
||||
$this->assertSame(['collects_payment'], $options['collection']['collection.own']['unconfirmed']);
|
||||
$this->assertNotSame([], $options['contract_documents']['contract_docs.external']['hints']);
|
||||
|
||||
$fewo = $this->channel('FeWo-direkt Profil', [], 'mixed');
|
||||
$suggested = app(ChannelProcessConfiguration::class)->templateOptions($fewo, app(ProcessCatalogue::class)->model('external.booking'));
|
||||
$this->assertContains('collects_payment', $suggested['collection']['collection.portal']['unconfirmed'], 'a suggestion of the channel profile is not a confirmation');
|
||||
$this->assertStringContainsString('nicht als bestätigt', implode(' ', $suggested['collection']['collection.portal']['hints']));
|
||||
}
|
||||
|
||||
/** The A4 → A3 regression of the archetypes, now as a switch of the collection template */
|
||||
public function test_switching_the_collection_template_shows_every_consequence_and_needs_the_confirmation(): void
|
||||
{
|
||||
$ds = $this->channel('Destination Solution', ['booking' => ['payments' => 'portal', 'guest_messages' => 'portal', 'contract_delivery' => 'manual', 'steps' => ['review.request' => ['on' => false]]]]);
|
||||
$ds->update(['settings' => [...(array) $ds->settings, 'capabilities' => ['messages_guest' => ['value' => false, 'at' => now()->toIso8601String(), 'by' => 'Lars']]]]);
|
||||
$page = Livewire::test(ChannelProcess::class, ['record' => $ds->getRouteKey()])->set('intake', 'booking');
|
||||
|
||||
$page->set('capabilityDraft.collects_payment', '0')->call('chooseModel', 'external.booking')->call('chooseTemplate', 'collection', 'collection.own');
|
||||
$conflicts = collect($page->instance()->conflicts())->map(fn (array $conflict): string => $conflict['setting']->value)->all();
|
||||
$this->assertEqualsCanonicalizing(['payments', 'guest_messages'], $conflicts, 'the stale collection and the stale portal communication are conflicts, not silent changes');
|
||||
$page->assertSee('Bisherige Einstellungen widersprechen');
|
||||
|
||||
$page->call('save')->assertNotified('Nicht gespeichert');
|
||||
$this->assertSame('portal', $ds->fresh()->process_overrides['booking']['payments'], 'nothing changed without the confirmation');
|
||||
|
||||
$page->set('acknowledge', true)->call('save')->assertNotified('Ablauf gespeichert');
|
||||
$saved = $ds->fresh()->process_overrides['booking'];
|
||||
$this->assertSame('external.booking', $saved['model']);
|
||||
$this->assertArrayNotHasKey('payments', $saved);
|
||||
$this->assertArrayNotHasKey('guest_messages', $saved);
|
||||
$this->assertSame('manual', $saved['contract_delivery'], 'parameters of the kept modules survive');
|
||||
$this->assertSame(['review.request' => ['on' => false]], $saved['steps'], 'so does a switched-off optional step');
|
||||
$this->assertStringContainsString('Bisher eingestellt', $ds->fresh()->settings['process_history'][0]['removed_settings'][0]);
|
||||
$this->assertEquals(['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own'], $saved['templates']);
|
||||
}
|
||||
|
||||
public function test_the_impact_of_a_template_change_names_modules_responsibility_and_open_ends(): void
|
||||
{
|
||||
$fewo = $this->channel('FeWo-direkt', ['booking' => ['steps' => []]], 'mixed');
|
||||
app(ConfigureChannelProcess::class)->handle($fewo, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]);
|
||||
|
||||
$impact = app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.external']]);
|
||||
|
||||
$impact = collect($impact)->keyBy('area');
|
||||
$this->assertEqualsCanonicalizing(['Finanzabwicklung (Inkasso)', 'Vertragsdokumentation'], $impact->keys()->all());
|
||||
$finance = $impact['Finanzabwicklung (Inkasso)'];
|
||||
$documents = $impact['Vertragsdokumentation'];
|
||||
$this->assertSame(['Portal-Inkasso', 'Eigenes Inkasso'], [$finance['from'], $finance['to']]);
|
||||
$this->assertSame(['Auszahlung des Portals'], $finance['removed']);
|
||||
$this->assertSame(['Zahlungen des Gastes'], $finance['kept']);
|
||||
$this->assertSame(['from' => 'Das Portal', 'to' => 'Wir'], $finance['responsibility']);
|
||||
$this->assertContains('Mehrstufige Mahnungen (rechtliche Ausgestaltung offen)', $finance['extensions']);
|
||||
$this->assertSame(['from' => 'Wir', 'to' => 'Das Portal'], $documents['responsibility']);
|
||||
$this->assertSame([], app(ConfigurationImpact::class)->ofTemplates($fewo->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.own']]), 'no change, no impact');
|
||||
}
|
||||
|
||||
public function test_the_modules_of_a_template_stay_individually_configurable_and_the_inheritance_holds(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['contract_delivery' => 'manual']]);
|
||||
$ds = $this->channel('Destination Solution', []);
|
||||
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]);
|
||||
|
||||
$page = Livewire::test(ChannelProcess::class, ['record' => $ds->fresh()->getRouteKey()])->set('intake', 'booking');
|
||||
$documents = collect($page->instance()->steps())->firstWhere('module', 'documents.send');
|
||||
$this->assertSame('Eigene Vertragsdokumentation', $documents['template']);
|
||||
$this->assertContains('contract_delivery', array_column($documents['parameters'], 'key'), 'the module of the template has its own parameters');
|
||||
$this->assertNotNull($documents['mode_setting'], 'and its own mode');
|
||||
$this->assertSame('manual', app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->value(ProcessSetting::ContractDelivery));
|
||||
$this->assertSame(ProcessProfile::TENANT, app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking)->source(ProcessSetting::ContractDelivery));
|
||||
|
||||
$page->set('drafts.booking.settings.contract_delivery', 'automatic')->set('drafts.booking.settings.processing', 'approval')->call('save')->assertNotified('Ablauf gespeichert');
|
||||
$profile = app(ProcessSettings::class)->resolve($this->property, $ds->fresh(), IntakeKind::Booking);
|
||||
$this->assertSame(['automatic', ProcessProfile::CHANNEL], [$profile->value(ProcessSetting::ContractDelivery), $profile->source(ProcessSetting::ContractDelivery)]);
|
||||
$this->assertSame(ProcessProfile::TEMPLATE, $profile->source(ProcessSetting::Payments));
|
||||
}
|
||||
|
||||
public function test_a_template_does_not_override_a_parameter_set_by_hand_and_a_contradicting_responsibility_is_refused(): void
|
||||
{
|
||||
$ds = $this->channel('Destination Solution', []);
|
||||
$configuration = app(ChannelProcessConfiguration::class);
|
||||
|
||||
$problems = $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]);
|
||||
$this->assertNotSame([], $problems, 'a responsibility set by hand may not contradict the template');
|
||||
$this->assertStringContainsString('widerspricht der Schablone', implode(' ', $problems));
|
||||
$this->assertSame([], $configuration->problems($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'landlord', 'contract_delivery' => 'manual']]));
|
||||
|
||||
$this->expectException(ValidationException::class);
|
||||
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own'], 'settings' => ['payments' => 'portal']]);
|
||||
}
|
||||
|
||||
public function test_changing_the_templates_leaves_running_cases_and_their_plans_untouched(): void
|
||||
{
|
||||
$ds = $this->channel('Destination Solution', []);
|
||||
app(ConfigureChannelProcess::class)->handle($ds, IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.own', 'contract_documents' => 'contract_docs.own']]);
|
||||
$running = $this->takeOver($ds->fresh(), 'DS-ALT');
|
||||
$frozen = $running->fresh()->profile;
|
||||
|
||||
app(ConfigureChannelProcess::class)->handle($ds->fresh(), IntakeKind::Booking, ['model' => 'external.booking', 'templates' => ['collection' => 'collection.portal', 'contract_documents' => 'contract_docs.external'], 'capabilities' => ['collects_payment' => '1', 'provides_contract_documents' => '1']]);
|
||||
$new = $this->takeOver($ds->fresh(), 'DS-NEU', '2027-09-10');
|
||||
|
||||
$this->assertSame($frozen, $running->fresh()->profile, 'the running case keeps profile and plan');
|
||||
$this->assertSame('collection.own@1', ProcessPlan::of($running->fresh())->templates['collection']);
|
||||
$this->assertSame('collection.portal@1', ProcessPlan::of($new)->templates['collection']);
|
||||
$this->assertSame(['landlord', 'portal'], [$running->fresh()->process()->payments()->value, $new->process()->payments()->value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
private function channel(string $name, array $overrides, string $model = 'portal_booking'): Channel
|
||||
{
|
||||
return Channel::factory()->for($this->property)->create(['name' => $name, 'booking_model' => $model, 'process_overrides' => $overrides, '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]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Process;
|
||||
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Property;
|
||||
use App\Models\User;
|
||||
use App\Process\Tester\ProcessSandbox;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Acceptance of the template composition: the four combinations of collection and contract documentation are played
|
||||
* through the isolated process tester with a synthetic externally binding booking. The report must show the templates
|
||||
* used, which steps run independently of waiting ones and which evidence is missing – and the combinations must differ in
|
||||
* exactly the way their templates promise.
|
||||
*/
|
||||
#[Group('sandbox')]
|
||||
class TemplateProcessTesterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Property $property;
|
||||
|
||||
private User $user;
|
||||
|
||||
private Channel $portal;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-23 10:00'));
|
||||
$this->seed([PropertySeeder::class, SiteSeeder::class]);
|
||||
$this->property = Property::sole();
|
||||
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051', 'test_recipient' => 'vermieter@example.org', 'process_defaults' => ['processing' => 'automatic']]);
|
||||
$this->user = User::factory()->create();
|
||||
ProcessTesterTest::template();
|
||||
$this->portal = Channel::factory()->for($this->property)->create(['name' => 'Destination Solution', 'booking_model' => 'portal_booking', 'status' => 'setup', 'is_active' => false, 'import_enabled' => false, 'settings' => ['import_url' => 'https://ds.example/a.ics', 'email_senders' => 'ds.example', 'portal_profile' => 'generic']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string}>
|
||||
*/
|
||||
public static function combinations(): array
|
||||
{
|
||||
return [
|
||||
'eigenes Inkasso + eigene Vertragsdokumentation' => ['collection.own', 'contract_docs.own'],
|
||||
'Portal-Inkasso + eigene Vertragsdokumentation' => ['collection.portal', 'contract_docs.own'],
|
||||
'Portal-Inkasso + externe Vertragsunterlagen' => ['collection.portal', 'contract_docs.external'],
|
||||
'eigenes Inkasso + externe Vertragsunterlagen' => ['collection.own', 'contract_docs.external'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('combinations')]
|
||||
public function test_every_combination_runs_in_the_tester_and_differs_as_its_templates_promise(string $collection, string $documents): void
|
||||
{
|
||||
$report = $this->play($collection, $documents);
|
||||
|
||||
$this->assertNull($report['aborted'] ?? null, json_encode($report));
|
||||
$this->assertSame([], $report['violations']);
|
||||
$this->assertSame(['external.booking', 1], [$report['plan']['model'], $report['plan']['version']]);
|
||||
$this->assertEqualsCanonicalizing([$collection.'@1', $documents.'@1'], array_column($report['plan']['templates'], 'reference'), 'the report names the templates used');
|
||||
foreach ($report['plan']['templates'] as $template) {
|
||||
$this->assertNotEmpty($template['modules']);
|
||||
$this->assertFalse($template['capabilities'][0]['confirmed'], 'a capability nobody confirmed is not shown as proven');
|
||||
}
|
||||
|
||||
[$known, , $confirmed] = $report['timeline'];
|
||||
$labels = fn (array $event): array => array_column($event['activities'], 'label');
|
||||
$states = fn (array $event): array => array_column($event['activities'], 'state_key', 'label');
|
||||
|
||||
// Finance: exactly one of the two collections shows up.
|
||||
if ($collection === 'collection.own') {
|
||||
$this->assertContains('Anzahlung erhalten', $labels($known));
|
||||
$this->assertNotContains('Auszahlung von Destination Solution auf unser Konto', $labels($known));
|
||||
$this->assertEmpty(array_filter($labels($known), fn (string $label): bool => str_starts_with($label, 'Zahlung des Gastes an')), 'no portal collection');
|
||||
$this->assertContains('Anzahlung erhalten', $known['waiting'], 'we wait for the guest payments: evidence is missing');
|
||||
} else {
|
||||
$this->assertNotContains('Anzahlung erhalten', $labels($known), 'no own payment request towards the guest');
|
||||
$this->assertSame('external', $states($known)['Zahlung des Gastes an Destination Solution']);
|
||||
$this->assertContains('Auszahlung von Destination Solution auf unser Konto', $known['waiting'], 'the payout evidence is missing');
|
||||
}
|
||||
|
||||
// Contract documentation: ours has to be checked and sent, the portal's is external. Only ours ever goes out as a contract.
|
||||
if ($documents === 'contract_docs.own') {
|
||||
$this->assertSame('waiting', $states($known)['Buchungsunterlagen prüfen und senden'], 'our documents wait for the portal confirmation');
|
||||
$this->assertSame('open', $states($confirmed)['Buchungsunterlagen prüfen und senden'], 'then the landlord sends them (approval, not automatic)');
|
||||
} else {
|
||||
$this->assertSame('external', $states($known)['Buchungsunterlagen an den Gast']);
|
||||
$this->assertNotContains('Buchungsunterlagen prüfen und senden', $labels($confirmed));
|
||||
$this->assertEmpty(array_filter(array_column($confirmed['mails'], 'subject'), fn (string $subject): bool => str_contains($subject, 'Buchungsbestätigung') || str_contains($subject, 'Mietvertrag')), 'no contract from us');
|
||||
}
|
||||
|
||||
// Independent steps keep running while the confirmation, the documents and the payments wait.
|
||||
$this->assertContains('Kontaktdaten des Gastes', $known['independent']);
|
||||
$this->assertContains('Anreisedaten', $known['independent']);
|
||||
$this->assertContains('Bestätigung des Portals abwarten', $confirmed['independent'], 'the confirmation ends while the payments still wait');
|
||||
$this->assertContains('Buchungsinformation an den Gast (automatisch)', $confirmed['independent']);
|
||||
|
||||
$this->assertSame(0, Booking::query()->count(), 'nothing reached the real data');
|
||||
$this->assertSame(0, BookingTask::query()->count());
|
||||
}
|
||||
|
||||
public function test_the_tester_runs_the_fourth_combination_and_marks_it_as_such(): void
|
||||
{
|
||||
$report = $this->play('collection.own', 'contract_docs.external');
|
||||
|
||||
$this->assertSame('A3', $report['plan']['case_type'], 'classified by who collects – no archetype of its own');
|
||||
$values = collect($report['plan']['configuration'])->keyBy('question');
|
||||
$this->assertSame(['Wir', 'festgelegt durch die gewählte Funktionsschablone'], [$values['Wer kümmert sich um die Zahlungen des Gastes?']['value'] ?? null, $values['Wer kümmert sich um die Zahlungen des Gastes?']['source'] ?? null]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function play(string $collection, string $documents): array
|
||||
{
|
||||
$draft = ['model' => 'external.booking', 'templates' => ['collection' => $collection, 'contract_documents' => $documents], 'settings' => ['await_portal_confirmation' => '1', 'booking_notice' => 'automatic']];
|
||||
|
||||
return app(ProcessSandbox::class)->run($this->portal, IntakeKind::Booking, $draft, 'portal_confirmation_wait', ['arrival' => '2026-11-14', 'nights' => 4, 'guests' => 2, 'confirmation' => 'late'], 6, $this->user)->report;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user