- Gäste, Buchungen (Status-Workflow), Sperrzeiten, Sonderangebote - Vorreservierung mit Haltezeit je Wohnung; abgelaufene Holds geben den Kalender sofort frei, Cron setzt Status und benachrichtigt - Sonderangebote/Sonderkonditionen: %, € pro Aufenthalt, Sonderpreis/Nacht, Gratis-Nächte; Bedingungen u. a. Saison, Vorlauf, Wochentag, Nächte, Aktionscode; bestes Einzel- vs. kombinierte Angebote - Öffentliche Seite /buchen: Belegungskalender, Live-Preis, Anfrageformular (Honeypot, Rate-Limit) - E-Mails: Angebot an Gast, Benachrichtigung Vermieter, Bestätigung, Absage, Ablauf - Filament: Anfragen & Buchungen (bestätigen, ablehnen, verlängern, stornieren, Telefonbuchung), Gäste, Sperrzeiten, Sonderangebote - Deutsche Validierungstexte Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
165 lines
8.6 KiB
PHP
165 lines
8.6 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||
|
||
use App\Enums\DiscountType;
|
||
use App\Models\SpecialOffer;
|
||
use App\Support\Money;
|
||
use Filament\Actions\CreateAction;
|
||
use Filament\Actions\DeleteAction;
|
||
use Filament\Actions\EditAction;
|
||
use Filament\Actions\ReplicateAction;
|
||
use Filament\Forms\Components\CheckboxList;
|
||
use Filament\Forms\Components\DatePicker;
|
||
use Filament\Forms\Components\DateTimePicker;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Forms\Components\Toggle;
|
||
use Filament\Resources\RelationManagers\RelationManager;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Tables\Columns\IconColumn;
|
||
use Filament\Tables\Columns\TextColumn;
|
||
use Filament\Tables\Table;
|
||
|
||
class SpecialOffersRelationManager extends RelationManager
|
||
{
|
||
protected static string $relationship = 'specialOffers';
|
||
|
||
protected static ?string $title = 'Sonderangebote';
|
||
|
||
protected static ?string $modelLabel = 'Sonderangebot';
|
||
|
||
protected static ?string $pluralModelLabel = 'Sonderangebote';
|
||
|
||
public function form(Schema $schema): Schema
|
||
{
|
||
return $schema
|
||
->components([
|
||
Section::make('Angebot')
|
||
->columns(2)
|
||
->schema([
|
||
TextInput::make('name')
|
||
->label('Bezeichnung')
|
||
->helperText('Erscheint so in Angebot und Rechnung, z. B. „Last Minute“ oder „Special Weekend“.')
|
||
->required()
|
||
->maxLength(255),
|
||
TextInput::make('public_description')
|
||
->label('Kurzbeschreibung für die Webseite')
|
||
->maxLength(255),
|
||
Select::make('discount_type')
|
||
->label('Art')
|
||
->options(DiscountType::class)
|
||
->default(DiscountType::Percent)
|
||
->live()
|
||
->required(),
|
||
TextInput::make('discount_value')
|
||
->label(fn (Get $get): string => match ($this->discountType($get)) {
|
||
DiscountType::Percent => 'Rabatt',
|
||
DiscountType::AmountPerStay => 'Rabatt pro Aufenthalt',
|
||
DiscountType::NightlyRate => 'Sonderpreis pro Nacht',
|
||
DiscountType::FreeNights => 'Anzahl Gratis-Nächte',
|
||
})
|
||
->suffix(fn (Get $get): string => match ($this->discountType($get)) {
|
||
DiscountType::Percent => '%',
|
||
DiscountType::FreeNights => 'Nächte',
|
||
default => '€',
|
||
})
|
||
->helperText(fn (Get $get): ?string => $this->discountType($get) === DiscountType::FreeNights ? 'Die günstigsten Nächte des Aufenthalts sind gratis.' : null)
|
||
->numeric()
|
||
->minValue(0)
|
||
->required()
|
||
->formatStateUsing(fn (?int $state, ?SpecialOffer $record): int|string|null => $state !== null && $this->isMoney($record?->discount_type) ? number_format($state / 100, 2, '.', '') : $state)
|
||
->dehydrateStateUsing(fn (string|int|float|null $state, Get $get): int => $this->isMoney($this->discountType($get)) ? (int) round((float) $state * 100) : (int) $state),
|
||
Toggle::make('is_active')->label('Aktiv')->default(true),
|
||
Toggle::make('is_public')->label('Auf der Webseite bewerben')->default(true),
|
||
Toggle::make('is_combinable')
|
||
->label('Mit anderen kombinierbaren Angeboten kombinierbar')
|
||
->helperText('Sonst erhält der Gast automatisch das für ihn beste Einzelangebot.')
|
||
->columnSpanFull(),
|
||
]),
|
||
Section::make('Bedingungen')
|
||
->description('Leere Felder bedeuten: keine Einschränkung.')
|
||
->columns(2)
|
||
->schema([
|
||
TextInput::make('code')
|
||
->label('Aktionscode (Sonderkondition)')
|
||
->helperText('Nur mit diesem Code gültig, z. B. für Stammgäste. Leer = gilt automatisch.')
|
||
->maxLength(50)
|
||
->columnSpanFull(),
|
||
CheckboxList::make('season_names')
|
||
->label('Nur bei Anreise in Saison')
|
||
->options(fn (): array => $this->getOwnerRecord()->seasons()->reorder('name')->distinct()->pluck('name', 'name')->all())
|
||
->columns(3)
|
||
->columnSpanFull(),
|
||
TextInput::make('max_days_before_arrival')
|
||
->label('Buchung höchstens … Tage vor Anreise')
|
||
->helperText('Last Minute, z. B. 14')
|
||
->integer()
|
||
->minValue(0),
|
||
TextInput::make('min_days_before_arrival')
|
||
->label('Buchung mindestens … Tage vor Anreise')
|
||
->helperText('Frühbucher, z. B. 180')
|
||
->integer()
|
||
->minValue(0),
|
||
TextInput::make('min_nights')->label('Mindestens Nächte')->integer()->minValue(1),
|
||
TextInput::make('max_nights')->label('Höchstens Nächte')->integer()->minValue(1),
|
||
CheckboxList::make('arrival_weekdays')
|
||
->label('Anreise nur am')
|
||
->options([1 => 'Mo', 2 => 'Di', 3 => 'Mi', 4 => 'Do', 5 => 'Fr', 6 => 'Sa', 7 => 'So'])
|
||
->columns(7)
|
||
->columnSpanFull(),
|
||
DatePicker::make('stay_from')->label('Aufenthalt frühestens ab'),
|
||
DatePicker::make('stay_until')->label('Abreise spätestens am'),
|
||
DateTimePicker::make('bookable_from')->label('Buchbar ab')->seconds(false),
|
||
DateTimePicker::make('bookable_until')->label('Buchbar bis')->seconds(false),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
public function table(Table $table): Table
|
||
{
|
||
return $table
|
||
->recordTitleAttribute('name')
|
||
->description('Sonderangebote werden bei jeder Preisberechnung automatisch geprüft und angewendet.')
|
||
->columns([
|
||
TextColumn::make('name')
|
||
->label('Angebot')
|
||
->description(fn (SpecialOffer $record): ?string => $record->public_description),
|
||
TextColumn::make('discount')
|
||
->label('Vorteil')
|
||
->state(fn (SpecialOffer $record): string => match ($record->discount_type) {
|
||
DiscountType::Percent => "−{$record->discount_value} %",
|
||
DiscountType::AmountPerStay => '−'.Money::format($record->discount_value),
|
||
DiscountType::NightlyRate => Money::format($record->discount_value).' / Nacht',
|
||
DiscountType::FreeNights => "{$record->discount_value} Nacht/Nächte gratis",
|
||
}),
|
||
TextColumn::make('code')->label('Code')->placeholder('automatisch')->badge(),
|
||
TextColumn::make('season_names')->label('Saisons')->badge()->placeholder('alle'),
|
||
IconColumn::make('is_combinable')->label('Kombinierbar')->boolean(),
|
||
IconColumn::make('is_active')->label('Aktiv')->boolean(),
|
||
])
|
||
->headerActions([
|
||
CreateAction::make(),
|
||
])
|
||
->recordActions([
|
||
EditAction::make(),
|
||
ReplicateAction::make()->label('Duplizieren')->schema(fn (Schema $schema): Schema => $this->form($schema)),
|
||
DeleteAction::make(),
|
||
]);
|
||
}
|
||
|
||
private function discountType(Get $get): DiscountType
|
||
{
|
||
$type = $get('discount_type');
|
||
|
||
return $type instanceof DiscountType ? $type : (DiscountType::tryFrom((string) $type) ?? DiscountType::Percent);
|
||
}
|
||
|
||
private function isMoney(?DiscountType $type): bool
|
||
{
|
||
return in_array($type, [DiscountType::AmountPerStay, DiscountType::NightlyRate], true);
|
||
}
|
||
}
|