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

@@ -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).',
];
}
}
+112
View File
@@ -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();
}
}
+78
View File
@@ -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.',
];
}
}
+49
View File
@@ -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,
};
}
}
+192
View File
@@ -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;
}
}