- Gäste: Markierungen, Aufenthalte & Umsatz, Stammgast-/Einwilligungsfilter, CSV-Export, Anonymisierung (manuell + automatisch nach Aufbewahrungsfrist) - Werbe-Einwilligung per Double-Opt-in aus dem Anfrageformular, signierte Bestätigungs-/Abmeldelinks - Bewertungen: automatische Einladung nach Abreise, Bewertungsformular mit Kategorien und internem Feedback, Freigabe und öffentliche Antwort im Admin - Konzept: Rollen, Inhalte, Customer Voice, Architektur Portal-Sync/Buchungshoheit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.8 KiB
PHP
59 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Guests\Tables;
|
||
|
||
use App\Enums\BookingStatus;
|
||
use App\Models\Guest;
|
||
use Filament\Actions\EditAction;
|
||
use Filament\Tables\Columns\IconColumn;
|
||
use Filament\Tables\Columns\TextColumn;
|
||
use Filament\Tables\Filters\Filter;
|
||
use Filament\Tables\Filters\SelectFilter;
|
||
use Filament\Tables\Filters\TernaryFilter;
|
||
use Filament\Tables\Table;
|
||
use Illuminate\Database\Eloquent\Builder;
|
||
|
||
class GuestsTable
|
||
{
|
||
public static function configure(Table $table): Table
|
||
{
|
||
$countedBookings = ['bookings' => fn (Builder $query): Builder => $query->whereIn('status', BookingStatus::occupying())];
|
||
|
||
return $table
|
||
->defaultSort('last_name')
|
||
->columns([
|
||
TextColumn::make('last_name')
|
||
->label('Name')
|
||
->formatStateUsing(fn (Guest $record): string => "{$record->last_name}, {$record->first_name}")
|
||
->description(fn (Guest $record): string => $record->email)
|
||
->searchable(['first_name', 'last_name', 'email'])
|
||
->sortable(),
|
||
TextColumn::make('phone')->label('Telefon')->placeholder('–'),
|
||
TextColumn::make('city')->label('Ort')->placeholder('–')->toggleable(),
|
||
TextColumn::make('tags')->label('Markierungen')->badge(),
|
||
TextColumn::make('bookings_count')->label('Aufenthalte')->counts($countedBookings)->sortable(),
|
||
TextColumn::make('bookings_sum_total')->label('Umsatz')->sum($countedBookings, 'total')->money('EUR', divideBy: 100, locale: 'de')->sortable(),
|
||
IconColumn::make('marketing_consent_at')->label('Angebote')->boolean()->getStateUsing(fn (Guest $record): bool => $record->marketing_consent_at !== null),
|
||
])
|
||
->filters([
|
||
Filter::make('returning')
|
||
->label('Stammgäste (ab 2 Aufenthalten)')
|
||
->query(fn (Builder $query): Builder => $query->has('bookings', '>=', 2)),
|
||
TernaryFilter::make('marketing_consent_at')
|
||
->label('Einwilligung Angebote')
|
||
->nullable(),
|
||
SelectFilter::make('tag')
|
||
->label('Markierung')
|
||
->options(fn (): array => Guest::query()->whereNotNull('tags')->pluck('tags')->flatten()->unique()->sort()->mapWithKeys(fn (string $tag): array => [$tag => $tag])->all())
|
||
->query(fn (Builder $query, array $data): Builder => $query->when($data['value'], fn (Builder $query, string $tag): Builder => $query->whereJsonContains('tags', $tag))),
|
||
TernaryFilter::make('anonymized_at')
|
||
->label('Anonymisierte anzeigen')
|
||
->nullable()
|
||
->default(false),
|
||
])
|
||
->recordActions([
|
||
EditAction::make(),
|
||
]);
|
||
}
|
||
}
|