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

+43 -11
View File
@@ -5,40 +5,59 @@
use App\Enums\IntakeKind;
use App\Enums\ProcessSetting;
use App\Models\Channel;
use App\Process\ChannelCapabilities;
use App\Process\ChannelProcessConfiguration;
use Illuminate\Support\Facades\DB;
use Illuminate\Validation\ValidationException;
/**
* Saves the process of a channel for one intake kind (Kanal › Ablauf, docs/Prozessarchitektur/Architektur/03): the
* chosen model and variant, the step switches and the step settings – in channels.process_overrides[intake], next to
* the existing settings, so their inheritance stays as it is. Refuses everything the configuration does not admit
* (mandatory steps off, responsibilities the model does not allow, tester-only variants). Changes apply to new cases
* only (decision E3): running cases keep their frozen plan.
* Saves the process of a channel for one intake kind (Kanal › Ablauf, docs/Prozessarchitektur/Architektur/03 and V2.1/02):
* the confirmed capabilities of the portal, the chosen model and variant, the step switches and the step settings – in
* channels.settings and channels.process_overrides[intake], next to the existing settings, so their inheritance stays
* as it is. Refuses everything the configuration does not admit (mandatory steps off, responsibilities the model does not
* allow, a model the capabilities do not fit, tester-only variants). Stored settings that the chosen model overrides are
* removed only after the landlord confirmed that, and the change is kept in the channel's history. Changes apply to new
* cases only (decision E3): running cases keep their frozen plan.
*/
class ConfigureChannelProcess
{
public function __construct(private ChannelProcessConfiguration $configuration) {}
public const HISTORY_LIMIT = 20;
public function __construct(private ChannelProcessConfiguration $configuration, private ChannelCapabilities $capabilities) {}
/**
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>} $draft
* @param array{model: string, variant?: string, steps?: array<string, array{on?: bool}>, settings?: array<string, mixed>, capabilities?: array<string, bool|string|null>} $draft
* @param bool $acknowledgeConflicts the landlord confirmed that stored settings the model overrides are removed
*
* @throws ValidationException
*/
public function handle(Channel $channel, IntakeKind $intake, array $draft, ?string $by = null): Channel
public function handle(Channel $channel, IntakeKind $intake, array $draft, ?string $by = null, bool $acknowledgeConflicts = false): Channel
{
$problems = $this->configuration->problems($channel, $intake, $draft);
if ($problems !== []) {
throw ValidationException::withMessages(['process' => $problems]);
}
return DB::transaction(function () use ($channel, $intake, $draft, $by): Channel {
$conflicts = $this->configuration->conflicts($channel, $intake, (string) $draft['model']);
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:',
...array_column($conflicts, 'text'),
]]);
}
return DB::transaction(function () use ($channel, $intake, $draft, $by, $conflicts): Channel {
$channel = Channel::query()->lockForUpdate()->findOrFail($channel->id);
$by ??= auth()->user()?->name;
$overrides = (array) ($channel->process_overrides ?? []);
$current = (array) ($overrides[$intake->value] ?? []);
$removed = array_map(fn (array $conflict): string => $conflict['setting']->value, $conflicts);
$settings = [];
foreach (ProcessSetting::cases() as $setting) {
if (in_array($setting->value, $removed, true)) {
continue;
}
$value = array_key_exists($setting->value, (array) ($draft['settings'] ?? [])) ? $setting->normalize($draft['settings'][$setting->value]) : $setting->normalize($current[$setting->value] ?? null);
if ($value !== null && in_array($intake, $setting->channelIntakes(), true)) {
$settings[$setting->value] = $value;
@@ -58,9 +77,22 @@ public function handle(Channel $channel, IntakeKind $intake, array $draft, ?stri
'variant' => $draft['variant'] ?? 'standard',
'steps' => $steps,
'configured_at' => now()->toIso8601String(),
'configured_by' => $by ?? auth()->user()?->name,
'configured_by' => $by,
];
$channel->update(['process_overrides' => $overrides]);
$channelSettings = (array) ($channel->settings ?? []);
$changes = [];
if (! $channel->isWebsite() && filled($draft['capabilities'] ?? null)) {
$confirmed = $this->capabilities->confirm($channel, (array) $draft['capabilities'], $by);
$channelSettings['capabilities'] = $confirmed['capabilities'];
$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',
'capabilities' => $changes, 'removed_settings' => array_map(fn (array $conflict): string => $conflict['text'], $conflicts),
]], -self::HISTORY_LIMIT);
$channel->update(['process_overrides' => $overrides, 'settings' => $channelSettings]);
return $channel;
});
+19
View File
@@ -12,9 +12,11 @@
use App\Enums\TenantServiceKey;
use App\Mail\PortalMailNotification;
use App\Models\BlockedPeriod;
use App\Models\Booking;
use App\Models\Channel;
use App\Models\IntakeObservation;
use App\Models\PortalEmail;
use App\Process\ProcessRunner;
use App\Support\Settings;
use App\Tenancy\TenantFeatures;
use Carbon\CarbonInterface;
@@ -79,6 +81,7 @@ public function handle(PortalMail $mail): ?PortalEmail
// One intake for all channels (package 4): bookings, requests and cancellations reach their case.
rescue(fn () => $this->intake($channel, $parsed, $record));
rescue(fn () => $this->resume($channel, $parsed, $record));
if (in_array($record->status, [PortalEmailStatus::Blocked, PortalEmailStatus::Released, PortalEmailStatus::NeedsReview], true)) {
rescue(fn () => Mail::to(Settings::notificationRecipients())->send(new PortalMailNotification($record)));
@@ -91,6 +94,22 @@ public function handle(PortalMail $mail): ?PortalEmail
return $record;
}
/**
* A booking mail of the portal can be the confirmation a case waits for (V2.1, docs/Prozessarchitektur/V2.1/02 §5): the
* case is evaluated again. Only cases whose channel makes them wait are touched – everything else stays as it was.
*/
private function resume(Channel $channel, ParsedPortalMail $parsed, PortalEmail $record): void
{
if ($parsed->type !== PortalEmailType::Booking) {
return;
}
$case = $record->blocked_period_id !== null ? Booking::query()->find(BlockedPeriod::withTrashed()->whereKey($record->blocked_period_id)->value('linked_booking_id')) : null;
$case ??= $parsed->reference !== null ? app(PortalIntake::class)->caseByReference($channel, $parsed->reference) : null;
if ($case !== null && $case->isBinding() && $case->process()->awaitsPortalConfirmation()) {
app(ProcessRunner::class)->advance($case, 'portal.mail');
}
}
private function intake(Channel $channel, ParsedPortalMail $parsed, PortalEmail $record): void
{
$intake = app(PortalIntake::class);
+35
View File
@@ -49,6 +49,41 @@ public function automatically(Booking $booking): array
return $this->send($booking, $composition, acknowledged: false, automatic: true) ? [] : ['Die Unterlagen konnten nicht versendet werden (siehe Postfach).'];
}
/**
* Creates the contract document and files it internally – without sending anything to the guest (delivery „internal“,
* docs/Prozessarchitektur/V2.1/02 §4). Same gate as the automatic dispatch: the composition must be clean.
*
* @return list<string> reasons why it was not created (empty: filed or already there)
*/
public function storeInternally(Booking $booking): array
{
if ($booking->contract_path !== null) {
return [];
}
$composition = $this->compose($booking);
if (! $composition->canSendAutomatically()) {
return [...$composition->blockers(), ...array_map(fn (string $point): string => 'Bitte prüfen: '.$point, $composition->toConfirm())];
}
$lock = Cache::lock('booking-documents-'.$booking->id, 120);
if (! $lock->get()) {
return ['Die Unterlagen werden gerade bearbeitet.'];
}
try {
$booking->refresh();
if (! $composition->termsFrozen && $composition->terms !== null) {
$booking->update(['offer_terms' => $composition->terms]);
}
return CaseLog::context(fn (): bool => $this->confirm->deliver($booking, notifyGuest: false, kind: $composition->kind), actor: CaseLog::SYSTEM.' (automatisch)')
? [] : ['Das Vertragsdokument konnte nicht erstellt werden (siehe Postfach).'];
} finally {
$lock->release();
}
}
/**
* Sending by hand after the landlord saw the composition.
*
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace App\Actions;
use App\Enums\BookingNoticeMode;
use App\Exceptions\ReservationException;
use App\Mail\BookingNotice;
use App\Models\Booking;
use App\Process\CaseLog;
use App\Process\ChannelCapabilities;
use App\Process\PortalConfirmation;
use Illuminate\Support\Facades\Mail;
/**
* Sends the guest of a binding booking a short booking information (V2.1, docs/Prozessarchitektur/V2.1/02 §4) – separate
* from the contract documentation, which has its own step. Once only (the history entry `booking_notice` is the record).
* Where the landlord chose „unless the portal confirmed“, it is not sent when the portal informs the guest itself (confirmed
* capability of the channel) and its booking confirmation for this case is on record; the reason is kept in the history.
*/
class SendBookingNotice
{
public const EVENT = 'booking_notice';
public static function sent(Booking $booking): bool
{
return $booking->events()->where('type', self::EVENT)->where('summary', 'not like', 'Keine eigene%')->exists();
}
/**
* Why no own notice is needed, or null when it is.
*/
public static function suppression(Booking $booking): ?string
{
if ($booking->process()->bookingNotice() !== BookingNoticeMode::AutomaticUnlessPortalConfirmed) {
return null;
}
$channel = $booking->processChannel();
if ($channel === null || app(ChannelCapabilities::class)->value($channel, ChannelCapabilities::MESSAGES_GUEST) !== true) {
return null;
}
$evidence = PortalConfirmation::evidence($booking);
return $evidence === null ? null : 'Das Portal informiert den Gast selbst und hat die Buchung bestätigt ('.$evidence['label'].').';
}
/**
* @throws ReservationException
*/
public function handle(Booking $booking, bool $automatic = false): bool
{
$booking->loadMissing(['guest', 'property']);
if (! $booking->isBinding()) {
throw ReservationException::invalidTransition($booking->status->getLabel(), 'mit einer Buchungsinformation bedacht');
}
if (self::sent($booking)) {
return true;
}
if (blank($booking->guest?->email)) {
throw new ReservationException('Vor dem Versand bitte die E-Mail-Adresse des Gastes ergänzen.');
}
if ($automatic && ($reason = self::suppression($booking)) !== null) {
if (! $booking->events()->where('type', self::EVENT)->exists()) {
CaseLog::record($booking, self::EVENT, 'Keine eigene Buchungsinformation nötig', reason: $reason, data: ['level' => 'stated_by_portal']);
}
return false;
}
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingNotice($booking));
CaseLog::record($booking, self::EVENT, 'Buchungsinformation an den Gast gesendet', actor: $automatic ? CaseLog::SYSTEM.' (automatisch)' : null);
return true;
}
}