*/ public array $data = []; public static function canAccess(): bool { return (bool) auth()->user()?->hasRole(UserRole::Admin); } /** * @return list */ public static function settings(): array { return array_values(array_filter(ProcessSetting::cases(), fn (ProcessSetting $setting): bool => $setting->isLandlordSetting())); } public function mount(): void { $this->form->fill(ProcessSettingFields::state((array) ($this->tenant()->process_defaults ?? []))); } public function form(Schema $schema): Schema { return $schema ->statePath('data') ->components([ Section::make('Ihre Standardeinstellungen') ->description('Gilt für alle Wohnungen und Portale, solange dort nichts anderes eingestellt ist. Neue Einstellungen gelten für neue Vorgänge; laufende Vorgänge behalten ihre Regeln.') ->columns(2) ->schema(ProcessSettingFields::make('', self::settings(), fn (ProcessSetting $setting): string => 'Grundeinstellung ('.$setting->describe($setting->default()).')')), Section::make('Abweichungen') ->description('Wo Portale oder Wohnungen anders arbeiten. Ändern unter Portale bzw. Wohnungen (Expertenansicht).') ->collapsed() ->schema([Text::make(fn (): HtmlString => $this->deviations())]), ]); } public function content(Schema $schema): Schema { return $schema->components([ Form::make([EmbeddedSchema::make('form')]) ->id('form') ->livewireSubmitHandler('save') ->footer([Actions::make([Action::make('save')->label('Speichern')->submit('save')])]), ]); } public function save(): void { $this->tenant()->update(['process_defaults' => ProcessSettingFields::values($this->form->getState(), self::settings())]); Notification::make()->title('Gespeichert')->body('Gilt für neue Vorgänge.')->success()->send(); } /** * Every deviation of a property or a channel, in plain words. */ private function deviations(): HtmlString { $lines = []; foreach (Property::query()->orderBy('name')->get() as $property) { foreach ((array) ($property->process_overrides ?? []) as $key => $value) { $setting = ProcessSetting::tryFrom((string) $key); if ($setting !== null && $setting->normalize($value) !== null) { $lines[] = e($property->name).': '.e($setting->question()).' → '.e($setting->describe($setting->normalize($value))).''; } } } foreach (Channel::query()->with('property')->orderBy('name')->get() as $channel) { foreach ((array) ($channel->process_overrides ?? []) as $intake => $values) { foreach ((array) $values as $key => $value) { $setting = ProcessSetting::tryFrom((string) $key); if ($setting !== null && $setting->normalize($value) !== null) { $lines[] = e($channel->name.' ('.$channel->property?->name.', '.(IntakeKind::tryFrom((string) $intake)?->getLabel() ?? $intake).')').': '.e($setting->question()).' → '.e($setting->describe($setting->normalize($value))).''; } } } } return new HtmlString($lines === [] ? 'Keine – überall gelten Ihre Standardeinstellungen.' : ''); } private function tenant(): Tenant { $tenant = Settings::tenant(); abort_if($tenant === null, 404); return $tenant; } }