Buchungsakte: Vorgang, naechster Schritt, Vertrag, Mailverlauf, Storno mit Mail, Archiv
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s

- Buchungsseite zeigt Art des Vorgangs, Verlaufsleiste und den naechsten Schritt in Klartext
- Vertragsabschnitt (Vorlage, Dokumente mit Pruefsumme, Zustellung) und Vertragstext-Ansicht
- Reiter Aufgaben und Mailverlauf (jede Mail zur Buchung wird protokolliert)
- Stornieren in der Verwaltung informiert Gast und Vermieter und legt eine Aufgabe fuer Stornokosten an
- Stornierte/abgelehnte/abgelaufene Buchungen aus der Hauptliste, Filter Archiv anzeigen

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-10-30 16:16:42 +01:00
1 parent 89d569b6c8
commit 5baf39441f
15 files changed
+684 -7

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
<?php
namespace App\Actions;
use App\Enums\BookingStatus;
use App\Enums\BookingTaskKind;
use App\Enums\BookingTaskStatus;
use App\Exceptions\ReservationException;
use App\Mail\BookingCancelled;
use App\Mail\CancellationRequested;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Support\Settings;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Throwable;
/**
* The landlord cancels a binding booking. The dates are free again; the guest and the landlord are informed by mail
* (the guest mail can be switched off, e.g. when the guest cancelled by phone and was told already) and a task for
* the cancellation costs is created. Open cancellation requests of the guest are completed.
*/
class CancelBooking
{
/**
* @return bool whether the guest has been informed (true as well when no mail was wanted; false when it failed)
*
* @throws ReservationException
*/
public function handle(Booking $booking, bool $notifyGuest = true, bool $costsTask = true, string $by = 'Verwaltung'): bool
{
if ($notifyGuest && blank($booking->guest?->email)) {
throw new ReservationException('Der Gast hat keine E-Mail-Adresse – bitte ohne Mail an den Gast stornieren oder die Adresse ergänzen.');
}
DB::transaction(function () use ($booking, $costsTask, $by): void {
$booking->lockForTransition();
if (! in_array($booking->status, BookingStatus::occupying(), true)) {
throw ReservationException::invalidTransition($booking->status->getLabel(), 'storniert');
}
$booking->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]);
BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::CancellationRequest)->where('status', BookingTaskStatus::Open)
->update(['status' => BookingTaskStatus::Done, 'completed_by' => $by, 'completed_at' => now()]);
if ($costsTask) {
BookingTask::query()->firstOrCreate(['booking_id' => $booking->id, 'kind' => BookingTaskKind::CancellationFee], ['status' => BookingTaskStatus::Open, 'due_on' => today()]);
}
});
$booking->loadMissing(['guest', 'property']);
return $this->notify($booking, $notifyGuest);
}
private function notify(Booking $booking, bool $notifyGuest): bool
{
$informed = true;
try {
Mail::to(Settings::notificationRecipients())->send(new CancellationRequested($booking, cancelled: true));
} catch (Throwable $exception) {
Log::warning('Stornomitteilung an den Vermieter nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]);
}
if ($notifyGuest) {
try {
Mail::to($booking->guest->email, $booking->guest->full_name)->send(new BookingCancelled($booking, cancelled: true));
} catch (Throwable $exception) {
$informed = false;
Log::warning('Stornomail an den Gast nicht zugestellt', ['booking' => $booking->id, 'exception' => $exception::class]);
}
}
return $informed;
}
}
+4 -2
View File
@@ -15,6 +15,7 @@ enum BookingTaskKind: string implements HasLabel
case BalanceRequest = 'balance_request';
case BalanceReminder = 'balance_reminder';
case CancellationRequest = 'cancellation_request';
case CancellationFee = 'cancellation_fee';
public function getLabel(): string
{
@@ -23,12 +24,13 @@ public function getLabel(): string
self::BalanceRequest => 'Restzahlung bald fällig – anfordern',
self::BalanceReminder => 'Restzahlung überfällig – anmahnen',
self::CancellationRequest => 'Stornierungswunsch des Gastes',
self::CancellationFee => 'Stornokosten prüfen und abrechnen',
};
}
public function isPayment(): bool
{
return $this !== self::CancellationRequest;
return ! in_array($this, [self::CancellationRequest, self::CancellationFee], true);
}
/**
@@ -42,7 +44,7 @@ public function reminder(): ?array
self::DepositReminder => [PaymentReminder::DEPOSIT_OVERDUE, 'deposit_reminded_at'],
self::BalanceRequest => [PaymentReminder::BALANCE_REQUEST, 'balance_requested_at'],
self::BalanceReminder => [PaymentReminder::BALANCE_OVERDUE, 'balance_reminded_at'],
self::CancellationRequest => null,
self::CancellationRequest, self::CancellationFee => null,
};
}
}
@@ -8,7 +8,9 @@
use App\Filament\Resources\Bookings\Pages\CreateBooking;
use App\Filament\Resources\Bookings\Pages\ListBookings;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Bookings\RelationManagers\MessagesRelationManager;
use App\Filament\Resources\Bookings\RelationManagers\PaymentsRelationManager;
use App\Filament\Resources\Bookings\RelationManagers\TasksRelationManager;
use App\Filament\Resources\Bookings\Schemas\BookingForm;
use App\Filament\Resources\Bookings\Schemas\BookingInfolist;
use App\Filament\Resources\Bookings\Tables\BookingsTable;
@@ -72,6 +74,8 @@ public static function getRelations(): array
{
return [
PaymentsRelationManager::class,
TasksRelationManager::class,
MessagesRelationManager::class,
];
}
@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Bookings\Pages;
use App\Actions\CancelBooking;
use App\Actions\ConfirmBooking;
use App\Actions\DeclineBooking;
use App\Actions\SendOffer;
@@ -189,6 +190,16 @@ protected function getHeaderActions(): array
$notification = Notification::make()->title($sent ? 'Bestätigung gesendet' : 'Versand fehlgeschlagen');
($sent ? $notification->success() : $notification->danger()->body('Details im Postfach.'))->send();
}),
Action::make('contractText')
->label('Vertragstext ansehen')
->icon(Heroicon::OutlinedDocumentMagnifyingGlass)
->color('gray')
->visible(fn (): bool => $this->record->offer_terms !== null)
->modalHeading(fn (): string => 'Vertrag '.$this->record->reference)
->modalContent(fn () => view('filament.booking-contract', ['booking' => $this->record]))
->modalSubmitAction(false)
->modalCancelActionLabel('Schließen')
->modalWidth('4xl'),
Action::make('contract')
->label('Mietvertrag')
->icon(Heroicon::OutlinedDocumentText)
@@ -209,12 +220,23 @@ protected function getHeaderActions(): array
->icon(Heroicon::OutlinedNoSymbol)
->color('danger')
->visible(fn (): bool => in_array($this->record->status, BookingStatus::occupying(), true))
->requiresConfirmation()
->modalDescription('Der Zeitraum wird wieder freigegeben. Der Gast wird nicht automatisch benachrichtigt.')
->action(function (): void {
$this->record->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]);
->modalHeading('Buchung stornieren')
->modalDescription('Der Zeitraum wird wieder freigegeben. Gast und Vermieter erhalten eine Stornierungs-E-Mail; die Stornokosten bleiben als Aufgabe offen.')
->schema([
Toggle::make('notify_guest')->label('Gast per E-Mail informieren')->default(true),
Toggle::make('costs_task')->label('Aufgabe „Stornokosten prüfen“ anlegen')->default(true),
])
->action(function (array $data, CancelBooking $cancel): void {
try {
$informed = $cancel->handle($this->record, (bool) $data['notify_guest'], (bool) $data['costs_task'], auth()->user()->name);
} catch (ReservationException $exception) {
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
Notification::make()->title('Buchung storniert')->success()->send();
return;
}
$notification = Notification::make()->title('Buchung storniert');
($informed ? $notification->success() : $notification->warning()->body('Die Mail an den Gast konnte nicht gesendet werden – bitte den Gast selbst informieren.'))->send();
}),
]),
];
@@ -0,0 +1,40 @@
<?php
namespace App\Filament\Resources\Bookings\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
/**
* Communication log: every e-mail that went out for this booking.
*/
class MessagesRelationManager extends RelationManager
{
protected static string $relationship = 'messages';
protected static ?string $title = 'Mailverlauf';
public function isReadOnly(): bool
{
return true;
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('subject')
->defaultSort('sent_at', 'desc')
->emptyStateHeading('Noch keine E-Mails zu dieser Buchung')
->description('Betreff und Empfängerart jeder E-Mail zu dieser Buchung. Im Testbetrieb gehen alle Mails an die Testadresse.')
->columns([
TextColumn::make('sent_at')->label('Gesendet')->dateTime('d.m.Y, H:i'),
TextColumn::make('audience')->label('An')->badge()->formatStateUsing(fn (string $state): string => match ($state) {
'guest' => 'Gast',
'landlord' => 'Vermieter',
default => 'Testadresse',
}),
TextColumn::make('subject')->label('Betreff')->wrap(),
]);
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Filament\Resources\Bookings\RelationManagers;
use App\Enums\BookingTaskStatus;
use App\Models\BookingTask;
use Filament\Actions\Action;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
/**
* Tasks of this booking (payment reminders, cancellation requests and costs).
*/
class TasksRelationManager extends RelationManager
{
protected static string $relationship = 'tasks';
protected static ?string $title = 'Aufgaben';
public function isReadOnly(): bool
{
return false;
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('kind')
->defaultSort('created_at', 'desc')
->emptyStateHeading('Keine Aufgaben zu dieser Buchung')
->columns([
TextColumn::make('kind')->label('Aufgabe')->badge(),
TextColumn::make('status')->label('Status')->badge(),
TextColumn::make('due_on')->label('Seit / fällig')->date('d.m.Y')->placeholder('–'),
TextColumn::make('note')->label('Hinweis')->wrap()->placeholder('–'),
])
->recordActions([
Action::make('done')
->label('Erledigt')
->icon(Heroicon::OutlinedCheck)
->color('success')
->visible(fn (BookingTask $record): bool => $record->status === BookingTaskStatus::Open)
->action(fn (BookingTask $record) => $record->complete(auth()->user()->name)),
]);
}
}
@@ -3,24 +3,68 @@
namespace App\Filament\Resources\Bookings\Schemas;
use App\Models\Booking;
use App\Support\BookingProgress;
use App\Support\Money;
use Carbon\CarbonImmutable;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Support\HtmlString;
class BookingInfolist
{
/**
* The steps of the process as a row of chips.
*/
private static function timeline(Booking $booking): HtmlString
{
$style = [
'done' => 'background:#dcfce7;color:#14532d',
'current' => 'background:#fef3c7;color:#78350f;font-weight:700',
'todo' => 'background:#f3f4f6;color:#4b5563',
'skipped' => 'background:#f3f4f6;color:#9ca3af;text-decoration:line-through',
];
$icon = ['done' => '✓ ', 'current' => '● ', 'todo' => '', 'skipped' => ''];
return new HtmlString('<div style="display:flex;flex-wrap:wrap;gap:.4rem">'.collect(BookingProgress::steps($booking))->map(fn (array $step): string => '<span style="padding:.25rem .6rem;border-radius:999px;font-size:.8rem;'.$style[$step['state']].'">'.$icon[$step['state']].e($step['label']).($step['detail'] ? ' · '.e($step['detail']) : '').'</span>')->implode('').'</div>');
}
public static function configure(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Section::make('Vorgang')
->columnSpanFull()
->schema([
TextEntry::make('process')->label('Art des Vorgangs')->state(fn (Booking $record): string => BookingProgress::kindLabel($record)),
TextEntry::make('next')
->label(fn (Booking $record): string => 'Nächster Schritt: '.BookingProgress::next($record)['title'])
->state(fn (Booking $record): string => BookingProgress::next($record)['text'])
->color(fn (Booking $record): string => BookingProgress::next($record)['color'])
->weight('bold'),
TextEntry::make('steps')
->label('Verlauf')
->state(fn (Booking $record): HtmlString => self::timeline($record))
->html()
->columnSpanFull(),
]),
Grid::make(1)
->columnSpan(2)
->schema([
Section::make('Vertrag')
->columns(2)
->schema([
TextEntry::make('contract_template')->label('Vorlage')->state(fn (Booking $record): string => isset($record->offer_terms['template']) ? $record->offer_terms['template']['name'].' (Version '.$record->offer_terms['template']['version'].')' : ($record->offer_terms ? 'Texte der Webseite (Stand '.CarbonImmutable::parse($record->offer_terms['captured_at'])->format('d.m.Y').')' : 'Noch kein Angebot / Vertrag')),
TextEntry::make('contract_state')->label('Dokumente')->state(fn (Booking $record): string => collect([
$record->offer_path ? 'Angebot (PDF) Version '.$record->offer_version : null,
$record->contract_path ? 'Mietvertrag (PDF, unveränderlich, Prüfsumme '.substr((string) $record->contract_pdf_sha256, 0, 10).')' : null,
])->filter()->implode(' · ') ?: 'Noch kein Dokument – der Vertrag entsteht mit dem Angebot bzw. der Bestätigung'),
TextEntry::make('contract_mail')->label('Zustellung')->state(fn (Booking $record): string => $record->confirmation_sent_at ? 'Bestätigung mit Vertrag gesendet am '.$record->confirmation_sent_at->format('d.m.Y, H:i') : ($record->confirmation_failed_at ? 'Versand fehlgeschlagen' : 'Noch nicht gesendet'))->columnSpanFull(),
]),
Section::make('Aufenthalt')
->columns(3)
->schema([
@@ -37,6 +37,9 @@ public static function configure(Table $table, ?int $guestId = null): Table
}
if (filled($filters['status']['values'] ?? [])) {
$records = $records->whereIn('status_key', $filters['status']['values']);
} elseif (! ($filters['show_closed']['isActive'] ?? false)) {
// Cancelled, declined and expired requests leave the main list (they stay available as archive).
$records = $records->reject(fn (array $record): bool => in_array($record['status_key'], ['cancelled', 'declined', 'expired'], true));
}
$column = in_array($sortColumn, ['arrival', 'departure', 'reference', 'guest', 'source', 'total'], true) ? $sortColumn : 'arrival';
$records = $records->sortBy($column, SORT_REGULAR, $sortDirection === 'desc');
@@ -69,6 +72,7 @@ public static function configure(Table $table, ?int $guestId = null): Table
'imported' => 'Im Portalkalender geführt', 'archived' => 'Nicht mehr im Kalenderfeed',
]),
Filter::make('upcoming')->label('Nur kommende Aufenthalte'),
Filter::make('show_closed')->label('Archiv anzeigen (storniert, abgelehnt, abgelaufen)'),
Filter::make('without_guest')->label('Gastzuordnung offen'),
])
->recordUrl(fn (array $record): string => $record['url'])
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Listeners;
use App\Models\Booking;
use App\Models\BookingMessage;
use App\Support\Settings;
use Illuminate\Mail\Events\MessageSent;
use Throwable;
/**
* Writes every mail that belongs to a booking (the mailable has a public $booking) into the booking's communication
* log. Who received it is derived from the recipient address – in test operation everything goes to the test
* address and is marked as such. A logging problem never disturbs the mail.
*/
class LogBookingMail
{
public function handle(MessageSent $event): void
{
try {
$booking = $event->data['booking'] ?? null;
if (! $booking instanceof Booking) {
return;
}
$recipients = collect($event->message->getTo())->map(fn ($address): string => mb_strtolower($address->getAddress()));
$guest = mb_strtolower((string) $booking->guest?->email);
$audience = ! Settings::isLive() ? 'test' : ($guest !== '' && $recipients->contains($guest) ? 'guest' : 'landlord');
BookingMessage::query()->create([
'booking_id' => $booking->id,
'audience' => $audience,
'subject' => mb_substr((string) $event->message->getSubject(), 0, 255),
'sent_at' => now(),
]);
} catch (Throwable) {
// The log is a convenience; the mail has been sent.
}
}
}
+16
View File
@@ -236,6 +236,22 @@ public function review(): HasOne
return $this->hasOne(Review::class);
}
/**
* @return HasMany<BookingMessage, $this>
*/
public function messages(): HasMany
{
return $this->hasMany(BookingMessage::class);
}
/**
* @return HasMany<BookingTask, $this>
*/
public function tasks(): HasMany
{
return $this->hasMany(BookingTask::class);
}
/**
* @return HasMany<Payment, $this>
*/
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* An e-mail that went out for a booking (communication log). Only subject and audience are kept.
*/
#[Fillable(['booking_id', 'audience', 'subject', 'sent_at'])]
class BookingMessage extends Model
{
public $timestamps = false;
use BelongsToTenant;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return ['sent_at' => 'immutable_datetime'];
}
/**
* @return BelongsTo<Booking, $this>
*/
public function booking(): BelongsTo
{
return $this->belongsTo(Booking::class);
}
}
+128
View File
@@ -0,0 +1,128 @@
<?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 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')];
$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;
}
/**
* @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' => $costs !== null || $wish !== null ? 'Stornokosten bzw. Rückzahlung sind noch zu klären (siehe Aufgaben).' : 'Nichts mehr zu tun. Die Buchung bleibt zur Historie erhalten.', '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'],
$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'],
};
}
}