- CaseRequirements: Vor einem eigenen verbindlichen Angebot und vor der verbindlichen Bestätigung eines Buchungswunsches müssen Vor- und Nachname, E-Mail, vollständige Anschrift mit Land, Personenzahl und Zeitraum vorliegen – harter Blocker, auch von Hand (G2a, B3). Die Auskunft unter Vorbehalt bleibt ohne dieses Gate. - ContributeCaseFacts (S5): jede Angabe mit Herkunft und Ergebnis in case_facts; fehlend → übernommen, gleich → bestätigt, abweichend vom Gast → Prüfaufgabe (Kartei bleibt), Vermieterin maßgeblich, Zeitraum und Personen → Änderungswunsch; idempotent; danach einmal CaseAutomation. - ProvideGuestContact und Webformular nutzen den Fakteneingang. - Land als ISO-Code mit „Deutschland“ als änderbarem Formularstandard; guests.country ohne stillen Standardwert (B4). - Testdaten bestehender Tests um Anschriften ergänzt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
166 lines
11 KiB
PHP
166 lines
11 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Bookings\Schemas;
|
||
|
||
use App\Enums\InternalKind;
|
||
use App\Filament\Forms\Components\EuroInput;
|
||
use App\Models\Channel;
|
||
use App\Models\Extra;
|
||
use App\Models\Property;
|
||
use App\Support\Countries;
|
||
use App\Support\CurrentProperty;
|
||
use App\Support\Money;
|
||
use Filament\Forms\Components\DatePicker;
|
||
use Filament\Forms\Components\Radio;
|
||
use Filament\Forms\Components\Repeater;
|
||
use Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\Textarea;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Forms\Components\Toggle;
|
||
use Filament\Schemas\Components\Section;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
|
||
/**
|
||
* "Neu": one entry for everything that arrives outside the website. The first question is what it is – a request,
|
||
* a booking already binding on a portal, or own use / a block – and only the fields that matter for that answer follow.
|
||
* Nothing has to be invented: unknown guest data, number of guests or portal price stay empty.
|
||
*/
|
||
class BookingForm
|
||
{
|
||
public const INQUIRY = 'inquiry';
|
||
|
||
public const EXTERNAL = 'external';
|
||
|
||
public const OWN_USE = 'own_use';
|
||
|
||
public const BLOCK = 'block';
|
||
|
||
public static function configure(Schema $schema): Schema
|
||
{
|
||
$is = fn (string $kind): \Closure => fn (Get $get): bool => $get('kind') === $kind;
|
||
$isCase = fn (Get $get): bool => in_array($get('kind'), [self::INQUIRY, self::EXTERNAL], true);
|
||
$isInternal = fn (Get $get): bool => in_array($get('kind'), [self::OWN_USE, self::BLOCK], true);
|
||
$hasGuests = fn (Get $get): bool => $get('kind') === self::OWN_USE && $get('internal_kind') === InternalKind::PrivateStay->value;
|
||
|
||
return $schema
|
||
->components([
|
||
Section::make('Was möchten Sie eintragen?')
|
||
->schema([
|
||
Radio::make('kind')
|
||
->hiddenLabel()
|
||
->options([
|
||
self::INQUIRY => 'Eine Anfrage – per Telefon, E-Mail oder Nachricht über ein Portal',
|
||
self::EXTERNAL => 'Eine Buchung, die bei einem Portal schon fest gebucht ist',
|
||
self::OWN_USE => 'Eigene Nutzung oder Besuch von Familie und Freunden',
|
||
self::BLOCK => 'Eine Sperre ohne Gäste (z. B. Wartung, Renovierung)',
|
||
])
|
||
->default(self::INQUIRY)
|
||
->required()
|
||
->live(),
|
||
Radio::make('internal_kind')
|
||
->label('Wer wohnt in der Wohnung?')
|
||
->options([InternalKind::OwnUse->value => 'Wir selbst (eigene Nutzung)', InternalKind::PrivateStay->value => 'Familie oder Freunde (private Überlassung, ohne Mietvertrag)'])
|
||
->default(InternalKind::OwnUse->value)
|
||
->visible($is(self::OWN_USE))
|
||
->live(),
|
||
TextInput::make('occasion')->label(fn (Get $get): string => $get('kind') === self::BLOCK ? 'Grund der Sperre' : 'Anlass')
|
||
->placeholder(fn (Get $get): string => $get('kind') === self::BLOCK ? 'z. B. Malerarbeiten im Bad' : 'z. B. Besuch von Tochter Anna')
|
||
->maxLength(255)->required($is(self::BLOCK))->visible($isInternal),
|
||
]),
|
||
Section::make('Zeitraum')
|
||
->columns(2)
|
||
->visible(fn (Get $get): bool => $isCase($get) || $isInternal($get))
|
||
->schema([
|
||
Select::make('property_id')
|
||
->label('Wohnung')
|
||
->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all())
|
||
->default(fn (): ?int => app(CurrentProperty::class)->id())
|
||
->required()
|
||
->live(),
|
||
TextInput::make('guests')
|
||
->label('Personen')
|
||
->integer()
|
||
->minValue(1)
|
||
->helperText(fn (Get $get): ?string => $get('kind') === self::EXTERNAL ? 'Leer lassen, wenn nicht bekannt.' : null)
|
||
->visible(fn (Get $get): bool => $get('kind') !== self::BLOCK)
|
||
->live(onBlur: true)
|
||
->required($is(self::INQUIRY)),
|
||
DatePicker::make('arrival')->label(fn (Get $get): string => $isInternal($get) ? 'Beginn' : 'Anreise')->required(),
|
||
DatePicker::make('departure')->label(fn (Get $get): string => $isInternal($get) ? 'Ende (erster freier Tag)' : 'Abreise')->after('arrival')->required(),
|
||
]),
|
||
Section::make('Gäste')
|
||
->description('Nur eintragen, was Sie brauchen – z. B. für eine Aufenthaltsbestätigung.')
|
||
->columns(2)
|
||
->visible($hasGuests)
|
||
->schema([
|
||
TextInput::make('stay_first_name')->label('Vorname')->maxLength(255),
|
||
TextInput::make('stay_last_name')->label('Nachname')->maxLength(255),
|
||
TextInput::make('stay_email')->label('E-Mail (für eine Bestätigung)')->email()->maxLength(255),
|
||
TextInput::make('stay_phone')->label('Telefon')->tel()->maxLength(50),
|
||
]),
|
||
Section::make('Leistungen und Kosten (optional)')
|
||
->description('Miete ist bei Familie meist 0 €. Zahlungen lassen sich später erfassen; es gibt keine Zahlungserinnerungen.')
|
||
->columns(2)
|
||
->visible($is(self::OWN_USE))
|
||
->collapsed(fn (Get $get): bool => $get('internal_kind') !== InternalKind::PrivateStay->value)
|
||
->schema([
|
||
EuroInput::make('rent')->label('Vereinbarte Miete')->default(0),
|
||
TextInput::make('tourist_tax_persons')->label('Kurabgabe: Personen')->integer()->minValue(0)
|
||
->helperText(fn (Get $get): string => ($rate = Property::query()->find($get('property_id'))?->tourist_tax_rate) ? 'Satz je Person und Nacht: '.Money::format((int) $rate).' (Wohnung › Kurabgabe)' : 'Kein Satz hinterlegt (Wohnung › Kurabgabe) – es wird nichts berechnet.'),
|
||
TextInput::make('tourist_tax_note')->label('Befreiungen / Hinweis zur Kurabgabe')->maxLength(255)->columnSpanFull(),
|
||
Repeater::make('items')->label('Zusatzleistungen')->columns(2)->defaultItems(0)->addActionLabel('Leistung hinzufügen')->columnSpanFull()->schema([
|
||
Select::make('extra_id')->label('Leistung')->options(fn (Get $get): array => Extra::query()->where('property_id', $get('../../property_id'))->orderBy('name')->pluck('name', 'id')->all())->required(),
|
||
TextInput::make('quantity')->label('Menge')->integer()->minValue(1)->default(1)->required(),
|
||
]),
|
||
]),
|
||
Section::make('Portal')
|
||
->columns(2)
|
||
->visible($isCase)
|
||
->schema([
|
||
Select::make('channel_id')
|
||
->label(fn (Get $get): string => $get('kind') === self::EXTERNAL ? 'Gebucht über' : 'Über ein Portal (optional)')
|
||
->placeholder('Direkt – kein Portal')
|
||
->options(fn (Get $get): array => Channel::query()->portals()->where('property_id', $get('property_id'))->orderBy('name')->pluck('name', 'id')->all())
|
||
->required($is(self::EXTERNAL)),
|
||
TextInput::make('portal_reference')->label('Buchungsnummer im Portal')->maxLength(100)->visible($is(self::EXTERNAL)),
|
||
EuroInput::make('portal_total')
|
||
->label('Gesamtpreis laut Portal')
|
||
->helperText('Der Betrag, den der Gast beim Portal gebucht hat. Leer lassen, wenn noch nicht bekannt – er wird nicht geschätzt.')
|
||
->visible($is(self::EXTERNAL)),
|
||
]),
|
||
Section::make('Gast')
|
||
->description('Nur eintragen, was bekannt ist. Fehlendes wird später ergänzt; das System erinnert daran.')
|
||
->columns(2)
|
||
->visible($isCase)
|
||
->schema([
|
||
TextInput::make('first_name')->label('Vorname')->required($is(self::INQUIRY))->maxLength(255),
|
||
TextInput::make('last_name')->label('Nachname')->required($is(self::INQUIRY))->maxLength(255),
|
||
TextInput::make('email')->label('E-Mail')->email()->maxLength(255),
|
||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||
Select::make('country')->label('Land')->options(Countries::options())->placeholder('nicht bekannt'),
|
||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung bereits per E-Mail bestätigt')->visible($is(self::EXTERNAL)),
|
||
]),
|
||
Section::make('Wie geht es weiter?')
|
||
->visible($is(self::INQUIRY))
|
||
->schema([
|
||
Toggle::make('confirm_immediately')
|
||
->label('Die Buchung ist mit dem Gast schon fest vereinbart – gleich verbindlich eintragen')
|
||
->helperText('Aus: Das System bereitet das Angebot vor; je nach Einstellung geht es automatisch hinaus oder wartet auf Ihre Freigabe.')
|
||
->default(false),
|
||
Toggle::make('send_mails')->label('Dem Gast E-Mails senden (Eingangsbestätigung bzw. Buchungsbestätigung)')->default(true),
|
||
TextInput::make('promo_code')->label('Aktionscode')->maxLength(50),
|
||
]),
|
||
Section::make('Notiz')
|
||
->visible(fn (Get $get): bool => $isCase($get) || $isInternal($get))
|
||
->collapsed()
|
||
->schema([
|
||
Textarea::make('internal_notes')->hiddenLabel()->placeholder('Interne Notiz (nur für Sie sichtbar)'),
|
||
]),
|
||
]);
|
||
}
|
||
}
|