Schablonenkomposition: Basisprozess external.booking mit Platz für Finanz- und Dokumentenschablonen

Vier Schablonen (Eigenes/Portal-Inkasso, Eigene/Externe Vertragsdokumentation) in
app/Process/Templates, TemplateComposer prüft Ergebnisse, Verantwortlichkeiten, Ausschlüsse
und harte Modulabhängigkeiten. Der Plan friert die Schablonenversionen ein. A3–A5 bleiben
als Voreinstellungen; die vierte Kombination (eigenes Inkasso + externe Unterlagen) ist
darstellbar. Konfigurator-Logik und ConfigureChannelProcess kennen die Schablonenwahl.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-05 10:48:49 +01:00
1 parent 381720763c
commit e95ba4f986
24 files changed
+1666 -37

No files matched your search

+125 -15
View File
@@ -13,6 +13,9 @@
use App\Models\Channel;
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 +42,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 +137,85 @@ 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 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 +223,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.
@@ -184,7 +252,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 +267,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 +333,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 +371,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 +407,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 +436,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 +483,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);