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

76 lines
2.7 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\Actions\AutoOffer;
use App\Actions\SendBookingDocuments;
use App\Enums\BookingStatus;
use App\Enums\IntakeKind;
use App\Enums\ProcessingMode;
use App\Enums\Responsibility;
use App\Models\Booking;
use Throwable;
/**
* Carries a case on by itself as far as its data allows – only when the case is handled automatically. What it may do
* is what the landlord would do next anyway: send the offer of a request, or send the documents of a binding booking
* once their composition is complete and needs no confirmation (template released and, for portal bookings, confirmed
* as the portal's terms). Whatever stops it is returned in plain
* words; the case then shows it as a task. Never touches a case whose profile was taken over from the old data (the
* automation did not exist for those cases before).
*/
class CaseAutomation
{
public function __construct(private AutoOffer $autoOffer, private SendBookingDocuments $documents) {}
/**
* @return list<string> what keeps the case from going on automatically (empty: nothing to do or done)
*/
public function advance(Booking $booking): array
{
$booking->loadMissing(['guest', 'property']);
if ($booking->processingMode() !== ProcessingMode::Automatic) {
return [];
}
try {
return CaseLog::context(fn (): array => $this->step($booking), actor: CaseLog::SYSTEM.' (automatisch)');
} catch (Throwable $exception) {
report($exception);
return ['Technischer Fehler beim automatischen Weiterbearbeiten – bitte von Hand fortsetzen.'];
}
}
/**
* @return list<string>
*/
private function step(Booking $booking): array
{
if ($booking->status === BookingStatus::Reserved && $booking->offer_version === 0 && $booking->intake !== IntakeKind::Booking) {
return $this->autoOffer->handle($booking);
}
if ($booking->isBinding() && $booking->confirmation_sent_at === null && $booking->process()->documents() === Responsibility::Landlord && $booking->process()->origin !== 'migration') {
return $this->documents->automatically($booking);
}
return [];
}
/**
* What is missing before the documents of a binding case can go to the guest.
*
* @return list<string>
*/
public function documentBlockers(Booking $booking): array
{
return array_values(array_filter([
$booking->guest === null ? 'Name und Kontaktdaten des Gastes fehlen.' : null,
$booking->guest !== null && blank($booking->guest->email) ? 'Die E-Mail-Adresse des Gastes fehlt.' : null,
$booking->total === null ? 'Der Gesamtpreis (laut Portal) fehlt.' : null,
]));
}
}