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:
1 parent
9005c12164
commit
3a728c3255
78 files changed
+4296
-1180
No files matched your search
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\ChannelBookingModel;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingMessage;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\Cancellation;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* One view on where a booking stands: what kind of process it is, the steps with their state and the next
|
||||
* thing the landlord has to do. Everything is derived from the booking, nothing is stored.
|
||||
*/
|
||||
class BookingProgress
|
||||
{
|
||||
public const OWN = 'own';
|
||||
|
||||
public const MANUAL = 'manual';
|
||||
|
||||
public const PORTAL_BOOKING = 'portal_booking';
|
||||
|
||||
public const PORTAL_INQUIRY = 'portal_inquiry';
|
||||
|
||||
public static function kind(Booking $booking): string
|
||||
{
|
||||
$channel = $booking->importChannel ?? $booking->originChannel;
|
||||
if ($channel !== null) {
|
||||
return $channel->booking_model === ChannelBookingModel::PortalBooking ? self::PORTAL_BOOKING : self::PORTAL_INQUIRY;
|
||||
}
|
||||
|
||||
return $booking->source === 'website' ? self::OWN : self::MANUAL;
|
||||
}
|
||||
|
||||
public static function kindLabel(Booking $booking): string
|
||||
{
|
||||
$portal = ($booking->importChannel ?? $booking->originChannel)?->name;
|
||||
|
||||
return match (self::kind($booking)) {
|
||||
self::OWN => 'Eigene Webseite: Anfrage → Angebot → Annahme',
|
||||
self::MANUAL => 'Manuell erfasste Buchung',
|
||||
self::PORTAL_BOOKING => 'Portal-Buchung'.($portal ? " ({$portal})" : '').': beim Portal verbindlich, Vertrag von uns',
|
||||
default => 'Portal-Anfrage'.($portal ? " ({$portal})" : '').': wir antworten persönlich, Angebot und Vertrag von uns',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The milestones of the process with the activities that belong to each. An activity names the action on the
|
||||
* booking page that does it ("action"), so the landlord sees what was done, what is open and where to do it.
|
||||
*
|
||||
* @return list<array{label: string, state: string, detail: ?string, activities: list<array{label: string, done: bool, action: ?string}>}>
|
||||
*/
|
||||
public static function steps(Booking $booking): array
|
||||
{
|
||||
$today = CarbonImmutable::today();
|
||||
$kind = self::kind($booking);
|
||||
$closed = in_array($booking->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true);
|
||||
$binding = in_array($booking->status, BookingStatus::occupying(), true);
|
||||
$hasEmail = filled($booking->guest?->email);
|
||||
$activity = fn (string $label, bool $done, ?string $action = null): array => ['label' => $label, 'done' => $done, 'action' => $done ? null : $action];
|
||||
$steps = [];
|
||||
|
||||
$steps[] = ['label' => 'Anfrage / Eingang', 'state' => 'done', 'detail' => $booking->created_at?->format('d.m.Y'), 'activities' => [
|
||||
$activity($kind === self::OWN ? 'Anfrage über die Webseite eingegangen' : 'Vorgang angelegt ('.$booking->bookingChannelLabel().')', true),
|
||||
]];
|
||||
|
||||
if (in_array($kind, [self::PORTAL_BOOKING, self::PORTAL_INQUIRY], true)) {
|
||||
$asked = $booking->contact_requested_at !== null;
|
||||
$steps[] = ['label' => 'Gast & Kontaktdaten', 'state' => $hasEmail ? 'done' : ($closed ? 'skipped' : 'current'), 'detail' => $hasEmail ? null : ($asked ? 'erfragt am '.$booking->contact_requested_at->format('d.m.Y') : 'fehlen noch'), 'activities' => [
|
||||
$activity('Gast um Kontaktdaten bitten', $hasEmail || $asked, 'Gast um Kontaktdaten bitten'),
|
||||
$activity('Kontaktdaten eintragen (Name, E-Mail, Anschrift)', $hasEmail, 'Kontaktdaten eintragen'),
|
||||
]];
|
||||
}
|
||||
|
||||
$needsOffer = in_array($kind, [self::OWN, self::PORTAL_INQUIRY, self::MANUAL], true);
|
||||
if ($needsOffer) {
|
||||
$steps[] = [
|
||||
'label' => 'Angebot',
|
||||
'state' => $booking->offer_version > 0 || $binding ? 'done' : ($closed ? 'skipped' : 'current'),
|
||||
'detail' => $booking->offer_version > 0 ? 'Version '.$booking->offer_version.', '.$booking->offer_sent_at?->format('d.m.Y') : null,
|
||||
'activities' => [$activity('Angebot mit Vertragsentwurf an den Gast senden', $booking->offer_version > 0 || $binding, 'Angebot senden')],
|
||||
];
|
||||
}
|
||||
|
||||
$steps[] = [
|
||||
'label' => $needsOffer ? 'Annahme / Vertrag' : 'Bestätigung / Vertrag',
|
||||
'state' => $binding ? ($booking->confirmation_sent_at !== null || $booking->accepted_at !== null || $needsOffer ? 'done' : 'current') : ($closed ? 'skipped' : ($booking->status === BookingStatus::OfferSent ? 'current' : 'todo')),
|
||||
'detail' => $booking->accepted_at ? 'angenommen '.$booking->accepted_at->format('d.m.Y') : ($booking->confirmation_sent_at ? 'Vertrag gesendet '.$booking->confirmation_sent_at->format('d.m.Y') : null),
|
||||
'activities' => array_values(array_filter([
|
||||
$needsOffer ? $activity('Gast nimmt das Angebot an (oder Buchung direkt bestätigen)', $binding, 'Direkt bestätigen') : $activity('Buchung bestätigen (Zeitraum fest belegen)', $binding, 'Direkt bestätigen'),
|
||||
$activity('Mietvertrag mit Anlagen an den Gast senden', $booking->confirmation_sent_at !== null, $binding ? 'Bestätigung erneut senden' : null),
|
||||
$booking->guest_confirmed_at ? $activity('Gast hat die Buchung per E-Mail bestätigt', true) : null,
|
||||
])),
|
||||
];
|
||||
|
||||
if ($booking->wantsPaymentTasks()) {
|
||||
$paid = $booking->paidAmount();
|
||||
$steps[] = ['label' => 'Anzahlung', 'state' => $closed ? 'skipped' : ($paid >= $booking->deposit && $binding ? 'done' : ($binding ? 'current' : 'todo')), 'detail' => $booking->deposit_due_on ? 'fällig '.$booking->deposit_due_on->format('d.m.Y') : null, 'activities' => [
|
||||
$activity('Zahlungseingang erfassen', $paid >= $booking->deposit && $binding, 'Zahlungen (unten)'),
|
||||
]];
|
||||
$steps[] = ['label' => 'Restzahlung', 'state' => $closed ? 'skipped' : ($paid >= $booking->total && $binding ? 'done' : ($binding && $paid >= $booking->deposit ? 'current' : 'todo')), 'detail' => 'fällig '.$booking->balance_due_on?->format('d.m.Y'), 'activities' => [
|
||||
$activity('Restzahlung erfassen', $paid >= $booking->total && $binding, 'Zahlungen (unten)'),
|
||||
]];
|
||||
} else {
|
||||
$steps[] = ['label' => 'Zahlung', 'state' => 'skipped', 'detail' => 'läuft über das Portal', 'activities' => []];
|
||||
}
|
||||
|
||||
$arrived = ! $closed && $binding && $booking->arrival <= $today;
|
||||
$left = ! $closed && $binding && $booking->departure <= $today;
|
||||
$steps[] = ['label' => 'Anreise', 'state' => $closed ? 'skipped' : ($arrived ? 'done' : 'todo'), 'detail' => $booking->arrival->format('d.m.Y'), 'activities' => [
|
||||
$activity('Anreise-Informationen ('.$booking->property->arrival_info_days_before.' Tage vorher, automatisch)', $booking->arrival_info_sent_at !== null),
|
||||
]];
|
||||
$steps[] = ['label' => 'Vor Ort', 'state' => $closed ? 'skipped' : ($arrived && ! $left ? 'current' : ($left ? 'done' : 'todo')), 'detail' => null, 'activities' => []];
|
||||
$steps[] = ['label' => 'Abreise', 'state' => $closed ? 'skipped' : ($left ? 'done' : 'todo'), 'detail' => $booking->departure->format('d.m.Y'), 'activities' => []];
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* What has happened so far, oldest first: milestones from the booking's own timestamps, payments and mails.
|
||||
*
|
||||
* @return list<array{at: CarbonImmutable, label: string}>
|
||||
*/
|
||||
public static function history(Booking $booking): array
|
||||
{
|
||||
$events = [];
|
||||
$add = function (mixed $at, string $label) use (&$events): void {
|
||||
if ($at !== null) {
|
||||
$events[] = ['at' => CarbonImmutable::instance($at), 'label' => $label];
|
||||
}
|
||||
};
|
||||
|
||||
$add($booking->created_at, 'Vorgang angelegt ('.$booking->bookingChannelLabel().')');
|
||||
$add($booking->contact_requested_at, 'Gast um Kontaktdaten gebeten');
|
||||
$add($booking->offer_sent_at, 'Angebot Version '.$booking->offer_version.' gesendet');
|
||||
$add($booking->accepted_at, 'Angebot vom Gast angenommen');
|
||||
$add($booking->guest_confirmed_at, 'Gast hat die Buchung per E-Mail bestätigt');
|
||||
$add($booking->confirmed_at, 'Buchung verbindlich bestätigt');
|
||||
$add($booking->confirmation_sent_at, 'Bestätigung mit Mietvertrag an den Gast gesendet');
|
||||
$add($booking->confirmation_failed_at, 'Versand der Bestätigung fehlgeschlagen');
|
||||
$add($booking->arrival_info_sent_at, 'Anreise-Informationen gesendet');
|
||||
$add($booking->cancelled_at, 'Storniert');
|
||||
$add($booking->archived_at, 'Archiviert');
|
||||
|
||||
foreach ($booking->payments()->get() as $payment) {
|
||||
$add($payment->paid_on ?? $payment->created_at, ($payment->amount < 0 ? 'Erstattung ' : 'Zahlung ').Money::format(abs($payment->amount)).' erfasst');
|
||||
}
|
||||
foreach (BookingMessage::query()->where('booking_id', $booking->id)->get() as $message) {
|
||||
$add($message->sent_at, 'E-Mail: '.$message->subject.' ('.$message->audience.')');
|
||||
}
|
||||
foreach (BookingTask::query()->where('booking_id', $booking->id)->where('status', BookingTaskStatus::Done)->get() as $task) {
|
||||
$add($task->completed_at, 'Aufgabe erledigt: '.$task->kind->getLabel());
|
||||
}
|
||||
|
||||
usort($events, fn (array $a, array $b): int => $a['at'] <=> $b['at']);
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
private static function cancelledText(Booking $booking, bool $open): string
|
||||
{
|
||||
$cancellation = Cancellation::query()->where('booking_id', $booking->id)->first();
|
||||
if ($cancellation === null) {
|
||||
return $open ? 'Stornokosten bzw. Rückzahlung sind noch zu klären (siehe Aufgaben).' : 'Nichts mehr zu tun. Die Buchung bleibt zur Historie erhalten.';
|
||||
}
|
||||
|
||||
$balance = $cancellation->balance();
|
||||
$text = 'Storniert am '.$cancellation->cancelled_on->format('d.m.Y').' ('.($cancellation->days_before ?? '?').' Tage vor Anreise). Stornokosten '.Money::format($cancellation->fee()).', bezahlt '.Money::format($cancellation->paid_amount).'.';
|
||||
|
||||
return $text.($cancellation->status === Cancellation::OPEN ? ($balance > 0 ? ' Noch einzufordern: '.Money::format($balance).'.' : ($balance < 0 ? ' Zu erstatten: '.Money::format(-$balance).'.' : ' Ausgeglichen – bitte als abgerechnet markieren.')) : ' Erledigt.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{title: string, text: string, color: string}
|
||||
*/
|
||||
public static function next(Booking $booking): array
|
||||
{
|
||||
$today = CarbonImmutable::today();
|
||||
$kind = self::kind($booking);
|
||||
$money = fn (int $cents): string => Money::format($cents);
|
||||
|
||||
$openTasks = BookingTask::query()->where('booking_id', $booking->id)->where('status', BookingTaskStatus::Open)->get();
|
||||
$costs = $openTasks->firstWhere('kind', BookingTaskKind::CancellationFee);
|
||||
$wish = $openTasks->firstWhere('kind', BookingTaskKind::CancellationRequest);
|
||||
|
||||
if ($wish !== null && $booking->status !== BookingStatus::Cancelled) {
|
||||
return ['title' => 'Stornierungswunsch des Gastes', 'text' => 'Der Gast möchte stornieren. Bitte prüfen: stornieren (mit Mail an den Gast) oder ablehnen, und Stornokosten klären.', 'color' => 'danger'];
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$booking->status === BookingStatus::Cancelled => ['title' => 'Storniert', 'text' => self::cancelledText($booking, $costs !== null || $wish !== null), 'color' => $costs !== null ? 'warning' : 'gray'],
|
||||
$booking->status === BookingStatus::Declined => ['title' => 'Abgelehnt', 'text' => 'Der Zeitraum ist wieder frei.', 'color' => 'gray'],
|
||||
$booking->status === BookingStatus::Expired => ['title' => 'Abgelaufen', 'text' => 'Die Haltefrist ist verstrichen. Sie können die Anfrage trotzdem noch bestätigen, solange der Zeitraum frei ist.', 'color' => 'gray'],
|
||||
blank($booking->guest?->email) && $booking->departure > $today => ['title' => 'Kontaktdaten fehlen', 'text' => ($booking->contact_requested_at ? 'Die Kontaktdaten wurden am '.$booking->contact_requested_at->format('d.m.Y').' erfragt – Antwort abwarten. ' : 'Den Gast um Kontaktdaten bitten („Gast um Kontaktdaten bitten“). ').'Sobald sie da sind: „Kontaktdaten eintragen“ – dort lässt sich der Vertragsprozess automatisch starten oder von Hand weiterführen.', 'color' => 'warning'],
|
||||
$booking->status === BookingStatus::Reserved => ['title' => 'Anfrage prüfen', 'text' => $kind === self::PORTAL_BOOKING
|
||||
? 'Kontaktdaten des Gastes eintragen, dann „Direkt bestätigen“ – der Vertrag geht per E-Mail an den Gast.'
|
||||
: 'Angebot senden („Angebot senden“) oder ablehnen.'.($booking->hold_expires_at ? ' Vorgemerkt bis '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr.' : ' Es ist kein Zeitraum vorgemerkt.'), 'color' => 'warning'],
|
||||
$booking->status === BookingStatus::OfferSent => ['title' => 'Wartet auf den Gast', 'text' => 'Angebot Version '.$booking->offer_version.' ist beim Gast. Gültig bis '.$booking->hold_expires_at?->format('d.m.Y, H:i').' Uhr.', 'color' => 'info'],
|
||||
$booking->confirmation_failed_at !== null && $booking->confirmation_sent_at === null => ['title' => 'Bestätigung nicht zugestellt', 'text' => 'Die Buchung steht, aber die Bestätigungs-E-Mail ist nicht beim Gast angekommen. „Bestätigung erneut senden“.', 'color' => 'danger'],
|
||||
$kind === self::PORTAL_BOOKING && $booking->confirmation_sent_at === null && $booking->contract_path === null => ['title' => 'Vertrag senden', 'text' => 'Die Buchung ist beim Portal verbindlich. Bitte den Vertrag an den Gast senden (Bestätigung erneut senden).', 'color' => 'warning'],
|
||||
$booking->wantsPaymentTasks() && $booking->openDeposit() > 0 && $booking->status === BookingStatus::Confirmed => ['title' => 'Anzahlung offen', 'text' => $money($booking->openDeposit()).' fällig bis '.$booking->deposit_due_on?->format('d.m.Y').'. Zahlungseingang unter „Zahlungen“ erfassen.', 'color' => $booking->deposit_due_on?->isPast() ? 'danger' : 'warning'],
|
||||
$booking->wantsPaymentTasks() && $booking->openAmount() > 0 && $booking->balance_due_on?->lessThanOrEqualTo($today->addDays(14)) => ['title' => 'Restzahlung offen', 'text' => $money($booking->openAmount()).' fällig bis '.$booking->balance_due_on->format('d.m.Y').'.', 'color' => $booking->balance_due_on->isPast() ? 'danger' : 'warning'],
|
||||
$booking->arrival <= $today && $booking->departure > $today => ['title' => 'Gast ist vor Ort', 'text' => 'Abreise am '.$booking->departure->format('d.m.Y').'.', 'color' => 'success'],
|
||||
$booking->arrival > $today => ['title' => 'Anreise in '.$today->diffInDays($booking->arrival).' Tagen', 'text' => 'Anreise am '.$booking->arrival->format('d.m.Y').'. Anreise-Informationen gehen '.$booking->property->arrival_info_days_before.' Tage vorher automatisch an den Gast.', 'color' => 'success'],
|
||||
default => ['title' => 'Aufenthalt beendet', 'text' => 'Abreise war am '.$booking->departure->format('d.m.Y').'.', 'color' => 'gray'],
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user