Phase 2: Kalender, Anfrage, Vorreservierung & Sonderangebote

- 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>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 09:43:12 +02:00
1 parent 2e9a391b37
commit 08b6582fa1
79 files changed
+6213 -76

No files matched your search

@@ -0,0 +1,71 @@
<?php
namespace App\Filament\Resources\Bookings;
use App\Enums\BookingStatus;
use App\Filament\Resources\Bookings\Pages\CreateBooking;
use App\Filament\Resources\Bookings\Pages\ListBookings;
use App\Filament\Resources\Bookings\Pages\ViewBooking;
use App\Filament\Resources\Bookings\Schemas\BookingForm;
use App\Filament\Resources\Bookings\Schemas\BookingInfolist;
use App\Filament\Resources\Bookings\Tables\BookingsTable;
use App\Models\Booking;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
class BookingResource extends Resource
{
protected static ?string $model = Booking::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
protected static ?string $modelLabel = 'Buchung';
protected static ?string $pluralModelLabel = 'Anfragen & Buchungen';
protected static ?string $recordTitleAttribute = 'reference';
protected static ?int $navigationSort = 1;
public static function form(Schema $schema): Schema
{
return BookingForm::configure($schema);
}
public static function infolist(Schema $schema): Schema
{
return BookingInfolist::configure($schema);
}
public static function table(Table $table): Table
{
return BookingsTable::configure($table);
}
/**
* Number of open requests waiting for a decision.
*/
public static function getNavigationBadge(): ?string
{
$open = Booking::query()->where('status', BookingStatus::Reserved)->count();
return $open > 0 ? (string) $open : null;
}
public static function getNavigationBadgeColor(): string
{
return 'warning';
}
public static function getPages(): array
{
return [
'index' => ListBookings::route('/'),
'create' => CreateBooking::route('/create'),
'view' => ViewBooking::route('/{record}'),
];
}
}
@@ -0,0 +1,61 @@
<?php
namespace App\Filament\Resources\Bookings\Pages;
use App\Actions\ConfirmBooking;
use App\Actions\CreateReservation;
use App\Exceptions\ReservationException;
use App\Filament\Resources\Bookings\BookingResource;
use App\Models\Property;
use App\Pricing\QuoteException;
use App\Pricing\StayRequest;
use Carbon\CarbonImmutable;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
class CreateBooking extends CreateRecord
{
protected static string $resource = BookingResource::class;
protected static ?string $title = 'Buchung erfassen';
/**
* @param array<string, mixed> $data
*/
protected function handleRecordCreation(array $data): Model
{
try {
$booking = app(CreateReservation::class)->handle(
Property::findOrFail($data['property_id']),
new StayRequest(
CarbonImmutable::parse($data['arrival']),
CarbonImmutable::parse($data['departure']),
(int) $data['guests'],
promoCode: $data['promo_code'] ?: null,
),
Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']),
source: 'manual',
sendMails: $data['send_mails'],
);
if ($data['confirm_immediately']) {
app(ConfirmBooking::class)->handle($booking, notifyGuest: $data['send_mails']);
}
} catch (QuoteException|ReservationException $exception) {
Notification::make()->title('Buchung nicht möglich')->body($exception->getMessage())->danger()->send();
$this->halt();
}
$booking->update(['internal_notes' => $data['internal_notes'] ?: null]);
return $booking;
}
protected function getRedirectUrl(): string
{
return BookingResource::getUrl('view', ['record' => $this->getRecord()]);
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Bookings\Pages;
use App\Filament\Resources\Bookings\BookingResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListBookings extends ListRecords
{
protected static string $resource = BookingResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
@@ -0,0 +1,115 @@
<?php
namespace App\Filament\Resources\Bookings\Pages;
use App\Actions\ConfirmBooking;
use App\Actions\DeclineBooking;
use App\Enums\BookingStatus;
use App\Exceptions\ReservationException;
use App\Filament\Resources\Bookings\BookingResource;
use App\Models\Booking;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
use Filament\Support\Icons\Heroicon;
/**
* @property Booking $record
*/
class ViewBooking extends ViewRecord
{
protected static string $resource = BookingResource::class;
public function getTitle(): string
{
return "{$this->record->reference} · {$this->record->guest->full_name}";
}
protected function getHeaderActions(): array
{
return [
Action::make('confirm')
->label('Bestätigen')
->icon(Heroicon::OutlinedCheckCircle)
->color('success')
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::Expired], true))
->requiresConfirmation()
->modalHeading('Buchung bestätigen')
->modalDescription('Die Buchung wird verbindlich und der Zeitraum dauerhaft belegt.')
->schema([
Toggle::make('notify')->label('Buchungsbestätigung an den Gast senden')->default(true),
])
->action(fn (array $data, ConfirmBooking $confirm) => $this->runWorkflow(
fn () => $confirm->handle($this->record, $data['notify']),
'Buchung bestätigt',
)),
Action::make('decline')
->label('Ablehnen')
->icon(Heroicon::OutlinedXCircle)
->color('danger')
->visible(fn (): bool => in_array($this->record->status, [BookingStatus::Reserved, BookingStatus::Expired], true))
->requiresConfirmation()
->modalHeading('Anfrage ablehnen')
->schema([
Toggle::make('notify')->label('Absage an den Gast senden')->default(true),
])
->action(fn (array $data, DeclineBooking $decline) => $this->runWorkflow(
fn () => $decline->handle($this->record, $data['notify']),
'Anfrage abgelehnt',
)),
Action::make('extendHold')
->label('Vormerkung verlängern')
->icon(Heroicon::OutlinedClock)
->color('gray')
->visible(fn (): bool => $this->record->status === BookingStatus::Reserved)
->schema([
TextInput::make('hours')->label('Um')->integer()->minValue(1)->default(24)->suffix('Stunden')->required(),
])
->action(function (array $data): void {
$from = $this->record->hold_expires_at?->isFuture() ? $this->record->hold_expires_at : now()->toImmutable();
$this->record->update(['hold_expires_at' => $from->addHours((int) $data['hours'])]);
Notification::make()->title('Vorgemerkt bis '.$this->record->hold_expires_at->format('d.m.Y, H:i'))->success()->send();
}),
ActionGroup::make([
Action::make('notes')
->label('Interne Notiz bearbeiten')
->icon(Heroicon::OutlinedPencilSquare)
->fillForm(fn (): array => ['internal_notes' => $this->record->internal_notes])
->schema([
Textarea::make('internal_notes')->label('Interne Notizen')->rows(6),
])
->action(fn (array $data) => $this->record->update($data)),
Action::make('cancel')
->label('Stornieren')
->icon(Heroicon::OutlinedNoSymbol)
->color('danger')
->visible(fn (): bool => in_array($this->record->status, BookingStatus::occupying(), true))
->requiresConfirmation()
->modalDescription('Der Zeitraum wird wieder freigegeben. Der Gast wird nicht automatisch benachrichtigt.')
->action(function (): void {
$this->record->update(['status' => BookingStatus::Cancelled, 'cancelled_at' => now()]);
Notification::make()->title('Buchung storniert')->success()->send();
}),
]),
];
}
private function runWorkflow(callable $workflow, string $successTitle): void
{
try {
$workflow();
} catch (ReservationException $exception) {
Notification::make()->title('Nicht möglich')->body($exception->getMessage())->danger()->send();
return;
}
Notification::make()->title($successTitle)->success()->send();
}
}
@@ -0,0 +1,66 @@
<?php
namespace App\Filament\Resources\Bookings\Schemas;
use App\Models\Property;
use Filament\Forms\Components\DatePicker;
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\Schema;
/**
* Manual entry of a booking received by phone or e-mail. The price is calculated automatically.
*/
class BookingForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Aufenthalt')
->columns(2)
->schema([
Select::make('property_id')
->label('Wohnung')
->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all())
->default(fn (): ?int => Property::query()->value('id'))
->required(),
TextInput::make('guests')
->label('Personen')
->integer()
->minValue(1)
->default(2)
->required(),
DatePicker::make('arrival')
->label('Anreise')
->required(),
DatePicker::make('departure')
->label('Abreise')
->after('arrival')
->required(),
TextInput::make('promo_code')
->label('Aktionscode'),
]),
Section::make('Gast')
->columns(2)
->schema([
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
TextInput::make('last_name')->label('Nachname')->required()->maxLength(255),
TextInput::make('email')->label('E-Mail')->email()->required()->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),
]),
Section::make('Abschluss')
->schema([
Textarea::make('internal_notes')->label('Interne Notiz'),
Toggle::make('confirm_immediately')->label('Sofort verbindlich bestätigen')->default(true),
Toggle::make('send_mails')->label('E-Mails an den Gast senden')->default(false),
]),
]);
}
}
@@ -0,0 +1,87 @@
<?php
namespace App\Filament\Resources\Bookings\Schemas;
use App\Models\Booking;
use App\Support\Money;
use Filament\Infolists\Components\RepeatableEntry;
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
class BookingInfolist
{
public static function configure(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Grid::make(1)
->columnSpan(2)
->schema([
Section::make('Aufenthalt')
->columns(3)
->schema([
TextEntry::make('property.name')->label('Wohnung'),
TextEntry::make('arrival')->label('Anreise')->date('l, d.m.Y'),
TextEntry::make('departure')->label('Abreise')->date('l, d.m.Y'),
TextEntry::make('nights')->label('Nächte')->state(fn (Booking $record): int => $record->nights()),
TextEntry::make('guests')->label('Personen'),
TextEntry::make('promo_code')->label('Aktionscode')->placeholder('–'),
]),
Section::make('Preis')
->schema([
RepeatableEntry::make('quote.lines')
->hiddenLabel()
->table([
TableColumn::make('Leistung'),
TableColumn::make('Betrag')->alignEnd(),
])
->schema([
TextEntry::make('label'),
TextEntry::make('amount')->formatStateUsing(fn (int $state): string => Money::format($state))->alignEnd(),
]),
Grid::make(4)->schema([
TextEntry::make('total')->label('Gesamtpreis')->money('EUR', divideBy: 100, locale: 'de')->weight('bold'),
TextEntry::make('deposit')->label('Anzahlung')->money('EUR', divideBy: 100, locale: 'de'),
TextEntry::make('balance')->label('Restzahlung')->state(fn (Booking $record): string => Money::format($record->total - $record->deposit)),
TextEntry::make('balance_due_on')->label('Rest fällig am')->date('d.m.Y'),
]),
]),
Section::make('Nachricht des Gastes')
->visible(fn (Booking $record): bool => filled($record->message))
->schema([
TextEntry::make('message')->hiddenLabel(),
]),
]),
Grid::make(1)
->columnSpan(1)
->schema([
Section::make('Status')
->schema([
TextEntry::make('status')->label('Status')->badge(),
TextEntry::make('hold_expires_at')->label('Vorgemerkt bis')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->hold_expires_at !== null),
TextEntry::make('confirmed_at')->label('Bestätigt am')->dateTime('d.m.Y, H:i')->visible(fn (Booking $record): bool => $record->confirmed_at !== null),
TextEntry::make('created_at')->label('Eingegangen')->dateTime('d.m.Y, H:i'),
TextEntry::make('source')->label('Quelle'),
]),
Section::make('Gast')
->schema([
TextEntry::make('guest.full_name')->label('Name'),
TextEntry::make('guest.email')->label('E-Mail')->copyable(),
TextEntry::make('guest.phone')->label('Telefon')->placeholder('–'),
TextEntry::make('guest_address')
->label('Adresse')
->state(fn (Booking $record): ?string => collect([$record->guest->street, trim("{$record->guest->postal_code} {$record->guest->city}")])->filter()->implode(', ') ?: null)
->placeholder('–'),
]),
Section::make('Interne Notizen')
->schema([
TextEntry::make('internal_notes')->hiddenLabel()->placeholder('Keine Notizen'),
]),
]),
]);
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Filament\Resources\Bookings\Tables;
use App\Enums\BookingStatus;
use App\Models\Booking;
use Filament\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class BookingsTable
{
public static function configure(Table $table): Table
{
return $table
->modifyQueryUsing(fn (Builder $query): Builder => $query->with(['guest', 'property']))
->defaultSort('created_at', 'desc')
->columns([
TextColumn::make('reference')
->label('Nr.')
->searchable(),
TextColumn::make('status')
->label('Status')
->badge()
->description(fn (Booking $record): ?string => $record->isHoldActive() ? 'bis '.$record->hold_expires_at->format('d.m. H:i') : null),
TextColumn::make('guest.last_name')
->label('Gast')
->formatStateUsing(fn (Booking $record): string => $record->guest->full_name)
->description(fn (Booking $record): string => $record->guest->email)
->searchable(['first_name', 'last_name', 'email']),
TextColumn::make('property.name')
->label('Wohnung')
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('arrival')
->label('Anreise')
->date('D, d.m.Y')
->sortable(),
TextColumn::make('departure')
->label('Abreise')
->date('D, d.m.Y')
->description(fn (Booking $record): string => $record->nights().' Nächte'),
TextColumn::make('guests')
->label('Pers.'),
TextColumn::make('total')
->label('Gesamt')
->money('EUR', divideBy: 100, locale: 'de'),
TextColumn::make('source')
->label('Quelle')
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('created_at')
->label('Eingang')
->since()
->sortable(),
])
->filters([
SelectFilter::make('status')
->label('Status')
->options(BookingStatus::class)
->multiple(),
Filter::make('upcoming')
->label('Nur kommende Aufenthalte')
->query(fn (Builder $query): Builder => $query->whereDate('departure', '>=', today())),
])
->recordActions([
ViewAction::make(),
]);
}
}