Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)

- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes
  Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge
  dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt
- Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung
  (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße
- Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt
  RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition
- Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter,
  "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus
- Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben
  als Abweichung), Bericht: php artisan process:settings-report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-01 16:25:46 +01:00
1 parent 9005c12164
commit 3a728c3255
78 files changed
+4296 -1180

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
<?php
namespace App\Process;
use App\Enums\BookingStatus;
use App\Models\Booking;
use App\Models\Guest;
/**
* Model hooks of a case: freezes the process profile when the case comes in (and again when what defines it – intake
* kind, channel, property – changes) and writes the facts of every change into the stored history.
*/
class CaseRecorder
{
/** Attributes that decide which profile applies; changing one re-freezes the profile. */
private const DEFINING = ['intake', 'origin_channel_id', 'import_channel_id', 'property_id'];
public static function freeze(Booking $booking): void
{
if ($booking->isDirty('profile') && filled($booking->profile)) {
return;
}
$changed = $booking->exists && $booking->isDirty(self::DEFINING);
if (filled($booking->profile) && ! $changed) {
return;
}
$booking->intake ??= ProcessSettings::intakeFor($booking);
$profile = app(ProcessSettings::class)->forBooking($booking)->withOrigin($booking->exists ? 'changed' : 'intake');
$booking->profile = $profile->toArray();
$booking->case_type = $profile->caseType;
}
public static function created(Booking $booking): void
{
CaseLog::record($booking, 'created', 'Vorgang angelegt: '.$booking->caseType()->getLabel().' ('.$booking->bookingChannelLabel().')', data: [
'intake' => $booking->intake?->value,
'case_type' => $booking->case_type?->value,
]);
}
public static function updated(Booking $booking): void
{
$changes = $booking->getChanges();
$original = fn (string $key): mixed => $booking->getOriginal($key);
if (array_key_exists('profile', $changes) && $booking->wasChanged(self::DEFINING)) {
CaseLog::record($booking, 'profile', 'Abwicklung neu bestimmt: '.$booking->caseType()->getLabel());
}
if (array_key_exists('guest_id', $changes) && $booking->guest_id !== null) {
CaseLog::record($booking, 'guest', 'Gast zugeordnet: '.(Guest::query()->find($booking->guest_id)?->full_name ?? '–'));
}
if (array_key_exists('offer_version', $changes) && $booking->offer_version > 0) {
CaseLog::record($booking, 'offer', 'Angebot Version '.$booking->offer_version.' gesendet'.($booking->hold_expires_at ? ', gültig bis '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr' : ''));
} elseif (array_key_exists('hold_expires_at', $changes) && $booking->hold_expires_at !== null && in_array($booking->status, BookingStatus::holding(), true) && ! array_key_exists('status', $changes)) {
CaseLog::record($booking, 'hold', 'Reservierung verlängert bis '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr');
}
if (array_key_exists('status', $changes) && $original('status') !== $booking->status && ! ($booking->status === BookingStatus::OfferSent && array_key_exists('offer_version', $changes))) {
CaseLog::record($booking, 'status', self::statusSummary($booking, $original('status')), data: [
'from' => $original('status') instanceof BookingStatus ? $original('status')->value : $original('status'),
'to' => $booking->status->value,
]);
}
if (array_key_exists('arrival', $changes) || array_key_exists('departure', $changes)) {
CaseLog::record($booking, 'dates', 'Zeitraum: '.$booking->arrival->format('d.m.Y').' – '.$booking->departure->format('d.m.Y'));
}
$facts = [
'contact_requested_at' => 'Gast um Kontaktdaten gebeten',
'guest_confirmed_at' => 'Gast hat die Buchung per E-Mail bestätigt',
'confirmation_sent_at' => 'Bestätigung mit Unterlagen an den Gast gesendet',
'confirmation_failed_at' => 'Versand der Bestätigung fehlgeschlagen',
'arrival_info_sent_at' => 'Anreise-Informationen gesendet',
'review_requested_at' => 'Gast um eine Bewertung gebeten',
];
foreach ($facts as $column => $summary) {
if (array_key_exists($column, $changes) && $booking->{$column} !== null) {
CaseLog::record($booking, 'fact', $summary);
}
}
if (array_key_exists('processing_mode', $changes)) {
CaseLog::record($booking, 'mode', 'Bearbeitung dieses Vorgangs: '.($booking->processing_mode?->getLabel() ?? 'wie eingestellt ('.$booking->process()->processing()->getLabel().')'));
}
if (array_key_exists('archived_at', $changes)) {
CaseLog::record($booking, 'archive', $booking->archived_at ? 'Archiviert' : 'Aus dem Archiv geholt');
}
}
private static function statusSummary(Booking $booking, mixed $from): string
{
$from = $from instanceof BookingStatus ? $from : BookingStatus::tryFrom((string) $from);
return match ($booking->status) {
BookingStatus::Confirmed => $booking->wasChanged('accepted_at') && $booking->accepted_at !== null
? 'Angebot vom Gast angenommen – Buchung verbindlich'
: ($booking->caseType()->isExternallyBinding() ? 'Beim Portal verbindlich gebucht – übernommen' : 'Buchung verbindlich bestätigt'),
BookingStatus::DepositPaid => 'Anzahlung eingegangen',
BookingStatus::Paid => 'Vollständig bezahlt',
BookingStatus::Completed => 'Aufenthalt abgeschlossen',
BookingStatus::Declined => 'Ohne Buchung beendet (abgelehnt'.($booking->declined_by ? ' durch '.($booking->declined_by === 'guest' ? 'den Gast' : 'uns') : '').')',
BookingStatus::Expired => 'Ohne Buchung beendet (Frist abgelaufen)',
BookingStatus::Cancelled => 'Storniert',
BookingStatus::Reserved => $from === null ? 'Anfrage vorgemerkt' : 'Wieder als Anfrage geführt (vorher: '.$from->getLabel().')',
BookingStatus::OfferSent => 'Angebot liegt beim Gast',
};
}
}