Files
fewo-stommer/app/Filament/Forms/ProcessSettingFields.php
T
LarsandClaude Opus 5.5 3bcfc09417
Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m44s
Pakete 8, 5 und 6: Beträge und Zahlungen, Ändern und Stornieren, A6 im Vorgang
- Paket 8: Zahlungsarten (Gast an uns, laut Portal, Auszahlung, Erstattung),
  Portalbeträge als Angaben mit Quelle, Übersicht nach Zuständigkeit (R09).
- Paket 5: Ändern mit Folgenvorschau, vereinbart oder dem Gast vorgeschlagen
  (signierter Link), ein Stornoweg mit Grund und Erstattung, Portalstorno erst
  nach Bestätigung.
- Paket 6: eigene Nutzung, Besuch und Sperre als Vorgang mit Kurabgabe und
  Aufenthaltsbestätigung; Bestandsübernahme der Sperren mit identischem Export.
- Wirksame Einstellungen (Expertenansicht), Abnahmekatalog T01–T14, Ergebnis-,
  Abnahme- und Konfigurationsdokument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 22:16:47 +01:00

78 lines
3.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Forms;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
use App\Models\ContractTemplate;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
/**
* Form fields of the process settings, asked as plain questions. On a deviation level (property, channel) an empty
* field means "as the level above" and the placeholder says which value that is; on the landlord level an empty field
* means the built-in default.
*/
class ProcessSettingFields
{
/**
* @param list<ProcessSetting> $settings
* @param callable(ProcessSetting): string $inherited plain-words value used when the field stays empty
* @return list<Field>
*/
public static function make(string $prefix, array $settings, callable $inherited): array
{
return array_map(fn (ProcessSetting $setting): Field => self::field($prefix.$setting->value, $setting, $inherited($setting)), $settings);
}
public static function field(string $name, ProcessSetting $setting, string $inheritedLabel): Field
{
$placeholder = 'wie Standard: '.$inheritedLabel;
return (match ($setting) {
ProcessSetting::Processing => Select::make($name)->options(ProcessingMode::class)->placeholder($placeholder)
->helperText('Automatisch: Das System sendet Angebote bzw. Unterlagen selbst, sobald alle Angaben da sind. Sonst bereitet es alles vor und Sie geben frei.'),
ProcessSetting::PreReservation => Select::make($name)->options(['1' => 'Ja – der Zeitraum ist bis zum Ablauf des Angebots reserviert', '0' => 'Nein – eine Anfrage reserviert nichts'])->placeholder($placeholder),
ProcessSetting::HoldHours => TextInput::make($name)->integer()->minValue(1)->maxValue(720)->suffix('Stunden')->placeholder($placeholder),
ProcessSetting::Documents, ProcessSetting::Payments, ProcessSetting::GuestMessages => Select::make($name)->options([Responsibility::Landlord->value => Responsibility::Landlord->getLabel(), Responsibility::Portal->value => Responsibility::Portal->getLabel()])->placeholder($placeholder),
ProcessSetting::ArrivalInfoDaysBefore => TextInput::make($name)->integer()->minValue(1)->maxValue(14)->suffix('Tage vor Anreise')->placeholder($placeholder),
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),
})->label($setting->question());
}
/**
* Normalised values of submitted fields; empty fields are dropped (not set = inherit).
*
* @param array<string, mixed> $data
* @param list<ProcessSetting> $settings
* @return array<string, string|int|bool>
*/
public static function values(array $data, array $settings): array
{
$values = [];
foreach ($settings as $setting) {
$value = $setting->normalize($data[$setting->value] ?? null);
if ($value !== null) {
$values[$setting->value] = $value;
}
}
return $values;
}
/**
* Stored values as form state (booleans as the select keys).
*
* @param array<string, mixed> $values
* @return array<string, mixed>
*/
public static function state(array $values): array
{
return array_map(fn (mixed $value): mixed => is_bool($value) ? ($value ? '1' : '0') : $value, $values);
}
}