Files
fewo-stommer/app/Filament/Resources/Properties/RelationManagers/BlockedPeriodsRelationManager.php
T
2026-10-27 21:51:56 +01:00

76 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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
->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('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()->mutateDataUsing(fn (array $data): array => [...$data, 'source' => 'manual']),
])
->recordActions([
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
]);
}
}