withTrashed()->whereIn('source', ['channel', 'email'])->with(['guest', 'channel', 'originChannel', 'property', 'linkedBooking.guest', 'canonicalBlock.guest']); } public static function getNavigationBadge(): ?string { $count = BlockedPeriod::query()->unclear()->count(); return $count ? (string) $count : null; } public static function getNavigationBadgeColor(): string { return 'warning'; } public static function table(Table $table): Table { return $table->description('Unbekannte Belegungen und mögliche Mehrfachdarstellungen persönlich klären. Auch ungeklärte führende Einträge halten ihre Nächte belegt.') ->defaultSort('starts_on')->columns([ TextColumn::make('starts_on')->label('Anreise / Beginn')->date('d.m.Y')->sortable(), TextColumn::make('ends_on')->label('Abreise / Ende')->date('d.m.Y'), TextColumn::make('business_kind')->label('Einordnung')->state(fn (BlockedPeriod $record): string => $record->occupationKind()->getLabel())->badge(), TextColumn::make('guest_name')->label('Gast / Namensinformation')->state(fn (BlockedPeriod $record): ?string => $record->guestName())->placeholder('Zuordnung offen') ->description(fn (BlockedPeriod $record): string => $record->guest_id ? 'Gast zugeordnet' : 'Keine bestätigte Gastzuordnung'), TextColumn::make('channel.name')->label('Importkanal'), TextColumn::make('property.name')->label('Wohnung')->toggleable(), TextColumn::make('needs_review')->label('Prüffall')->formatStateUsing(fn (bool $state): string => $state ? 'Bitte prüfen' : '–')->description(fn (BlockedPeriod $record): ?string => $record->review_note), ])->recordActions([ViewAction::make(), ActionGroup::make(static::occupationActions())->label('Weitere Aktionen')]); } 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(); }), ...BlockedPeriodResource::portalActions(), ]; } public static function infolist(Schema $schema): Schema { return $schema->components([ Section::make('Portalbelegung')->columns(3)->schema([ TextEntry::make('property.name')->label('Wohnung'), 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('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), TextEntry::make('guest_email')->label('E-Mail')->state(fn (BlockedPeriod $record): ?string => $record->assignedGuest()?->email)->placeholder('Unbekannt'), TextEntry::make('assignment')->label('Gastzuordnung')->state(fn (BlockedPeriod $record): string => $record->is_representation ? 'Wird an der führenden Belegung gepflegt' : ($record->guest_id ? 'Persönlich zugeordnet' : 'Noch offen; Namensfragment allein ist kein Identitätsnachweis')), TextEntry::make('calendar_state')->label('Kalenderstatus')->state(fn (BlockedPeriod $record): string => $record->trashed() ? 'Nicht mehr im Feed – keine Aussage über den Stornogrund' : ($record->is_representation ? 'Weitere Darstellung einer führenden Belegung' : 'Belegt den Zeitraum')), TextEntry::make('leading_record')->label('Führende Belegung')->state(fn (BlockedPeriod $record): string => $record->linkedBooking ? 'Buchung '.$record->linkedBooking->reference : ($record->canonical_block_id ? 'Kalenderbelegung #'.$record->canonical_block_id : 'Dieser Eintrag')) ->url(fn (BlockedPeriod $record): ?string => $record->linked_booking_id ? BookingResource::getUrl('view', ['record' => $record->linked_booking_id]) : null), TextEntry::make('review_note')->label('Prüfhinweis')->placeholder('Kein zusätzlicher Prüfhinweis')->columnSpanFull(), ]), Section::make('Kalenderquelle')->schema([ TextEntry::make('external_uid')->label('Externe Ereignis-ID'), TextEntry::make('import_note')->hiddenLabel()->state('Kalenderdaten liefern Belegungszeiträume. Preis, Personenanzahl, Zahlungsstand und Vertragsstatus sind daraus nicht gesichert bekannt.'), TextEntry::make('ical_raw')->label('Originalereignis')->placeholder('Keine iCal-Originaldaten vorhanden')->wrap()->extraAttributes(['style' => 'white-space:pre-wrap;overflow-wrap:anywhere']), ]), ]); } public static function getPages(): array { return ['index' => ManagePortalOccupations::route('/'), 'view' => ViewPortalOccupation::route('/{record}')]; } }