['✓', '#16a34a', 'erledigt'],
'current' => ['●', '#d97706', 'jetzt'],
'todo' => ['○', '#9ca3af', 'später'],
'skipped' => ['–', '#9ca3af', 'entfällt'],
];
$rows = collect(BookingProgress::steps($booking))->map(function (array $step) use ($badge): string {
[$icon, $color, $word] = $badge[$step['state']];
$activities = collect($step['activities'])->map(fn (array $activity): string => '
'.($activity['done'] ? '✓ ' : '○ ').e($activity['label']).($activity['action'] && $step['state'] !== 'skipped' ? ' → Aktion „'.e($activity['action']).'“' : '').'')->implode('');
return ''
.'
'.$icon.'
'
.'
'.e($step['label']).($step['detail'] ? ' · '.e($step['detail']).'' : '').'
'
.($activities !== '' ? '
' : '').'
';
})->implode('');
return new HtmlString(''.$rows.'
');
}
/**
* What has happened so far, oldest first.
*/
private static function chronicle(Booking $booking): HtmlString
{
$rows = collect(BookingProgress::history($booking))->map(fn (array $event): string => ''.$event['at']->format('d.m.Y H:i').' · '.e($event['label']).'')->implode('');
return new HtmlString('');
}
/**
* The standard process that applies to this booking: which template (with cancellation rule and annexes) comes from
* the portal and booking type, and whether payments become tasks.
*/
private static function setup(Booking $booking): string
{
$channel = $booking->importChannel ?? $booking->originChannel;
$template = OfferTerms::templateFor($booking);
$policy = $template?->cancellationPolicy;
$annexes = $template?->annexesFor($booking)->map(fn ($annex) => $annex->name)->implode(', ');
return collect([
$channel ? 'Portal: '.$channel->name : 'Eigene Buchung (Webseite / manuell)',
'Vertragsvorlage: '.($template ? $template->label() : 'Texte der Webseite'),
'Stornoregel: '.($policy ? $policy->name : 'keine hinterlegt'),
'Anlagen: '.($annexes ?: 'keine'),
'Zahlungsaufgaben: '.($booking->wantsPaymentTasks() ? 'ja' : 'nein (läuft über das Portal)'),
])->implode(' · ');
}
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('setup')
->label('Standardprozess (aus Portal und Buchungstyp)')
->state(fn (Booking $record): string => self::setup($record))
->columnSpanFull(),
TextEntry::make('steps')
->label('Ablauf: Meilensteine und Aktivitäten')
->state(fn (Booking $record): HtmlString => self::timeline($record))
->html()
->columnSpanFull(),
TextEntry::make('chronicle')
->label('Bisheriger Verlauf')
->state(fn (Booking $record): HtmlString => self::chronicle($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([
TextEntry::make('property.name')->label('Wohnung'),
TextEntry::make('arrival')->label('Anreise')->date('l, d.m.Y'),
TextEntry::make('departure')->label('Abreise')->date('l, d.m.Y'),
TextEntry::make('nights')->label('Nächte')->state(fn (Booking $record): int => $record->nights()),
TextEntry::make('guests')->label('Personen'),
TextEntry::make('promo_code')->label('Aktionscode')->placeholder('–'),
]),
Section::make('Preis')
->schema([
RepeatableEntry::make('quote.lines')
->hiddenLabel()
->table([
TableColumn::make('Leistung'),
TableColumn::make('Betrag')->alignEnd(),
])
->schema([
TextEntry::make('label'),
TextEntry::make('amount')->formatStateUsing(fn (int $state): string => Money::format($state))->alignEnd(),
]),
Grid::make(4)->schema([
TextEntry::make('total')->label('Gesamtpreis')->money('EUR', divideBy: 100, locale: 'de')->weight('bold'),
TextEntry::make('deposit')->label('Anzahlung')->money('EUR', divideBy: 100, locale: 'de'),
TextEntry::make('balance')->label('Restzahlung')->state(fn (Booking $record): string => Money::format($record->total - $record->deposit)),
TextEntry::make('balance_due_on')->label('Rest fällig am')->date('d.m.Y'),
TextEntry::make('paid')->label('Bezahlt')->state(fn (Booking $record): string => Money::format($record->paidAmount())),
TextEntry::make('open')->label('Offen')->state(fn (Booking $record): string => Money::format($record->openAmount()))->color(fn (Booking $record): string => $record->openAmount() > 0 ? 'danger' : 'success'),
TextEntry::make('deposit_due_on')->label('Anzahlung fällig am')->date('d.m.Y')->placeholder('–'),
]),
]),
Section::make('Nachricht des Gastes')
->visible(fn (Booking $record): bool => filled($record->message))
->schema([
TextEntry::make('message')->hiddenLabel(),
]),
]),
Grid::make(1)
->columnSpan(1)
->schema([
Section::make('Status')
->schema([
TextEntry::make('status')->label('Status')->badge(),
TextEntry::make('hold_expires_at')->label('Vorgemerkt bis')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->hold_expires_at !== null),
TextEntry::make('confirmed_at')->label('Bestätigt am')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->confirmed_at !== null),
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
TextEntry::make('processing')
->label('Bearbeitung / Vorreservierung')
->state(fn (Booking $record): string => $record->property->offer_mode->value === 'automatic' ? 'Automatisch' : 'Manuell')
->visible(fn (Booking $record): bool => $record->isDirect()),
TextEntry::make('offer')
->label('Angebot')
->state(fn (Booking $record): string => 'Version '.$record->offer_version.', gesendet '.$record->offer_sent_at?->format('d.m.Y, H:i').' · Prüfsumme '.substr((string) $record->offer_hash, 0, 12).(isset($record->offer_terms['template']) ? ' · Vorlage '.$record->offer_terms['template']['name'].' v'.$record->offer_terms['template']['version'] : ''))
->visible(fn (Booking $record): bool => $record->offer_version > 0),
TextEntry::make('accepted_at')->label('Angenommen am')->dateTime('d.m.Y, H:i:s')->visible(fn (Booking $record): bool => $record->accepted_at !== null),
TextEntry::make('confirmation')
->label('Bestätigungs-E-Mail')
->state(fn (Booking $record): string => $record->confirmation_sent_at !== null ? 'Gesendet '.$record->confirmation_sent_at->format('d.m.Y, H:i') : 'Nicht zugestellt – bitte „Bestätigung erneut senden“')
->color(fn (Booking $record): string => $record->confirmation_sent_at !== null ? 'success' : 'danger')
->visible(fn (Booking $record): bool => $record->confirmation_sent_at !== null || $record->confirmation_failed_at !== null),
TextEntry::make('source')->label('Buchungskanal / Quelle')->state(fn (Booking $record): string => $record->bookingChannelLabel()),
TextEntry::make('referral_source')->label('Aufmerksam geworden durch')->placeholder('–'),
TextEntry::make('utm')
->label('Kampagne (UTM)')
->state(fn (Booking $record): ?string => collect([$record->utm_source, $record->utm_medium, $record->utm_campaign])->filter()->implode(' / ') ?: null)
->visible(fn (Booking $record): bool => filled($record->utm_source)),
]),
Section::make('Gast')
->schema([
TextEntry::make('guest.full_name')->label('Name'),
TextEntry::make('guest.email')->label('E-Mail')->placeholder('Unbekannt')->copyable(),
TextEntry::make('guest.phone')->label('Telefon')->placeholder('–'),
TextEntry::make('guest_address')
->label('Adresse')
->state(fn (Booking $record): ?string => collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null)
->placeholder('–'),
]),
Section::make('Interne Notizen')
->schema([
TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen'),
]),
]),
]);
}
}