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>
114 lines
4.9 KiB
PHP
114 lines
4.9 KiB
PHP
<?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;
|
||
}
|
||
}
|