Geschäftsentscheidungen zuerst (Schablonen je Bereich, Voreinstellungen A3–A5), Einzelschritte eingeklappt, Auswirkungsanalyse beim Schablonenwechsel, unbestätigte Portal-Fähigkeiten gekennzeichnet. Tester-Bericht nennt Schablonen, unabhängig laufende Schritte und fehlende Nachweise; alle vier Kombinationen sind als Szenario getestet. Doku: SCHABLONEN.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
266 lines
18 KiB
PHP
266 lines
18 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Bookings\Schemas;
|
||
|
||
use App\Documents\OfferTerms;
|
||
use App\Enums\ActivityState;
|
||
use App\Enums\AdminMode;
|
||
use App\Enums\DocumentKind;
|
||
use App\Enums\ProcessingMode;
|
||
use App\Enums\ProcessSetting;
|
||
use App\Enums\Responsibility;
|
||
use App\Models\BlockedPeriod;
|
||
use App\Models\Booking;
|
||
use App\Models\IntakeObservation;
|
||
use App\Models\User;
|
||
use App\Pricing\CaseMoney;
|
||
use App\Process\CaseActivities;
|
||
use App\Process\CaseAutomation;
|
||
use App\Process\ProcessCatalogue;
|
||
use App\Process\ProcessPlan;
|
||
use App\Process\ProcessProfile;
|
||
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;
|
||
|
||
/**
|
||
* The case page: first where it stands and what is next, then the activities and the history, then the facts (guest,
|
||
* stay, price and payments, documents). Technical details are shown in the expert view only.
|
||
*/
|
||
class BookingInfolist
|
||
{
|
||
public static function configure(Schema $schema): Schema
|
||
{
|
||
return $schema
|
||
->columns(3)
|
||
->components([
|
||
Section::make('Als Nächstes')
|
||
->columnSpanFull()
|
||
->schema([
|
||
TextEntry::make('next')
|
||
->hiddenLabel()
|
||
->state(fn (Booking $record): HtmlString => self::nextStep($record))
|
||
->html(),
|
||
]),
|
||
Grid::make(1)
|
||
->columnSpan(2)
|
||
->schema([
|
||
Section::make('Ablauf')
|
||
->description('Was erledigt ist, was wartet und was noch kommt. Ein Klick auf einen Schritt zeigt, was dort geschah und woher die Angaben stammen.')
|
||
->schema([TextEntry::make('activities')->hiddenLabel()->state(fn (Booking $record): HtmlString => self::activities($record))->html()]),
|
||
Section::make('Preis und Zahlungen')
|
||
->schema([
|
||
TextEntry::make('price_unknown')
|
||
->hiddenLabel()
|
||
->state('Der Gesamtpreis ist noch nicht bekannt.')
|
||
->color('warning')
|
||
->visible(fn (Booking $record): bool => $record->total === null),
|
||
RepeatableEntry::make('quote.lines')
|
||
->hiddenLabel()
|
||
->visible(fn (Booking $record): bool => filled($record->quote['lines'] ?? null))
|
||
->table([TableColumn::make('Leistung'), TableColumn::make('Betrag')->alignEnd()])
|
||
->schema([
|
||
TextEntry::make('label'),
|
||
TextEntry::make('amount')->formatStateUsing(fn (int $state): string => Money::format($state))->alignEnd(),
|
||
]),
|
||
TextEntry::make('money')->hiddenLabel()->html()
|
||
->state(fn (Booking $record): HtmlString => new HtmlString(view('filament.case-money', ['money' => CaseMoney::of($record), 'booking' => $record])->render())),
|
||
TextEntry::make('balance_due_on')->label('Restzahlung fällig am')->date('d.m.Y')
|
||
->visible(fn (Booking $record): bool => $record->wantsPaymentTasks() && $record->balance_due_on !== null),
|
||
]),
|
||
Section::make('Verlauf')
|
||
->collapsible()
|
||
->schema([TextEntry::make('history')->hiddenLabel()->state(fn (Booking $record): HtmlString => self::history($record))->html()]),
|
||
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('Gast')
|
||
->schema([
|
||
TextEntry::make('guest_name')->label('Name')->state(fn (Booking $record): string => $record->guestName())
|
||
->color(fn (Booking $record): ?string => $record->guest === null ? 'warning' : null),
|
||
TextEntry::make('guest.email')->label('E-Mail')->placeholder('noch nicht bekannt')->copyable(),
|
||
TextEntry::make('guest.phone')->label('Telefon')->placeholder('–'),
|
||
TextEntry::make('guest_address')
|
||
->label('Adresse')
|
||
->state(fn (Booking $record): ?string => $record->guest === null ? null : (collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null))
|
||
->placeholder('–'),
|
||
]),
|
||
Section::make('Aufenthalt')
|
||
->schema([
|
||
TextEntry::make('property.name')->label('Wohnung'),
|
||
TextEntry::make('period')->label('Zeitraum')->state(fn (Booking $record): string => $record->arrival->translatedFormat('D, d.m.Y').' – '.$record->departure->translatedFormat('D, d.m.Y').' ('.$record->nights().' Nächte)'),
|
||
TextEntry::make('guests')->label('Personen')->placeholder('noch nicht bekannt'),
|
||
TextEntry::make('channel')->label('Über')->state(fn (Booking $record): string => $record->bookingChannelLabel().($record->portal_reference ? ' · Nr. '.$record->portal_reference : '')),
|
||
]),
|
||
Section::make('Dokumente')
|
||
->schema([
|
||
TextEntry::make('documents')->hiddenLabel()->html()->state(fn (Booking $record): HtmlString => self::documents($record)),
|
||
TextEntry::make('document_kind')->label('Vorgesehen')->state(fn (Booking $record): string => DocumentKind::forCase($record)?->getLabel() ?? 'Unterlagen schickt das Portal'),
|
||
TextEntry::make('template')->label('Vorlage')->visible(fn (Booking $record): bool => ! $record->isInternal())->state(fn (Booking $record): string => isset($record->offer_terms['template']) && ($record->contract_path !== null || $record->offer_path !== null)
|
||
? $record->offer_terms['template']['name'].' (Version '.$record->offer_terms['template']['version'].', festgeschrieben)'
|
||
: (OfferTerms::templateFor($record)?->label() ?? 'Texte der Webseite').' (vorgesehen)'),
|
||
]),
|
||
Section::make('Interne Notizen')
|
||
->collapsible()
|
||
->schema([TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen')]),
|
||
]),
|
||
Section::make('Technische Angaben')
|
||
->description('Expertenansicht')
|
||
->columnSpanFull()
|
||
->collapsed()
|
||
->visible(fn (): bool => auth()->user() instanceof User && auth()->user()->adminMode() === AdminMode::Expert)
|
||
->columns(3)
|
||
->schema([
|
||
TextEntry::make('status')->label('Status')->badge(),
|
||
TextEntry::make('case_type')->label('Vorgangsart')->state(fn (Booking $record): string => strtoupper($record->caseType()->value).' – '.$record->caseType()->getLabel()),
|
||
TextEntry::make('templates')->label('Funktionsschablonen')->state(fn (Booking $record): ?string => self::templates($record))->placeholder('– (fester Ablauf)'),
|
||
TextEntry::make('intake')->label('Eingangsart')->state(fn (Booking $record): string => $record->intake?->getLabel() ?? '–'),
|
||
TextEntry::make('sources')->label('Quellen und Kalenderdarstellungen')->state(fn (Booking $record): HtmlString => self::sources($record))->html()->columnSpanFull(),
|
||
TextEntry::make('profile')->label('Abwicklungsprofil (eingefroren)')->state(fn (Booking $record): HtmlString => self::profile($record))->html()->columnSpanFull(),
|
||
TextEntry::make('hold_expires_at')->label('Reserviert bis')->dateTime('d.m.Y, H:i')->placeholder('–'),
|
||
TextEntry::make('offer_hash')->label('Angebot (Prüfsumme)')->state(fn (Booking $record): ?string => $record->offer_version > 0 ? 'Version '.$record->offer_version.' · '.substr((string) $record->offer_hash, 0, 16) : null)->placeholder('–'),
|
||
TextEntry::make('contract_pdf_sha256')->label('Vertrag (Prüfsumme)')->formatStateUsing(fn (?string $state): string => substr((string) $state, 0, 16))->placeholder('–'),
|
||
TextEntry::make('accepted_at')->label('Angenommen am')->dateTime('d.m.Y, H:i:s')->placeholder('–'),
|
||
TextEntry::make('source')->label('Quelle'),
|
||
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)->placeholder('–'),
|
||
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* The next step in large type, with what keeps an automatic case waiting.
|
||
*/
|
||
private static function nextStep(Booking $booking): HtmlString
|
||
{
|
||
$next = CaseActivities::next($booking);
|
||
$automatic = $booking->processingMode() === ProcessingMode::Automatic;
|
||
$waiting = collect(CaseActivities::for($booking))->first(fn ($activity): bool => $activity->state === ActivityState::Waiting);
|
||
|
||
$title = match (true) {
|
||
$next !== null => e($next->label),
|
||
$waiting !== null => 'Nichts zu tun – es wartet: '.e($waiting->label),
|
||
default => 'Nichts zu tun.',
|
||
};
|
||
$color = $next?->state === ActivityState::Problem ? '#dc2626' : ($next !== null ? '#b45309' : '#15803d');
|
||
$detail = $next !== null ? $next->detail : $waiting?->detail;
|
||
$mode = $automatic
|
||
? 'Dieser Vorgang läuft automatisch weiter, sobald alle Angaben da sind.'.(($blockers = self::blockers($booking)) !== [] ? ' Es fehlt: '.e(implode(' ', $blockers)) : '')
|
||
: 'Sie geben jeden Schritt selbst frei. Der Knopf oben rechts führt zum nächsten Schritt.';
|
||
|
||
return new HtmlString('<div style="font-size:1.35rem;font-weight:700;color:'.$color.'">'.$title.'</div>'
|
||
.($detail ? '<div style="margin-top:.2rem">'.e($detail).'</div>' : '')
|
||
.'<div style="margin-top:.5rem;color:#6b7280;font-size:.9rem">'.$mode.'</div>');
|
||
}
|
||
|
||
/**
|
||
* Every portal entry (calendar or e-mail) that belongs to the case, and what the intake recorded about it.
|
||
*/
|
||
private static function sources(Booking $booking): HtmlString
|
||
{
|
||
$lines = BlockedPeriod::query()->withTrashed()->with('channel')->where('linked_booking_id', $booking->id)->orderBy('id')->get()
|
||
->map(fn (BlockedPeriod $entry): string => e(($entry->source === 'email' ? 'E-Mail' : 'Kalender').' von '.($entry->channel?->name ?? '–').': '.$entry->starts_on->format('d.m.').'–'.$entry->ends_on->format('d.m.Y')
|
||
.($entry->trashed() ? ' · nicht mehr im Kalender' : '').($entry->starts_on->equalTo($booking->arrival) && $entry->ends_on->equalTo($booking->departure) ? '' : ' · abweichende Termine').' · Kennung '.$entry->external_uid));
|
||
$observations = IntakeObservation::query()->with('channel')->where('booking_id', $booking->id)->orderBy('occurred_at')->get()
|
||
->map(fn (IntakeObservation $observation): string => e($observation->occurred_at->format('d.m.Y H:i').' · '.$observation->sourceLabel().' '.$observation->channel?->name.' · '.$observation->outcome->getLabel().($observation->applied ? '' : ' (nur protokolliert)')));
|
||
|
||
$html = $lines->isEmpty() ? 'Keine Portaleinträge zugeordnet.' : $lines->implode('<br>');
|
||
|
||
return new HtmlString($observations->isEmpty() ? $html : $html.'<br><span style="color:#6b7280">Eingang: '.$observations->implode('<br>').'</span>');
|
||
}
|
||
|
||
/**
|
||
* The documents made for the case, as recorded when they were created (kind, template, date).
|
||
*/
|
||
private static function documents(Booking $booking): HtmlString
|
||
{
|
||
$lines = $booking->events()->where('type', 'document')->whereNotNull('data')->reorder()->orderBy('occurred_at')->orderBy('id')->get()
|
||
->filter(fn ($event): bool => isset($event->data['kind']))
|
||
->map(fn ($event): string => e($event->occurred_at->format('d.m.Y').' · '.$event->summary));
|
||
|
||
if ($lines->isEmpty()) {
|
||
$lines = collect([
|
||
$booking->offer_path ? 'Angebot Version '.$booking->offer_version : null,
|
||
$booking->contract_path ? 'Mietvertrag' : null,
|
||
$booking->confirmation_sent_at ? 'Bestätigung gesendet am '.$booking->confirmation_sent_at->format('d.m.Y') : null,
|
||
])->filter()->map(fn (string $line): string => e($line));
|
||
}
|
||
|
||
return new HtmlString($lines->isEmpty() ? 'Noch keine' : $lines->implode('<br>'));
|
||
}
|
||
|
||
/**
|
||
* @return list<string>
|
||
*/
|
||
private static function blockers(Booking $booking): array
|
||
{
|
||
return $booking->isBinding() && $booking->confirmation_sent_at === null && $booking->process()->documents() === Responsibility::Landlord
|
||
? app(CaseAutomation::class)->documentBlockers($booking)
|
||
: [];
|
||
}
|
||
|
||
private static function activities(Booking $booking): HtmlString
|
||
{
|
||
$colors = ['success' => '#15803d', 'warning' => '#b45309', 'danger' => '#dc2626', 'info' => '#2563eb', 'gray' => '#9ca3af'];
|
||
|
||
$rows = collect(CaseActivities::for($booking))
|
||
->reject(fn ($activity): bool => $activity->state === ActivityState::NotApplicable)
|
||
->map(function ($activity) use ($colors): string {
|
||
$color = $colors[$activity->state->getColor()];
|
||
$strong = $activity->state->needsAction() ? 'font-weight:700' : '';
|
||
|
||
// A click opens what lies behind the step (ViewBooking::activityDetailsAction).
|
||
return '<li style="display:flex;gap:.75rem;padding:.45rem 0;border-bottom:1px solid rgba(128,128,128,.2);cursor:pointer" title="Einzelheiten ansehen" wire:click="mountAction('activityDetails', { key: ''.e($activity->key).'' })">'
|
||
.'<span style="width:1.4rem;text-align:center;font-weight:700;color:'.$color.'">'.$activity->state->icon().'</span>'
|
||
.'<span style="flex:1;'.$strong.'">'.e($activity->label)
|
||
.($activity->detail ? ' <span style="font-weight:400;color:#6b7280">· '.e($activity->detail).'</span>' : '')
|
||
.($activity->url && $activity->state->needsAction() ? ' <a href="'.e($activity->url).'" style="color:#2563eb;text-decoration:underline">erledigen</a>' : '')
|
||
.'</span><span style="color:'.$color.';font-size:.85rem">'.e($activity->state->getLabel()).'</span></li>';
|
||
})->implode('');
|
||
|
||
return new HtmlString('<ul style="list-style:none;margin:0;padding:0">'.$rows.'</ul>');
|
||
}
|
||
|
||
private static function history(Booking $booking): HtmlString
|
||
{
|
||
$rows = $booking->events()->get()->map(fn ($event): string => '<li style="margin:.25rem 0"><span style="color:#6b7280">'.$event->occurred_at->format('d.m.Y H:i').'</span> · '.e($event->summary)
|
||
.($event->actor ? ' <span style="color:#6b7280">('.e($event->actor).')</span>' : '')
|
||
.($event->reason ? '<div style="color:#6b7280;margin-left:1rem">Grund: '.e($event->reason).'</div>' : '').'</li>')->implode('');
|
||
|
||
return new HtmlString($rows === '' ? 'Noch keine Einträge.' : '<ul style="list-style:none;padding:0;margin:0;font-size:.9rem">'.$rows.'</ul>');
|
||
}
|
||
|
||
/**
|
||
* The function templates the case was composed with, as frozen in its plan (null for the fixed models).
|
||
*/
|
||
private static function templates(Booking $record): ?string
|
||
{
|
||
$catalogue = app(ProcessCatalogue::class);
|
||
$labels = array_map(fn (string $reference): string => ($class = $catalogue->templateClass($reference)) !== null ? $class::label().' ('.$reference.')' : $reference, ProcessPlan::of($record)->templates);
|
||
|
||
return $labels === [] ? null : implode(' · ', $labels);
|
||
}
|
||
|
||
private static function profile(Booking $booking): HtmlString
|
||
{
|
||
$profile = $booking->process();
|
||
$rows = collect(ProcessSetting::cases())
|
||
->reject(fn (ProcessSetting $setting): bool => in_array($setting, ProcessProfile::LIVE, true))
|
||
->map(fn (ProcessSetting $setting): string => '<li>'.e($setting->question()).' <strong>'.e($setting->describe($profile->value($setting))).'</strong> <span style="color:#6b7280">('.e(ProcessProfile::sourceLabel($profile->source($setting))).')</span></li>')
|
||
->implode('');
|
||
|
||
return new HtmlString('<ul style="list-style:disc;padding-left:1.2rem">'.$rows.'</ul><div style="color:#6b7280;font-size:.85rem">Festgelegt '.e(($profile->origin === 'migration' ? 'bei der Übernahme der bisherigen Daten' : 'beim Eingang').($profile->frozenAt ? ' am '.CarbonImmutable::parse($profile->frozenAt)->format('d.m.Y H:i') : '')).($booking->processing_mode ? ' · Bearbeitung für diesen Vorgang: '.e($booking->processing_mode->getLabel()) : '').'</div>');
|
||
}
|
||
}
|