Files
fewo-stommer/app/Filament/Resources/Bookings/Pages/ViewBooking.php
T
Lars StommerandClaude Opus 5.5 08b6582fa1 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>
2026-10-22 09:43:12 +02:00

116 lines
5.0 KiB
PHP

<?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();
}
}