U-A/U-B: Prozesskern mit Fachmodulen, versionierten Modellen, eingefrorenem Prozessplan, ProcessRunner (harte/weiche Abhängigkeiten), CasePricing, Loyalty nur im Tester

CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11:
11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002).
Volle Suite vor U-B: 785/785.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-04 14:49:44 +01:00
1 parent 98df5e9e3b
commit 7e22e12cac
80 files changed
+4628 -445

No files matched your search

@@ -0,0 +1,19 @@
<?php
namespace App\Process\Modules;
use App\Pricing\PriceQuote;
use App\Pricing\QuoteLine;
use App\Process\CaseContext;
/**
* A module that adds lines to the price before it is fixed (extension point BeforePriceFixing). CasePricing asks it only
* for cases that are not binding yet; once the offer is made the lines are frozen in the case's quote.
*/
interface ContributesToPrice
{
/**
* @return list<QuoteLine> lines to add (empty: no contribution)
*/
public function priceLines(CaseContext $case, PriceQuote $quote): array;
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Process\Modules;
/**
* A dependency of one step on another (requirement T1, docs/Prozessarchitektur/Architektur/02 §7.1).
*
* - **hard:** the step may only run when the other step is done. Nothing switches this off – there is no flag on the
* other step that could lift it.
* - **soft:** the step should run after the other one when both are due in the same round; when the other one waits,
* fails or does not apply, the step goes on as long as its own requirements are met.
*
* Independent steps simply declare no dependency on each other; conditional steps express their condition in
* {@see ProcessModule::applies()}.
*/
final readonly class Dependency
{
private function __construct(public string $module, public bool $hard) {}
public static function hard(string $module): self
{
return new self($module, true);
}
public static function soft(string $module): self
{
return new self($module, false);
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Process\Modules\Intake;
use App\Availability\AvailabilityChecker;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
/**
* P01/P02: the dates are free (calendar truth of AvailabilityChecker, fresh imports by CalendarClearance). Mandatory
* and never switched off; the offer depends on it hard.
*/
final class AvailabilityCheck extends Module
{
public static function key(): string
{
return 'availability.check';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Verfügbarkeit',
purpose: 'Prüft, ob der Zeitraum frei ist und die Kalender der Portale aktuell sind.',
phase: 'P01',
effects: ['network'],
triggers: ['intake', 'facts.applied'],
);
}
public function applies(CaseContext $case): bool
{
return $case->inquiry && ! $case->binding;
}
public function activities(CaseContext $case): array
{
return [];
}
public function state(CaseContext $case): ?StepState
{
$booking = $case->booking;
return app(AvailabilityChecker::class)->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking) ? StepState::Done : StepState::Problem;
}
}
@@ -0,0 +1,60 @@
<?php
namespace App\Process\Modules\Intake;
use App\Enums\ActivityState;
use App\Enums\ChannelTaskStatus;
use App\Filament\Resources\ChannelTasks\ChannelTaskResource;
use App\Models\ChannelTask;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
/**
* Blocking and releasing the dates in portals that need it by hand (requires_manual_blocking): the tasks come from the
* observers (CreateChannelTasks) and are proven per portal (ChannelTaskProof). Mandatory, never switched off.
*/
final class ChannelBlocks extends Module
{
public static function key(): string
{
return 'channels.block';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Andere Kanäle sperren',
purpose: 'Sperrt den Zeitraum in Portalen, die nicht automatisch abgleichen, und gibt ihn bei Ende wieder frei – mit Nachweis je Portal.',
phase: 'P02',
effects: ['channel_task', 'landlord_mail', 'network'],
waits: ['landlord', 'portal'],
triggers: ['booking.occupies', 'booking.released'],
performers: ['landlord', 'system'],
);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
return ChannelTask::query()
->with('channel')
->whereHas('channel', fn ($query) => $query->where('property_id', $booking->property_id))
->whereDate('starts_on', $booking->arrival)
->whereDate('ends_on', $booking->departure)
->where('status', '!=', ChannelTaskStatus::Dismissed)
->orderBy('id')
->get()
->map(fn (ChannelTask $task): Activity => new Activity('channel_block', ($task->action->value === 'block' ? 'In ' : 'Freigeben in ').$task->channel?->name.($task->action->value === 'block' ? ' sperren' : ''), $task->status === ChannelTaskStatus::Open ? ActivityState::Open : ActivityState::Done, $task->period().' · '.$task->proofLabel(), url: ChannelTaskResource::getUrl()))
->all();
}
/** Listed on its own in the work list; it never holds another step back. */
public function state(CaseContext $case): ?StepState
{
return null;
}
}
@@ -0,0 +1,95 @@
<?php
namespace App\Process\Modules\Intake;
use App\Actions\RequestCaseData;
use App\Enums\ActivityState;
use App\Enums\ProcessSetting;
use App\Models\DataRequest;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\CaseRequirements;
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\StepResult;
/**
* P01: asks the guest for missing details by link and reminds (v0.11). It runs in its own mode (automatic / after
* release / by hand) whatever the case's processing is, and independently of the other steps: a clarification hold
* keeps its deadline while the request waits for the guest.
*/
final class GuestDataRequest extends Module implements RunsAutomatically
{
public static function key(): string
{
return 'guest.data_request';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Fehlende Angaben beim Gast anfragen',
purpose: 'Fragt fehlende Pflichtangaben per Link beim Gast an, erinnert und übergibt an Sie, wenn der Gast nicht antwortet.',
phase: 'P01',
requires: [Dependency::hard('intake.record')],
effects: ['case_write', 'guest_mail'],
waits: ['guest', 'landlord', 'time'],
triggers: ['request.created', 'booking.taken_over', 'wish'],
parameters: [ProcessSetting::DataRequest, ProcessSetting::DataRequestRemindersMax, ProcessSetting::DataRequestFollowupsMax, ProcessSetting::DataRequestReminderHours, ProcessSetting::GuestLinkValidDays],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
performers: ['system', 'landlord'],
modes: ['automatic', 'approval', 'manual'],
events: ['data_request', 'mail_in', 'facts', 'fact'],
);
}
/**
* Shown as a step of its own only for a binding booking (a request shows it inside the guest's details).
*/
public function activities(CaseContext $case): array
{
$request = $case->binding ? $case->booking->openDataRequest() : null;
if ($request === null) {
return [];
}
return [new Activity('data_request', 'Fehlende Angaben beim Gast anfragen', $case->later($request->status === DataRequest::OPEN ? ActivityState::Waiting : ActivityState::Open),
implode(', ', CaseRequirements::labels($request->fields)).' · '.$request->statusLabel(), $request->status === DataRequest::OPEN ? null : 'approveDataRequest')];
}
public function state(CaseContext $case): ?StepState
{
$request = $case->booking->openDataRequest();
return match (true) {
$request === null => RequestCaseData::needs($case->booking) === null ? StepState::Done : StepState::Open,
$request->status === DataRequest::OPEN => StepState::Waiting,
default => StepState::Open,
};
}
public function due(CaseContext $case): bool
{
return RequestCaseData::needs($case->booking) !== null && $case->booking->openDataRequest() === null;
}
public function blockers(CaseContext $case): array
{
return CaseRequirements::isValid('guest.email', $case->booking->guest?->email) ? [] : ['Die E-Mail-Adresse des Gastes fehlt.'];
}
public function run(CaseContext $case): StepResult
{
$request = app(RequestCaseData::class)->forNextStep($case->booking);
return $request === null ? StepResult::blocked(['Nichts anzufragen.']) : StepResult::ran();
}
public function isOutward(): bool
{
return false;
}
}
@@ -0,0 +1,84 @@
<?php
namespace App\Process\Modules\Intake;
use App\Enums\ActivityState;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Models\DataRequest;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\CaseRequirements;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P01: who the guest is and whether every detail the next step needs is there and valid (v0.11 G2a). The details
* themselves come in through the common fact intake (ContributeCaseFacts) from every source.
*/
final class GuestDetails extends Module
{
public static function key(): string
{
return 'guest.details';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Angaben des Gastes',
purpose: 'Identifiziert den Gast, führt seine Angaben aus allen Quellen zusammen und prüft, ob alles für den nächsten Schritt da ist.',
phase: 'P01',
requires: [Dependency::hard('intake.record')],
effects: ['case_write'],
waits: ['guest', 'landlord'],
triggers: ['facts.applied'],
parameters: [ProcessSetting::FormRequiresAddress],
performers: ['guest', 'landlord'],
events: ['facts', 'fact', 'guest', 'data_request', 'mail_in'],
);
}
/** We correspond with the guest ourselves (a request, or our documents, messages or payments). */
public function applies(CaseContext $case): bool
{
$profile = $case->profile;
return $case->inquiry || $profile->documents() === Responsibility::Landlord || $profile->guestMessages() === Responsibility::Landlord || $profile->payments() === Responsibility::Landlord;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$profile = $case->profile;
$hasEmail = filled($booking->guest?->email);
// v0.11 (G2a): before the own binding offer – or the binding confirmation of a wish – every required detail.
$action = $profile->preReservation() || $booking->offer_version > 0 ? CaseRequirements::OFFER : CaseRequirements::WISH_CONFIRMATION;
$needsDetails = $case->inquiry && ! $case->binding && $booking->offer_version === 0 && ($action === CaseRequirements::OFFER || $booking->wish_at !== null);
$missing = $hasEmail && $needsDetails ? CaseRequirements::missing($booking, $action) : [];
$request = $booking->openDataRequest();
$asked = $booking->contact_requested_at !== null || $request?->status === DataRequest::OPEN;
$state = match (true) {
$hasEmail && $missing === [] => ActivityState::Done,
$asked => ActivityState::Waiting,
default => ActivityState::Open,
};
$title = match (true) {
$booking->guest === null => 'Name und Kontaktdaten des Gastes eintragen',
! $hasEmail => 'E-Mail-Adresse des Gastes eintragen',
$missing !== [] => $action === CaseRequirements::OFFER ? 'Angaben für das Angebot vervollständigen' : 'Angaben für die Bestätigung vervollständigen',
default => 'Kontaktdaten des Gastes',
};
$detail = match (true) {
$state === ActivityState::Done => $booking->guestName(),
$missing !== [] => 'fehlt: '.implode(', ', CaseRequirements::labels($missing)).($request !== null ? ' · '.$request->statusLabel() : ($asked ? ' · beim Gast angefragt' : '')),
$booking->contact_requested_at !== null => 'beim Gast erfragt am '.$booking->contact_requested_at->format('d.m.Y'),
default => 'fehlt noch',
};
// A prepared data request waits for the landlord's release: that is the next step, otherwise entering the details.
$draft = $needsDetails && $request?->status === DataRequest::DRAFT;
return [new Activity('contact', $title, $case->later($draft ? ActivityState::Open : $state), $detail, $state === ActivityState::Done ? null : ($draft ? 'approveDataRequest' : 'provideContact'))];
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Process\Modules\Intake;
use App\Enums\ProcessSetting;
use App\Models\Booking;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
/**
* P01/P02: the hold of a request – clarification hold of an incomplete request or offer hold – and its deadline. It is
* set by the intake (RequestHold under the calendar lock) and by SendOffer, it ends by ExpireReservations or the
* release; this step only watches it. It depends on the intake alone, never on the guest's details, so a request that
* waits for its address keeps its clarification hold running (requirement K1/T1).
*/
final class Hold extends Module
{
public static function key(): string
{
return 'hold';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Reservierung des Zeitraums',
purpose: 'Hält den Zeitraum während der Klärung bzw. der Angebotsfrist frei und gibt ihn nach Ablauf wieder frei.',
phase: 'P01',
requires: [Dependency::hard('intake.record')],
effects: ['calendar_hold'],
waits: ['time'],
triggers: ['intake', 'offer.sent', 'schedule:bookings:expire-holds'],
parameters: [ProcessSetting::PreReservation, ProcessSetting::HoldHours, ProcessSetting::ClarificationHoldAutoMinutes, ProcessSetting::ClarificationHoldManualMinutes],
toggle: ModuleDefinition::TOGGLE_CONDITIONAL,
events: ['hold'],
);
}
public function applies(CaseContext $case): bool
{
return $case->inquiry && $case->profile->preReservation();
}
/** The hold has no line of its own: the offer step and the situation show it. */
public function activities(CaseContext $case): array
{
return [];
}
public function state(CaseContext $case): ?StepState
{
$booking = $case->booking;
return match (true) {
$booking->isHoldActive() => StepState::Waiting,
$booking->hold_expires_at === null && $booking->hold_purpose === Booking::HOLD_CLARIFICATION => StepState::NotApplicable,
default => StepState::Done,
};
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Process\Modules\Intake;
use App\Enums\ActivityState;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P01: the case came in – request, portal booking or internal occasion. Recording it (and the hold of a request,
* under the calendar lock) is done by the intake actions; the step only shows it.
*/
final class IntakeRecord extends Module
{
public static function key(): string
{
return 'intake.record';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Eingang',
purpose: 'Hält den Eingang der Anfrage, Buchung oder Eigenbelegung fest und friert den Ablauf ein.',
phase: 'P01',
effects: ['case_write', 'calendar_hold'],
triggers: ['intake'],
events: ['created', 'intake', 'profile', 'hold', 'mode'],
);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
if ($booking->isInternal()) {
return [new Activity('intake', ($booking->internal_kind?->getLabel() ?? 'Eigene Belegung').' eingetragen', ActivityState::Done, $booking->occasion)];
}
return [new Activity('intake', $case->inquiry ? 'Anfrage eingegangen' : 'Buchung beim Portal eingegangen', ActivityState::Done, $booking->created_at?->format('d.m.Y').' · '.$booking->bookingChannelLabel())];
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Process\Modules\Intake;
use App\Enums\ActivityState;
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\Support\Money;
/**
* P02 for A3–A5: the booking is binding at the portal (E-036) – no second acceptance, no own price. The guest's total
* comes "laut Portal" (RecordPortalAmounts) and is never recalculated.
*/
final class PortalBinding extends Module
{
public static function key(): string
{
return 'binding.portal';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Verbindlichkeit beim Portal',
purpose: 'Stellt fest, dass die Buchung beim Portal verbindlich ist, und übernimmt den Gesamtpreis laut Portal.',
phase: 'P02',
requires: [Dependency::hard('intake.record')],
effects: ['case_write'],
waits: ['portal', 'landlord'],
triggers: ['intake', 'portal.amounts'],
performers: ['portal', 'landlord'],
events: ['status', 'portal_signal', 'price', 'amount'],
readsContractData: true,
);
}
public function applies(CaseContext $case): bool
{
return ! $case->inquiry;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
return [
new Activity('binding', 'Beim Portal fest gebucht', $case->binding || $case->closed ? ActivityState::External : ActivityState::Open, $booking->portal_reference ? 'Buchungsnummer '.$booking->portal_reference : null, $case->binding ? null : 'confirm'),
new Activity('price', 'Gesamtpreis laut Portal eintragen', $case->later($booking->total === null ? ActivityState::Open : ActivityState::Done), $booking->total === null ? 'noch nicht bekannt' : Money::format($booking->total), $booking->total === null ? 'portalPrice' : null),
];
}
}
@@ -0,0 +1,69 @@
<?php
namespace App\Process\Modules\Loyalty;
use App\Enums\ActivityState;
use App\Enums\QuoteLineType;
use App\Pricing\PriceQuote;
use App\Pricing\QuoteLine;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\ContributesToPrice;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Support\Money;
/**
* Architecture proof (decision E7): a returning guest's discount as a Discount line before the price is fixed. Tester
* only. Test assumptions (E5/E6, not released business rules): a percentage of the rent with a cap; no discount when the
* quote already has a special offer discount; once the offer is made the line is frozen in the quote and never
* recalculated (also not when the booking changes).
*/
final class LoyaltyDiscount extends Module implements ContributesToPrice
{
public static function key(): string
{
return 'pricing.loyalty_discount';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Stammgastrabatt',
purpose: 'Gewährt Stammgästen einen Rabatt auf die Miete, bevor der Preis festgelegt wird (Architekturnachweis, nur im Prozess-Tester).',
phase: 'P02',
requires: [Dependency::hard('guest.loyalty_status')],
effects: [],
parameters: ['percent', 'max'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
points: ['before_price_fixing'],
readsContractData: true,
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
);
}
public function priceLines(CaseContext $case, PriceQuote $quote): array
{
$status = app(LoyaltyStatusCheck::class)->status($case);
if ($status['status'] !== LoyaltyStatusCheck::QUALIFIED || $quote->discount() > 0) {
return [];
}
$percent = (int) ($case->parameter(self::key(), 'percent') ?? 5);
$max = (int) ($case->parameter(self::key(), 'max') ?? 10000);
$amount = min($max, (int) round($quote->rent() * $percent / 100));
if ($amount <= 0) {
return [];
}
return [new QuoteLine(QuoteLineType::Discount, 'Stammgastrabatt '.$percent.' % ('.count($status['stays']).' frühere Aufenthalte)', 1, -$amount, -$amount)];
}
public function activities(CaseContext $case): array
{
$line = collect((array) ($case->booking->quote['lines'] ?? []))->first(fn (array $line): bool => str_starts_with((string) ($line['label'] ?? ''), 'Stammgastrabatt'));
return [new Activity('loyalty_discount', 'Stammgastrabatt', ActivityState::Done, $line !== null ? Money::format(-(int) $line['amount']).' im Angebot' : 'kein Rabatt im Angebot')];
}
}
@@ -0,0 +1,90 @@
<?php
namespace App\Process\Modules\Loyalty;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Models\Booking;
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\StepState;
/**
* Architecture proof (decision E7, docs/Prozessarchitektur/Architektur/02 §6): whether the guest is a returning guest –
* completed, not cancelled stays of the same guest e-mail at the same landlord within the look-back. Tester only: never
* part of a real case's plan. The status is derived from the stays on every evaluation (no second truth); the rules
* (count, look-back) are test assumptions, not released business rules.
*/
final class LoyaltyStatusCheck extends Module
{
public const QUALIFIED = 'qualified';
public const NOT_QUALIFIED = 'not_qualified';
public const UNKNOWN = 'unknown';
public static function key(): string
{
return 'guest.loyalty_status';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Stammgaststatus feststellen',
purpose: 'Stellt fest, ob der Gast schon bei Ihnen zu Gast war (Architekturnachweis, nur im Prozess-Tester).',
phase: 'P01',
requires: [Dependency::hard('guest.details')],
triggers: ['facts.applied'],
parameters: ['min_stays', 'lookback_years'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
events: ['facts'],
points: ['after_guest_identified'],
availability: ModuleDefinition::AVAILABILITY_TESTER_ONLY,
);
}
/**
* @return array{status: string, stays: list<string>}
*/
public function status(CaseContext $case): array
{
$email = mb_strtolower(trim((string) $case->booking->guest?->email));
if ($email === '') {
return ['status' => self::UNKNOWN, 'stays' => []];
}
$years = (int) ($case->parameter(self::key(), 'lookback_years') ?? 5);
$minimum = (int) ($case->parameter(self::key(), 'min_stays') ?? 1);
$stays = Booking::query()
->whereKeyNot($case->booking->id)
->where('status', BookingStatus::Completed)
->whereDate('departure', '>=', $case->today->subYears($years))
->whereHas('guest', fn ($query) => $query->whereRaw('lower(email) = ?', [$email]))
->orderBy('arrival')
->get()
->map(fn (Booking $stay): string => (string) $stay->reference)
->all();
return ['status' => count($stays) >= $minimum ? self::QUALIFIED : self::NOT_QUALIFIED, 'stays' => $stays];
}
public function activities(CaseContext $case): array
{
$status = $this->status($case);
return [new Activity('loyalty_status', 'Stammgaststatus feststellen', ActivityState::Done, match ($status['status']) {
self::QUALIFIED => 'Stammgast: '.count($status['stays']).' frühere Aufenthalte ('.implode(', ', $status['stays']).')',
self::NOT_QUALIFIED => 'kein Stammgast',
default => 'Status nicht feststellbar (keine E-Mail-Adresse) – kein Rabatt',
})];
}
public function state(CaseContext $case): ?StepState
{
return StepState::Done;
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace App\Process\Modules;
use App\Process\CaseContext;
/**
* Common ground of the modules: version 1, the state of the step is the state of its (first) activity.
*/
abstract class Module implements ProcessModule
{
public static function version(): int
{
return 1;
}
public function applies(CaseContext $case): bool
{
return true;
}
public function state(CaseContext $case): ?StepState
{
$activity = $this->activities($case)[0] ?? null;
return $activity === null ? null : StepState::fromActivity($activity->state);
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Process\Modules;
use App\Enums\ProcessSetting;
/**
* The contract of a module as data (docs/Prozessarchitektur/Architektur/02 §3.2). Fields marked "checked" are verified
* by `process:check` or the contract tests; the others describe and are reviewed by hand – they promise nothing a test
* cannot verify.
*
* @phpstan-type Performer 'system'|'landlord'|'guest'|'portal'|'service_provider'
*/
final readonly class ModuleDefinition
{
public const TOGGLE_MANDATORY = 'mandatory';
public const TOGGLE_OPTIONAL = 'optional';
public const TOGGLE_CONDITIONAL = 'conditional';
public const TOGGLE_EVENT_DRIVEN = 'event_driven';
public const AVAILABILITY_PRODUCTION = 'production';
/** Only in the process tester; never part of a real case's plan (decision E7, loyalty). */
public const AVAILABILITY_TESTER_ONLY = 'tester_only';
/**
* @param string $label name of the step for the landlord (describes)
* @param string $purpose what the step does, in plain words (describes)
* @param string $phase P01–P05 (checked)
* @param list<Dependency> $requires dependencies for readiness (checked: every module exists, no cycle)
* @param list<string> $effects kinds of effects the step may cause: case_write, guest_mail, landlord_mail, document, calendar_hold, channel_task, network (checked by the contract test)
* @param list<string> $waits whom or what the step can wait for: guest, portal, landlord, time (describes)
* @param list<string> $triggers events after which the step is evaluated again (describes; listed in process:check)
* @param list<ProcessSetting|string> $parameters settings or module parameters that shape the step (checked: known)
* @param string $toggle mandatory / optional / conditional / event_driven (checked: mandatory cannot be switched off)
* @param list<string> $performers who may carry the step out (checked against the models' responsibilities)
* @param list<string> $modes automatic / approval / manual (checked in the configurator)
* @param list<string> $events history types that belong to the step (shown behind the step)
* @param list<string> $points extension points the module may be inserted at (checked; empty = fixed place in a model)
* @param bool $readsContractData evaluates frozen contract data – needs an ongoing-case test (checked)
*/
public function __construct(
public string $label,
public string $purpose,
public string $phase,
public array $requires = [],
public array $effects = [],
public array $waits = [],
public array $triggers = [],
public array $parameters = [],
public string $toggle = self::TOGGLE_MANDATORY,
public array $performers = ['system'],
public array $modes = [],
public array $events = [],
public array $points = [],
public bool $readsContractData = false,
public string $availability = self::AVAILABILITY_PRODUCTION,
) {}
public function isOptional(): bool
{
return $this->toggle === self::TOGGLE_OPTIONAL;
}
public function isTesterOnly(): bool
{
return $this->availability === self::AVAILABILITY_TESTER_ONLY;
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Process\Modules\Money;
use App\Enums\ActivityState;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Support\Money;
/**
* A6: payment of an internal occasion with a price (e.g. linen, visitor's tax) – recorded, never reminded.
*/
final class InternalPayment extends Module
{
public static function key(): string
{
return 'payments.internal';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Zahlung (ohne Erinnerungen)',
purpose: 'Hält fest, was bei einer Eigenbelegung oder privaten Überlassung bezahlt wurde – ohne Erinnerungen.',
phase: 'P03',
effects: ['case_write'],
toggle: ModuleDefinition::TOGGLE_CONDITIONAL,
performers: ['landlord'],
events: ['payment'],
);
}
public function applies(CaseContext $case): bool
{
return $case->booking->total !== null && $case->booking->total > 0;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$paid = $booking->paidAmount();
return [new Activity('payment', 'Zahlung (ohne Erinnerungen)', $case->later($paid >= $booking->total ? ActivityState::Done : ActivityState::Later), Money::format($paid).' von '.Money::format($booking->total).' bezahlt')];
}
}
@@ -0,0 +1,81 @@
<?php
namespace App\Process\Modules\Money;
use App\Enums\ActivityState;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Support\Money;
/**
* P03: the guest's payments – deposit and balance when we collect (A1–A3), the portal's collection when it collects
* (A4/A5: only "laut Portal", never money on our account). Reminders are sent by SendBookingReminders.
*/
final class PaymentMonitoring extends Module
{
public static function key(): string
{
return 'payments.monitor';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Zahlungen des Gastes',
purpose: 'Überwacht Anzahlung und Restzahlung und erinnert rechtzeitig – oder zeigt, was das Portal laut eigener Angabe eingezogen hat.',
phase: 'P03',
effects: ['case_write', 'guest_mail'],
waits: ['guest', 'portal', 'time'],
triggers: ['payment.recorded', 'portal.amounts', 'schedule:reminders'],
parameters: [ProcessSetting::Payments, ProcessSetting::GuestMessages],
performers: ['landlord', 'portal'],
events: ['payment', 'amount'],
readsContractData: true,
);
}
public function applies(CaseContext $case): bool
{
return ! $case->booking->isInternal();
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$binding = $case->binding;
if ($case->profile->payments() === Responsibility::Portal) {
$portal = $booking->processChannel()?->name ?? 'das Portal';
$viaPortal = $booking->paidViaPortal();
return [new Activity('payment', 'Zahlung des Gastes an '.$portal, ActivityState::External, match (true) {
$booking->total === null => 'zieht das Portal ein',
$viaPortal > 0 => 'laut Portal bezahlt: '.Money::format($viaPortal).' von '.Money::format($booking->total).' (Angabe des Portals, kein Geld bei uns)',
default => 'zieht das Portal ein; noch keine Zahlungsangabe',
})];
}
if ($booking->total === null) {
return [new Activity('payment', 'Zahlungen überwachen', $case->later(ActivityState::Waiting), 'erst möglich, wenn der Preis bekannt ist')];
}
$paid = $booking->paidAmount();
return [
new Activity('deposit', 'Anzahlung erhalten', $case->later(match (true) {
$binding && $paid >= (int) $booking->deposit => ActivityState::Done,
$binding => ActivityState::Waiting,
default => ActivityState::Later,
}), Money::format((int) $booking->deposit).($booking->deposit_due_on ? ', fällig '.$booking->deposit_due_on->format('d.m.Y') : '')),
new Activity('balance', 'Restzahlung erhalten', $case->later(match (true) {
$binding && $paid >= $booking->total => ActivityState::Done,
$binding && $paid >= (int) $booking->deposit => ActivityState::Waiting,
default => ActivityState::Later,
}), Money::format(max(0, $booking->total - (int) $booking->deposit)).($booking->balance_due_on ? ', fällig '.$booking->balance_due_on->format('d.m.Y') : '')),
];
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Process\Modules\Money;
use App\Enums\ActivityState;
use App\Enums\Responsibility;
use App\Pricing\CaseMoney;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Support\Money;
/**
* P03 for portal collection (A4/A5): the portal's payout on our account. Only a payout the landlord recorded as
* received counts (PaymentKind::PortalPayout); an announced payout or a portal report is no proof (decision O5).
*/
final class PortalPayout extends Module
{
public static function key(): string
{
return 'portal.payout';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Auszahlung des Portals',
purpose: 'Prüft, ob die Auszahlung des Portals tatsächlich auf unserem Konto eingegangen ist und zu den Angaben passt.',
phase: 'P03',
effects: ['case_write'],
waits: ['portal', 'landlord', 'time'],
triggers: ['portal.amounts', 'payment.recorded'],
performers: ['landlord'],
events: ['payment', 'amount'],
readsContractData: true,
);
}
public function applies(CaseContext $case): bool
{
return ! $case->booking->isInternal() && $case->profile->payments() === Responsibility::Portal;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$portal = $booking->processChannel()?->name ?? 'das Portal';
$payout = CaseMoney::of($booking)->payout();
return [new Activity('payout', 'Auszahlung von '.$portal.' auf unser Konto', $case->later(match (true) {
! $case->binding => ActivityState::Later,
$payout['received'] > 0 && ($payout['outstanding'] ?? 0) === 0 && $payout['difference'] === 0 => ActivityState::Done,
default => ActivityState::Waiting,
}), trim(($payout['values'] !== [] ? 'angekündigt '.implode(' bzw. ', array_map(fn (int $value): string => Money::format($value), $payout['values'])).' · ' : '').'eingegangen '.Money::format($payout['received']).($payout['difference'] > 0 ? ' · Angaben weichen um '.Money::format($payout['difference']).' ab' : '')))];
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Process\Modules\Offer;
use App\Actions\AutoOffer;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Enums\ProcessingMode;
use App\Process\CaseContext;
use App\Process\StepResult;
/**
* The automatic answer of a request (binding offer or information "unter Vorbehalt"): due while the request waits for
* its first answer and the case is handled automatically; carried out by {@see AutoOffer}, which checks every release
* rule (dates, contract texts, calendar clearance, document composition) itself.
*/
trait AnswersRequest
{
public function due(CaseContext $case): bool
{
$booking = $case->booking;
return $booking->processingMode() === ProcessingMode::Automatic
&& $booking->status === BookingStatus::Reserved && $booking->offer_version === 0 && $booking->information_version === 0
&& $booking->intake !== IntakeKind::Booking;
}
public function blockers(CaseContext $case): array
{
return app(AutoOffer::class)->blockers($case->booking);
}
public function run(CaseContext $case): StepResult
{
$reasons = app(AutoOffer::class)->handle($case->booking);
return $reasons === [] ? StepResult::ran() : StepResult::blocked($reasons);
}
public function isOutward(): bool
{
return true;
}
}
@@ -0,0 +1,86 @@
<?php
namespace App\Process\Modules\Offer;
use App\Availability\AvailabilityChecker;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\CaseRequirements;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\RunsAutomatically;
/**
* P02: our own binding offer with the contract draft (SendOffer, versioned). The price is fixed here – extension point
* BeforePriceFixing lies before it. Never without every required detail (hard dependency on guest.details) and never
* for dates that are taken.
*/
final class BindingOffer extends Module implements RunsAutomatically
{
use AnswersRequest;
public static function key(): string
{
return 'offer.binding';
}
public static function version(): int
{
// 2: dates taken meanwhile are a problem of the step, an expired hold is not shown as reserved (F-001, F-002).
return 2;
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Verbindliches Angebot',
purpose: 'Erstellt das verbindliche Angebot mit Vertragsentwurf und sendet es dem Gast; der Zeitraum ist für die Haltefrist reserviert.',
phase: 'P02',
requires: [Dependency::hard('guest.details'), Dependency::hard('availability.check'), Dependency::soft('guest.data_request')],
effects: ['case_write', 'guest_mail', 'landlord_mail', 'document', 'calendar_hold', 'network'],
waits: ['guest', 'landlord'],
triggers: ['automation', 'request.created', 'schedule:bookings:auto-offers'],
parameters: [ProcessSetting::Processing, ProcessSetting::HoldHours, ProcessSetting::ContractTemplate],
performers: ['system', 'landlord'],
modes: ['automatic', 'manual'],
events: ['offer', 'hold', 'mail', 'status'],
);
}
/** The binding way: the request reserves (pre-reservation) or an offer was made anyway. */
public function applies(CaseContext $case): bool
{
return $case->inquiry && ! ($case->profile->preReservation() === false && $case->booking->offer_version === 0);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$offerDone = $booking->offer_version > 0 || $case->binding;
// G2a (v0.11): without every required detail there is no offer – the step waits for the guest's answer
// (mail, link or the landlord's entry) instead of being offered as the next step.
$offerMissing = $offerDone ? [] : CaseRequirements::missing($booking, CaseRequirements::OFFER);
$open = ! $offerDone && $offerMissing === [] && $booking->status === BookingStatus::Reserved && filled($booking->guest?->email);
$taken = $open && ! app(AvailabilityChecker::class)->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking);
return [new Activity('offer', $booking->processingMode() === ProcessingMode::Automatic ? 'Angebot senden (automatisch)' : 'Angebot prüfen und senden', $case->later(match (true) {
$offerDone => ActivityState::Done,
$offerMissing !== [] => ActivityState::Later,
$taken => ActivityState::Problem,
$open => ActivityState::Open,
default => ActivityState::Later,
}), match (true) {
$booking->offer_version > 0 => 'Version '.$booking->offer_version.' vom '.$booking->offer_sent_at?->format('d.m.Y'),
$offerMissing !== [] => 'erst wenn alle Angaben da sind',
$taken => 'Der Zeitraum ist inzwischen belegt.',
$booking->isHoldActive() => 'Zeitraum reserviert bis '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr',
$booking->hold_expires_at !== null => 'Reservierung abgelaufen am '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr – Zeitraum nicht reserviert',
default => null,
}, $offerDone || $offerMissing !== [] || $taken ? null : 'sendOffer')];
}
}
+86
View File
@@ -0,0 +1,86 @@
<?php
namespace App\Process\Modules\Offer;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\ProcessingMode;
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;
/**
* P02 (package 7): a request without a hold is answered with an information "unter Vorbehalt"; the guest asks for
* the booking (wish) and we check again and confirm bindingly.
*/
final class Information extends Module implements RunsAutomatically
{
use AnswersRequest;
public static function key(): string
{
return 'offer.information';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Unverbindliche Auskunft und Buchungswunsch',
purpose: 'Beantwortet die Anfrage mit einer unverbindlichen Auskunft ohne Reservierung; fragt der Gast die Buchung an, wird erneut geprüft und verbindlich bestätigt.',
phase: 'P02',
requires: [Dependency::hard('intake.record'), Dependency::soft('guest.data_request')],
effects: ['case_write', 'guest_mail', 'landlord_mail', 'document'],
waits: ['guest', 'landlord'],
triggers: ['automation', 'request.created', 'schedule:bookings:auto-offers'],
parameters: [ProcessSetting::Processing, ProcessSetting::GuestLinkValidDays],
performers: ['system', 'landlord', 'guest'],
modes: ['automatic', 'manual'],
events: ['information', 'mail', 'hold', 'wish', 'status'],
);
}
public function applies(CaseContext $case): bool
{
return $case->inquiry && ! $case->profile->preReservation() && $case->booking->offer_version === 0;
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$binding = $case->binding;
$informed = $booking->information_version > 0 || $binding;
return [
new Activity('information', $booking->processingMode() === ProcessingMode::Automatic ? 'Unverbindliche Auskunft senden (automatisch)' : 'Unverbindliche Auskunft prüfen und senden', $case->later(match (true) {
$booking->information_version > 0 => ActivityState::Done,
$binding => ActivityState::NotApplicable,
$booking->status === BookingStatus::Reserved && filled($booking->guest?->email) => ActivityState::Open,
default => ActivityState::Later,
}), $booking->information_version > 0 ? 'Version '.$booking->information_version.' vom '.$booking->information_sent_at?->format('d.m.Y').' · ohne Reservierung' : 'der Zeitraum wird nicht reserviert', $informed ? null : 'sendInformation'),
new Activity('wish', 'Gast fragt die Buchung an', $case->later(match (true) {
$booking->wish_at !== null => ActivityState::Done,
$binding => ActivityState::NotApplicable,
$booking->information_version > 0 && $booking->information_valid_until?->isFuture() => ActivityState::Waiting,
default => ActivityState::Later,
}), match (true) {
$booking->wish_at !== null => 'angefragt am '.$booking->wish_at->format('d.m.Y, H:i').' Uhr',
$booking->information_version > 0 => 'möglich bis '.$booking->information_valid_until?->format('d.m.Y, H:i').' Uhr',
default => null,
}),
new Activity('wish_check', 'Erneut prüfen und verbindlich bestätigen', $case->later(match (true) {
$binding => ActivityState::Done,
$booking->wish_at !== null && $booking->status === BookingStatus::Reserved => ActivityState::Waiting,
default => ActivityState::Later,
}), match (true) {
$booking->accepted_at !== null && ($booking->acceptance['via'] ?? null) === 'booking_wish' => 'bestätigt am '.$booking->confirmed_at?->format('d.m.Y').' ('.($booking->acceptance['confirmed_by'] ?? '').')',
$booking->wish_at !== null && $booking->status === BookingStatus::Reserved => 'siehe Aufgabe „Buchungswunsch bestätigen?“',
$binding => 'direkt verbindlich bestätigt (ohne Buchungswunsch)',
default => $booking->processingMode() === ProcessingMode::Automatic ? 'automatisch, wenn alles passt' : 'durch Sie',
}),
];
}
}
@@ -0,0 +1,59 @@
<?php
namespace App\Process\Modules\Offer;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P02: the guest accepts (AcceptOffer, acceptance record) or declines (RejectOffer); the booking becomes binding
* (ConfirmBooking). Cannot be switched off – our own way never binds without the guest's acceptance.
*/
final class OfferAcceptance extends Module
{
public static function key(): string
{
return 'offer.acceptance';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Annahme durch den Gast',
purpose: 'Der Gast nimmt das Angebot an oder lehnt es ab; mit der Annahme wird die Buchung verbindlich.',
phase: 'P02',
requires: [Dependency::hard('offer.binding')],
effects: ['case_write', 'guest_mail', 'landlord_mail', 'document'],
waits: ['guest', 'time'],
triggers: ['offer.accepted', 'offer.declined'],
performers: ['guest'],
events: ['offer', 'status'],
);
}
public function applies(CaseContext $case): bool
{
return app(BindingOffer::class)->applies($case);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
return [new Activity('acceptance', 'Gast nimmt das Angebot an', $case->later(match (true) {
$case->binding => ActivityState::Done,
$booking->status === BookingStatus::OfferSent => ActivityState::Waiting,
default => ActivityState::Later,
}), match (true) {
$booking->accepted_at !== null => 'angenommen am '.$booking->accepted_at->format('d.m.Y'),
$case->binding => 'direkt bestätigt',
$booking->status === BookingStatus::OfferSent => 'Angebot gültig bis '.$booking->hold_expires_at?->format('d.m.Y, H:i').' Uhr',
default => null,
})];
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Process\Modules;
use App\Process\Activity;
use App\Process\CaseContext;
/**
* A business capability of the process (docs/Prozessarchitektur/Architektur/02 §3): it offers one step of a case's
* course and derives where that step stands from the case's data. Reading methods never write; a module that can carry
* its step out by itself also implements {@see RunsAutomatically}.
*/
interface ProcessModule
{
/** Stable key, e.g. 'offer.binding'. */
public static function key(): string;
/** Version of the module's business behaviour (raised for every change of behaviour, not for wording). */
public static function version(): int;
/** What the configurator, the impact analysis and the contract tests read (pure data, no I/O). */
public static function definition(): ModuleDefinition;
/** Whether the step belongs to this case at all. */
public function applies(CaseContext $case): bool;
/**
* Where the step stands, as the landlord sees it – usually one activity, some steps show none (they only watch) or
* several (one per portal task).
*
* @return list<Activity>
*/
public function activities(CaseContext $case): array;
/** The state the runner uses for dependencies (null: the step has no state of its own and never blocks). */
public function state(CaseContext $case): ?StepState;
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace App\Process\Modules;
use App\Process\CaseContext;
use App\Process\StepResult;
/**
* A module whose step the system may carry out by itself (docs/Prozessarchitektur/Architektur/02 §7): the runner asks
* whether it is due, checks its hard dependencies, then runs it through the existing actions. `run` must be idempotent:
* a second run of a step that is already carried out has no effect.
*/
interface RunsAutomatically
{
/** Whether the system may carry the step out now by itself (its mode is automatic and the step is still to do). */
public function due(CaseContext $case): bool;
/**
* What keeps the step from being carried out now (plain words; empty = it may run).
*
* @return list<string>
*/
public function blockers(CaseContext $case): array;
/** Carries the step out by calling the existing action(s). */
public function run(CaseContext $case): StepResult;
/** Whether the step speaks to the guest or a third party (suspended while a portal report is open, decision O4). */
public function isOutward(): bool;
}
@@ -0,0 +1,116 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Actions\SendBookingDocuments;
use App\Enums\ActivityState;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Process\Activity;
use App\Process\CaseAutomation;
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\StepResult;
/**
* P03: the binding contract documentation for the guest (booking confirmation with contract, or the documents of a
* portal booking). Who is responsible for it decides the case type (decision O1): ours in A1–A4, the portal's in A5 –
* then the step is shown as external.
*/
final class BookingDocuments extends Module implements RunsAutomatically
{
public static function key(): string
{
return 'documents.send';
}
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')],
effects: ['case_write', 'guest_mail', 'document'],
waits: ['landlord', 'portal'],
triggers: ['automation', 'booking.taken_over'],
parameters: [ProcessSetting::Documents, ProcessSetting::Processing, ProcessSetting::ContractTemplate],
performers: ['system', 'landlord', 'portal'],
modes: ['automatic', 'manual'],
events: ['document', 'mail'],
readsContractData: true,
);
}
public function applies(CaseContext $case): bool
{
return ! $case->booking->isInternal();
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
if ($case->profile->documents() === Responsibility::Portal) {
return [new Activity('documents', 'Buchungsunterlagen an den Gast', ActivityState::External)];
}
$binding = $case->binding;
$state = match (true) {
$booking->confirmation_sent_at !== null => ActivityState::Done,
! $binding => ActivityState::Later,
$booking->confirmation_failed_at !== null => ActivityState::Problem,
default => ActivityState::Open,
};
$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() : [];
return [new Activity('documents', match (true) {
$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),
match (true) {
$booking->confirmation_sent_at !== null => 'gesendet am '.$booking->confirmation_sent_at->format('d.m.Y'),
$state === ActivityState::Problem => 'Versand fehlgeschlagen',
$missing !== [] => 'wartet: '.implode(' ', $missing),
$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',
default => null,
})];
}
/** The guest's e-mail and the price are what the documents need – not every detail of a request. */
public function due(CaseContext $case): bool
{
$booking = $case->booking;
return $booking->processingMode() === ProcessingMode::Automatic
&& $case->binding && $booking->confirmation_sent_at === null
&& $case->profile->documents() === Responsibility::Landlord && $case->profile->origin !== 'migration';
}
public function blockers(CaseContext $case): array
{
return app(CaseAutomation::class)->documentBlockers($case->booking);
}
public function run(CaseContext $case): StepResult
{
$reasons = app(SendBookingDocuments::class)->automatically($case->booking);
return $reasons === [] ? StepResult::ran() : StepResult::blocked($reasons);
}
public function isOutward(): bool
{
return true;
}
}
@@ -0,0 +1,90 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Availability\AvailabilityChecker;
use App\Enums\ActivityState;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Models\BookingTask;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\CaseRequirements;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
use Carbon\CarbonImmutable;
/**
* Event-driven work on the case (docs/Prozessarchitektur/Architektur/02 §4.1): every open task – a portal's
* cancellation or change report, a booking wish to decide, conflicting details, payment and service tasks – and the done
* tasks of the stay as its record. Tasks have no fixed place in the course; the model shows them where it lists events.
*/
final class CaseTasks extends Module
{
public static function key(): string
{
return 'case.tasks';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Aufgaben und Meldungen',
purpose: 'Zeigt offene Aufgaben des Vorgangs – Meldungen der Portale, Entscheidungen, Zahlungs- und Leistungsaufgaben.',
phase: 'P03',
effects: ['case_write'],
waits: ['landlord'],
triggers: ['task.created', 'portal.report'],
toggle: ModuleDefinition::TOGGLE_EVENT_DRIVEN,
performers: ['landlord'],
events: ['task'],
);
}
public function activities(CaseContext $case): array
{
return BookingTask::query()->where('booking_id', $case->booking->id)
->where(fn ($query) => $query->where('status', BookingTaskStatus::Open)
->orWhere(fn ($done) => $done->where('status', BookingTaskStatus::Done)->whereIn('kind', [BookingTaskKind::Service, BookingTaskKind::Issue, BookingTaskKind::FollowUp, BookingTaskKind::PayoutCheck, BookingTaskKind::OpenClaim])))
->orderByRaw('due_on is null')->orderBy('due_on')->orderBy('id')->get()
->map(fn (BookingTask $task): Activity => self::task($task))
->all();
}
public function state(CaseContext $case): ?StepState
{
return null;
}
/**
* An open task of the case and the action that settles it.
*/
public static function task(BookingTask $task): Activity
{
$action = match ($task->kind) {
BookingTaskKind::PortalCancellation, BookingTaskKind::PortalCancellationReported => 'confirmPortalCancellation',
BookingTaskKind::PortalChangeReported => 'change',
BookingTaskKind::BookingWish => 'decideWish',
BookingTaskKind::ArrivalDetails => 'arrivalDetails',
BookingTaskKind::CancellationRequest => 'end',
BookingTaskKind::FactConflict => 'provideContact',
default => $task->kind->isPayment() ? null : 'completeTask',
};
$today = CarbonImmutable::today();
$state = match (true) {
$task->status === BookingTaskStatus::Done => ActivityState::Done,
$task->kind === BookingTaskKind::PayoutCheck && $task->due_on?->isAfter($today) => ActivityState::Waiting,
$task->kind === BookingTaskKind::Service && $task->due_on?->isAfter($today) => ActivityState::Later,
$task->kind === BookingTaskKind::BookingWish && $task->booking !== null && ! app(AvailabilityChecker::class)->isAvailable($task->booking->property, $task->booking->arrival, $task->booking->departure, ignore: $task->booking) => ActivityState::Problem,
// v0.11 (B3): the binding confirmation waits for the missing details as well.
$task->kind === BookingTaskKind::BookingWish && $task->booking !== null && CaseRequirements::missing($task->booking, CaseRequirements::WISH_CONFIRMATION) !== [] => ActivityState::Waiting,
default => ActivityState::Open,
};
$detail = $task->status === BookingTaskStatus::Done
? 'erledigt am '.$task->completed_at?->format('d.m.Y').($task->completed_by ? ' von '.$task->completed_by : '').($task->note ? ' · '.$task->note : '')
: trim(($state === ActivityState::Problem ? 'Achtung: Der Zeitraum ist inzwischen belegt – bitte absagen. · ' : '').($task->due_on ? 'fällig '.$task->due_on->format('d.m.Y') : '').($task->responsible ? ' · zuständig: '.$task->responsible : '').($task->note ? ' · '.$task->note : ''), ' ·');
return new Activity('task_'.$task->kind->value, $task->label(), $state, $detail, $state === ActivityState::Done ? null : $action);
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Enums\ActivityState;
use App\Enums\ChangeStatus;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\StepState;
/**
* Event-driven: a change of a binding booking proposed to the guest (ChangeBooking) – shown while it waits for the guest.
*/
final class ChangeProposal extends Module
{
public static function key(): string
{
return 'change.proposal';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Änderungsvorschlag',
purpose: 'Zeigt einen Änderungsvorschlag, der beim Gast liegt.',
phase: 'P03',
effects: ['case_write', 'guest_mail'],
waits: ['guest', 'time'],
triggers: ['change.proposed'],
toggle: ModuleDefinition::TOGGLE_EVENT_DRIVEN,
performers: ['landlord', 'guest'],
events: ['change'],
readsContractData: true,
);
}
public function activities(CaseContext $case): array
{
$activities = [];
foreach ($case->booking->changes()->where('status', ChangeStatus::Proposed)->get() as $change) {
$activities[] = new Activity('change_proposed', 'Änderungsvorschlag liegt beim Gast', ActivityState::Waiting, $change->summary().($change->expires_at ? ' · bis '.$change->expires_at->format('d.m.Y') : ''));
}
return $activities;
}
public function state(CaseContext $case): ?StepState
{
return null;
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Process\Activity;
use App\Process\CaseClosure;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P05 (package 9): the commercial closing – payments, refunds and payouts cleared (CaseClosure::commercialPoints). With
* portal collection only after financial clearance; a portal report of a payout is no proof (decision O5).
*/
final class CommercialSettlement extends Module
{
public static function key(): string
{
return 'case.settlement';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Kaufmännisch abschließen',
purpose: 'Schließt den Vorgang kaufmännisch ab, wenn Zahlungen, Erstattungen und Auszahlungen geklärt sind.',
phase: 'P05',
requires: [Dependency::soft('case.closure')],
effects: ['case_write'],
waits: ['landlord', 'portal'],
triggers: ['payment.recorded', 'stay.closed'],
performers: ['landlord', 'system'],
events: ['settled'],
readsContractData: true,
);
}
public function applies(CaseContext $case): bool
{
$booking = $case->booking;
$settlementApplies = $booking->status === BookingStatus::Completed || $booking->status === BookingStatus::Cancelled;
return $settlementApplies || ($booking->isBinding() && ! $booking->isInternal()) || ($booking->isInternal() && (int) $booking->total > 0);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$settlementApplies = $booking->status === BookingStatus::Completed || $booking->status === BookingStatus::Cancelled;
$points = $settlementApplies && $booking->settled_at === null ? CaseClosure::commercialPoints($booking) : [];
return [new Activity('settlement', 'Kaufmännisch abschließen', match (true) {
$booking->settled_at !== null => ActivityState::Done,
! $settlementApplies => ActivityState::Later,
default => ActivityState::Waiting,
}, match (true) {
$booking->settled_at !== null => 'abgeschlossen am '.$booking->settled_at->format('d.m.Y').($booking->settled_by && $booking->settled_by !== CaseClosure::AUTOMATIC ? ' von '.$booking->settled_by : '').($booking->settled_note ? ' · '.$booking->settled_note : ''),
! $settlementApplies => 'nach dem Aufenthalt, wenn Zahlungen, Erstattungen und Auszahlungen geklärt sind',
default => 'offen: '.implode(' ', $points),
}, $settlementApplies && $booking->settled_at === null && $points !== [] ? 'settle' : null)];
}
}
@@ -0,0 +1,62 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\InternalKind;
use App\Models\BookingTask;
use App\Process\Activity;
use App\Process\CaseClosure;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P05 (package 9): closing the stay once nothing is open for it (CaseClosure, overnight or by hand).
*/
final class StayClosure extends Module
{
public static function key(): string
{
return 'case.closure';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Aufenthalt abschließen',
purpose: 'Schließt den Aufenthalt ab, sobald nach der Abreise nichts mehr für ihn offen ist.',
phase: 'P05',
effects: ['case_write'],
waits: ['time', 'landlord'],
triggers: ['schedule:daily'],
performers: ['system', 'landlord'],
events: ['task', 'status', 'settled'],
);
}
public function applies(CaseContext $case): bool
{
return ! $case->closed && ($case->booking->isBinding() || $case->booking->status === BookingStatus::Completed);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$today = $case->today;
$completed = $booking->status === BookingStatus::Completed;
$blockers = $booking->isBinding() && ! $completed ? CaseClosure::stayBlockers($booking) : collect();
return [new Activity('closure', $booking->isInternal() && $booking->internal_kind === InternalKind::Block ? 'Sperrzeit abschließen' : 'Aufenthalt abschließen', match (true) {
$completed => ActivityState::Done,
! $booking->isBinding() || $booking->departure > $today => ActivityState::Later,
default => ActivityState::Waiting,
}, match (true) {
$completed => 'abgeschlossen am '.($booking->completed_at ?? $booking->updated_at)?->format('d.m.Y'),
$blockers->isNotEmpty() => 'wartet auf: '.$blockers->map(fn (BookingTask $task): string => $task->label())->implode(', '),
$booking->isBinding() && $booking->departure <= $today => 'geschieht automatisch über Nacht – oder jetzt von Hand',
default => 'nach der Abreise, sobald nichts mehr für den Aufenthalt offen ist',
}, $booking->isBinding() && ! $completed && $booking->departure <= $today ? 'closeStay' : null)];
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Process\Modules\Settlement;
use App\Enums\ActivityState;
use App\Enums\InternalKind;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* A6: an optional stay confirmation for the guests of an own use or private stay (no rental contract).
*/
final class StayConfirmation extends Module
{
public static function key(): string
{
return 'documents.stay_confirmation';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Aufenthaltsbestätigung',
purpose: 'Bestätigt den Gästen einer Eigenbelegung oder privaten Überlassung den Aufenthalt – nur bei Bedarf.',
phase: 'P03',
effects: ['guest_mail', 'document'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
performers: ['landlord'],
events: ['document', 'mail'],
);
}
public function applies(CaseContext $case): bool
{
return $case->booking->internal_kind !== InternalKind::Block && filled($case->booking->guest?->email);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
return [new Activity('documents', 'Aufenthaltsbestätigung an die Gäste (optional)', $case->later($booking->confirmation_sent_at !== null ? ActivityState::Done : ActivityState::Later),
$booking->confirmation_sent_at ? 'gesendet am '.$booking->confirmation_sent_at->format('d.m.Y') : 'nur bei Bedarf', $booking->confirmation_sent_at === null && ! $case->closed ? 'sendDocuments' : null)];
}
}
@@ -0,0 +1,57 @@
<?php
namespace App\Process\Modules\Stay;
use App\Actions\PrepareStays;
use App\Enums\ActivityState;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Models\BookingTask;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P04: contact and arrival time for the stay (PrepareStays reports missing ones in time as a task).
*/
final class ArrivalDetails extends Module
{
public static function key(): string
{
return 'arrival.details';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Anreisedaten',
purpose: 'Sammelt Telefon und Anreisezeit für die Übergabe und meldet rechtzeitig, was fehlt.',
phase: 'P04',
effects: ['case_write'],
waits: ['guest', 'landlord', 'time'],
triggers: ['schedule:prepare-stays'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
performers: ['landlord', 'guest', 'service_provider'],
events: ['task', 'services'],
);
}
public function applies(CaseContext $case): bool
{
return $case->binding && ! BookingTask::query()->where('booking_id', $case->booking->id)->where('kind', BookingTaskKind::ArrivalDetails)->where('status', BookingTaskStatus::Open)->exists();
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$missing = PrepareStays::missingArrivalDetails($booking);
$left = $case->binding && $booking->departure <= $case->today;
return [new Activity('arrival_details', 'Anreisedaten', $case->later(match (true) {
$missing === [] => ActivityState::Done,
$left => ActivityState::NotApplicable,
default => ActivityState::Later,
}), $missing === [] ? implode(' · ', array_filter([$booking->guest?->phone ?: $booking->guest?->email, $booking->arrival_time ? 'Anreise '.$booking->arrival_time : null])) : 'es fehlt: '.implode(', ', $missing).' – wird rechtzeitig als Aufgabe gemeldet')];
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Process\Modules\Stay;
use App\Enums\ActivityState;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P04: the arrival information for the guest – sent by us (SendBookingReminders) or announced by the portal. Who sends
* it is variable within the model (supplementary, not contract documentation; decision O1).
*/
final class ArrivalInformation extends Module
{
public static function key(): string
{
return 'arrival.info';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Anreise-Informationen',
purpose: 'Wegbeschreibung, Schlüssel und Kontakt vor Ort rechtzeitig vor der Anreise.',
phase: 'P04',
effects: ['guest_mail'],
waits: ['time', 'portal'],
triggers: ['schedule:reminders'],
parameters: [ProcessSetting::GuestMessages, ProcessSetting::ArrivalInfoDaysBefore],
performers: ['system', 'portal', 'service_provider'],
events: ['document', 'mail'],
);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$profile = $case->profile;
return [$profile->guestMessages() === Responsibility::Portal
? new Activity('arrival_info', 'Anreise-Informationen an den Gast', ActivityState::External, 'durch '.($booking->processChannel()?->name ?? 'das Portal').' (angekündigt) – eine Zustellung ist damit nicht nachgewiesen')
: new Activity('arrival_info', 'Anreise-Informationen an den Gast (automatisch)', $case->later($booking->arrival_info_sent_at !== null ? ActivityState::Done : ActivityState::Later), $booking->arrival_info_sent_at ? 'gesendet am '.$booking->arrival_info_sent_at->format('d.m.Y') : $profile->arrivalInfoDaysBefore().' Tage vor Anreise')];
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Process\Modules\Stay;
use App\Enums\ActivityState;
use App\Enums\Responsibility;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P05: asking the guest for a review after the stay (RequestReviews). Optional; today it follows who writes to the
* guest (GuestMessages = us).
*/
final class ReviewRequest extends Module
{
public static function key(): string
{
return 'review.request';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Bitte um eine Bewertung',
purpose: 'Bittet den Gast nach dem Aufenthalt um eine Bewertung.',
phase: 'P05',
requires: [Dependency::hard('stay')],
effects: ['guest_mail'],
waits: ['time'],
triggers: ['schedule:reviews'],
toggle: ModuleDefinition::TOGGLE_OPTIONAL,
performers: ['system'],
events: ['mail'],
);
}
public function applies(CaseContext $case): bool
{
return $case->profile->guestMessages() === Responsibility::Landlord && ! $case->booking->isInternal();
}
public function activities(CaseContext $case): array
{
return [new Activity('review', 'Bitte um eine Bewertung (automatisch)', $case->later($case->booking->review_requested_at !== null ? ActivityState::Done : ActivityState::Later))];
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Process\Modules\Stay;
use App\Enums\ActivityState;
use App\Enums\InternalKind;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
/**
* P04: the stay itself (or the time of an internal occupation).
*/
final class Stay extends Module
{
public static function key(): string
{
return 'stay';
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Aufenthalt',
purpose: 'Der Aufenthalt vom Anreise- bis zum Abreisetag.',
phase: 'P04',
waits: ['time'],
triggers: ['schedule:daily'],
performers: ['guest', 'landlord'],
events: ['task', 'services', 'status'],
);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
if ($booking->isInternal()) {
$kind = $booking->internal_kind;
return [new Activity('stay', $kind === InternalKind::Block ? 'Sperrzeit' : 'Aufenthalt', $case->closed ? ActivityState::NotApplicable : ($booking->departure <= $case->today ? ActivityState::Done : ActivityState::Later), $booking->arrival->format('d.m.Y').' – '.$booking->departure->format('d.m.Y'))];
}
$arrived = $case->binding && $booking->arrival <= $case->today;
$left = $case->binding && $booking->departure <= $case->today;
return [new Activity('stay', 'Aufenthalt', $case->later(match (true) {
$left => ActivityState::Done,
$arrived => ActivityState::Waiting,
default => ActivityState::Later,
}), $booking->arrival->format('d.m.Y').' – '.$booking->departure->format('d.m.Y'))];
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace App\Process\Modules;
use App\Enums\ActivityState;
/**
* The state of a step as the runner reads it for dependencies (docs/Prozessarchitektur/Architektur/02 §7.2). Derived
* from the case's data on every evaluation, never stored.
*/
enum StepState: string
{
/** Carried out (by us or, where the model says so, by the portal). */
case Done = 'done';
/** To do now. */
case Open = 'open';
/** Waits for the guest, the portal, the landlord or a deadline. */
case Waiting = 'waiting';
/** Something went wrong or stands in the way (e.g. the dates are taken). */
case Problem = 'problem';
/** Not yet: a previous step of the case is not there. */
case Later = 'later';
/** Does not apply (any more) to this case. */
case NotApplicable = 'not_applicable';
public static function fromActivity(ActivityState $state): self
{
return match ($state) {
ActivityState::Done, ActivityState::External => self::Done,
ActivityState::Open => self::Open,
ActivityState::Waiting => self::Waiting,
ActivityState::Problem => self::Problem,
ActivityState::Later => self::Later,
ActivityState::NotApplicable => self::NotApplicable,
};
}
/** Whether a hard dependency on a step in this state is fulfilled. */
public function fulfils(): bool
{
return $this === self::Done;
}
}