Files
fewo-stommer/app/Filament/Resources/CancellationPolicies/CancellationPolicyResource.php
T
LarsandClaude Sonnet 5.5 0c4187edaf
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
- Stornoregel (Stufen nach Tagen vor Anreise, Mietpreis oder Gesamtpreis, Ersatzmieter-Gebuehr), je Vertragsvorlage,
  beim Angebot eingefroren, als Platzhalter im Vertrag
- Stornierung (Gast-Link oder Verwaltung) berechnet die Kosten, legt einen Stornofall an; Verwaltung Stornierungen
  mit Vorschlag, Festlegung, Saldo, Abrechnung und Erlass; Gast sieht die Kosten vorab auf der Storno-Seite
- Vertragsanlagen als eigene versionierte Dokumente mit Bedingung (immer, Zusatzleistung, Portal, von Hand),
  je Angebot ausgewaehlt und eingefroren; Zusatzleistungen in der Buchung erfassbar
- FeWo-direkt-Installation legt die Stornoregel aus Paragraf 13 an

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 16:32:48 +01:00

94 lines
4.5 KiB
PHP

<?php
namespace App\Filament\Resources\CancellationPolicies;
use App\Filament\Concerns\FollowsAdminMode;
use App\Filament\Forms\Components\EuroInput;
use App\Filament\Resources\CancellationPolicies\Pages\CreateCancellationPolicy;
use App\Filament\Resources\CancellationPolicies\Pages\EditCancellationPolicy;
use App\Filament\Resources\CancellationPolicies\Pages\ListCancellationPolicies;
use App\Models\CancellationPolicy;
use BackedEnum;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Text;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;
use UnitEnum;
/**
* Cancellation rules: stepped percentages by days before arrival. Assigned to contract templates.
*/
class CancellationPolicyResource extends Resource
{
use FollowsAdminMode;
protected static ?string $model = CancellationPolicy::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedReceiptPercent;
protected static string|UnitEnum|null $navigationGroup = 'Vermietung';
protected static ?string $modelLabel = 'Stornoregel';
protected static ?string $pluralModelLabel = 'Stornoregeln';
protected static ?int $navigationSort = 7;
public static function form(Schema $schema): Schema
{
return $schema->components([
TextInput::make('name')->label('Name')->required()->maxLength(120)->helperText('z. B. „Direktbuchung“ oder „FeWo-direkt“.'),
Select::make('base')
->label('Berechnungsgrundlage')
->options([CancellationPolicy::BASE_RENT => 'Mietpreis (ohne Endreinigung, Service und Kurtaxe)', CancellationPolicy::BASE_TOTAL => 'Gesamtpreis'])
->default(CancellationPolicy::BASE_RENT)
->required(),
Repeater::make('tiers')
->label('Stufen')
->helperText('Jede Stufe gilt, wenn bis zur Anreise mindestens so viele Tage bleiben. Beispiel: ab 60 Tagen 0 %, ab 30 Tagen 50 %, ab 0 Tagen 100 %. Die letzte Stufe (0 Tage) gilt für alles danach.')
->schema([
TextInput::make('min_days')->label('Ab Tagen vor Anreise')->integer()->minValue(0)->required(),
TextInput::make('percent')->label('Entschädigung')->integer()->minValue(0)->maxValue(100)->suffix('%')->required(),
])
->columns(2)
->default([['min_days' => 60, 'percent' => 0], ['min_days' => 30, 'percent' => 50], ['min_days' => 0, 'percent' => 100]])
->minItems(1)
->required()
->columnSpanFull(),
EuroInput::make('replacement_fee')->label('Gebühr bei Ersatzmieter (optional)'),
Text::make(fn (?CancellationPolicy $record): HtmlString => new HtmlString($record ? '<strong>So steht es im Vertrag ({{ storno_regel }}):</strong><ul style="margin-top:.4rem">'.collect(CancellationPolicy::describe($record->snapshot()))->map(fn (string $line): string => '<li>'.e($line).'</li>')->implode('').'</ul>' : ''))->columnSpanFull(),
Textarea::make('notes')->label('Interne Notiz')->rows(2)->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('name')
->columns([
TextColumn::make('name')->label('Regel')->weight('medium')->searchable(),
TextColumn::make('base')->label('Grundlage')->formatStateUsing(fn (string $state): string => $state === CancellationPolicy::BASE_TOTAL ? 'Gesamtpreis' : 'Mietpreis'),
TextColumn::make('steps')->label('Stufen')->state(fn (CancellationPolicy $record): string => collect(CancellationPolicy::normalise((array) $record->tiers))->map(fn (array $tier): string => 'ab '.$tier['min_days'].' T: '.$tier['percent'].' %')->implode(' · ')),
])
->recordActions([EditAction::make(), DeleteAction::make()]);
}
public static function getPages(): array
{
return [
'index' => ListCancellationPolicies::route('/'),
'create' => CreateCancellationPolicy::route('/create'),
'edit' => EditCancellationPolicy::route('/{record}/edit'),
];
}
}