Files
fewo-stommer/app/Process/CaseAutomation.php
LarsandClaude Opus 5.5 40d20cb7d1 Pakete 7 und 9: Auskunft und Buchungswunsch, Aufenthalt und Abschluss (Zwischenstand)
- Haltefrist 0: unverbindliche Auskunft mit signiertem Link "Buchung anfragen",
  erneute Prüfung unter Sperre, automatische oder manuelle Bestätigung, Absage
  bei vergebenem Zeitraum, Ablauf unbeantworteter Auskünfte
- Aufenthalt: Anreisedaten, Aufgaben je Wohnung, gebuchte Leistungen,
  Abweichungen und Folgeaufgaben als Aufgaben am Vorgang
- Abschluss getrennt: Aufenthalt abgeschlossen / kaufmännisch abgeschlossen,
  Nachläufer (Forderung, Auszahlung) bleiben sichtbar
- Zahlungsstatus nur aus Geld auf unserem Konto; Altbestand per Vorschau-Befehl
- Verlauf weist Testzustellungen als solche aus
- Abnahmetests T16-T25, T23 über isolierten SMTP-Empfänger

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

76 lines
2.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\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->information_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,
]));
}
}