diff --git a/app/Actions/CreateReservation.php b/app/Actions/CreateReservation.php index 9eef590..7bcf143 100644 --- a/app/Actions/CreateReservation.php +++ b/app/Actions/CreateReservation.php @@ -77,7 +77,9 @@ private function create(Property $property, StayRequest $stay, array $guestData, $quote = $this->calculator->calculate($property, $stay); [$guest, $differences] = $this->guestFor($guestData); - $profile = app(ProcessSettings::class)->resolve($property, $originChannel, IntakeKind::Inquiry); + $profile = $originChannel === null && $source === 'website' + ? app(ProcessSettings::class)->forWebsite($property) + : app(ProcessSettings::class)->resolve($property, $originChannel, IntakeKind::Inquiry); return $property->bookings()->create([ 'guest_id' => $guest->id, diff --git a/app/Console/Commands/AdoptPortalOccupations.php b/app/Console/Commands/AdoptPortalOccupations.php index f76d13c..2b562da 100644 --- a/app/Console/Commands/AdoptPortalOccupations.php +++ b/app/Console/Commands/AdoptPortalOccupations.php @@ -39,7 +39,7 @@ public function handle(TenantRunner $runner, PortalIntake $intake): int $firstTask = (int) ChannelTask::query()->withoutGlobalScopes()->max('id'); $succeeded = $runner->each(function (Tenant $tenant) use ($intake, $apply, &$report): void { - $channels = Channel::query()->when($this->option('channel'), fn ($query, $ids) => $query->whereKey($ids))->orderBy('id')->get(); + $channels = Channel::query()->portals()->when($this->option('channel'), fn ($query, $ids) => $query->whereKey($ids))->orderBy('id')->get(); foreach ($channels as $channel) { $entries = $channel->blockedPeriods()->whereIn('source', ['channel', 'email'])->whereNull('linked_booking_id') ->where('is_representation', false)->whereDate('ends_on', '>', today())->orderBy('starts_on')->get(); diff --git a/app/Enums/AdminMode.php b/app/Enums/AdminMode.php index 0d2320b..2646d7e 100644 --- a/app/Enums/AdminMode.php +++ b/app/Enums/AdminMode.php @@ -7,6 +7,7 @@ use App\Filament\Pages\PricesAndOffers; use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource; use App\Filament\Resources\Bookings\BookingResource; +use App\Filament\Resources\Channels\ChannelResource; use App\Filament\Resources\Guests\GuestResource; use Filament\Support\Contracts\HasDescription; use Filament\Support\Contracts\HasLabel; @@ -32,6 +33,7 @@ enum AdminMode: string implements HasDescription, HasLabel GuestResource::class, BlockedPeriodResource::class, PricesAndOffers::class, + ChannelResource::class, ]; public function getLabel(): string diff --git a/app/Enums/DataRequestMode.php b/app/Enums/DataRequestMode.php new file mode 100644 index 0000000..9bc8082 --- /dev/null +++ b/app/Enums/DataRequestMode.php @@ -0,0 +1,25 @@ + 'Automatisch beim Gast nachfragen', + self::Approval => 'Rückfrage vorbereiten, Sie geben den Versand frei', + self::Manual => 'Sie fragen selbst nach (Aufgabe mit Textvorschlag)', + }; + } +} diff --git a/app/Enums/ProcessSetting.php b/app/Enums/ProcessSetting.php index 6a4736a..3ea70c5 100644 --- a/app/Enums/ProcessSetting.php +++ b/app/Enums/ProcessSetting.php @@ -17,6 +17,14 @@ enum ProcessSetting: string case GuestMessages = 'guest_messages'; case ArrivalInfoDaysBefore = 'arrival_info_days_before'; case ContractTemplate = 'contract_template_id'; + case ClarificationHoldAutoMinutes = 'clarification_hold_auto_minutes'; + case ClarificationHoldManualMinutes = 'clarification_hold_manual_minutes'; + case DataRequest = 'data_request_mode'; + case DataRequestRemindersMax = 'data_request_reminders_max'; + case DataRequestFollowupsMax = 'data_request_followups_max'; + case DataRequestReminderHours = 'data_request_reminder_hours'; + case GuestLinkValidDays = 'guest_link_valid_days'; + case FormRequiresAddress = 'form_requires_address'; /** * Built-in default (the behaviour before any landlord setting existed). @@ -30,6 +38,14 @@ public function default(): string|int|bool|null self::Documents, self::Payments, self::GuestMessages => Responsibility::Landlord->value, self::ArrivalInfoDaysBefore => 3, self::ContractTemplate => null, + self::ClarificationHoldAutoMinutes => 15, + self::ClarificationHoldManualMinutes => 180, + self::DataRequest => DataRequestMode::Approval->value, + self::DataRequestRemindersMax => 2, + self::DataRequestFollowupsMax => 2, + self::DataRequestReminderHours => 24, + self::GuestLinkValidDays => 14, + self::FormRequiresAddress => false, }; } @@ -47,6 +63,14 @@ public function question(): string self::GuestMessages => 'Wer schickt dem Gast Anreise-Informationen und die Bitte um eine Bewertung?', self::ArrivalInfoDaysBefore => 'Wann gehen die Anreise-Informationen an den Gast?', self::ContractTemplate => 'Welche Vertragsvorlage wird verwendet?', + self::ClarificationHoldAutoMinutes => 'Wie lange wird der Zeitraum einer unvollständigen Anfrage vorläufig reserviert, wenn automatisch nachgefragt wird (0 = gar nicht)?', + self::ClarificationHoldManualMinutes => 'Wie lange wird der Zeitraum einer unvollständigen Anfrage vorläufig reserviert, wenn Sie die Rückfrage freigeben oder selbst nachfragen (0 = gar nicht)?', + self::DataRequest => 'Wie wird nach fehlenden Angaben gefragt?', + self::DataRequestRemindersMax => 'Wie oft wird höchstens erinnert, wenn der Gast nicht antwortet?', + self::DataRequestFollowupsMax => 'Wie viele gezielte Folgefragen gehen höchstens hinaus, wenn eine Antwort unvollständig ist?', + self::DataRequestReminderHours => 'Nach wie vielen Stunden ohne Antwort wird erinnert?', + self::GuestLinkValidDays => 'Wie lange gilt der Link, über den der Gast Angaben ergänzt?', + self::FormRequiresAddress => 'Muss die vollständige Anschrift schon im Anfrageformular der Webseite angegeben werden?', }; } @@ -61,7 +85,9 @@ public function channelIntakes(): array self::Processing, self::Payments, self::GuestMessages, self::ContractTemplate => [IntakeKind::Inquiry, IntakeKind::Booking], self::PreReservation, self::HoldHours => [IntakeKind::Inquiry], self::Documents => [IntakeKind::Booking], - self::ArrivalInfoDaysBefore => [], + self::ArrivalInfoDaysBefore, self::GuestLinkValidDays => [], + self::ClarificationHoldAutoMinutes, self::ClarificationHoldManualMinutes, self::FormRequiresAddress => [IntakeKind::Inquiry], + self::DataRequest, self::DataRequestRemindersMax, self::DataRequestFollowupsMax, self::DataRequestReminderHours => [IntakeKind::Inquiry, IntakeKind::Booking], }; } @@ -85,8 +111,12 @@ public function normalize(mixed $value): string|int|bool|null return match ($this) { self::Processing => ($value instanceof ProcessingMode ? $value : ProcessingMode::tryFrom((string) $value))?->value, self::Documents, self::Payments, self::GuestMessages => ($value instanceof Responsibility ? $value : Responsibility::tryFrom((string) $value))?->value, - self::PreReservation => filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), + self::PreReservation, self::FormRequiresAddress => is_bool($value) ? $value : filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE), self::HoldHours, self::ArrivalInfoDaysBefore, self::ContractTemplate => is_numeric($value) ? (int) $value : null, + self::DataRequest => ($value instanceof DataRequestMode ? $value : DataRequestMode::tryFrom((string) $value))?->value, + // 0 is a value of its own: no clarification hold, no reminder, no follow-up question. + self::ClarificationHoldAutoMinutes, self::ClarificationHoldManualMinutes, self::DataRequestRemindersMax, self::DataRequestFollowupsMax => is_numeric($value) ? max(0, (int) $value) : null, + self::DataRequestReminderHours, self::GuestLinkValidDays => is_numeric($value) ? max(1, (int) $value) : null, }; } @@ -102,6 +132,13 @@ public function describe(string|int|bool|null $value): string self::HoldHours => $value.' Stunden', self::ArrivalInfoDaysBefore => $value.' Tage vor Anreise', self::ContractTemplate => $value === null ? 'Texte der Webseite' : 'Vorlage Nr. '.$value, + self::ClarificationHoldAutoMinutes, self::ClarificationHoldManualMinutes => (int) $value === 0 ? 'keine vorläufige Reservierung' : $value.' Minuten', + self::DataRequest => DataRequestMode::tryFrom((string) $value)?->getLabel() ?? '–', + self::DataRequestRemindersMax => (int) $value === 0 ? 'keine Erinnerung' : 'höchstens '.$value.' Erinnerung'.((int) $value === 1 ? '' : 'en'), + self::DataRequestFollowupsMax => (int) $value === 0 ? 'keine Folgefrage' : 'höchstens '.$value.' Folgefrage'.((int) $value === 1 ? '' : 'n'), + self::DataRequestReminderHours => 'nach '.$value.' Stunden', + self::GuestLinkValidDays => $value.' Tage', + self::FormRequiresAddress => $value ? 'ja, Pflichtangabe' : 'nein, kann nachgefragt werden', }; } } diff --git a/app/Filament/Forms/ProcessSettingFields.php b/app/Filament/Forms/ProcessSettingFields.php index 863364c..f4cc957 100644 --- a/app/Filament/Forms/ProcessSettingFields.php +++ b/app/Filament/Forms/ProcessSettingFields.php @@ -2,6 +2,7 @@ namespace App\Filament\Forms; +use App\Enums\DataRequestMode; use App\Enums\ProcessingMode; use App\Enums\ProcessSetting; use App\Enums\Responsibility; @@ -41,6 +42,14 @@ public static function field(string $name, ProcessSetting $setting, string $inhe ProcessSetting::ContractTemplate => Select::make($name) ->options(fn (): array => ContractTemplate::query()->orderBy('name')->orderBy('version')->get()->mapWithKeys(fn (ContractTemplate $template): array => [$template->id => $template->label()])->all()) ->placeholder($placeholder), + ProcessSetting::ClarificationHoldAutoMinutes, ProcessSetting::ClarificationHoldManualMinutes => TextInput::make($name)->integer()->minValue(0)->maxValue(1440)->suffix('Minuten')->placeholder($placeholder) + ->helperText('Nur für Anfragen, denen noch Angaben für ein Angebot fehlen, und nur wenn der Zeitraum frei ist. Endet von selbst und wird durch Rückfragen nicht verlängert. Die Reservierung eines Angebots bleibt davon unberührt.'), + ProcessSetting::DataRequest => Select::make($name)->options(DataRequestMode::class)->placeholder($placeholder) + ->helperText('Unabhängig davon, ob Angebote automatisch hinausgehen.'), + ProcessSetting::DataRequestRemindersMax, ProcessSetting::DataRequestFollowupsMax => TextInput::make($name)->integer()->minValue(0)->maxValue(5)->placeholder($placeholder), + ProcessSetting::DataRequestReminderHours => TextInput::make($name)->integer()->minValue(1)->maxValue(336)->suffix('Stunden')->placeholder($placeholder), + ProcessSetting::GuestLinkValidDays => TextInput::make($name)->integer()->minValue(1)->maxValue(60)->suffix('Tage')->placeholder($placeholder), + ProcessSetting::FormRequiresAddress => Select::make($name)->options(['1' => 'Ja – ohne vollständige Anschrift kann nicht angefragt werden', '0' => 'Nein – fehlt sie, wird beim Gast nachgefragt'])->placeholder($placeholder), })->label($setting->question()); } diff --git a/app/Filament/Pages/EffectiveSettings.php b/app/Filament/Pages/EffectiveSettings.php index 558c40c..c2c8a29 100644 --- a/app/Filament/Pages/EffectiveSettings.php +++ b/app/Filament/Pages/EffectiveSettings.php @@ -64,8 +64,11 @@ public function matrix(): array $settings = app(ProcessSettings::class); return Property::query()->orderBy('name')->get()->map(function (Property $property) use ($settings): array { - $columns = [['label' => 'Direkte Anfrage (Webseite, Telefon)', 'profile' => $settings->resolve($property, null, IntakeKind::Inquiry)]]; - foreach (Channel::query()->where('property_id', $property->id)->orderBy('name')->get() as $channel) { + $columns = [ + ['label' => 'Eigene Webseite – Anfrage', 'profile' => $settings->forWebsite($property)], + ['label' => 'Direkte Anfrage (Telefon, E-Mail)', 'profile' => $settings->resolve($property, null, IntakeKind::Inquiry)], + ]; + foreach (Channel::query()->portals()->where('property_id', $property->id)->orderBy('name')->get() as $channel) { $columns[] = ['label' => $channel->name.' – Anfrage', 'profile' => $settings->resolve($property, $channel, IntakeKind::Inquiry)]; $columns[] = ['label' => $channel->name.' – feste Buchung', 'profile' => $settings->resolve($property, $channel, IntakeKind::Booking)]; } diff --git a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php index 1720a59..23eb0a5 100644 --- a/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php +++ b/app/Filament/Resources/BlockedPeriods/BlockedPeriodResource.php @@ -147,7 +147,7 @@ public static function portalActions(): array ->mapWithKeys(fn (BlockedPeriod $block): array => [$block->id => '#'.$block->id.' · '.$block->occupationKind()->getLabel().' · '.($block->reason ?? 'Kalenderbelegung').($block->leading_priority ? ' · bevorzugter Führungskandidat' : '')])->all(); }), Select::make('origin_channel_id')->label('Ursprünglicher Buchungskanal, sofern persönlich bekannt') - ->options(fn (BlockedPeriod $record): array => Channel::query()->where('property_id', $record->property_id)->pluck('name', 'id')->all()) + ->options(fn (BlockedPeriod $record): array => Channel::query()->portals()->where('property_id', $record->property_id)->pluck('name', 'id')->all()) ->default(fn (BlockedPeriod $record): ?int => $record->origin_channel_id)->placeholder('Unbekannt / eigene Vermietung'), ]) ->action(function (BlockedPeriod $record, array $data, ResolveChannelOccupation $resolve): void { diff --git a/app/Filament/Resources/Bookings/Schemas/BookingForm.php b/app/Filament/Resources/Bookings/Schemas/BookingForm.php index 334b079..b1907c8 100644 --- a/app/Filament/Resources/Bookings/Schemas/BookingForm.php +++ b/app/Filament/Resources/Bookings/Schemas/BookingForm.php @@ -120,7 +120,7 @@ public static function configure(Schema $schema): Schema Select::make('channel_id') ->label(fn (Get $get): string => $get('kind') === self::EXTERNAL ? 'Gebucht über' : 'Über ein Portal (optional)') ->placeholder('Direkt – kein Portal') - ->options(fn (Get $get): array => Channel::query()->where('property_id', $get('property_id'))->orderBy('name')->pluck('name', 'id')->all()) + ->options(fn (Get $get): array => Channel::query()->portals()->where('property_id', $get('property_id'))->orderBy('name')->pluck('name', 'id')->all()) ->required($is(self::EXTERNAL)), TextInput::make('portal_reference')->label('Buchungsnummer im Portal')->maxLength(100)->visible($is(self::EXTERNAL)), EuroInput::make('portal_total') diff --git a/app/Filament/Resources/Bookings/Tables/BookingsTable.php b/app/Filament/Resources/Bookings/Tables/BookingsTable.php index 6863d0f..bc0c4f5 100644 --- a/app/Filament/Resources/Bookings/Tables/BookingsTable.php +++ b/app/Filament/Resources/Bookings/Tables/BookingsTable.php @@ -91,7 +91,7 @@ public static function configure(Table $table, ?int $guestId = null): Table ...collect(BookingStatus::cases())->mapWithKeys(fn (BookingStatus $status): array => [$status->value => $status->getLabel()])->all(), 'imported' => 'Im Portalkalender geführt', 'archived' => 'Nicht mehr im Kalenderfeed', ]), - SelectFilter::make('channel')->label('Buchungskanal')->options(fn (): array => Channel::query()->orderBy('name')->pluck('name', 'id')->all()), + SelectFilter::make('channel')->label('Buchungskanal')->options(fn (): array => Channel::query()->portals()->orderBy('name')->pluck('name', 'id')->all()), Filter::make('period')->label('Anreise im Zeitraum')->schema([ DatePicker::make('arrival_from')->label('Anreise ab'), DatePicker::make('arrival_until')->label('Anreise bis'), diff --git a/app/Filament/Resources/Channels/ChannelResource.php b/app/Filament/Resources/Channels/ChannelResource.php index 08133a8..48b9725 100644 --- a/app/Filament/Resources/Channels/ChannelResource.php +++ b/app/Filament/Resources/Channels/ChannelResource.php @@ -29,11 +29,11 @@ class ChannelResource extends Resource protected static string|UnitEnum|null $navigationGroup = 'Einrichtung'; - protected static ?string $navigationLabel = 'Kalenderabgleich (iCal)'; + protected static ?string $navigationLabel = 'Kanäle'; - protected static ?string $modelLabel = 'iCal-Verbindung'; + protected static ?string $modelLabel = 'Kanal'; - protected static ?string $pluralModelLabel = 'Kalenderabgleich (iCal)'; + protected static ?string $pluralModelLabel = 'Kanäle (Webseite, Portale, iCal)'; protected static ?int $navigationSort = 4; diff --git a/app/Filament/Resources/Channels/Pages/EditChannel.php b/app/Filament/Resources/Channels/Pages/EditChannel.php index ca99f01..7d8e91e 100644 --- a/app/Filament/Resources/Channels/Pages/EditChannel.php +++ b/app/Filament/Resources/Channels/Pages/EditChannel.php @@ -6,6 +6,7 @@ use App\Actions\ConfigureChannel; use App\Channels\ChannelSyncException; use App\Filament\Resources\Channels\ChannelResource; +use App\Models\Channel; use Filament\Actions\Action; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; @@ -18,8 +19,8 @@ class EditChannel extends EditRecord protected function getHeaderActions(): array { return [ - Action::make('rules')->label('Regeln & Exportfelder')->url(fn (): string => ChannelResource::getUrl('rules', ['record' => $this->record])), - Action::make('analyze')->label('Kalender analysieren')->action(function (AnalyzeChannelCalendar $analyze): void { + Action::make('rules')->label('Regeln & Exportfelder')->url(fn (): string => ChannelResource::getUrl('rules', ['record' => $this->record]))->visible(fn (): bool => $this->record->isPortal()), + Action::make('analyze')->label('Kalender analysieren')->visible(fn (): bool => $this->record->isPortal())->action(function (AnalyzeChannelCalendar $analyze): void { try { $analyze->handle($this->record); $this->redirect(ChannelResource::getUrl('rules', ['record' => $this->record])); @@ -37,6 +38,13 @@ protected function mutateFormDataBeforeFill(array $data): array protected function handleRecordUpdate(Model $record, array $data): Model { + // The own website's entry only keeps its settings; there is no connection to configure. + if ($record instanceof Channel && $record->isWebsite()) { + $record->update(['process_overrides' => $data['process_overrides'] ?? []]); + + return $record; + } + return app(ConfigureChannel::class)->handle($record->property, $data, $record); } diff --git a/app/Filament/Resources/Channels/Pages/ListChannels.php b/app/Filament/Resources/Channels/Pages/ListChannels.php index c658df5..9a2b501 100644 --- a/app/Filament/Resources/Channels/Pages/ListChannels.php +++ b/app/Filament/Resources/Channels/Pages/ListChannels.php @@ -3,20 +3,44 @@ namespace App\Filament\Resources\Channels\Pages; use App\Filament\Concerns\ListsCurrentProperty; +use App\Filament\Pages\HandlingSettings; use App\Filament\Resources\Channels\ChannelResource; +use App\Models\Channel; +use App\Models\Property; +use Filament\Actions\Action; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; +use Filament\Support\Icons\Heroicon; +/** + * The channel manager (v0.11, E-037): the own website and every portal of the landlord in one list. The landlord's + * defaults for all channels stay on "So arbeite ich"; each channel only keeps its deviations. + */ class ListChannels extends ListRecords { use ListsCurrentProperty; protected static string $resource = ChannelResource::class; + public function mount(): void + { + parent::mount(); + + // Every property has its website entry (created by the migration; new properties get it here). + Property::query()->get()->each(fn (Property $property): Channel => Channel::websiteOf($property)); + } + + public function getSubheading(): ?string + { + return 'Alle Eingangskanäle an einer Stelle: Ihre eigene Webseite und die Portale. Was für alle Kanäle gilt, stellen Sie unter „Ihre Standards“ ein; hier steht nur, was ein Kanal anders macht.'; + } + protected function getHeaderActions(): array { return [ - CreateAction::make()->label('iCal-Verbindung anlegen'), + Action::make('defaults')->label('Ihre Standards (alle Kanäle)')->icon(Heroicon::OutlinedAdjustmentsHorizontal)->color('gray') + ->url(fn (): string => HandlingSettings::getUrl()), + CreateAction::make()->label('Portal (iCal-Verbindung) anlegen'), ]; } } diff --git a/app/Filament/Resources/Channels/Schemas/ChannelForm.php b/app/Filament/Resources/Channels/Schemas/ChannelForm.php index 5f5ebdf..849d993 100644 --- a/app/Filament/Resources/Channels/Schemas/ChannelForm.php +++ b/app/Filament/Resources/Channels/Schemas/ChannelForm.php @@ -39,77 +39,110 @@ public static function configure(Schema $schema, bool $selectProperty = false): ->options(fn (): array => Property::query()->orderBy('name')->pluck('name', 'id')->all()) ->default(fn (): ?int => app(CurrentProperty::class)->id()) ->disabled(fn (?Channel $record): bool => $record !== null)->dehydrated()->columnSpanFull()] : []), - TextEntry::make('export_url') - ->label('Eigener iCal-Exportlink') - ->state(fn (?Channel $record): ?string => $record?->exportUrl()) - ->visible(fn (?Channel $record): bool => $record?->exists ?? false) - ->copyable() - ->copyMessage('Exportlink kopiert') - ->wrap() - ->extraAttributes(['style' => 'overflow-wrap:anywhere']) - ->columnSpanFull(), - TextInput::make('name') - ->label('Name der Kalenderverbindung') - ->placeholder('z. B. FeWo-direkt') - ->required() - ->maxLength(100), - Select::make('status')->label('Kanalstatus')->options(ChannelStatus::class)->default(ChannelStatus::Setup)->required(), - Select::make('booking_model')->label('Was kommt über dieses Portal?')->options(ChannelBookingModel::class)->default(ChannelBookingModel::Mixed)->required() - ->helperText('„Portalbuchung“ und „Gemischt“ gelten als Sofortbuchung: automatische Angebote für diese Wohnung warten, bis das Portal unseren Kalender abgerufen hat. „Vermittlung / Anfrage“: keine Sofortbuchung.'), - Select::make('case_intake') - ->label('Erkannte Buchungen automatisch als Vorgang übernehmen?') - ->options(CaseIntakeMode::class) - ->default(CaseIntakeMode::Off) - ->required() - ->helperText('Zuerst „Beobachten“: Dann entsteht nichts, aber das Eingangsprotokoll (Expertenansicht) zeigt, welche Vorgänge entstanden wären. Unklare Belegungen und Meldungen zu gebuchten Vorgängen erscheinen unter „Zu erledigen“. Unterlagen gehen nie ohne Ihre Freigabe hinaus.') - ->columnSpanFull(), - ...self::processSections(), - Select::make('connector') - ->label('Kalenderanbindung') - ->helperText('Diese Verbindung gleicht Belegungszeiträume über iCal ab. Weitere Portalfunktionen benötigen eine eigene Anbindung.') - ->options($registry->options()) - ->default('ical') - ->live() - ->required(), Group::make() + ->columns(2) ->columnSpanFull() - ->schema(fn (Get $get): array => filled($get('connector')) ? $registry->connectors()[$get('connector')]::settingsSchema() : []), - Toggle::make('import_enabled')->label('Import aktiviert')->default(false) - ->helperText('Abruf durch FewoPortal alle fünf Minuten, sofern der Kanal aktiv ist.'), - Toggle::make('export_enabled')->label('Export aktiviert')->default(false) - ->helperText('Ausgeschaltet bleibt der letzte gültige Export eingefroren erreichbar. Ohne Stand: HTTP 503, kein leerer Kalender.'), - Select::make('export_mode')->label('Exportmodus')->options(ChannelExportMode::class)->default(ChannelExportMode::Test)->required() - ->helperText('Testbetrieb exportiert keine Fremdbelegungen und gewährleistet keine vollständige kanalübergreifende Sperrung. Regulär nur nach bewusster Freigabe wählen.') - ->columnSpanFull(), - TextInput::make('external_poll_minutes')->label('Erwarteter externer Abrufabstand (Minuten)') - ->integer()->minValue(1)->maxValue(43200) - ->helperText('Nur eine Annahme zum Portal; verändert weder unseren Abruf noch bestätigt sie eine Übernahme.'), - Select::make('echo_behavior')->label('Beobachtetes Rückkopplungsverhalten')->options(ChannelEchoBehavior::class)->default(ChannelEchoBehavior::Unverified)->required()->columnSpanFull() - ->helperText('Bei Weitergabe mit neuen UIDs bleiben neue Importereignisse bis zur persönlichen Klärung vom Export ausgeschlossen. Sie sperren intern weiterhin.'), - Textarea::make('echo_notes')->label('Nachweis / Beobachtung zum Rückkopplungsverhalten')->maxLength(4000)->columnSpanFull(), - DateTimePicker::make('portal_verified_at')->label('Tatsächliche Übernahme im Portal zuletzt persönlich geprüft')->seconds(false) - ->helperText('Nur nach Sichtkontrolle im Portal eintragen. Wird durch einen Feedabruf nicht automatisch gesetzt.'), - Textarea::make('operating_notes')->label('Zusätzliche Anforderungen dieses Portals')->maxLength(4000)->columnSpanFull() - ->helperText('Zum Beispiel eine zusätzliche Bestätigung, dass der Belegungskalender gepflegt ist.'), - TextInput::make('settings.email_senders') - ->label('Absender der Buchungs-E-Mails (Schnellerkennung)') - ->helperText('Komma-getrennt, z. B. „fewo-direkt.de, vrbo.com“. Buchungsbestätigungen dieser Absender werden sofort gesperrt.') - ->maxLength(500) - ->columnSpanFull(), - Toggle::make('requires_manual_blocking') - ->label('Zusätzlich von Hand sperren (Sofortbuchung)') - ->helperText('Bei jeder Belegung über andere Wege entsteht eine Aufgabe „Im Portal sperren“ – für Portale, die unseren Kalender zu selten abholen.') - ->live() - ->columnSpanFull(), - TextInput::make('manage_url') - ->label('Link zum Kalender im Vermieterbereich') - ->url() - ->maxLength(2048) - ->visible(fn (Get $get): bool => (bool) $get('requires_manual_blocking')) - ->columnSpanFull(), + ->visible(fn (?Channel $record): bool => ! ($record?->isWebsite() ?? false)) + ->schema([ + TextEntry::make('export_url') + ->label('Eigener iCal-Exportlink') + ->state(fn (?Channel $record): ?string => $record?->exportUrl()) + ->visible(fn (?Channel $record): bool => $record?->exists ?? false) + ->copyable() + ->copyMessage('Exportlink kopiert') + ->wrap() + ->extraAttributes(['style' => 'overflow-wrap:anywhere']) + ->columnSpanFull(), + TextInput::make('name') + ->label('Name der Kalenderverbindung') + ->placeholder('z. B. FeWo-direkt') + ->required() + ->maxLength(100), + Select::make('status')->label('Kanalstatus')->options(ChannelStatus::class)->default(ChannelStatus::Setup)->required(), + Select::make('booking_model')->label('Was kommt über dieses Portal?')->options(ChannelBookingModel::class)->default(ChannelBookingModel::Mixed)->required() + ->helperText('„Portalbuchung“ und „Gemischt“ gelten als Sofortbuchung: automatische Angebote für diese Wohnung warten, bis das Portal unseren Kalender abgerufen hat. „Vermittlung / Anfrage“: keine Sofortbuchung.'), + Select::make('case_intake') + ->label('Erkannte Buchungen automatisch als Vorgang übernehmen?') + ->options(CaseIntakeMode::class) + ->default(CaseIntakeMode::Off) + ->required() + ->helperText('Zuerst „Beobachten“: Dann entsteht nichts, aber das Eingangsprotokoll (Expertenansicht) zeigt, welche Vorgänge entstanden wären. Unklare Belegungen und Meldungen zu gebuchten Vorgängen erscheinen unter „Zu erledigen“. Unterlagen gehen nie ohne Ihre Freigabe hinaus.') + ->columnSpanFull(), + ...self::processSections(), + Select::make('connector') + ->label('Kalenderanbindung') + ->helperText('Diese Verbindung gleicht Belegungszeiträume über iCal ab. Weitere Portalfunktionen benötigen eine eigene Anbindung.') + ->options($registry->options()) + ->default('ical') + ->live() + ->required(), + Group::make() + ->columnSpanFull() + ->schema(fn (Get $get): array => isset($registry->connectors()[$get('connector')]) ? $registry->connectors()[$get('connector')]::settingsSchema() : []), + Toggle::make('import_enabled')->label('Import aktiviert')->default(false) + ->helperText('Abruf durch FewoPortal alle fünf Minuten, sofern der Kanal aktiv ist.'), + Toggle::make('export_enabled')->label('Export aktiviert')->default(false) + ->helperText('Ausgeschaltet bleibt der letzte gültige Export eingefroren erreichbar. Ohne Stand: HTTP 503, kein leerer Kalender.'), + Select::make('export_mode')->label('Exportmodus')->options(ChannelExportMode::class)->default(ChannelExportMode::Test)->required() + ->helperText('Testbetrieb exportiert keine Fremdbelegungen und gewährleistet keine vollständige kanalübergreifende Sperrung. Regulär nur nach bewusster Freigabe wählen.') + ->columnSpanFull(), + TextInput::make('external_poll_minutes')->label('Erwarteter externer Abrufabstand (Minuten)') + ->integer()->minValue(1)->maxValue(43200) + ->helperText('Nur eine Annahme zum Portal; verändert weder unseren Abruf noch bestätigt sie eine Übernahme.'), + Select::make('echo_behavior')->label('Beobachtetes Rückkopplungsverhalten')->options(ChannelEchoBehavior::class)->default(ChannelEchoBehavior::Unverified)->required()->columnSpanFull() + ->helperText('Bei Weitergabe mit neuen UIDs bleiben neue Importereignisse bis zur persönlichen Klärung vom Export ausgeschlossen. Sie sperren intern weiterhin.'), + Textarea::make('echo_notes')->label('Nachweis / Beobachtung zum Rückkopplungsverhalten')->maxLength(4000)->columnSpanFull(), + DateTimePicker::make('portal_verified_at')->label('Tatsächliche Übernahme im Portal zuletzt persönlich geprüft')->seconds(false) + ->helperText('Nur nach Sichtkontrolle im Portal eintragen. Wird durch einen Feedabruf nicht automatisch gesetzt.'), + Textarea::make('operating_notes')->label('Zusätzliche Anforderungen dieses Portals')->maxLength(4000)->columnSpanFull() + ->helperText('Zum Beispiel eine zusätzliche Bestätigung, dass der Belegungskalender gepflegt ist.'), + TextInput::make('settings.email_senders') + ->label('Absender der Buchungs-E-Mails (Schnellerkennung)') + ->helperText('Komma-getrennt, z. B. „fewo-direkt.de, vrbo.com“. Buchungsbestätigungen dieser Absender werden sofort gesperrt.') + ->maxLength(500) + ->columnSpanFull(), + Toggle::make('requires_manual_blocking') + ->label('Zusätzlich von Hand sperren (Sofortbuchung)') + ->helperText('Bei jeder Belegung über andere Wege entsteht eine Aufgabe „Im Portal sperren“ – für Portale, die unseren Kalender zu selten abholen.') + ->live() + ->columnSpanFull(), + TextInput::make('manage_url') + ->label('Link zum Kalender im Vermieterbereich') + ->url() + ->maxLength(2048) + ->visible(fn (Get $get): bool => (bool) $get('requires_manual_blocking')) + ->columnSpanFull(), + ]), + ...self::websiteSections(), ]); } + /** + * The own website's entry (v0.11 channel manager): only the settings of requests from the website. Empty fields + * follow the defaults (System › So arbeite ich); there is no calendar connection. + * + * @return list
+ */ + private static function websiteSections(): array + { + $defaults = (array) (Settings::tenant()?->process_defaults ?? []); + $inherited = function (ProcessSetting $setting) use ($defaults): string { + $value = $setting->normalize($defaults[$setting->value] ?? null) ?? $setting->default(); + + return $setting === ProcessSetting::ContractTemplate ? 'Vorlage der Wohnung' : $setting->describe($value); + }; + $settings = array_values(array_filter(ProcessSetting::cases(), fn (ProcessSetting $setting): bool => in_array(IntakeKind::Inquiry, $setting->channelIntakes(), true))); + + return [ + Section::make('Anfragen über die eigene Webseite') + ->description('Nur ausfüllen, was für Anfragen über Ihre Webseite anders sein soll als in Ihren Standardeinstellungen (System › So arbeite ich). Telefon- und E-Mail-Anfragen folgen weiter den Standardeinstellungen.') + ->columns(2) + ->columnSpanFull() + ->visible(fn (?Channel $record): bool => $record?->isWebsite() ?? false) + ->schema(ProcessSettingFields::make('process_overrides.inquiry.', $settings, $inherited)), + ]; + } + /** * What a contract template brings along, shown under the template choice. */ @@ -127,7 +160,7 @@ private static function processSections(): array return $setting === ProcessSetting::ContractTemplate ? 'Vorlage der Wohnung' : $setting->describe($value); }; - $settingsFor = fn (IntakeKind $intake): array => array_values(array_filter(ProcessSetting::cases(), fn (ProcessSetting $setting): bool => in_array($intake, $setting->channelIntakes(), true))); + $settingsFor = fn (IntakeKind $intake): array => array_values(array_filter(ProcessSetting::cases(), fn (ProcessSetting $setting): bool => $setting !== ProcessSetting::FormRequiresAddress && in_array($intake, $setting->channelIntakes(), true))); return [ Section::make('Anfragen über dieses Portal') diff --git a/app/Filament/Resources/Channels/Tables/ChannelsTable.php b/app/Filament/Resources/Channels/Tables/ChannelsTable.php index 3a1adf8..94c7dd1 100644 --- a/app/Filament/Resources/Channels/Tables/ChannelsTable.php +++ b/app/Filament/Resources/Channels/Tables/ChannelsTable.php @@ -46,6 +46,7 @@ public static function configure(Table $table, ?Property $owner = null): Table TextColumn::make('property.name')->label('Wohnung')->visible($owner === null)->searchable()->color('gray')->wrap(), TextColumn::make('channel_state')->label('Status')->badge()->wrap() ->state(fn (Channel $record): string => match (true) { + $record->isWebsite() => 'Eigene Webseite – nur Einstellungen', ! $record->importsOccupations() => $record->status->getLabel(), $record->last_error !== null => 'Importfehler', $record->last_success_at === null => 'Erster Import ausstehend', @@ -53,6 +54,7 @@ public static function configure(Table $table, ?Property $owner = null): Table default => $record->status->getLabel(), }) ->color(fn (Channel $record): string => match (true) { + $record->isWebsite() => 'info', ! $record->is_active => 'gray', ! $record->importsOccupations() => 'success', $record->last_error !== null => 'danger', @@ -62,12 +64,12 @@ public static function configure(Table $table, ?Property $owner = null): Table }) ->description(fn (Channel $record): ?string => $record->review_count || count($record->sync_warnings ?? []) ? 'Prüffälle: '.$record->review_count.' · Hinweise: '.count($record->sync_warnings ?? []) : null) ->tooltip(fn (Channel $record): ?string => $record->last_error), - TextColumn::make('directions')->label('Richtungen')->color('gray')->wrap() + TextColumn::make('directions')->label('Richtungen')->color('gray')->wrap()->hidden(fn (?Channel $record): bool => $record?->isWebsite() ?? false) ->state(fn (Channel $record): string => ($record->importsOccupations() ? 'Import aktiv' : 'Import aus').' · '.($record->exportsOccupations() ? 'Export aktiv' : ($record->export_snapshot_at ? 'Export eingefroren' : 'Export aus'))), - TextColumn::make('last_sync')->label('Letzter Sync-Lauf')->wrap() + TextColumn::make('last_sync')->label('Letzter Sync-Lauf')->wrap()->hidden(fn (?Channel $record): bool => $record?->isWebsite() ?? false) ->state(fn (Channel $record): string => 'Letzter Sync: '.($record->last_synced_at?->format('d.m.Y H:i') ?? 'noch kein Lauf')) ->description(fn (Channel $record): ?string => $record->last_error !== null ? 'Letzter Lauf mit Fehler' : null), - TextColumn::make('last_export_request')->label('Letzter Kalenderabruf')->wrap()->color('gray') + TextColumn::make('last_export_request')->label('Letzter Kalenderabruf')->wrap()->color('gray')->hidden(fn (?Channel $record): bool => $record?->isWebsite() ?? false) ->state(fn (Channel $record): string => 'Letzter Abruf: '.($record->last_export_requested_at?->format('d.m.Y H:i') ?? 'noch keiner')) ->tooltip('Empfangener Aufruf dieses Kanalfeeds. Client und tatsächliche Übernahme im Portal sind damit nicht bestätigt.'), ])->space(2), @@ -78,7 +80,7 @@ public static function configure(Table $table, ?Property $owner = null): Table ->successNotificationTitle('iCal-Verbindung angelegt – Exportlink automatisch erzeugt'), ] : []) ->recordActions([ - Action::make('exportLink')->label('Exportlink')->icon(Heroicon::OutlinedLink)->button() + Action::make('exportLink')->label('Exportlink')->icon(Heroicon::OutlinedLink)->button()->visible(fn (Channel $record): bool => $record->isPortal()) ->modalDescription('Diese Adresse erlaubt den Kalenderabruf. Nur dem vorgesehenen Portal geben. Ein Abruf beweist keine tatsächliche Übernahme.') ->schema([ TextEntry::make('export_url')->label('Vertrauliche Kalenderadresse')->state(fn (Channel $record): string => $record->exportUrl())->copyable()->wrap()->extraAttributes(['style' => 'overflow-wrap:anywhere']), @@ -162,7 +164,7 @@ public static function configure(Table $table, ?Property $owner = null): Table TextEntry::make('warnings'), ]), ]), - ])->label('Weitere Aktionen')->icon(Heroicon::OutlinedEllipsisVertical), + ])->label('Weitere Aktionen')->icon(Heroicon::OutlinedEllipsisVertical)->visible(fn (Channel $record): bool => $record->isPortal()), ]); } } diff --git a/app/Filament/Resources/ContractAnnexes/ContractAnnexResource.php b/app/Filament/Resources/ContractAnnexes/ContractAnnexResource.php index 9858e95..2c64947 100644 --- a/app/Filament/Resources/ContractAnnexes/ContractAnnexResource.php +++ b/app/Filament/Resources/ContractAnnexes/ContractAnnexResource.php @@ -68,7 +68,7 @@ public static function form(Schema $schema): Schema ->label('Zusatzleistung / Portal') ->options(fn (Get $get): array => match ($get('condition_type')) { ContractAnnex::EXTRA => Extra::query()->orderBy('name')->pluck('name', 'id')->all(), - ContractAnnex::CHANNEL => Channel::query()->orderBy('name')->pluck('name', 'id')->all(), + ContractAnnex::CHANNEL => Channel::query()->portals()->orderBy('name')->pluck('name', 'id')->all(), default => [], }) ->visible(fn (Get $get): bool => in_array($get('condition_type'), [ContractAnnex::EXTRA, ContractAnnex::CHANNEL], true)) diff --git a/app/Filament/Resources/IntakeObservations/IntakeObservationResource.php b/app/Filament/Resources/IntakeObservations/IntakeObservationResource.php index 72ae55f..fb0c74c 100644 --- a/app/Filament/Resources/IntakeObservations/IntakeObservationResource.php +++ b/app/Filament/Resources/IntakeObservations/IntakeObservationResource.php @@ -70,7 +70,7 @@ public static function table(Table $table): Table TextColumn::make('missing')->label('Fehlt noch')->state(fn (IntakeObservation $record): string => implode(', ', (array) $record->missing))->placeholder('–')->wrap()->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ - SelectFilter::make('channel_id')->label('Portal')->options(fn (): array => Channel::query()->orderBy('name')->pluck('name', 'id')->all()), + SelectFilter::make('channel_id')->label('Portal')->options(fn (): array => Channel::query()->portals()->orderBy('name')->pluck('name', 'id')->all()), SelectFilter::make('outcome')->label('Ergebnis')->options(IntakeOutcome::class), SelectFilter::make('applied')->label('Ausgeführt')->options(['1' => 'ja', '0' => 'nur protokolliert']), ]); diff --git a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php index 29059c5..2a0c366 100644 --- a/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php +++ b/app/Filament/Resources/PortalOccupations/PortalOccupationResource.php @@ -217,7 +217,7 @@ public static function classificationAction(): Action ->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()), + ->options(fn (BlockedPeriod $record): array => ['private' => 'Privat'] + Channel::query()->portals()->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, [ diff --git a/app/Http/Controllers/ChannelController.php b/app/Http/Controllers/ChannelController.php index 723e25f..dd6f5d8 100644 --- a/app/Http/Controllers/ChannelController.php +++ b/app/Http/Controllers/ChannelController.php @@ -25,7 +25,7 @@ class ChannelController extends Controller { public function feed(string $token, ICalExport $feed, Request $request): Response { - $channel = Channel::query()->where(fn ($query) => $query->where('export_token', $token) + $channel = Channel::query()->portals()->where(fn ($query) => $query->where('export_token', $token) ->orWhere(fn ($previous) => $previous->where('previous_export_token', $token)->where('previous_export_token_expires_at', '>', now())))->firstOrFail(); abort_unless($channel->servesItsLandlord(), 404); diff --git a/app/Livewire/BookingRequest.php b/app/Livewire/BookingRequest.php index 86d577b..129eeec 100644 --- a/app/Livewire/BookingRequest.php +++ b/app/Livewire/BookingRequest.php @@ -6,7 +6,6 @@ use App\Actions\RequestMarketingConsent; use App\Availability\AvailabilityChecker; use App\Enums\BookingStatus; -use App\Enums\IntakeKind; use App\Enums\ReferralSource; use App\Exceptions\ReservationException; use App\Models\Booking; @@ -112,7 +111,7 @@ public function property(): Property #[Computed] public function reservesDates(): bool { - return app(ProcessSettings::class)->resolve($this->property, null, IntakeKind::Inquiry)->preReservation(); + return app(ProcessSettings::class)->forWebsite($this->property)->preReservation(); } /** diff --git a/app/Models/Channel.php b/app/Models/Channel.php index 18b2b5b..ce95305 100644 --- a/app/Models/Channel.php +++ b/app/Models/Channel.php @@ -24,20 +24,26 @@ use Illuminate\Support\Str; /** - * A sales channel (portal) of a property. Our system leads: occupations are imported from the - * channel and every channel gets its own export feed without its own occupations. + * A sales channel of a property. A portal (kind "portal"): our system leads, occupations are imported from the + * channel and every channel gets its own export feed without its own occupations. The own website (kind "website", + * v0.11 channel manager) only carries the settings for requests from the website: it is never synchronised, + * exported, monitored or given blocking tasks, and cases from the website stay direct (A1) without a channel. */ -#[Fillable(['property_id', 'name', 'connector', 'settings', 'is_active', 'requires_manual_blocking', 'manage_url', 'status', 'booking_model', 'import_enabled', 'export_enabled', 'export_mode', 'external_poll_minutes', 'echo_behavior', 'echo_notes', 'operating_notes', 'portal_verified_at', 'payment_tasks_inquiry', 'payment_tasks_reservation', 'contract_template_id', 'contract_template_reservation_id', 'process_overrides', 'case_intake'])] +#[Fillable(['property_id', 'name', 'connector', 'settings', 'is_active', 'requires_manual_blocking', 'manage_url', 'status', 'booking_model', 'import_enabled', 'export_enabled', 'export_mode', 'external_poll_minutes', 'echo_behavior', 'echo_notes', 'operating_notes', 'portal_verified_at', 'payment_tasks_inquiry', 'payment_tasks_reservation', 'contract_template_id', 'contract_template_reservation_id', 'process_overrides', 'case_intake', 'kind'])] #[Hidden(['export_token', 'previous_export_token', 'export_snapshot', 'settings', 'ical_analysis'])] class Channel extends Model { /** @use HasFactory */ use BelongsToTenant, HasFactory; + public const KIND_PORTAL = 'portal'; + + public const KIND_WEBSITE = 'website'; + protected $attributes = [ 'status' => 'setup', 'booking_model' => 'mixed', 'import_enabled' => false, 'export_enabled' => false, 'export_mode' => 'test', - 'echo_behavior' => 'unverified', 'case_intake' => 'off', + 'echo_behavior' => 'unverified', 'case_intake' => 'off', 'kind' => self::KIND_PORTAL, ]; protected static function booted(): void @@ -138,7 +144,48 @@ public function tasks(): HasMany #[Scope] protected function active(Builder $query): Builder { - return $query->where('is_active', true)->where('status', ChannelStatus::Active); + return $query->where('is_active', true)->where('status', ChannelStatus::Active)->where('kind', self::KIND_PORTAL); + } + + /** + * Portals only (active or not) – everything except the own website's settings entry. + * + * @param Builder $query + * @return Builder + */ + #[Scope] + protected function portals(Builder $query): Builder + { + return $query->where('kind', self::KIND_PORTAL); + } + + public function isWebsite(): bool + { + return $this->kind === self::KIND_WEBSITE; + } + + public function isPortal(): bool + { + return ! $this->isWebsite(); + } + + /** + * The settings entry of the property's own website, created on first use. + */ + public static function websiteOf(Property $property): self + { + return self::withoutGlobalScopes()->firstOrCreate( + ['property_id' => $property->id, 'kind' => self::KIND_WEBSITE], + ['tenant_id' => $property->tenant_id, 'name' => 'Eigene Webseite', 'connector' => self::KIND_WEBSITE, 'status' => ChannelStatus::Active, 'booking_model' => ChannelBookingModel::Inquiry], + ); + } + + /** + * The settings entry of the property's own website if there is one (no write, for resolving settings). + */ + public static function existingWebsiteOf(Property $property): ?self + { + return self::withoutGlobalScopes()->where('property_id', $property->id)->where('kind', self::KIND_WEBSITE)->first(); } public function connector(): ChannelConnector diff --git a/app/Models/Property.php b/app/Models/Property.php index e6785b8..603754b 100644 --- a/app/Models/Property.php +++ b/app/Models/Property.php @@ -132,9 +132,12 @@ public function blockedPeriods(): HasMany /** * @return HasMany */ + /** + * The portals of the property (the own website's settings entry is not a portal). + */ public function channels(): HasMany { - return $this->hasMany(Channel::class); + return $this->hasMany(Channel::class)->where('kind', Channel::KIND_PORTAL); } /** diff --git a/app/Process/ProcessProfile.php b/app/Process/ProcessProfile.php index 18ba8da..2149157 100644 --- a/app/Process/ProcessProfile.php +++ b/app/Process/ProcessProfile.php @@ -3,6 +3,7 @@ namespace App\Process; use App\Enums\CaseType; +use App\Enums\DataRequestMode; use App\Enums\IntakeKind; use App\Enums\ProcessingMode; use App\Enums\ProcessSetting; @@ -23,6 +24,9 @@ final class ProcessProfile public const CHANNEL = 'channel'; + /** The own website's entry of the channel manager (v0.11). */ + public const WEBSITE = 'website'; + /** Fixed by the case type (A6), not settable. */ public const CASE_TYPE = 'case_type'; @@ -104,6 +108,47 @@ public function arrivalInfoDaysBefore(): int return max(1, (int) $this->value(ProcessSetting::ArrivalInfoDaysBefore)); } + public function dataRequestMode(): DataRequestMode + { + return DataRequestMode::tryFrom((string) $this->value(ProcessSetting::DataRequest)) ?? DataRequestMode::Approval; + } + + /** + * Minutes of the clarification hold of an incomplete request (E-033): the value for automatic requests when the + * guest is asked automatically, otherwise the one for release or manual requests. 0 = no hold. + */ + public function clarificationHoldMinutes(): int + { + $setting = $this->dataRequestMode() === DataRequestMode::Automatic ? ProcessSetting::ClarificationHoldAutoMinutes : ProcessSetting::ClarificationHoldManualMinutes; + + return max(0, (int) $this->value($setting)); + } + + public function remindersMax(): int + { + return max(0, (int) $this->value(ProcessSetting::DataRequestRemindersMax)); + } + + public function followupsMax(): int + { + return max(0, (int) $this->value(ProcessSetting::DataRequestFollowupsMax)); + } + + public function reminderHours(): int + { + return max(1, (int) $this->value(ProcessSetting::DataRequestReminderHours)); + } + + public function guestLinkValidDays(): int + { + return max(1, (int) $this->value(ProcessSetting::GuestLinkValidDays)); + } + + public function formRequiresAddress(): bool + { + return (bool) $this->value(ProcessSetting::FormRequiresAddress); + } + public function contractTemplateId(): ?int { $value = $this->value(ProcessSetting::ContractTemplate); @@ -120,6 +165,7 @@ public static function sourceLabel(string $source): string self::TENANT => 'Ihre Standardeinstellung', self::PROPERTY => 'Abweichung der Wohnung', self::CHANNEL => 'Abweichung des Portals', + self::WEBSITE => 'Einstellung der eigenen Webseite', self::CASE_TYPE => 'fest für diese Vorgangsart', 'migration' => 'aus dem bisherigen Stand übernommen', default => 'Grundeinstellung', diff --git a/app/Process/ProcessSettings.php b/app/Process/ProcessSettings.php index 811b4b1..ed6c719 100644 --- a/app/Process/ProcessSettings.php +++ b/app/Process/ProcessSettings.php @@ -28,7 +28,7 @@ public function resolve(Property $property, ?Channel $channel, IntakeKind $intak $levels = [ ProcessProfile::TENANT => $this->tenantDefaults($property->tenant_id), ProcessProfile::PROPERTY => $propertyLevel, - ProcessProfile::CHANNEL => $intake === IntakeKind::Internal || $channel === null ? [] : (array) (($channel->process_overrides ?? [])[$intake->value] ?? []), + ($channel?->isWebsite() ? ProcessProfile::WEBSITE : ProcessProfile::CHANNEL) => $intake === IntakeKind::Internal || $channel === null ? [] : (array) (($channel->process_overrides ?? [])[$intake->value] ?? []), ]; $values = []; @@ -38,7 +38,7 @@ public function resolve(Property $property, ?Channel $channel, IntakeKind $intak $sources[$setting->value] = ProcessProfile::SYSTEM; foreach ($levels as $level => $settings) { - if ($level === ProcessProfile::CHANNEL && ! in_array($intake, $setting->channelIntakes(), true)) { + if (in_array($level, [ProcessProfile::CHANNEL, ProcessProfile::WEBSITE], true) && ! in_array($intake, $setting->channelIntakes(), true)) { continue; } $value = $setting->normalize($settings[$setting->value] ?? null); @@ -65,7 +65,16 @@ public function resolve(Property $property, ?Channel $channel, IntakeKind $intak $documents = Responsibility::from((string) $values[ProcessSetting::Documents->value]); $payments = Responsibility::from((string) $values[ProcessSetting::Payments->value]); - return new ProcessProfile($intake, ProcessProfile::caseTypeFor($intake, $channel !== null, $documents, $payments), $values, $sources); + return new ProcessProfile($intake, ProcessProfile::caseTypeFor($intake, $channel?->isPortal() ?? false, $documents, $payments), $values, $sources); + } + + /** + * Settings of a request from the own website: the website's entry of the channel manager is its channel level + * (the case itself stays direct, without a channel). + */ + public function forWebsite(Property $property, IntakeKind $intake = IntakeKind::Inquiry): ProcessProfile + { + return $this->resolve($property, Channel::existingWebsiteOf($property), $intake); } /** @@ -76,7 +85,9 @@ public function forBooking(Booking $booking): ProcessProfile // The case's own landlord counts, whichever landlord is current (e.g. a case written by the system). $property = $booking->property ?? Property::withoutGlobalScope('tenant')->findOrFail($booking->property_id); - return $this->resolve($property, $booking->processChannel(), $booking->intake ?? self::intakeFor($booking)); + $channel = $booking->processChannel() ?? ($booking->source === 'website' ? Channel::existingWebsiteOf($property) : null); + + return $this->resolve($property, $channel, $booking->intake ?? self::intakeFor($booking)); } /** @@ -100,7 +111,7 @@ public function tenantDefaults(?int $tenantId): array public static function intakeFor(Booking $booking): IntakeKind { $channel = $booking->processChannel(); - if ($channel === null) { + if ($channel === null || $channel->isWebsite()) { return IntakeKind::Inquiry; } diff --git a/database/migrations/2026_11_06_090000_add_channel_kind_for_the_channel_manager.php b/database/migrations/2026_11_06_090000_add_channel_kind_for_the_channel_manager.php new file mode 100644 index 0000000..1d5aad9 --- /dev/null +++ b/database/migrations/2026_11_06_090000_add_channel_kind_for_the_channel_manager.php @@ -0,0 +1,54 @@ +string('kind', 20)->default('portal')->after('property_id'); + $table->index(['property_id', 'kind']); + }); + + foreach (DB::table('properties')->get(['id', 'tenant_id']) as $property) { + $exists = DB::table('channels')->where('property_id', $property->id)->where('kind', 'website')->exists(); + if ($exists) { + continue; + } + + DB::table('channels')->insert([ + 'tenant_id' => $property->tenant_id, + 'property_id' => $property->id, + 'kind' => 'website', + 'name' => 'Eigene Webseite', + 'connector' => 'website', + 'export_token' => Str::random(48), + 'is_active' => true, + 'status' => 'active', + 'booking_model' => 'inquiry', + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + } + + public function down(): void + { + DB::table('channels')->where('kind', 'website')->delete(); + + Schema::table('channels', function (Blueprint $table) { + $table->dropIndex(['property_id', 'kind']); + $table->dropColumn('kind'); + }); + } +}; diff --git a/resources/views/filament/pages/effective-settings.blade.php b/resources/views/filament/pages/effective-settings.blade.php index 2a93130..e91f3d3 100644 --- a/resources/views/filament/pages/effective-settings.blade.php +++ b/resources/views/filament/pages/effective-settings.blade.php @@ -2,11 +2,11 @@ @php $cell = 'padding:.4rem .5rem;border-bottom:1px solid rgba(128,128,128,.2);vertical-align:top'; $muted = 'color:#6b7280;font-size:.8rem'; - $levels = [\App\Process\ProcessProfile::SYSTEM => 'Grundeinstellung', \App\Process\ProcessProfile::TENANT => 'Ihr Standard', \App\Process\ProcessProfile::PROPERTY => 'Wohnung', \App\Process\ProcessProfile::CHANNEL => 'Portal', \App\Process\ProcessProfile::CASE_TYPE => 'fest (A6)']; + $levels = [\App\Process\ProcessProfile::SYSTEM => 'Grundeinstellung', \App\Process\ProcessProfile::TENANT => 'Ihr Standard', \App\Process\ProcessProfile::PROPERTY => 'Wohnung', \App\Process\ProcessProfile::CHANNEL => 'Portal', \App\Process\ProcessProfile::WEBSITE => 'Webseite', \App\Process\ProcessProfile::CASE_TYPE => 'fest (A6)']; @endphp -

Jede Spalte ist ein Eingangsweg. Jede Zelle zeigt den Wert, der für einen neuen Vorgang auf diesem Weg gilt, und darunter, woher er kommt: Grundeinstellung → Ihr Standard (So arbeite ich) → Abweichung der Wohnung → Abweichung des Portals für Anfragen bzw. feste Buchungen. Laufende Vorgänge behalten ihr beim Eingang festgehaltenes Profil – das zeigt der Abschnitt „Einen Vorgang prüfen“. Ändern lassen sich die Werte nur an ihrer Stelle (rechte Spalte).

+

Jede Spalte ist ein Eingangsweg. Jede Zelle zeigt den Wert, der für einen neuen Vorgang auf diesem Weg gilt, und darunter, woher er kommt: Grundeinstellung → Ihr Standard (So arbeite ich) → Abweichung der Wohnung → Abweichung des Kanals (eigene Webseite bzw. Portal für Anfragen und feste Buchungen). Laufende Vorgänge behalten ihr beim Eingang festgehaltenes Profil – das zeigt der Abschnitt „Einen Vorgang prüfen“. Ändern lassen sich die Werte nur an ihrer Stelle (rechte Spalte).

@foreach ($this->matrix() as $block) diff --git a/tests/Feature/ChannelManagerTest.php b/tests/Feature/ChannelManagerTest.php new file mode 100644 index 0000000..ca56780 --- /dev/null +++ b/tests/Feature/ChannelManagerTest.php @@ -0,0 +1,148 @@ +travelTo(CarbonImmutable::parse('2026-10-22 10:00')); + $this->seed([PropertySeeder::class, SiteSeeder::class]); + $this->property = Property::sole(); + Mail::fake(); + } + + public function test_the_website_entry_overrides_the_landlord_default_for_website_requests_and_the_case_stays_direct(): void + { + Settings::tenant()->update(['process_defaults' => ['hold_hours' => 48]]); + Channel::websiteOf($this->property)->update(['process_overrides' => ['inquiry' => ['hold_hours' => 24]]]); + + $website = $this->request(source: 'website'); + $phone = $this->request(email: 'telefon@example.org', arrival: '2026-11-20', departure: '2026-11-23', source: 'phone'); + + $this->assertTrue($website->hold_expires_at->equalTo(now()->addHours(24))); + $this->assertSame(ProcessProfile::WEBSITE, $website->process()->source(ProcessSetting::HoldHours)); + $this->assertSame(CaseType::A1, $website->case_type); + $this->assertNull($website->origin_channel_id); + $this->assertTrue($website->isDirect()); + $this->assertSame('Eigene Webseite', $website->bookingChannelLabel()); + + $this->assertTrue($phone->hold_expires_at->equalTo(now()->addHours(48)), 'phone and e-mail keep the landlord default'); + $this->assertSame(CaseType::A1, $phone->case_type); + } + + public function test_the_website_entry_is_never_treated_as_a_portal(): void + { + $website = Channel::websiteOf($this->property); + $portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'status' => 'active']); + + $this->assertSame([$portal->id], Channel::query()->active()->pluck('id')->all()); + $this->assertSame([$portal->id], $this->property->channels()->pluck('id')->all()); + $this->assertSame([$portal->id], Channel::query()->portals()->pluck('id')->all()); + $this->assertTrue($website->isWebsite()); + $this->get(route('channels.feed', ['token' => $website->export_token]))->assertNotFound(); + $this->assertSame($website->id, Channel::websiteOf($this->property)->id, 'one entry per property'); + } + + public function test_new_parameters_inherit_and_zero_is_a_value_of_its_own(): void + { + Settings::tenant()->update(['process_defaults' => ['data_request_mode' => DataRequestMode::Automatic->value, 'clarification_hold_auto_minutes' => 0]]); + $settings = app(ProcessSettings::class); + + $landlord = $settings->forWebsite($this->property); + $this->assertSame(0, $landlord->clarificationHoldMinutes()); + $this->assertSame('tenant', $landlord->source(ProcessSetting::ClarificationHoldAutoMinutes)); + $this->assertSame(2, $landlord->remindersMax()); + $this->assertFalse($landlord->formRequiresAddress()); + + Channel::websiteOf($this->property)->update(['process_overrides' => ['inquiry' => ['data_request_mode' => DataRequestMode::Manual->value, 'form_requires_address' => '1', 'clarification_hold_auto_minutes' => null]]]); + $website = $settings->forWebsite($this->property); + $this->assertSame(DataRequestMode::Manual, $website->dataRequestMode()); + $this->assertSame(180, $website->clarificationHoldMinutes(), 'manual requests use their own default'); + $this->assertTrue($website->formRequiresAddress()); + + $portal = Channel::factory()->for($this->property)->create(['process_overrides' => ['booking' => ['data_request_mode' => DataRequestMode::Manual->value, 'clarification_hold_auto_minutes' => 30]]]); + $booking = $settings->resolve($this->property, $portal, IntakeKind::Booking); + $this->assertSame(DataRequestMode::Manual, $booking->dataRequestMode()); + $this->assertSame('tenant', $booking->source(ProcessSetting::ClarificationHoldAutoMinutes), 'a portal cannot set the clarification hold for bookings'); + } + + public function test_the_channel_manager_lists_the_website_and_saves_its_settings(): void + { + $this->actingAs(User::factory()->create()); + Channel::query()->withoutGlobalScopes()->where('kind', Channel::KIND_WEBSITE)->delete(); + $portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt']); + + Livewire::test(ListChannels::class)->assertCanSeeTableRecords([$portal])->assertSee('Eigene Webseite'); + $website = Channel::websiteOf($this->property); + + Livewire::test(EditChannel::class, ['record' => $website->getRouteKey()]) + ->assertSee('Anfragen über die eigene Webseite') + ->assertDontSee('Eigener iCal-Exportlink') + ->fillForm(['process_overrides' => ['inquiry' => ['clarification_hold_manual_minutes' => '0', 'form_requires_address' => '1']]]) + ->call('save') + ->assertHasNoFormErrors(); + + $profile = app(ProcessSettings::class)->forWebsite($this->property); + $this->assertSame(0, $profile->clarificationHoldMinutes()); + $this->assertTrue($profile->formRequiresAddress()); + $this->assertSame(ProcessProfile::WEBSITE, $profile->source(ProcessSetting::FormRequiresAddress)); + } + + public function test_effective_settings_show_the_website_column(): void + { + $this->actingAs(User::factory()->create()); + Channel::websiteOf($this->property)->update(['process_overrides' => ['inquiry' => ['clarification_hold_auto_minutes' => 0]]]); + + Livewire::test(EffectiveSettings::class) + ->assertSee('Eigene Webseite – Anfrage') + ->assertSee('Direkte Anfrage (Telefon, E-Mail)') + ->assertSee('Webseite'); + } + + private function request(string $email = 'gast@example.org', string $arrival = '2026-11-07', string $departure = '2026-11-10', string $source = 'website'): Booking + { + return app(CreateReservation::class)->handle( + $this->property->fresh(), + new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), + ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], + source: $source, + sendMails: false, + ); + } +}