Files
fewo-stommer/app/Filament/Resources/Bookings/Schemas/BookingForm.php
T
LarsandClaude Opus 5.5 799869c6a4 v0.11 U1: Kanalmanager mit eigener Webseite und neuen Prozessparametern
- Eigene Webseite als Kanal eigener Art (channels.kind = website), nur zur
  Konfiguration: Webseiten-Anfragen bleiben direkt (A1) ohne Kanalbezug;
  der Eintrag nimmt an Sync, Export, Überwachung und Sperraufgaben nicht teil
  (active()/Property::channels() nur Portale, Feed nur für Portale).
- Neue Einstellungen im bestehenden ProcessSetting: Klärungsreservierung
  automatisch/Freigabe (15/180 min, 0 = keine), Rückfragemodus,
  Erinnerungen, Folgefragen, Erinnerungsabstand, Linkgültigkeit,
  Anschrift im Webformular verlangen (Standard: nein).
- „Kanäle“ in der einfachen Ansicht: Webseite und Portale an einer Stelle,
  Verweis auf „Ihre Standards“; „Wirksame Einstellungen“ mit Spalte
  „Eigene Webseite“ und Herkunft „Webseite“.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 12:52:50 +01:00

164 lines
10 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\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\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),
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)'),
]),
]);
}
}