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:
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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests;
|
||||
|
||||
use App\Filament\Resources\Guests\Pages\CreateGuest;
|
||||
use App\Filament\Resources\Guests\Pages\EditGuest;
|
||||
use App\Filament\Resources\Guests\Pages\ListGuests;
|
||||
use App\Filament\Resources\Guests\Schemas\GuestForm;
|
||||
use App\Filament\Resources\Guests\Tables\GuestsTable;
|
||||
use App\Models\Guest;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class GuestResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Guest::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static ?string $modelLabel = 'Gast';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Gäste';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'last_name';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return GuestForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return GuestsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListGuests::route('/'),
|
||||
'create' => CreateGuest::route('/create'),
|
||||
'edit' => EditGuest::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateGuest extends CreateRecord
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditGuest extends EditRecord
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Pages;
|
||||
|
||||
use App\Filament\Resources\Guests\GuestResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListGuests extends ListRecords
|
||||
{
|
||||
protected static string $resource = GuestResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class GuestForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
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),
|
||||
Select::make('country')
|
||||
->label('Land')
|
||||
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
|
||||
->default('DE')
|
||||
->required(),
|
||||
Textarea::make('notes')->label('Notizen')->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Guests\Tables;
|
||||
|
||||
use App\Models\Guest;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class GuestsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('last_name')
|
||||
->columns([
|
||||
TextColumn::make('last_name')
|
||||
->label('Name')
|
||||
->formatStateUsing(fn (Guest $record): string => "{$record->last_name}, {$record->first_name}")
|
||||
->searchable(['first_name', 'last_name'])
|
||||
->sortable(),
|
||||
TextColumn::make('email')->label('E-Mail')->searchable(),
|
||||
TextColumn::make('phone')->label('Telefon')->placeholder('–'),
|
||||
TextColumn::make('city')->label('Ort')->placeholder('–'),
|
||||
TextColumn::make('bookings_count')->label('Buchungen')->counts('bookings')->sortable(),
|
||||
TextColumn::make('created_at')->label('Seit')->date('m/Y')->sortable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,10 @@
|
||||
use App\Filament\Resources\Properties\Pages\CreateProperty;
|
||||
use App\Filament\Resources\Properties\Pages\EditProperty;
|
||||
use App\Filament\Resources\Properties\Pages\ListProperties;
|
||||
use App\Filament\Resources\Properties\RelationManagers\BlockedPeriodsRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\ExtrasRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\SeasonsRelationManager;
|
||||
use App\Filament\Resources\Properties\RelationManagers\SpecialOffersRelationManager;
|
||||
use App\Filament\Resources\Properties\Schemas\PropertyForm;
|
||||
use App\Filament\Resources\Properties\Tables\PropertiesTable;
|
||||
use App\Models\Property;
|
||||
@@ -42,7 +44,9 @@ public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
SeasonsRelationManager::class,
|
||||
SpecialOffersRelationManager::class,
|
||||
ExtrasRelationManager::class,
|
||||
BlockedPeriodsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||||
|
||||
use App\Models\BlockedPeriod;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BlockedPeriodsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'blockedPeriods';
|
||||
|
||||
protected static ?string $title = 'Sperrzeiten';
|
||||
|
||||
protected static ?string $modelLabel = 'Sperrzeit';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Sperrzeiten';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(2)
|
||||
->components([
|
||||
DatePicker::make('starts_on')
|
||||
->label('Von (erste gesperrte Nacht)')
|
||||
->required(),
|
||||
DatePicker::make('ends_on')
|
||||
->label('Bis (erster freier Tag)')
|
||||
->after('starts_on')
|
||||
->required(),
|
||||
TextInput::make('reason')
|
||||
->label('Grund')
|
||||
->placeholder('z. B. Eigennutzung, Renovierung')
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('reason')
|
||||
->description('Manuelle Sperren (z. B. Eigennutzung). Belegungen aus Portalen erscheinen hier später automatisch.')
|
||||
->defaultSort('starts_on')
|
||||
->columns([
|
||||
TextColumn::make('starts_on')->label('Von')->date('D, d.m.Y'),
|
||||
TextColumn::make('ends_on')->label('Bis')->date('D, d.m.Y'),
|
||||
TextColumn::make('reason')->label('Grund')->placeholder('–'),
|
||||
TextColumn::make('source')->label('Quelle'),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('upcoming')
|
||||
->label('Nur kommende')
|
||||
->default()
|
||||
->query(fn (Builder $query): Builder => $query->whereDate('ends_on', '>=', today())),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||||
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
use App\Pricing\PriceCalculator;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
@@ -30,7 +32,6 @@
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class SeasonsRelationManager extends RelationManager
|
||||
{
|
||||
@@ -224,29 +225,30 @@ private function priceCalculatorAction(): Action
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->default(2),
|
||||
TextInput::make('promo_code')
|
||||
->label('Aktionscode (optional)'),
|
||||
])
|
||||
->action(function (array $data, PriceCalculator $calculator): void {
|
||||
try {
|
||||
$quote = $calculator->calculate(
|
||||
$this->getOwnerRecord(),
|
||||
$quote = $calculator->calculate($this->getOwnerRecord(), new StayRequest(
|
||||
CarbonImmutable::parse($data['arrival']),
|
||||
CarbonImmutable::parse($data['departure']),
|
||||
(int) $data['guests'],
|
||||
);
|
||||
promoCode: $data['promo_code'] ?? null,
|
||||
));
|
||||
} catch (QuoteException $exception) {
|
||||
Notification::make()->title('Nicht buchbar')->body($exception->getMessage())->danger()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$euro = fn (int $cents): string => Number::currency($cents / 100, 'EUR', 'de');
|
||||
$lines = collect($quote->lines)
|
||||
->map(fn (QuoteLine $line): string => e($line->label).': '.$euro($line->amount))
|
||||
->push('Anzahlung: '.$euro($quote->deposit()).' · Rest: '.$euro($quote->balance()).' fällig am '.$quote->balanceDueOn->format('d.m.Y'))
|
||||
->map(fn (QuoteLine $line): string => e($line->label).': '.Money::format($line->amount))
|
||||
->push('Anzahlung: '.Money::format($quote->deposit()).' · Rest: '.Money::format($quote->balance()).' fällig am '.$quote->balanceDueOn->format('d.m.Y'))
|
||||
->implode('<br>');
|
||||
|
||||
Notification::make()
|
||||
->title('Gesamtpreis: '.$euro($quote->total()))
|
||||
->title('Gesamtpreis: '.Money::format($quote->total()))
|
||||
->body($lines)
|
||||
->success()
|
||||
->persistent()
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||||
|
||||
use App\Enums\DiscountType;
|
||||
use App\Models\SpecialOffer;
|
||||
use App\Support\Money;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SpecialOffersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'specialOffers';
|
||||
|
||||
protected static ?string $title = 'Sonderangebote';
|
||||
|
||||
protected static ?string $modelLabel = 'Sonderangebot';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Sonderangebote';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Angebot')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Bezeichnung')
|
||||
->helperText('Erscheint so in Angebot und Rechnung, z. B. „Last Minute“ oder „Special Weekend“.')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('public_description')
|
||||
->label('Kurzbeschreibung für die Webseite')
|
||||
->maxLength(255),
|
||||
Select::make('discount_type')
|
||||
->label('Art')
|
||||
->options(DiscountType::class)
|
||||
->default(DiscountType::Percent)
|
||||
->live()
|
||||
->required(),
|
||||
TextInput::make('discount_value')
|
||||
->label(fn (Get $get): string => match ($this->discountType($get)) {
|
||||
DiscountType::Percent => 'Rabatt',
|
||||
DiscountType::AmountPerStay => 'Rabatt pro Aufenthalt',
|
||||
DiscountType::NightlyRate => 'Sonderpreis pro Nacht',
|
||||
DiscountType::FreeNights => 'Anzahl Gratis-Nächte',
|
||||
})
|
||||
->suffix(fn (Get $get): string => match ($this->discountType($get)) {
|
||||
DiscountType::Percent => '%',
|
||||
DiscountType::FreeNights => 'Nächte',
|
||||
default => '€',
|
||||
})
|
||||
->helperText(fn (Get $get): ?string => $this->discountType($get) === DiscountType::FreeNights ? 'Die günstigsten Nächte des Aufenthalts sind gratis.' : null)
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->required()
|
||||
->formatStateUsing(fn (?int $state, ?SpecialOffer $record): int|string|null => $state !== null && $this->isMoney($record?->discount_type) ? number_format($state / 100, 2, '.', '') : $state)
|
||||
->dehydrateStateUsing(fn (string|int|float|null $state, Get $get): int => $this->isMoney($this->discountType($get)) ? (int) round((float) $state * 100) : (int) $state),
|
||||
Toggle::make('is_active')->label('Aktiv')->default(true),
|
||||
Toggle::make('is_public')->label('Auf der Webseite bewerben')->default(true),
|
||||
Toggle::make('is_combinable')
|
||||
->label('Mit anderen kombinierbaren Angeboten kombinierbar')
|
||||
->helperText('Sonst erhält der Gast automatisch das für ihn beste Einzelangebot.')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Bedingungen')
|
||||
->description('Leere Felder bedeuten: keine Einschränkung.')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('code')
|
||||
->label('Aktionscode (Sonderkondition)')
|
||||
->helperText('Nur mit diesem Code gültig, z. B. für Stammgäste. Leer = gilt automatisch.')
|
||||
->maxLength(50)
|
||||
->columnSpanFull(),
|
||||
CheckboxList::make('season_names')
|
||||
->label('Nur bei Anreise in Saison')
|
||||
->options(fn (): array => $this->getOwnerRecord()->seasons()->reorder('name')->distinct()->pluck('name', 'name')->all())
|
||||
->columns(3)
|
||||
->columnSpanFull(),
|
||||
TextInput::make('max_days_before_arrival')
|
||||
->label('Buchung höchstens … Tage vor Anreise')
|
||||
->helperText('Last Minute, z. B. 14')
|
||||
->integer()
|
||||
->minValue(0),
|
||||
TextInput::make('min_days_before_arrival')
|
||||
->label('Buchung mindestens … Tage vor Anreise')
|
||||
->helperText('Frühbucher, z. B. 180')
|
||||
->integer()
|
||||
->minValue(0),
|
||||
TextInput::make('min_nights')->label('Mindestens Nächte')->integer()->minValue(1),
|
||||
TextInput::make('max_nights')->label('Höchstens Nächte')->integer()->minValue(1),
|
||||
CheckboxList::make('arrival_weekdays')
|
||||
->label('Anreise nur am')
|
||||
->options([1 => 'Mo', 2 => 'Di', 3 => 'Mi', 4 => 'Do', 5 => 'Fr', 6 => 'Sa', 7 => 'So'])
|
||||
->columns(7)
|
||||
->columnSpanFull(),
|
||||
DatePicker::make('stay_from')->label('Aufenthalt frühestens ab'),
|
||||
DatePicker::make('stay_until')->label('Abreise spätestens am'),
|
||||
DateTimePicker::make('bookable_from')->label('Buchbar ab')->seconds(false),
|
||||
DateTimePicker::make('bookable_until')->label('Buchbar bis')->seconds(false),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->description('Sonderangebote werden bei jeder Preisberechnung automatisch geprüft und angewendet.')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Angebot')
|
||||
->description(fn (SpecialOffer $record): ?string => $record->public_description),
|
||||
TextColumn::make('discount')
|
||||
->label('Vorteil')
|
||||
->state(fn (SpecialOffer $record): string => match ($record->discount_type) {
|
||||
DiscountType::Percent => "−{$record->discount_value} %",
|
||||
DiscountType::AmountPerStay => '−'.Money::format($record->discount_value),
|
||||
DiscountType::NightlyRate => Money::format($record->discount_value).' / Nacht',
|
||||
DiscountType::FreeNights => "{$record->discount_value} Nacht/Nächte gratis",
|
||||
}),
|
||||
TextColumn::make('code')->label('Code')->placeholder('automatisch')->badge(),
|
||||
TextColumn::make('season_names')->label('Saisons')->badge()->placeholder('alle'),
|
||||
IconColumn::make('is_combinable')->label('Kombinierbar')->boolean(),
|
||||
IconColumn::make('is_active')->label('Aktiv')->boolean(),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
ReplicateAction::make()->label('Duplizieren')->schema(fn (Schema $schema): Schema => $this->form($schema)),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function discountType(Get $get): DiscountType
|
||||
{
|
||||
$type = $get('discount_type');
|
||||
|
||||
return $type instanceof DiscountType ? $type : (DiscountType::tryFrom((string) $type) ?? DiscountType::Percent);
|
||||
}
|
||||
|
||||
private function isMoney(?DiscountType $type): bool
|
||||
{
|
||||
return in_array($type, [DiscountType::AmountPerStay, DiscountType::NightlyRate], true);
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,14 @@ public static function configure(Schema $schema): Schema
|
||||
->minValue(0)
|
||||
->suffix('Tage vor Anreise')
|
||||
->default(28),
|
||||
TextInput::make('hold_hours')
|
||||
->label('Vorreservierung halten')
|
||||
->helperText('So lange bleibt ein angefragter Zeitraum ohne Ihre Bestätigung blockiert.')
|
||||
->required()
|
||||
->integer()
|
||||
->minValue(1)
|
||||
->suffix('Stunden')
|
||||
->default(48),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user