CaseActivities/CaseAutomation sind Fassaden über ProcessRunner. Verhaltensvergleich v0.11: 11 Abläufe und 198 Konstellationen gleich, beabsichtigte Abweichungen I-004/I-005 (F-001/F-002). Volle Suite vor U-B: 785/785. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
4.1 KiB
PHP
87 lines
4.1 KiB
PHP
<?php
|
||
|
||
namespace App\Process\Modules\Offer;
|
||
|
||
use App\Availability\AvailabilityChecker;
|
||
use App\Enums\ActivityState;
|
||
use App\Enums\BookingStatus;
|
||
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',
|
||
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')];
|
||
}
|
||
}
|