- Eigene Webseite als Kanal eigener Art (channels.kind = website), nur zur Konfiguration: Webseiten-Anfragen bleiben direkt (A1) ohne Kanalbezug; der Eintrag nimmt an Sync, Export, Überwachung und Sperraufgaben nicht teil (active()/Property::channels() nur Portale, Feed nur für Portale). - Neue Einstellungen im bestehenden ProcessSetting: Klärungsreservierung automatisch/Freigabe (15/180 min, 0 = keine), Rückfragemodus, Erinnerungen, Folgefragen, Erinnerungsabstand, Linkgültigkeit, Anschrift im Webformular verlangen (Standard: nein). - „Kanäle“ in der einfachen Ansicht: Webseite und Portale an einer Stelle, Verweis auf „Ihre Standards“; „Wirksame Einstellungen“ mit Spalte „Eigene Webseite“ und Herkunft „Webseite“. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
156 lines
6.1 KiB
PHP
156 lines
6.1 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Pages;
|
||
|
||
use App\Enums\IntakeKind;
|
||
use App\Enums\ProcessSetting;
|
||
use App\Enums\UserRole;
|
||
use App\Filament\Concerns\FollowsAdminMode;
|
||
use App\Models\Booking;
|
||
use App\Models\Channel;
|
||
use App\Models\ContractTemplate;
|
||
use App\Models\Property;
|
||
use App\Process\ProcessProfile;
|
||
use App\Process\ProcessSettings;
|
||
use App\Support\Money;
|
||
use BackedEnum;
|
||
use Filament\Pages\Page;
|
||
use Filament\Support\Icons\Heroicon;
|
||
use UnitEnum;
|
||
|
||
/**
|
||
* "Wirksame Einstellungen" (expert view, KONFIGURATION_UND_WIRKSAMKEIT): for every property, every way a case can come
|
||
* in (direct request, each portal for requests and for binding bookings, own use) the value of every process setting
|
||
* that applies right now and the level it comes from – and for one chosen case the profile that really was applied.
|
||
* Read only: settings are changed where they belong ("So arbeite ich", the property, the portal).
|
||
*/
|
||
class EffectiveSettings extends Page
|
||
{
|
||
use FollowsAdminMode;
|
||
|
||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedAdjustmentsHorizontal;
|
||
|
||
protected static string|UnitEnum|null $navigationGroup = 'System';
|
||
|
||
protected static ?string $navigationLabel = 'Wirksame Einstellungen';
|
||
|
||
protected static ?string $title = 'Wirksame Einstellungen';
|
||
|
||
protected static ?string $slug = 'wirksame-einstellungen';
|
||
|
||
protected static ?int $navigationSort = 3;
|
||
|
||
protected string $view = 'filament.pages.effective-settings';
|
||
|
||
public ?int $bookingId = null;
|
||
|
||
public static function canAccess(): bool
|
||
{
|
||
return (bool) auth()->user()?->hasRole(UserRole::Admin);
|
||
}
|
||
|
||
public function mount(): void
|
||
{
|
||
$this->bookingId = is_numeric(request()->query('vorgang')) ? (int) request()->query('vorgang') : null;
|
||
}
|
||
|
||
/**
|
||
* Every way a case of a property can come in, with the profile that would apply now.
|
||
*
|
||
* @return list<array{property: Property, columns: list<array{label: string, profile: ProcessProfile}>}>
|
||
*/
|
||
public function matrix(): array
|
||
{
|
||
$settings = app(ProcessSettings::class);
|
||
|
||
return Property::query()->orderBy('name')->get()->map(function (Property $property) use ($settings): array {
|
||
$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)];
|
||
}
|
||
$columns[] = ['label' => 'Eigene Nutzung / Sperre (A6)', 'profile' => $settings->resolve($property, null, IntakeKind::Internal)];
|
||
|
||
return ['property' => $property, 'columns' => $columns];
|
||
})->all();
|
||
}
|
||
|
||
/**
|
||
* @return list<ProcessSetting>
|
||
*/
|
||
public function settings(): array
|
||
{
|
||
return ProcessSetting::cases();
|
||
}
|
||
|
||
public function describe(ProcessSetting $setting, ProcessProfile $profile): string
|
||
{
|
||
$value = $profile->value($setting);
|
||
if ($setting === ProcessSetting::ContractTemplate) {
|
||
return $value === null ? 'Texte der Webseite' : (ContractTemplate::query()->find($value)?->label() ?? 'Vorlage Nr. '.$value);
|
||
}
|
||
|
||
return $setting->describe($value);
|
||
}
|
||
|
||
/**
|
||
* Where a setting is changed in the application.
|
||
*/
|
||
public static function where(ProcessSetting $setting): string
|
||
{
|
||
return $setting === ProcessSetting::ContractTemplate
|
||
? 'Wohnung › Abweichende Abwicklung (Experte) bzw. Portal › Anfragen / Feste Buchungen'
|
||
: 'System › So arbeite ich; Abweichung: Wohnung (Experte), Portal je Anfrage/feste Buchung'.($setting->channelIntakes() === [] ? ' (kein Portal)' : '');
|
||
}
|
||
|
||
/**
|
||
* What a request on this way is answered with (package 7): a binding offer that reserves, or an information.
|
||
*/
|
||
public static function answer(ProcessProfile $profile): string
|
||
{
|
||
return match ($profile->intake) {
|
||
IntakeKind::Inquiry => $profile->preReservation() ? 'Angebot mit Annahmelink, Zeitraum reserviert' : 'Unverbindliche Auskunft, „Buchung anfragen“, erneute Prüfung',
|
||
IntakeKind::Booking => 'keine – beim Portal bereits verbindlich',
|
||
IntakeKind::Internal => 'keine – eigene Belegung',
|
||
};
|
||
}
|
||
|
||
/**
|
||
* The stay settings of a property in one line (package 9).
|
||
*/
|
||
public static function stay(Property $property): string
|
||
{
|
||
$tasks = array_map(fn (array $task): string => $task['title'].' ('.match ($task['when']) {
|
||
'after_departure' => 'am Abreisetag',
|
||
'on_arrival' => 'am Anreisetag',
|
||
default => $task['days'].' Tag(e) vor Anreise',
|
||
}.($task['responsible'] ? ', '.$task['responsible'] : '').')', $property->stayTaskDefinitions());
|
||
|
||
return implode(' · ', [
|
||
'Anreisezeit erfragen: '.($property->asks_arrival_time ? 'ja' : 'nein'),
|
||
'Aufgaben je Aufenthalt: '.($tasks === [] ? 'keine eingestellt' : implode(', ', $tasks)),
|
||
'gebuchte Leistungen werden zu Aufgaben',
|
||
'Kurabgabe (A6): '.($property->tourist_tax_rate ? Money::format((int) $property->tourist_tax_rate).' je Person und Nacht' : 'kein Satz – keine Berechnung'),
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* Recent cases to check.
|
||
*
|
||
* @return array<int, string>
|
||
*/
|
||
public function cases(): array
|
||
{
|
||
return Booking::query()->with('guest')->latest('id')->limit(60)->get()
|
||
->mapWithKeys(fn (Booking $booking): array => [$booking->id => $booking->reference.' · '.$booking->guestName().' · '.$booking->caseType()->value])->all();
|
||
}
|
||
|
||
public function booking(): ?Booking
|
||
{
|
||
return $this->bookingId ? Booking::query()->find($this->bookingId) : null;
|
||
}
|
||
}
|