Sperrzeiten um Eigenbelegung und privaten Buchungskanal erweitern
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m49s

This commit is contained in:
Lars committed 2026-10-27 22:26:47 +01:00
1 parent 2b2e732612
commit 4389894959
12 files changed
+305 -28

No files matched your search

@@ -4,6 +4,7 @@
use App\Actions\ResolveChannelOccupation;
use App\Channels\ICal\ICalRuleEngine;
use App\Enums\BlockedPeriodPurpose;
use App\Filament\Concerns\FollowsAdminMode;
use App\Filament\Resources\BlockedPeriods\Pages\ManageBlockedPeriods;
use App\Filament\Resources\PortalOccupations\PortalOccupationResource;
@@ -32,7 +33,7 @@
/**
* Explicit blocks of all apartments. Imported reservations and unresolved periods have their own views.
* Portal and e-mail blocks are maintained by the sync and can only be viewed here.
* Portal dates remain maintained by the sync; business classification can be edited separately.
*/
class BlockedPeriodResource extends Resource
{
@@ -65,8 +66,11 @@ public static function form(Schema $schema): Schema
->dehydratedWhenHidden(),
DatePicker::make('starts_on')->label('Von (erste gesperrte Nacht)')->required(),
DatePicker::make('ends_on')->label('Bis (erster freier Tag)')->after('starts_on')->required(),
...static::purposeFields(),
Select::make('is_private')->label('Buchungskanal')->options([0 => 'Nicht angegeben', 1 => 'Privat'])
->default(0)->formatStateUsing(fn (mixed $state): int => (int) $state)->required(),
TextInput::make('reason')
->label('Grund')
->label('Bisheriger Sperrgrund / zusätzliche Angabe')
->placeholder('z. B. Eigennutzung, Renovierung')
->maxLength(255)
->columnSpanFull(),
@@ -78,6 +82,15 @@ public static function getEloquentQuery(): Builder
return parent::getEloquentQuery()->explicitBlocks()->occupying();
}
/** @return array<Select|TextInput> */
public static function purposeFields(): array
{
return [
Select::make('block_purpose')->label('Zweck der Sperrzeit')->options(BlockedPeriodPurpose::class)->placeholder('Noch nicht angegeben'),
TextInput::make('block_note')->label('Hinweis zum Zweck')->maxLength(255)->placeholder('z. B. Aufenthalt der Familie'),
];
}
public static function table(Table $table): Table
{
return $table
@@ -86,7 +99,8 @@ public static function table(Table $table): Table
->columns([
TextColumn::make('starts_on')->label('Von')->date('D, d.m.Y')->sortable(),
TextColumn::make('ends_on')->label('Bis / erster freier Tag')->date('D, d.m.Y'),
TextColumn::make('reason')->label('Grund')->placeholder('–'),
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('property.name')->label('Wohnung'),
TextColumn::make('channel.name')->label('Kalenderquelle')->placeholder('Eigene Sperre'),
])
@@ -98,6 +112,7 @@ public static function table(Table $table): Table
Action::make('viewPortal')->label('Details')->visible(fn (BlockedPeriod $record): bool => $record->source !== 'manual')
->url(fn (BlockedPeriod $record): string => PortalOccupationResource::getUrl('view', ['record' => $record->id])),
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
PortalOccupationResource::classificationAction(),
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
]);
}
@@ -22,6 +22,7 @@
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
@@ -83,24 +84,35 @@ public static function occupationActions(): array
{
return [
AssignGuestAction::make(),
Action::make('classify')->label('Belegungsart festlegen')
->visible(fn (BlockedPeriod $record): bool => ! $record->is_representation && ! $record->trashed())
->authorize(fn (BlockedPeriod $record): bool => auth()->user()?->can('update', $record) ?? false)
->modalDescription('Nur bekannte Sachverhalte bestätigen. Die Einordnung ändert keine Termine, hebt keine Sperre auf und führt keine Ereignisse automatisch zusammen. Überschneidungen bleiben gesonderte Prüffälle.')
->fillForm(fn (BlockedPeriod $record): array => ['occupation_kind' => $record->occupationKind()->value, 'origin_channel_id' => $record->origin_channel_id])
->schema([
Select::make('occupation_kind')->label('Fachliche Einordnung')->options(OccupationKind::class)->required(),
Select::make('origin_channel_id')->label('Buchungskanal, sofern persönlich bekannt')->placeholder('Unbekannt')
->options(fn (BlockedPeriod $record): array => Channel::query()->where('property_id', $record->property_id)->pluck('name', 'id')->all()),
])->action(function (BlockedPeriod $record, array $data, ClassifyPortalOccupation $classify): void {
$classify->handle($record, $data['occupation_kind'] instanceof OccupationKind ? $data['occupation_kind'] : OccupationKind::from($data['occupation_kind']), filled($data['origin_channel_id'] ?? null) ? (int) $data['origin_channel_id'] : null);
$record->refresh();
Notification::make()->title('Belegungsart gespeichert')->success()->send();
}),
static::classificationAction(),
...BlockedPeriodResource::portalActions(),
];
}
public static function classificationAction(): Action
{
return Action::make('classify')->label('Belegungsart / Zweck bearbeiten')
->visible(fn (BlockedPeriod $record): bool => in_array($record->source, ['channel', 'email'], true) && ! $record->is_representation && ! $record->trashed())
->authorize(fn (BlockedPeriod $record): bool => auth()->user()?->can('update', $record) ?? false)
->modalDescription('Nur bekannte Sachverhalte bestätigen. Die Einordnung ändert keine Termine, hebt keine Sperre auf und führt keine Ereignisse automatisch zusammen. Überschneidungen bleiben gesonderte Prüffälle.')
->fillForm(fn (BlockedPeriod $record): array => ['occupation_kind' => $record->occupationKind()->value, 'origin_channel_id' => $record->is_private ? 'private' : $record->origin_channel_id, 'block_purpose' => $record->block_purpose?->value, 'block_note' => $record->block_note])
->schema([
Select::make('occupation_kind')->label('Fachliche Einordnung')->options(OccupationKind::class)->required()->live(),
Section::make('Zweck der Sperrzeit')->columns(2)->schema(BlockedPeriodResource::purposeFields())
->visible(fn (Get $get): bool => in_array($get('occupation_kind'), [OccupationKind::Block, OccupationKind::Block->value], true)),
Select::make('origin_channel_id')->label('Buchungskanal, sofern persönlich bekannt')->placeholder('Unbekannt')
->helperText('Privat bezeichnet den fachlichen Ursprung. Der Importkanal bleibt als Kalenderquelle erhalten.')
->options(fn (BlockedPeriod $record): array => ['private' => 'Privat'] + Channel::query()->where('property_id', $record->property_id)->pluck('name', 'id')->all()),
])->action(function (BlockedPeriod $record, array $data, ClassifyPortalOccupation $classify): void {
$private = ($data['origin_channel_id'] ?? null) === 'private';
$classify->handle($record, $data['occupation_kind'] instanceof OccupationKind ? $data['occupation_kind'] : OccupationKind::from($data['occupation_kind']), ! $private && filled($data['origin_channel_id'] ?? null) ? (int) $data['origin_channel_id'] : null, [
'block_purpose' => $data['block_purpose'] ?? null, 'block_note' => $data['block_note'] ?? null, 'is_private' => $private,
]);
$record->refresh();
Notification::make()->title('Belegungsart gespeichert')->success()->send();
});
}
public static function infolist(Schema $schema): Schema
{
return $schema->components([
@@ -109,7 +121,9 @@ public static function infolist(Schema $schema): Schema
TextEntry::make('starts_on')->label('Anreise / Beginn')->date('d.m.Y'),
TextEntry::make('ends_on')->label('Abreise / erster freier Tag')->date('d.m.Y'),
TextEntry::make('kind')->label('Einordnung')->state(fn (BlockedPeriod $record): string => $record->occupationKind()->getLabel()),
TextEntry::make('originChannel.name')->label('Bestätigter Buchungskanal')->placeholder('Unbekannt'),
TextEntry::make('booking_channel')->label('Buchungskanal')->state(fn (BlockedPeriod $record): string => $record->bookingChannelLabel()),
TextEntry::make('block_description')->label('Zweck / Grund der Sperrzeit')->state(fn (BlockedPeriod $record): ?string => $record->blockDescription())
->visible(fn (BlockedPeriod $record): bool => $record->occupationKind() === OccupationKind::Block)->placeholder('Noch nicht angegeben'),
TextEntry::make('channel.name')->label('Importiert über'),
TextEntry::make('guest_name')->label('Gast / Namensinformation')->state(fn (BlockedPeriod $record): ?string => $record->guestName())->placeholder('Unbekannt')
->url(fn (BlockedPeriod $record): ?string => $record->assignedGuest() ? GuestResource::getUrl('edit', ['record' => $record->assignedGuest()->id]) : null),
@@ -2,11 +2,14 @@
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;
@@ -42,6 +45,9 @@ public function form(Schema $schema): Schema
->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(),
]);
}
@@ -55,7 +61,8 @@ public function table(Table $table): Table
->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('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([
@@ -69,6 +76,7 @@ public function table(Table $table): Table
])
->recordActions([
EditAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
PortalOccupationResource::classificationAction(),
DeleteAction::make()->visible(fn (BlockedPeriod $record): bool => $record->source === 'manual'),
]);
}