Files
fewo-stommer/app/Process/ProcessProfile.php
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

168 lines
5.8 KiB
PHP
Raw Permalink 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';
/** Fixed by the case type (A6), not settable. */
public const CASE_TYPE = 'case_type';
/** 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',
self::CASE_TYPE => 'fest für diese Vorgangsart',
'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);
}
}