defaultSort('cancelled_on', 'desc') ->description('Storno-Verwaltung: Kosten werden nach der Stornoregel der Vertragsvorlage vorgeschlagen. Sie legen den Betrag endgültig fest, rechnen ab oder erlassen ihn. Gäste erhalten hierzu keine automatische Mail.') ->columns([ TextColumn::make('booking.reference')->label('Buchung')->weight('medium')->description(fn (Cancellation $record): string => $record->booking->guest?->full_name ?? ''), TextColumn::make('cancelled_on')->label('Storniert am')->date('d.m.Y')->description(fn (Cancellation $record): string => $record->initiated_by === 'guest' ? 'durch den Gast' : 'durch die Verwaltung'), TextColumn::make('days_before')->label('Tage vor Anreise')->placeholder('–'), TextColumn::make('policy_name')->label('Stornoregel')->placeholder('Keine Regel')->description(fn (Cancellation $record): ?string => $record->percent !== null ? $record->percent.' % von '.Money::format((int) $record->base_amount) : null), TextColumn::make('calculated_fee')->label('Vorschlag')->formatStateUsing(fn (?int $state): string => $state === null ? '–' : Money::format($state)), TextColumn::make('final_fee')->label('Festgelegt')->formatStateUsing(fn (?int $state): string => $state === null ? '–' : Money::format($state)), TextColumn::make('paid_amount')->label('Bezahlt')->formatStateUsing(fn (int $state): string => Money::format($state)), TextColumn::make('balance')->label('Saldo')->state(fn (Cancellation $record): string => $record->balance() > 0 ? Money::format($record->balance()).' einzufordern' : ($record->balance() < 0 ? Money::format(-$record->balance()).' zu erstatten' : 'ausgeglichen')), TextColumn::make('status')->label('Status')->badge()->formatStateUsing(fn (string $state): string => match ($state) { Cancellation::SETTLED => 'Abgerechnet', Cancellation::WAIVED => 'Erlassen', default => 'Offen', })->color(fn (string $state): string => $state === Cancellation::OPEN ? 'warning' : 'success'), ]) ->filters([ SelectFilter::make('status')->label('Status')->options([Cancellation::OPEN => 'Offen', Cancellation::SETTLED => 'Abgerechnet', Cancellation::WAIVED => 'Erlassen'])->default(Cancellation::OPEN), ]) ->recordActions([ Action::make('booking')->label('Buchung')->icon(Heroicon::OutlinedArrowTopRightOnSquare)->color('gray') ->url(fn (Cancellation $record): string => BookingResource::getUrl('view', ['record' => $record->booking])), Action::make('decide') ->label('Kosten festlegen') ->icon(Heroicon::OutlinedPencilSquare) ->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN) ->fillForm(fn (Cancellation $record): array => ['final_fee' => $record->final_fee ?? $record->calculated_fee, 'note' => $record->note]) ->schema([ EuroInput::make('final_fee')->label('Endgültige Stornokosten')->required(), Textarea::make('note')->label('Begründung / Notiz')->rows(2), ]) ->action(fn (array $data, Cancellation $record) => $record->update(['final_fee' => $data['final_fee'], 'note' => $data['note']])), Action::make('settle') ->label('Abgerechnet') ->icon(Heroicon::OutlinedCheck) ->color('success') ->requiresConfirmation() ->modalDescription('Die Stornokosten sind beglichen bzw. Rückzahlung und Forderung sind erledigt.') ->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN) ->action(fn (Cancellation $record) => $record->update(['status' => Cancellation::SETTLED, 'settled_at' => now()])), Action::make('waive') ->label('Erlassen') ->icon(Heroicon::OutlinedXMark) ->color('gray') ->requiresConfirmation() ->modalDescription('Es werden keine Stornokosten berechnet.') ->visible(fn (Cancellation $record): bool => $record->status === Cancellation::OPEN) ->action(fn (Cancellation $record) => $record->update(['status' => Cancellation::WAIVED, 'settled_at' => now()])), ]); } public static function canCreate(): bool { return false; } public static function getNavigationBadge(): ?string { $open = Cancellation::query()->where('status', Cancellation::OPEN)->count(); return $open > 0 ? (string) $open : null; } public static function getNavigationBadgeColor(): string { return 'warning'; } public static function getPages(): array { return [ 'index' => ListCancellations::route('/'), ]; } }