Files
fewo-stommer/app/Process/Modules/Offer/BindingOffer.php
T
LarsandClaude Sonnet 5.5 8442d0a3d8 V2.1: Kanalfähigkeiten, Ausführungsvarianten, Dokumentenentkopplung, Portalbestätigung
Modellwahl über Kanalfähigkeiten mit erklärten Einschränkungen, Abgleich alter Werte,
Ausführungsvarianten je Modul, getrennte Vertrags-/Buchungsinformation, Warten auf
die Portalbestätigung mit Eskalation und Wiederaufnahme (Fälle C und D getestet).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 07:54:11 +01:00

91 lines
4.4 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\Modules\Offer;
use App\Availability\AvailabilityChecker;
use App\Enums\ActivityState;
use App\Enums\BookingStatus;
use App\Enums\Execution;
use App\Enums\ProcessingMode;
use App\Enums\ProcessSetting;
use App\Process\Activity;
use App\Process\CaseContext;
use App\Process\CaseRequirements;
use App\Process\Modules\Dependency;
use App\Process\Modules\Module;
use App\Process\Modules\ModuleDefinition;
use App\Process\Modules\RunsAutomatically;
/**
* P02: our own binding offer with the contract draft (SendOffer, versioned). The price is fixed here – extension point
* BeforePriceFixing lies before it. Never without every required detail (hard dependency on guest.details) and never
* for dates that are taken.
*/
final class BindingOffer extends Module implements RunsAutomatically
{
use AnswersRequest;
public static function key(): string
{
return 'offer.binding';
}
public static function version(): int
{
// 2: dates taken meanwhile are a problem of the step, an expired hold is not shown as reserved (F-001, F-002).
return 2;
}
public static function definition(): ModuleDefinition
{
return new ModuleDefinition(
label: 'Verbindliches Angebot',
purpose: 'Erstellt das verbindliche Angebot mit Vertragsentwurf und sendet es dem Gast; der Zeitraum ist für die Haltefrist reserviert.',
phase: 'P02',
executions: [Execution::Automatic, Execution::Manual],
condition: 'bei einer Anfrage mit Reservierung',
why: 'Ohne verbindliches Angebot gibt es auf eigenem Weg keinen Vertrag (E-003).',
requires: [Dependency::hard('guest.details'), Dependency::hard('availability.check'), Dependency::soft('guest.data_request')],
effects: ['case_write', 'guest_mail', 'landlord_mail', 'document', 'calendar_hold', 'network'],
waits: ['guest', 'landlord'],
triggers: ['automation', 'request.created', 'schedule:bookings:auto-offers'],
parameters: [ProcessSetting::Processing, ProcessSetting::HoldHours, ProcessSetting::ContractTemplate],
performers: ['system', 'landlord'],
modes: ['automatic', 'manual'],
events: ['offer', 'hold', 'mail', 'status'],
);
}
/** The binding way: the request reserves (pre-reservation) or an offer was made anyway. */
public function applies(CaseContext $case): bool
{
return $case->inquiry && ! ($case->profile->preReservation() === false && $case->booking->offer_version === 0);
}
public function activities(CaseContext $case): array
{
$booking = $case->booking;
$offerDone = $booking->offer_version > 0 || $case->binding;
// G2a (v0.11): without every required detail there is no offer – the step waits for the guest's answer
// (mail, link or the landlord's entry) instead of being offered as the next step.
$offerMissing = $offerDone ? [] : CaseRequirements::missing($booking, CaseRequirements::OFFER);
$open = ! $offerDone && $offerMissing === [] && $booking->status === BookingStatus::Reserved && filled($booking->guest?->email);
$taken = $open && ! app(AvailabilityChecker::class)->isAvailable($booking->property, $booking->arrival, $booking->departure, ignore: $booking);
return [new Activity('offer', $booking->processingMode() === ProcessingMode::Automatic ? 'Angebot senden (automatisch)' : 'Angebot prüfen und senden', $case->later(match (true) {
$offerDone => ActivityState::Done,
$offerMissing !== [] => ActivityState::Later,
$taken => ActivityState::Problem,
$open => ActivityState::Open,
default => ActivityState::Later,
}), match (true) {
$booking->offer_version > 0 => 'Version '.$booking->offer_version.' vom '.$booking->offer_sent_at?->format('d.m.Y'),
$offerMissing !== [] => 'erst wenn alle Angaben da sind',
$taken => 'Der Zeitraum ist inzwischen belegt.',
$booking->isHoldActive() => 'Zeitraum reserviert bis '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr',
$booking->hold_expires_at !== null => 'Reservierung abgelaufen am '.$booking->hold_expires_at->format('d.m.Y, H:i').' Uhr – Zeitraum nicht reserviert',
default => null,
}, $offerDone || $offerMissing !== [] || $taken ? null : 'sendOffer')];
}
}