84 lines
3.6 KiB
PHP
84 lines
3.6 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Properties\RelationManagers;
|
||
|
||
use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource;
|
||
use App\Filament\Resources\PortalOccupations\PortalOccupationResource;
|
||
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\Select;
|
||
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(),
|
||
...BlockedPeriodResource::purposeFields(),
|
||
Select::make('is_private')->label('Buchungskanal')->options([0 => 'Nicht angegeben', 1 => 'Privat'])
|
||
->default(0)->formatStateUsing(fn (mixed $state): int => (int) $state)->required(),
|
||
]);
|
||
}
|
||
|
||
public function table(Table $table): Table
|
||
{
|
||
return $table
|
||
->modifyQueryUsing(fn (Builder $query): Builder => $query->explicitBlocks()->occupying())
|
||
->recordTitleAttribute('reason')
|
||
->description('Ausdrückliche Sperrzeiten. Alle Belegungen stehen im Belegungsplan; Portalreservierungen unter Anfragen & Buchungen.')
|
||
->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('purpose')->label('Zweck / Grund')->state(fn (BlockedPeriod $record): ?string => $record->blockDescription())->placeholder('–'),
|
||
TextColumn::make('booking_channel')->label('Buchungskanal')->state(fn (BlockedPeriod $record): string => $record->bookingChannelLabel()),
|
||
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()->mutateDataUsing(fn (array $data): array => [...$data, 'source' => 'manual']),
|
||
])
|
||
->recordActions([
|
||
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||
PortalOccupationResource::classificationAction(),
|
||
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
|
||
]);
|
||
}
|
||
}
|