Files
fewo-stommer/app/Process/ProcessProfile.php
T
LarsandClaude Opus 5.5 3a728c3255 Vorgangskern und geführte Vorgangsbearbeitung (Pakete 1 und 2, Prozessarchitektur v0.10)
- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes
  Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge
  dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt
- Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung
  (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße
- Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt
  RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition
- Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter,
  "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus
- Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben
  als Abweichung), Bericht: php artisan process:settings-report

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

164 lines
5.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\Process;
use App\Enums\CaseType;
use App\Enums\IntakeKind;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Enums\Responsibility;
/**
* The rules that apply to one case: its intake kind, case type and the effective value of every process setting
* together with the level it came from. Frozen on the case when it comes in, so later changes of the settings only
* affect new cases.
*/
final class ProcessProfile
{
public const SYSTEM = 'system';
public const TENANT = 'tenant';
public const PROPERTY = 'property';
public const CHANNEL = 'channel';
/** Settings resolved when they are used instead of being frozen (documents capture their own template). */
public const LIVE = [ProcessSetting::ContractTemplate];
/**
* @param array<string, string|int|bool|null> $values setting key => effective value
* @param array<string, string> $sources setting key => level the value came from
*/
public function __construct(
public readonly IntakeKind $intake,
public readonly CaseType $caseType,
public readonly array $values,
public readonly array $sources,
public readonly ?string $frozenAt = null,
public readonly string $origin = 'intake',
) {}
/**
* The case type of a constellation: internal occasions are A6; requests are A1 (own way) or A2 (intermediary);
* binding external bookings are A3–A5 by who handles documents and payments.
*/
public static function caseTypeFor(IntakeKind $intake, bool $viaChannel, Responsibility $documents, Responsibility $payments): CaseType
{
return match ($intake) {
IntakeKind::Internal => CaseType::A6,
IntakeKind::Inquiry => $viaChannel ? CaseType::A2 : CaseType::A1,
IntakeKind::Booking => match (true) {
$documents === Responsibility::Portal => CaseType::A5,
$payments === Responsibility::Portal => CaseType::A4,
default => CaseType::A3,
},
};
}
public function value(ProcessSetting $setting): string|int|bool|null
{
return array_key_exists($setting->value, $this->values) ? $this->values[$setting->value] : $setting->default();
}
public function source(ProcessSetting $setting): string
{
return $this->sources[$setting->value] ?? self::SYSTEM;
}
public function processing(): ProcessingMode
{
return ProcessingMode::tryFrom((string) $this->value(ProcessSetting::Processing)) ?? ProcessingMode::Manual;
}
public function preReservation(): bool
{
return (bool) $this->value(ProcessSetting::PreReservation);
}
public function holdHours(): int
{
return max(1, (int) $this->value(ProcessSetting::HoldHours));
}
public function documents(): Responsibility
{
return Responsibility::tryFrom((string) $this->value(ProcessSetting::Documents)) ?? Responsibility::Landlord;
}
public function payments(): Responsibility
{
return Responsibility::tryFrom((string) $this->value(ProcessSetting::Payments)) ?? Responsibility::Landlord;
}
public function guestMessages(): Responsibility
{
return Responsibility::tryFrom((string) $this->value(ProcessSetting::GuestMessages)) ?? Responsibility::Landlord;
}
public function arrivalInfoDaysBefore(): int
{
return max(1, (int) $this->value(ProcessSetting::ArrivalInfoDaysBefore));
}
public function contractTemplateId(): ?int
{
$value = $this->value(ProcessSetting::ContractTemplate);
return $value === null ? null : (int) $value;
}
/**
* Plain words for a level, for the "where does this come from" hint.
*/
public static function sourceLabel(string $source): string
{
return match ($source) {
self::TENANT => 'Ihre Standardeinstellung',
self::PROPERTY => 'Abweichung der Wohnung',
self::CHANNEL => 'Abweichung des Portals',
'migration' => 'aus dem bisherigen Stand übernommen',
default => 'Grundeinstellung',
};
}
/**
* The profile as it is frozen on the case (settings resolved live are left out).
*
* @return array{intake: string, case_type: string, values: array<string, string|int|bool|null>, sources: array<string, string>, frozen_at: string, origin: string}
*/
public function toArray(): array
{
$live = array_flip(array_map(fn (ProcessSetting $setting): string => $setting->value, self::LIVE));
return [
'intake' => $this->intake->value,
'case_type' => $this->caseType->value,
'values' => array_diff_key($this->values, $live),
'sources' => array_diff_key($this->sources, $live),
'frozen_at' => $this->frozenAt ?? now()->toIso8601String(),
'origin' => $this->origin,
];
}
/**
* @param array<string, mixed> $data
*/
public static function fromArray(array $data): self
{
return new self(
IntakeKind::tryFrom((string) ($data['intake'] ?? '')) ?? IntakeKind::Inquiry,
CaseType::tryFrom((string) ($data['case_type'] ?? '')) ?? CaseType::A1,
(array) ($data['values'] ?? []),
(array) ($data['sources'] ?? []),
isset($data['frozen_at']) ? (string) $data['frozen_at'] : null,
(string) ($data['origin'] ?? 'intake'),
);
}
public function withOrigin(string $origin): self
{
return new self($this->intake, $this->caseType, $this->values, $this->sources, $this->frozenAt, $origin);
}
}