Files
fewo-stommer/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php
T
LarsandClaude Sonnet 5.5 5ba9ae08ab
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
Portal-Direktbuchung erfassen, Kontaktdaten-Prozess, manueller Statuswechsel, Archiv, Filter, Menue Verwaltung/Einrichtung
- Buchung erfassen: Buchungsweg Portal (Referenz, Portalpreis, ohne Kontaktdaten), Prozess bestaetigen/Vertrag sofort/nur erfassen
- Buchungsakte: Kontaktdaten eintragen (automatisch oder manuell weiter), Gast um Kontaktdaten bitten, Status von Hand aendern, Archivieren
- Liste: Filter Kanal, Anreisezeitraum, Kontaktdaten fehlen; Spalten ausblendbar; Archiv
- Klaerung: verstaendlichere Texte, eigenstaendige Belegung mit Kanal gilt als geklaert (Gitea #4)
- Akte per Button aus Liste und Belegungsplan erreichbar
- Menue: Gruppen Verwaltung (Tagesgeschaeft) und Einrichtung (Konfiguration), einfache Ansicht auf 8 Punkte

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-30 18:04:03 +01:00

154 lines
11 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\PortalOccupations;
use App\Actions\ClassifyPortalOccupation;
use App\Enums\OccupationKind;
use App\Filament\Actions\AssignGuestAction;
use App\Filament\Concerns\FollowsAdminMode;
use App\Filament\Concerns\SelectsRecordProperty;
use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource;
use App\Filament\Resources\Bookings\BookingResource;
use App\Filament\Resources\Guests\GuestResource;
use App\Filament\Resources\PortalOccupations\Pages\ManagePortalOccupations;
use App\Filament\Resources\PortalOccupations\Pages\ViewPortalOccupation;
use App\Models\BlockedPeriod;
use App\Models\Channel;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Actions\ViewAction;
use Filament\Forms\Components\Select;
use Filament\Infolists\Components\TextEntry;
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;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use UnitEnum;
class PortalOccupationResource extends Resource
{
use FollowsAdminMode, SelectsRecordProperty;
protected static ?string $model = BlockedPeriod::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedQuestionMarkCircle;
protected static string|UnitEnum|null $navigationGroup = 'Verwaltung';
protected static ?string $navigationLabel = 'Ungeklärte Belegungen';
protected static ?string $modelLabel = 'Portalbelegung';
protected static ?string $pluralModelLabel = 'Portalbelegungen & Klärung';
protected static ?int $navigationSort = 7;
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->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('So geht es: 1. „Einordnen“ – ist es eine Portalreservierung, eine Sperrzeit oder unbekannt? 2. „Klären“ – ist es eigenständig oder dieselbe Belegung wie ein anderer Eintrag (Doppelung)? 3. Der Gast lässt sich unter „Gast zuordnen“ ergänzen. 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->is_representation ? 'Kalenderspiegelung' : $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(),
static::classificationAction(),
...BlockedPeriodResource::portalActions(),
];
}
public static function classificationAction(): Action
{
return Action::make('classify')->label('Einordnen: Reservierung, Sperrzeit oder unbekannt')
->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([
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->is_representation ? 'Kalenderspiegelung' : $record->occupationKind()->getLabel()),
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),
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]) : ($record->canonical_block_id ? static::getUrl('view', ['record' => $record->canonical_block_id]) : null)),
TextEntry::make('representation_assignment')->label('Zuordnung der Kalenderdarstellung')
->state(fn (BlockedPeriod $record): string => $record->representation_automatic ? 'Automatisch; wird bei jedem Abgleich erneut geprüft' : 'Persönlich bestätigt')
->visible(fn (BlockedPeriod $record): bool => $record->is_representation),
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}')];
}
}