Files
fewo-stommer/app/Documents/DocumentComposition.php
T
LarsandClaude Opus 5.5 cf11c8a474
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m59s
Dokumentenzusammenstellung und Vorlagensteuerung (Paket 3, Prozessarchitektur v0.10)
Eine Zusammenstellung vor jedem Dokument (Angebot, Bestaetigung, Buchungsunterlagen
extern), Dokumentart je Vorgangsart, Freigaben fuer Vorlagen und Dokumentarten,
Schutz vor unvereinbarten Bedingungen bei Portalbuchungen (E-004), kein doppelter
Versand, Absicherung Hold 0 bis Paket 7, A6-Aufenthaltsbestaetigung vorbereitet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 19:44:52 +01:00

130 lines
4.2 KiB
PHP

<?php
namespace App\Documents;
use App\Enums\DocumentKind;
use App\Models\Booking;
use App\Models\ContractTemplate;
/**
* Everything a document of a case consists of before it is sent (UMSETZUNGSPLAN_v0.10 §4.5): recipient, stay, how the
* case came in, price with its origin, services, cancellation rule, template and annexes, and what has to be checked.
* The same composition is shown to the landlord, decides whether the automatic run may send, and is what is sent.
*/
final class DocumentComposition
{
/**
* @param Booking $draft the case as the document will show it (never saved)
* @param list<array{label: string, amount: int}> $priceLines
* @param list<string> $services
* @param list<string> $cancellation
* @param list<array{id: int, label: string}> $annexes
* @param array<string, mixed>|null $terms the terms the document freezes (null: the website texts apply live)
* @param list<DocumentFinding> $findings
*/
public function __construct(
public readonly DocumentKind $kind,
public readonly Booking $draft,
public readonly string $intakeLabel,
public readonly array $priceLines,
public readonly string $priceSource,
public readonly array $services,
public readonly array $cancellation,
public readonly ?ContractTemplate $template,
public readonly string $templateSource,
public readonly array $annexes,
public readonly ?array $terms,
public readonly bool $termsFrozen,
public readonly array $findings,
) {}
public function recipientName(): ?string
{
return $this->draft->guest?->full_name;
}
public function recipientEmail(): ?string
{
return filled($this->draft->guest?->email) ? $this->draft->guest->email : null;
}
/**
* @return list<string>
*/
public function blockers(): array
{
return $this->messages(DocumentFinding::BLOCKER);
}
/**
* @param list<string> $except codes of findings left out
* @return list<string>
*/
public function toConfirm(array $except = []): array
{
return $this->messages(DocumentFinding::CONFIRM, $except);
}
/**
* @return list<string>
*/
public function information(): array
{
return $this->messages(DocumentFinding::INFO);
}
/**
* The automatic run sends only a document without blockers and without anything the landlord has to confirm.
*/
public function canSendAutomatically(): bool
{
return $this->blockers() === [] && $this->toConfirm() === [];
}
/**
* By hand: no blockers, and every point to confirm was confirmed.
*/
public function canSendByHand(bool $acknowledged): bool
{
return $this->blockers() === [] && ($this->toConfirm() === [] || $acknowledged);
}
/**
* The template as the landlord reads it.
*/
public function templateLabel(): string
{
if ($this->terms !== null && isset($this->terms['template']['name'])) {
return $this->terms['template']['name'].' (Version '.$this->terms['template']['version'].')';
}
return $this->template?->label() ?? 'Texte der Webseite';
}
/**
* What is stored about the document in the case history.
*
* @return array<string, mixed>
*/
public function record(): array
{
return [
'kind' => $this->kind->value,
'template' => $this->terms['template'] ?? null,
'annexes' => array_map(fn (array $annex): string => $annex['label'], $this->annexes),
'recipient' => $this->recipientEmail(),
'total' => $this->draft->total,
'price_source' => $this->priceSource,
];
}
/**
* @param list<string> $except
* @return list<string>
*/
private function messages(string $severity, array $except = []): array
{
return array_values(array_map(fn (DocumentFinding $finding): string => $finding->message, array_filter($this->findings, fn (DocumentFinding $finding): bool => $finding->severity === $severity && ! in_array($finding->code, $except, true))));
}
}