diff --git a/app/Actions/ClassifyPortalOccupation.php b/app/Actions/ClassifyPortalOccupation.php index eb5e151..fad641c 100644 --- a/app/Actions/ClassifyPortalOccupation.php +++ b/app/Actions/ClassifyPortalOccupation.php @@ -2,19 +2,34 @@ namespace App\Actions; +use App\Enums\BlockedPeriodPurpose; use App\Enums\OccupationKind; use App\Models\BlockedPeriod; use App\Models\Channel; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; class ClassifyPortalOccupation { - public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $originId = null): void + /** @param array{block_purpose?: BlockedPeriodPurpose|string|null, block_note?: string|null, is_private?: bool} $details */ + public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $originId = null, array $details = []): void { Gate::authorize('update', $occupation); - DB::transaction(function () use ($occupation, $kind, $originId): void { + if (($details['block_purpose'] ?? null) instanceof BlockedPeriodPurpose) { + $details['block_purpose'] = $details['block_purpose']->value; + } + $details = Validator::make($details, [ + 'block_purpose' => ['nullable', Rule::enum(BlockedPeriodPurpose::class)], + 'block_note' => ['nullable', 'string', 'max:255'], + 'is_private' => ['sometimes', 'boolean'], + ])->validate(); + if (($details['is_private'] ?? false) && $originId !== null) { + throw ValidationException::withMessages(['origin_channel_id' => 'Privat und ein externer Buchungskanal können nicht gleichzeitig gewählt werden.']); + } + DB::transaction(function () use ($occupation, $kind, $originId, $details): void { $record = BlockedPeriod::query()->whereKey($occupation->id)->lockForUpdate()->firstOrFail(); if (! in_array($record->source, ['channel', 'email'], true) || $record->is_representation) { throw ValidationException::withMessages(['occupation_kind' => 'Nur eigenständige Portalereignisse können hier eingeordnet werden.']); @@ -22,7 +37,13 @@ public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $or if ($originId !== null && ! Channel::query()->where('property_id', $record->property_id)->whereKey($originId)->exists()) { throw ValidationException::withMessages(['origin_channel_id' => 'Der Ursprungskanal muss zur selben Wohnung gehören.']); } - $record->forceFill(['occupation_kind' => $kind, 'origin_channel_id' => $originId])->save(); + $record->forceFill([ + 'occupation_kind' => $kind, + 'origin_channel_id' => $originId, + 'is_private' => $details['is_private'] ?? false, + 'block_purpose' => $kind === OccupationKind::Block ? (array_key_exists('block_purpose', $details) ? $details['block_purpose'] : $record->block_purpose) : null, + 'block_note' => $kind === OccupationKind::Block ? (array_key_exists('block_note', $details) ? $details['block_note'] : $record->block_note) : null, + ])->save(); }); } } diff --git a/app/Actions/ResolveChannelOccupation.php b/app/Actions/ResolveChannelOccupation.php index c7b8853..5ecd1cb 100644 --- a/app/Actions/ResolveChannelOccupation.php +++ b/app/Actions/ResolveChannelOccupation.php @@ -24,7 +24,7 @@ public function handle(BlockedPeriod $block, string $resolution, ?int $targetId throw ValidationException::withMessages(['origin_channel_id' => 'Der Ursprungskanal muss zur selben Wohnung gehören.']); } $attributes = ['is_representation' => false, 'canonical_block_id' => null, 'linked_booking_id' => null, - 'origin_channel_id' => $originId, 'export_approved' => true, 'needs_review' => false, + 'origin_channel_id' => $originId, 'is_private' => $originId === null && $block->is_private, 'export_approved' => true, 'needs_review' => false, 'reviewed_at' => now(), 'review_note' => 'Als eigenständige Belegung persönlich bestätigt.']; if ($resolution !== 'independent') { $query = $resolution === 'booking' ? Booking::query()->occupying() : BlockedPeriod::query()->occupying()->whereKeyNot($block->id); diff --git a/app/Availability/OccupancyOverview.php b/app/Availability/OccupancyOverview.php index 60293fd..e113f9f 100644 --- a/app/Availability/OccupancyOverview.php +++ b/app/Availability/OccupancyOverview.php @@ -50,7 +50,7 @@ public function records(?int $propertyId = null, ?int $guestId = null, bool $inc 'guest_url' => $booking->guest_id ? GuestResource::getUrl('edit', ['record' => $booking->guest_id]) : null, ]); } - $blocks = BlockedPeriod::query()->select(['id', 'tenant_id', 'property_id', 'guest_id', 'channel_id', 'origin_channel_id', 'starts_on', 'ends_on', 'reason', 'source', 'occupation_kind', 'ical_event_type', 'ical_interpretation', 'is_representation', 'needs_review', 'review_note', 'deleted_at'])->withTrashed()->occupying()->with(['guest', 'property', 'channel', 'originChannel'])->withCount('channelRepresentations') + $blocks = BlockedPeriod::query()->select(['id', 'tenant_id', 'property_id', 'guest_id', 'channel_id', 'origin_channel_id', 'starts_on', 'ends_on', 'reason', 'source', 'occupation_kind', 'block_purpose', 'block_note', 'is_private', 'ical_event_type', 'ical_interpretation', 'is_representation', 'needs_review', 'review_note', 'deleted_at'])->withTrashed()->occupying()->with(['guest', 'property', 'channel', 'originChannel'])->withCount('channelRepresentations') ->when(! $includeBlocks, fn ($query) => $query->reservations()) ->when($propertyId, fn ($query) => $query->where('property_id', $propertyId)) ->when($guestId, fn ($query) => $query->where('guest_id', $guestId)->reservations()) @@ -68,10 +68,10 @@ public function records(?int $propertyId = null, ?int $guestId = null, bool $inc 'nights' => (int) $block->starts_on->diffInDays($block->ends_on), 'persons' => null, 'total' => null, 'guest_id' => $block->guest_id, 'guest' => $block->guestName() ?? 'Gastzuordnung offen', 'guest_email' => $block->guest?->email, 'guest_assigned' => $block->guest_id !== null, - 'source' => $block->originChannel?->name ?? $block->channel?->name ?? ($block->source === 'manual' ? 'Eigene Sperre' : 'Ursprung unbekannt'), + 'source' => $block->bookingChannelLabel(), 'status' => $block->trashed() ? 'Nicht mehr im Kalenderfeed' : ($block->needs_review ? 'Klärung erforderlich' : 'Im Kalender geführt'), 'status_key' => $block->trashed() ? 'archived' : 'imported', 'color' => $block->needs_review ? 'warning' : $kind->getColor(), - 'occupies' => ! $block->trashed(), 'needs_review' => $block->needs_review, 'review_note' => $block->review_note, 'reason' => $block->reason, + 'occupies' => ! $block->trashed(), 'needs_review' => $block->needs_review, 'review_note' => $block->review_note, 'reason' => $block->blockDescription(), 'archived' => $block->trashed(), 'representations' => $block->channel_representations_count, 'url' => $block->source === 'manual' ? BlockedPeriodResource::getUrl() : PortalOccupationResource::getUrl('view', ['record' => $block->id]), 'guest_url' => $block->guest_id ? GuestResource::getUrl('edit', ['record' => $block->guest_id]) : null, diff --git a/app/Enums/BlockedPeriodPurpose.php b/app/Enums/BlockedPeriodPurpose.php new file mode 100644 index 0000000..11009d8 --- /dev/null +++ b/app/Enums/BlockedPeriodPurpose.php @@ -0,0 +1,21 @@ + 'Eigenbelegung', + self::Maintenance => 'Wartung / Renovierung', + self::Other => 'Sonstige Sperre', + }; + } +} diff --git a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php index dc18294..7520ee8 100644 --- a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php +++ b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php @@ -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 */ + 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'), ]); } diff --git a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php index 850fce0..233b483 100644 --- a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php +++ b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php @@ -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), diff --git a/app/Filament/Resources/Properties/RelationManagers/BlockedPeriodsRelationManager.php b/app/Filament/Resources/Properties/RelationManagers/BlockedPeriodsRelationManager.php index d7b02b9..83cf34a 100644 --- a/app/Filament/Resources/Properties/RelationManagers/BlockedPeriodsRelationManager.php +++ b/app/Filament/Resources/Properties/RelationManagers/BlockedPeriodsRelationManager.php @@ -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'), ]); } diff --git a/app/Models/BlockedPeriod.php b/app/Models/BlockedPeriod.php index 28868df..66b7030 100644 --- a/app/Models/BlockedPeriod.php +++ b/app/Models/BlockedPeriod.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\BlockedPeriodPurpose; use App\Enums\OccupationKind; use App\Models\Concerns\BelongsToTenant; use App\Models\Concerns\HasChannelProvenance; @@ -25,7 +26,7 @@ */ #[ObservedBy(BlockedPeriodObserver::class)] #[Hidden(['ical_properties', 'ical_raw', 'ical_interpretation'])] -#[Fillable(['property_id', 'channel_id', 'origin_channel_id', 'guest_id', 'occupation_kind', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid', 'needs_review', 'review_note', 'missing_imports', 'is_representation', 'canonical_block_id', 'linked_booking_id', 'export_approved', 'reviewed_at'])] +#[Fillable(['property_id', 'channel_id', 'origin_channel_id', 'guest_id', 'occupation_kind', 'block_purpose', 'block_note', 'is_private', 'starts_on', 'ends_on', 'reason', 'source', 'external_uid', 'needs_review', 'review_note', 'missing_imports', 'is_representation', 'canonical_block_id', 'linked_booking_id', 'export_approved', 'reviewed_at'])] class BlockedPeriod extends Model { /** @use HasFactory */ @@ -41,6 +42,8 @@ class BlockedPeriod extends Model protected function casts(): array { return [ + 'block_purpose' => BlockedPeriodPurpose::class, + 'is_private' => 'boolean', 'occupation_kind' => OccupationKind::class, 'starts_on' => 'immutable_date', 'ends_on' => 'immutable_date', @@ -114,6 +117,20 @@ public function guestName(): ?string return $this->guest?->full_name ?? ($this->ical_interpretation['fields']['guest_full_name'] ?? $this->ical_interpretation['fields']['guest_first_name'] ?? null); } + public function bookingChannelLabel(): string + { + return $this->is_private ? 'Privat' : ($this->originChannel?->name ?? $this->channel?->name ?? ($this->source === 'manual' ? 'Eigene Sperre' : 'Ursprung unbekannt')); + } + + public function blockDescription(): ?string + { + if ($this->occupationKind() !== OccupationKind::Block) { + return $this->reason; + } + + return collect([$this->block_purpose?->getLabel(), $this->block_note])->filter()->implode(' · ') ?: $this->reason; + } + public function assignedGuest(): ?Guest { return $this->is_representation ? ($this->linkedBooking?->guest ?? $this->canonicalBlock?->assignedGuest()) : $this->guest; diff --git a/database/migrations/2026_10_27_222110_add_business_purpose_to_blocked_periods.php b/database/migrations/2026_10_27_222110_add_business_purpose_to_blocked_periods.php new file mode 100644 index 0000000..70d043c --- /dev/null +++ b/database/migrations/2026_10_27_222110_add_business_purpose_to_blocked_periods.php @@ -0,0 +1,31 @@ +string('block_purpose', 30)->nullable(); + $table->string('block_note')->nullable(); + $table->boolean('is_private')->default(false); + }); + } + + /** + * Reverse the migrations. + * Removing these fields discards manual purpose and private-origin assignments; prefer a forward fix on shared systems. + */ + public function down(): void + { + Schema::table('blocked_periods', function (Blueprint $table) { + $table->dropColumn(['block_purpose', 'block_note', 'is_private']); + }); + } +}; diff --git a/docs/STATUS.md b/docs/STATUS.md index 41153fc..5cbe392 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -1,5 +1,7 @@ # Projektstand +**Zweck und Privat-Kanal bei Sperrzeiten ergänzt (27.10.2026, Bereitstellung ausstehend):** Eigene und ausdrücklich als Sperrzeit eingeordnete importierte Einträge erhalten einen strukturierten Zweck (Eigenbelegung, Wartung / Renovierung, Sonstige Sperre), einen persönlichen Hinweis und die fachliche Kanalwahl Privat. Bei Importen direkt in der Sperrzeitenliste über „Belegungsart / Zweck bearbeiten“ sowie in den Details; eigene Sperren im normalen Formular und im Wohnungsbereich. Darstellung in Liste, Details und Belegungsplan. Importquelle und Ereignisidentität bleiben getrennt erhalten; Rückexport an den Importkanal weiterhin ausgeschlossen. Persönliche Angaben überstehen spätere Importänderungen, vorhandene Einträge werden nicht automatisch neu eingeordnet. Additive Migration `2026_10_27_222110_add_business_purpose_to_blocked_periods`; Rückbau würde die neuen Angaben verwerfen. **155 relevante Tests / 837 Assertions erfolgreich, darunter acht neue Fälle; Pint erfolgreich.** Keine zusätzliche visuelle Browserabnahme. + Stand: 27.10.2026 · **Zentrale Belegungsverwaltung auf stommer.info bereitgestellt**, Anwendungskommit `78aafd7`, Release `20261027211550-78aafd7c`, [Pipeline-Lauf 4672 erfolgreich](https://gitea.stommer.de/Lars/fewo-stommer/actions/runs/4672). Visuelle iCal-Regelengine zuvor mit `7c7955b` bereitgestellt. > Dieses Dokument ist der Einstieg für jede neue Arbeitssitzung. Bitte bei größeren Änderungen fortschreiben (Abschnitte „Fertig“, „Offen“, „Nächste Schritte“). diff --git a/docs/architecture/ical-kanalkonfiguration.md b/docs/architecture/ical-kanalkonfiguration.md index 8900075..9b58430 100644 --- a/docs/architecture/ical-kanalkonfiguration.md +++ b/docs/architecture/ical-kanalkonfiguration.md @@ -163,7 +163,11 @@ ### Zentrale Belegungsverwaltung **Gastzuordnung bleibt bei Portalreservierungen zunächst offen**, entsprechend der Entscheidung von Lars. Ein Namensfragment erzeugt keinen Gast automatisch und führt keine Gäste automatisch zusammen. Über **Details → Gast zuordnen** wird ein vorhandener Gast persönlich gewählt oder ein neuer mit den bekannten Angaben angelegt. Im selben Dialog stehen die vollständigen Kontakt- und Adressfelder einschließlich Straße, PLZ, Ort und Land sowie Notizen und Markierungen zur Verfügung. Ein erneutes Öffnen der Gästekartei ist für diese Eingaben nicht erforderlich. Beide Eingabewege verwenden dieselben Formularfelder. Nachname, E-Mail und Adressangaben dürfen fehlen; es werden keine Ersatzadressen erfunden. Die Zuordnung ist auch an eigenen Buchungen möglich. Beim Auswählen eines bestehenden Gastes werden dessen Stammdaten nicht überschrieben. Die Zuordnung sendet keine Nachricht, ersetzt keine Vertragsdatei und ändert keine Termine. Ein späterer Kalenderimport erhält die Gastzuordnung anhand derselben Ereignisidentität. Auch archivierte und wiederkehrende Ereignisse behalten diese Zuordnung. -**Belegungsart festlegen** bestätigt eine Portalreservierung, eine ausdrückliche Sperrzeit oder einen weiterhin unbekannten Sachverhalt. Diese persönliche Einordnung bleibt gegenüber späteren iCal-Regelauswertungen erhalten. Sie schließt Überschneidungen und mögliche Mehrfachdarstellungen nicht automatisch ab; dafür bleibt **Belegung zuordnen / klären** zuständig. Die führende Buchung oder Belegung erscheint einmal im Plan und in der gemeinsamen Liste. Zugeordnete Kalenderdarstellungen bleiben in den Quelldetails nachvollziehbar. +**Belegungsart / Zweck bearbeiten** bestätigt eine Portalreservierung, eine ausdrückliche Sperrzeit oder einen weiterhin unbekannten Sachverhalt. Für Sperrzeiten stehen **Eigenbelegung**, **Wartung / Renovierung** und **Sonstige Sperre** sowie ein eigener Hinweis zur Verfügung. Beim Buchungskanal kann **Privat** oder eine vorhandene iCal-Verbindung gewählt werden; unbekannte Angaben bleiben offen. Die Aktion steht auch direkt an importierten Sperrzeiten unter **Sperrzeiten** bereit. Eigene manuelle Sperren erhalten Zweck und Privat-Kennzeichnung im normalen Anlegen-/Bearbeiten-Dialog, ebenso im Wohnungsbereich. Zweck und Buchungskanal erscheinen in der Sperrzeitenliste, den Importdetails und im Belegungsplan. + +**Privat** ist eine fachliche Herkunftsangabe und legt keine zusätzliche Portalverbindung an. Der technische Importkanal, die externe Ereignis-ID und Originaldaten bleiben erhalten. Auch eine privat eingeordnete importierte Eigenbelegung wird deshalb weiterhin nicht an ihren eigenen Importkanal zurückexportiert. Zweck und persönlicher Hinweis werden getrennt vom automatisch gelieferten Sperrgrund gespeichert; spätere Importe können die Kalendertermine weiterhin aktualisieren, überschreiben diese persönlichen Angaben aber nicht. Vorhandene Einträge werden nicht automatisch zu Eigenbelegungen umgedeutet. Die neue additive Migration ergänzt nur optionale Zweck-/Hinweisfelder und eine zunächst nicht gesetzte Privat-Kennzeichnung. Ein Rückbau der Spalten würde diese neuen Angaben verwerfen. + +Diese persönliche Einordnung bleibt gegenüber späteren iCal-Regelauswertungen erhalten. Sie schließt Überschneidungen und mögliche Mehrfachdarstellungen nicht automatisch ab; dafür bleibt **Belegung zuordnen / klären** zuständig. Die führende Buchung oder Belegung erscheint einmal im Plan und in der gemeinsamen Liste. Zugeordnete Kalenderdarstellungen bleiben in den Quelldetails nachvollziehbar. Ein erkannter Portalaufenthalt aus iCal besitzt dadurch keine erfundenen Preise, Personenzahlen, Zahlungsstände oder Vertragsbestätigungen. Fehlende Angaben werden als unbekannt angezeigt. Ein verschwundenes Feedereignis heißt **„Nicht mehr im Kalenderfeed“**; daraus wird kein gesicherter Stornogrund abgeleitet. Ohne belegenden führenden Datensatz zählt ein zugeordneter Kalendereintrag nicht als zweite Belegung. diff --git a/tests/Feature/OccupancyManagementTest.php b/tests/Feature/OccupancyManagementTest.php index 48b9f39..4f334d5 100644 --- a/tests/Feature/OccupancyManagementTest.php +++ b/tests/Feature/OccupancyManagementTest.php @@ -8,11 +8,13 @@ use App\Actions\ClassifyPortalOccupation; use App\Actions\ConfirmBooking; use App\Actions\DeclineBooking; +use App\Actions\ResolveChannelOccupation; use App\Actions\SendOffer; use App\Actions\SyncChannel; use App\Availability\AvailabilityChecker; use App\Availability\OccupancyOverview; use App\Channels\ICal\ICalFeed; +use App\Enums\BlockedPeriodPurpose; use App\Enums\BookingStatus; use App\Enums\OccupationKind; use App\Enums\UserRole; @@ -125,6 +127,148 @@ public function test_manual_classification_preserves_calendar_identity_and_survi Livewire::test(ManageBlockedPeriods::class)->assertCanSeeTableRecords([$block]); } + public function test_imported_block_can_be_classified_as_private_own_use_without_exporting_it_back_to_its_source(): void + { + $property = $this->property(); + $block = $this->import($property, ['needs_review' => true]); + $identity = $block->only(['channel_id', 'external_uid', 'starts_on', 'ends_on', 'export_approved']); + $target = Channel::factory()->for($property)->create(); + + Livewire::test(ViewPortalOccupation::class, ['record' => $block->id])->callAction('classify', [ + 'occupation_kind' => 'block', 'block_purpose' => 'own_use', 'block_note' => 'Familienaufenthalt', 'origin_channel_id' => 'private', + ])->assertHasNoActionErrors()->assertNotified('Belegungsart gespeichert'); + + $block->refresh(); + $this->assertSame(BlockedPeriodPurpose::OwnUse, $block->block_purpose); + $this->assertTrue($block->is_private); + $this->assertNull($block->origin_channel_id); + $this->assertTrue($block->needs_review); + $this->assertEquals($identity, $block->only(array_keys($identity))); + $this->assertStringNotContainsString('UID:block-'.$block->id, app(ICalFeed::class)->build($block->channel)); + $this->assertStringContainsString('UID:block-'.$block->id, app(ICalFeed::class)->build($target)); + Livewire::test(ViewPortalOccupation::class, ['record' => $block->id])->assertSee('Eigenbelegung')->assertSee('Familienaufenthalt')->assertSee('Privat')->assertSee($block->channel->name); + $row = app(OccupancyOverview::class)->records(includeBlocks: true)['portal-'.$block->id]; + $this->assertSame('Privat', $row['source']); + $this->assertSame('Eigenbelegung · Familienaufenthalt', $row['reason']); + } + + public function test_private_purpose_and_note_survive_a_changed_calendar_import_and_rule_evaluation(): void + { + $property = $this->property(); + $block = $this->import($property, ['external_uid' => 'private-stay']); + app(ClassifyPortalOccupation::class)->handle($block, OccupationKind::Block, details: [ + 'block_purpose' => 'own_use', 'block_note' => 'Persönlich bestätigt', 'is_private' => true, + ]); + Http::preventStrayRequests(); + Http::fake(['https://portal.example/calendar.ics' => Http::response($this->feed('private-stay', '20261120', '20261125'))]); + + $result = app(SyncChannel::class)->handle($block->channel); + + $this->assertTrue($result->successful, $result->message ?? 'Import failed'); + $block->refresh(); + $this->assertSame('2026-11-20', $block->starts_on->toDateString()); + $this->assertSame(OccupationKind::Block, $block->occupationKind()); + $this->assertTrue($block->is_private); + $this->assertNull($block->origin_channel_id); + $this->assertSame('Eigenbelegung · Persönlich bestätigt', $block->blockDescription()); + Http::assertSentCount(1); + } + + public function test_manual_block_can_be_created_and_edited_with_own_use_and_private_channel(): void + { + $property = $this->property(); + + Livewire::test(ManageBlockedPeriods::class)->callAction('create', [ + 'property_id' => $property->id, 'starts_on' => '2026-11-10', 'ends_on' => '2026-11-12', + 'block_purpose' => 'own_use', 'block_note' => 'Eigener Aufenthalt', 'is_private' => true, + ])->assertHasNoActionErrors(); + + $block = BlockedPeriod::sole(); + $this->assertSame('manual', $block->source); + $this->assertTrue($block->is_private); + $this->assertSame(BlockedPeriodPurpose::OwnUse, $block->block_purpose); + Livewire::test(ManageBlockedPeriods::class)->callTableAction('edit', $block, [ + 'block_purpose' => 'maintenance', 'block_note' => 'Bad renovieren', 'is_private' => false, + ])->assertHasNoActionErrors(); + $block->refresh(); + $this->assertFalse($block->is_private); + $this->assertSame('Wartung / Renovierung · Bad renovieren', $block->blockDescription()); + } + + public function test_imported_block_purpose_can_be_changed_directly_in_blocked_periods_and_cleared(): void + { + $property = $this->property(); + $block = $this->import($property, ['occupation_kind' => OccupationKind::Block, 'block_purpose' => 'own_use', 'block_note' => 'Alter Hinweis', 'is_private' => true]); + + Livewire::test(ManageBlockedPeriods::class)->callTableAction('classify', $block, [ + 'occupation_kind' => 'block', 'block_purpose' => 'other', 'block_note' => null, 'origin_channel_id' => null, + ])->assertHasNoActionErrors(); + + $block->refresh(); + $this->assertSame(BlockedPeriodPurpose::Other, $block->block_purpose); + $this->assertNull($block->block_note); + $this->assertFalse($block->is_private); + Livewire::test(ViewPortalOccupation::class, ['record' => $block->id])->callAction('classify', [ + 'occupation_kind' => 'reservation', 'origin_channel_id' => $block->channel_id, + ])->assertHasNoActionErrors(); + $this->assertNull($block->fresh()->block_purpose); + $this->assertSame($block->channel_id, $block->fresh()->origin_channel_id); + } + + public function test_invalid_block_note_is_rejected_without_changing_the_classification(): void + { + $block = $this->import($this->property()); + + Livewire::test(ViewPortalOccupation::class, ['record' => $block->id])->callAction('classify', [ + 'occupation_kind' => 'block', 'block_purpose' => 'own_use', 'block_note' => str_repeat('x', 256), 'origin_channel_id' => 'private', + ])->assertHasActionErrors(['block_note' => 'max']); + + $this->assertNull($block->fresh()->occupation_kind); + $this->assertFalse($block->fresh()->is_private); + } + + public function test_private_and_external_origin_cannot_be_saved_together(): void + { + $block = $this->import($this->property()); + + try { + app(ClassifyPortalOccupation::class)->handle($block, OccupationKind::Block, $block->channel_id, ['is_private' => true]); + $this->fail('Contradicting booking channels must be rejected.'); + } catch (ValidationException $exception) { + $this->assertSame('Privat und ein externer Buchungskanal können nicht gleichzeitig gewählt werden.', $exception->errors()['origin_channel_id'][0]); + } + + $this->assertNull($block->fresh()->occupation_kind); + $this->assertFalse($block->fresh()->is_private); + } + + public function test_identity_resolution_preserves_private_origin_until_an_external_origin_is_explicitly_selected(): void + { + $block = $this->import($this->property(), ['occupation_kind' => OccupationKind::Block, 'is_private' => true]); + + app(ResolveChannelOccupation::class)->handle($block, 'independent'); + $this->assertTrue($block->fresh()->is_private); + $this->assertNull($block->fresh()->origin_channel_id); + + app(ResolveChannelOccupation::class)->handle($block, 'independent', originId: $block->channel_id); + $this->assertFalse($block->fresh()->is_private); + $this->assertSame($block->channel_id, $block->fresh()->origin_channel_id); + } + + public function test_invalid_business_purpose_is_rejected_by_the_action(): void + { + $block = $this->import($this->property()); + + try { + app(ClassifyPortalOccupation::class)->handle($block, OccupationKind::Block, details: ['block_purpose' => 'invented-purpose']); + $this->fail('Unknown purposes must be rejected.'); + } catch (ValidationException $exception) { + $this->assertArrayHasKey('block_purpose', $exception->errors()); + } + + $this->assertNull($block->fresh()->occupation_kind); + } + public function test_a_guest_with_only_known_information_can_be_created_and_assigned_from_portal_details(): void { $property = $this->property();