V2.1: Kanalfähigkeiten, Ausführungsvarianten, Dokumentenentkopplung, Portalbestätigung

Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte,
Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf
die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-05 07:54:11 +01:00
1 parent ef1635e59a
commit 8442d0a3d8
62 files changed
+1818 -69

No files matched your search

@@ -4,7 +4,8 @@
use App\Actions\SendBookingDocuments;
use App\Enums\ActivityState;
use App\Enums\ProcessingMode;
use App\Enums\ContractDelivery;
use App\Enums\Execution;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Process\Activity;
@@ -14,6 +15,7 @@
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\RunsAutomatically;
use App\Process\PortalConfirmation;
use App\Process\StepResult;
/**
@@ -28,17 +30,27 @@ public static function key(): string
return 'documents.send';
}
public static function version(): int
{
// 2: the contract document is created and filed separately from sending it (contract_delivery); waits for the portal's
// confirmation where the channel says so. Default behaviour is the one of version 1.
return 2;
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Buchungsunterlagen (Vertragsdokumentation)',
purpose: 'Sendet dem Gast die verbindliche Buchungsbestätigung mit Vertrag bzw. die Unterlagen der Portalbuchung.',
phase: 'P03',
requires: [Dependency::hard('guest.details')],
executions: [Execution::Automatic, Execution::Approval, Execution::Manual, Execution::Portal],
condition: 'bei jeder verbindlichen Buchung, für die wir die Unterlagen verantworten',
why: 'Die verbindliche Vertragsdokumentation muss den Gast erreichen – von uns oder vom Portal (O1). Wie, ist einstellbar.',
requires: [Dependency::hard('guest.details'), Dependency::hard('portal.confirmation')],
effects: ['case_write', 'guest_mail', 'document'],
waits: ['landlord', 'portal'],
triggers: ['automation', 'booking.taken_over'],
parameters: [ProcessSetting::Documents, ProcessSetting::Processing, ProcessSetting::ContractTemplate],
triggers: ['automation', 'booking.taken_over', 'portal.mail', 'schedule:waiting'],
parameters: [ProcessSetting::Documents, ProcessSetting::Processing, ProcessSetting::ContractDelivery, ProcessSetting::ContractTemplate],
performers: ['system', 'landlord', 'portal'],
modes: ['automatic', 'manual'],
events: ['document', 'mail'],
@@ -59,8 +71,14 @@ public function activities(CaseContext $case): array
}
$binding = $case->binding;
$delivery = $case->profile->contractDelivery();
$internal = $delivery === ContractDelivery::Internal;
$stored = $booking->contract_path !== null;
$awaiting = $binding && ! $case->inquiry && $case->profile->awaitsPortalConfirmation() && PortalConfirmation::evidence($booking) === null;
$state = match (true) {
$booking->confirmation_sent_at !== null => ActivityState::Done,
// Created and filed internally is how the landlord chose to fulfil the step; sending stays possible by hand.
$internal && $stored => ActivityState::Done,
! $binding => ActivityState::Later,
$booking->confirmation_failed_at !== null => ActivityState::Problem,
default => ActivityState::Open,
@@ -68,33 +86,42 @@ public function activities(CaseContext $case): array
$missing = $binding && $state === ActivityState::Open ? app(CaseAutomation::class)->documentBlockers($booking) : [];
// What the landlord still has to confirm (unreleased texts, terms not shown to be agreed on the portal).
$toConfirm = $binding && $state === ActivityState::Open && $missing === [] ? app(SendBookingDocuments::class)->compose($booking)->toConfirm() : [];
$waiting = $missing !== [] || ($awaiting && $state === ActivityState::Open);
return [new Activity('documents', match (true) {
$internal && $state === ActivityState::Done && $booking->confirmation_sent_at === null => 'Vertrag intern abgelegt',
$internal && $state === ActivityState::Open => 'Vertrag erstellen und intern ablegen',
$state !== ActivityState::Open => $case->inquiry ? 'Buchungsbestätigung mit Vertrag senden' : 'Buchungsunterlagen an den Gast senden',
$case->inquiry => 'Buchungsbestätigung mit Vertrag prüfen und senden',
default => 'Buchungsunterlagen prüfen und senden',
}, $case->later($missing !== [] ? ActivityState::Waiting : $state),
}, $case->later($waiting ? ActivityState::Waiting : $state),
match (true) {
$booking->confirmation_sent_at !== null => 'gesendet am '.$booking->confirmation_sent_at->format('d.m.Y'),
$internal && $state === ActivityState::Done => 'erstellt und intern abgelegt – nicht an den Gast gesendet (Einstellung des Kanals); Senden von Hand bleibt möglich',
$state === ActivityState::Problem => 'Versand fehlgeschlagen',
$missing !== [] => 'wartet: '.implode(' ', $missing),
$awaiting => 'wartet auf die Bestätigungsmail des Portals (die Belegung ist gesichert)',
$toConfirm !== [] => 'vor dem Versand zu prüfen: '.implode(' ', $toConfirm),
default => null,
}, match (true) {
$state === ActivityState::Problem => 'resendConfirmation',
$binding && $missing === [] && $booking->confirmation_sent_at === null => 'sendDocuments',
$binding && $missing === [] && $booking->confirmation_sent_at === null && ! ($internal && $stored) => 'sendDocuments',
default => null,
})];
}
/** The guest's e-mail and the price are what the documents need – not every detail of a request. */
/**
* The guest's e-mail and the price are what the documents need – not every detail of a request. Due when they are
* to go out automatically (as the case is processed or as chosen for the delivery), or – delivery „internal“ – when the
* contract is still to be created and filed.
*/
public function due(CaseContext $case): bool
{
$booking = $case->booking;
$delivery = $case->profile->contractDelivery();
$mine = $case->binding && $booking->confirmation_sent_at === null && $case->profile->documents() === Responsibility::Landlord && $case->profile->origin !== 'migration';
return $booking->processingMode() === ProcessingMode::Automatic
&& $case->binding && $booking->confirmation_sent_at === null
&& $case->profile->documents() === Responsibility::Landlord && $case->profile->origin !== 'migration';
return $mine && ($delivery === ContractDelivery::Internal ? $booking->contract_path === null : $delivery->sendsAutomatically($booking->processingMode()));
}
public function blockers(CaseContext $case): array
@@ -104,7 +131,8 @@ public function blockers(CaseContext $case): array
public function run(CaseContext $case): StepResult
{
$reasons = app(SendBookingDocuments::class)->automatically($case->booking);
$documents = app(SendBookingDocuments::class);
$reasons = $case->profile->contractDelivery() === ContractDelivery::Internal ? $documents->storeInternally($case->booking) : $documents->automatically($case->booking);
return $reasons === [] ? StepResult::ran() : StepResult::blocked($reasons);
}
@@ -0,0 +1,113 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Actions\SendBookingNotice;
use App\Enums\ActivityState;
use App\Enums\BookingNoticeMode;
use App\Enums\Execution;
use App\Enums\ProcessSetting;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\RunsAutomatically;
use App\Process\Modules\StepState;
use App\Process\PortalConfirmation;
use App\Process\StepResult;
/**
* P03 (V2.1, docs/Prozessarchitektur/V2.1/02 §4): a short booking information for the guest of a binding booking – without
* contract, independent of the contract documentation. Off by default. It waits for the portal's confirmation where the
* channel is set up that way, and is not needed where the portal informs the guest itself and confirmed (evidence on record).
*/
final class BookingNoticeStep extends Module implements RunsAutomatically
{
public static function key(): string
{
return 'documents.booking_notice';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Buchungsinformation an den Gast',
purpose: 'Sendet dem Gast eine kurze Information über seine Buchung – ohne Vertrag, unabhängig von den Vertragsunterlagen.',
phase: 'P03',
executions: [Execution::Automatic, Execution::Manual, Execution::Portal, Execution::NotRequired],
condition: 'nur bei extern verbindlicher Buchung und nur, wenn für den Kanal eine Buchungsinformation eingestellt ist',
requires: [Dependency::hard('portal.confirmation'), Dependency::hard('guest.details'), Dependency::soft('documents.send')],
effects: ['case_write', 'guest_mail'],
waits: ['portal', 'guest', 'landlord'],
triggers: ['automation', 'booking.taken_over', 'portal.mail', 'schedule:waiting'],
parameters: [ProcessSetting::BookingNotice],
toggle: ModuleDefinition::TOGGLE_CONDITIONAL,
performers: ['system', 'landlord', 'portal'],
modes: ['automatic', 'manual'],
events: ['booking_notice', 'mail'],
);
}
public function applies(CaseContext $case): bool
{
return ! $case->inquiry && $case->profile->bookingNotice() !== BookingNoticeMode::Off;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$suppression = SendBookingNotice::suppression($booking);
$sent = SendBookingNotice::sent($booking);
$waitsForPortal = $case->profile->awaitsPortalConfirmation() && PortalConfirmation::evidence($booking) === null;
$label = 'Buchungsinformation an den Gast'.($case->profile->bookingNotice()->isAutomatic() ? ' (automatisch)' : '');
return [new Activity('booking_notice', $label, $case->later(match (true) {
$sent => ActivityState::Done,
$suppression !== null => ActivityState::NotApplicable,
! $case->binding => ActivityState::Later,
$waitsForPortal => ActivityState::Waiting,
blank($booking->guest?->email) => ActivityState::Waiting,
default => ActivityState::Open,
}), match (true) {
$sent => 'gesendet',
$suppression !== null => 'nicht nötig: '.$suppression,
$waitsForPortal => 'wartet auf die Bestätigungsmail des Portals',
blank($booking->guest?->email) => 'wartet: Die E-Mail-Adresse des Gastes fehlt.',
default => null,
}, ! $sent && $suppression === null && $case->binding && filled($booking->guest?->email) ? 'sendBookingNotice' : null)];
}
public function state(CaseContext $case): ?StepState
{
$booking = $case->booking;
return match (true) {
SendBookingNotice::sent($booking) => StepState::Done,
SendBookingNotice::suppression($booking) !== null => StepState::NotApplicable,
! $case->binding => StepState::Later,
default => StepState::Open,
};
}
public function due(CaseContext $case): bool
{
return $case->profile->bookingNotice()->isAutomatic() && $case->binding && ! $case->closed
&& ! SendBookingNotice::sent($case->booking) && SendBookingNotice::suppression($case->booking) === null && $case->profile->origin !== 'migration';
}
public function blockers(CaseContext $case): array
{
return filled($case->booking->guest?->email) ? [] : ['Die E-Mail-Adresse des Gastes fehlt.'];
}
public function run(CaseContext $case): StepResult
{
return app(SendBookingNotice::class)->handle($case->booking, automatic: true) ? StepResult::ran() : StepResult::blocked([SendBookingNotice::suppression($case->booking) ?? 'Nicht gesendet.']);
}
public function isOutward(): bool
{
return true;
}
}
@@ -33,6 +33,8 @@ public static function definition(): ModuleDefinition
label: 'Aufgaben und Meldungen',
purpose: 'Zeigt offene Aufgaben des Vorgangs – Meldungen der Portale, Entscheidungen, Zahlungs- und Leistungsaufgaben.',
phase: 'P03',
executions: [],
condition: 'wenn eine Aufgabe oder Meldung vorliegt',
effects: ['case_write'],
waits: ['landlord'],
triggers: ['task.created', 'portal.report'],
@@ -26,6 +26,8 @@ public static function definition(): ModuleDefinition
label: 'Änderungsvorschlag',
purpose: 'Zeigt einen Änderungsvorschlag, der beim Gast liegt.',
phase: 'P03',
executions: [],
condition: 'wenn ein Änderungsvorschlag beim Gast liegt',
effects: ['case_write', 'guest_mail'],
waits: ['guest', 'time'],
triggers: ['change.proposed'],
@@ -4,6 +4,7 @@
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\Execution;
use App\Process\Activity;
use App\Process\CaseClosure;
use App\Process\CaseContext;
@@ -28,6 +29,9 @@ public static function definition(): ModuleDefinition
label: 'Kaufmännisch abschließen',
purpose: 'Schließt den Vorgang kaufmännisch ab, wenn Zahlungen, Erstattungen und Auszahlungen geklärt sind.',
phase: 'P05',
executions: [Execution::Manual],
condition: 'nach dem Aufenthalt',
why: 'Zahlungen, Erstattungen und Auszahlungen müssen geklärt sein; eine Portalmeldung ersetzt den Nachweis nicht (O5).',
requires: [Dependency::soft('case.closure')],
effects: ['case_write'],
waits: ['landlord', 'portal'],
@@ -4,6 +4,7 @@
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\Execution;
use App\Enums\InternalKind;
use App\Models\BookingTask;
use App\Process\Activity;
@@ -28,6 +29,9 @@ public static function definition(): ModuleDefinition
label: 'Aufenthalt abschließen',
purpose: 'Schließt den Aufenthalt ab, sobald nach der Abreise nichts mehr für ihn offen ist.',
phase: 'P05',
executions: [Execution::Automatic, Execution::Manual],
condition: 'nach der Abreise',
why: 'Ein Aufenthalt wird immer abgeschlossen, damit nichts offen bleibt (E-010).',
effects: ['case_write'],
waits: ['time', 'landlord'],
triggers: ['schedule:daily'],
@@ -3,6 +3,7 @@
namespace App\Process\Modules\Settlement;
use App\Enums\ActivityState;
use App\Enums\Execution;
use App\Enums\InternalKind;
use App\Process\Activity;
use App\Process\CaseContext;
@@ -25,6 +26,8 @@ public static function definition(): ModuleDefinition
label: 'Aufenthaltsbestätigung',
purpose: 'Bestätigt den Gästen einer Eigenbelegung oder privaten Überlassung den Aufenthalt – nur bei Bedarf.',
phase: 'P03',
executions: [Execution::Manual, Execution::NotRequired],
condition: 'bei einer privaten Überlassung mit Gästen',
effects: ['guest_mail', 'document'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
performers: ['landlord'],