- Zahlungen erfassen (inkl. Erstattungen), Status automatisch: Bestätigt → Anzahlung erhalten → Bezahlt → Abgeschlossen - Anzahlungsfrist bei Bestätigung; kurzfristige Buchungen: Gesamtbetrag sofort - Mietvertrag als PDF (dompdf, Font-Subsetting), bei Bestätigung gespeichert und angehängt; Texte im Admin (Muster) - Täglich: Zahlungserinnerungen (Anzahlung/Rest überfällig, Kopie an Vermieter), Zahlungsaufforderung Rest 7 Tage vorher, Anreiseinfos 7 Tage vorher, Abschluss nach Abreise - Admin: Zahlungen je Buchung, offene Beträge, Vertrag herunterladen/neu erzeugen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
133 lines
6.1 KiB
PHP
133 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Bookings\Pages;
|
|
|
|
use App\Actions\ConfirmBooking;
|
|
use App\Actions\DeclineBooking;
|
|
use App\Documents\RentalContract;
|
|
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();
|
|
}),
|
|
Action::make('contract')
|
|
->label('Mietvertrag')
|
|
->icon(Heroicon::OutlinedDocumentText)
|
|
->color('gray')
|
|
->visible(fn (): bool => $this->record->contract_path !== null)
|
|
->action(fn (RentalContract $contract) => response()->download($contract->absolutePath($this->record) ?? abort(404), "Mietvertrag-{$this->record->reference}.pdf")),
|
|
ActionGroup::make([
|
|
Action::make('regenerateContract')
|
|
->label('Mietvertrag neu erzeugen')
|
|
->icon(Heroicon::OutlinedArrowPath)
|
|
->visible(fn (): bool => in_array($this->record->status, [...BookingStatus::occupying()], true))
|
|
->requiresConfirmation()
|
|
->modalDescription('Der Vertrag wird mit den aktuellen Texten neu erstellt. Der Gast erhält ihn nicht automatisch.')
|
|
->action(function (RentalContract $contract): void {
|
|
$contract->generate($this->record);
|
|
Notification::make()->title('Mietvertrag neu erzeugt')->success()->send();
|
|
}),
|
|
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();
|
|
}
|
|
}
|