Files
fewo-stommer/app/Support/BookingProgress.php
T
LarsandClaude Sonnet 5.5 5ba9ae08ab
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
Portal-Direktbuchung erfassen, Kontaktdaten-Prozess, manueller Statuswechsel, Archiv, Filter, Menue Verwaltung/Einrichtung
- Buchung erfassen: Buchungsweg Portal (Referenz, Portalpreis, ohne Kontaktdaten), Prozess bestaetigen/Vertrag sofort/nur erfassen
- Buchungsakte: Kontaktdaten eintragen (automatisch oder manuell weiter), Gast um Kontaktdaten bitten, Status von Hand aendern, Archivieren
- Liste: Filter Kanal, Anreisezeitraum, Kontaktdaten fehlen; Spalten ausblendbar; Archiv
- Klaerung: verstaendlichere Texte, eigenstaendige Belegung mit Kanal gilt als geklaert (Gitea #4)
- Akte per Button aus Liste und Belegungsplan erreichbar
- Menue: Gruppen Verwaltung (Tagesgeschaeft) und Einrichtung (Konfiguration), einfache Ansicht auf 8 Punkte

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 18:04:03 +01:00

148 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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\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',
};
}
/**
* @return list<array{label: string, state: string, detail: ?string}> state: done | current | todo | skipped
*/
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);
$steps = [];
$steps[] = ['label' => 'Anfrage / Eingang', 'state' => 'done', 'detail' => $booking->created_at?->format('d.m.Y')];
if (in_array($kind, [self::PORTAL_BOOKING, self::PORTAL_INQUIRY], true)) {
$steps[] = ['label' => 'Kontaktdaten des Gastes', 'state' => filled($booking->guest?->email) ? 'done' : ($closed ? 'skipped' : 'current'), 'detail' => filled($booking->guest?->email) ? null : ($booking->contact_requested_at ? 'erfragt am '.$booking->contact_requested_at->format('d.m.Y') : 'fehlen noch')];
}
$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,
];
}
$steps[] = [
'label' => $needsOffer ? 'Annahme / Vertrag' : 'Vertrag senden',
'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),
];
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];
$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')];
} else {
$steps[] = ['label' => 'Zahlung', 'state' => 'skipped', 'detail' => 'läuft über das Portal'];
}
$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')];
$steps[] = ['label' => 'Vor Ort', 'state' => $closed ? 'skipped' : ($arrived && ! $left ? 'current' : ($left ? 'done' : 'todo')), 'detail' => null];
$steps[] = ['label' => 'Abreise', 'state' => $closed ? 'skipped' : ($left ? 'done' : 'todo'), 'detail' => $booking->departure->format('d.m.Y')];
return $steps;
}
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'],
};
}
}