Files
fewo-stommer/app/Filament/Resources/Cancellations/CancellationResource.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

120 lines
6.4 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\Filament\Resources\Cancellations;
use App\Filament\Concerns\FollowsAdminMode;
use App\Filament\Forms\Components\EuroInput;
use App\Filament\Resources\Bookings\BookingResource;
use App\Filament\Resources\Cancellations\Pages\ListCancellations;
use App\Models\Cancellation;
use App\Support\Money;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Forms\Components\Textarea;
use Filament\Resources\Resource;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use UnitEnum;
/**
* Cancellation management: every cancelled booking with the days before arrival, the cost proposed by its
* cancellation rule, the amount finally charged, what was paid and what is still to collect or refund.
*/
class CancellationResource extends Resource
{
use FollowsAdminMode;
protected static ?string $model = Cancellation::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArchiveBoxXMark;
protected static string|UnitEnum|null $navigationGroup = 'Verwaltung';
protected static ?string $modelLabel = 'Stornierung';
protected static ?string $pluralModelLabel = 'Stornierungen';
protected static ?int $navigationSort = 6;
public static function table(Table $table): Table
{
return $table
->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('/'),
];
}
}