v0.11 U2: Angebots-Gate, gemeinsamer Fakteneingang mit Herkunft

- CaseRequirements: Vor einem eigenen verbindlichen Angebot und vor der
  verbindlichen Bestätigung eines Buchungswunsches müssen Vor- und
  Nachname, E-Mail, vollständige Anschrift mit Land, Personenzahl und
  Zeitraum vorliegen – harter Blocker, auch von Hand (G2a, B3). Die
  Auskunft unter Vorbehalt bleibt ohne dieses Gate.
- ContributeCaseFacts (S5): jede Angabe mit Herkunft und Ergebnis in
  case_facts; fehlend → übernommen, gleich → bestätigt, abweichend vom
  Gast → Prüfaufgabe (Kartei bleibt), Vermieterin maßgeblich, Zeitraum und
  Personen → Änderungswunsch; idempotent; danach einmal CaseAutomation.
- ProvideGuestContact und Webformular nutzen den Fakteneingang.
- Land als ISO-Code mit „Deutschland“ als änderbarem Formularstandard;
  guests.country ohne stillen Standardwert (B4).
- Testdaten bestehender Tests um Anschriften ergänzt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-03 13:07:18 +01:00
1 parent 799869c6a4
commit ccac78a6c9
33 files changed
+1041 -47

No files matched your search

+21 -5
View File
@@ -64,14 +64,29 @@ public static function for(Booking $booking): array
$needsContact = $inquiry || $profile->documents() === Responsibility::Landlord || $profile->guestMessages() === Responsibility::Landlord || $profile->payments() === Responsibility::Landlord;
if ($needsContact) {
$hasEmail = filled($booking->guest?->email);
// v0.11 (G2a): before the own binding offer – or the binding confirmation of a wish – every required detail.
$action = $profile->preReservation() || $booking->offer_version > 0 ? CaseRequirements::OFFER : CaseRequirements::WISH_CONFIRMATION;
$needsDetails = $inquiry && ! $binding && $booking->offer_version === 0 && ($action === CaseRequirements::OFFER || $booking->wish_at !== null);
$missing = $hasEmail && $needsDetails ? CaseRequirements::missing($booking, $action) : [];
$asked = $booking->contact_requested_at !== null;
$state = match (true) {
$hasEmail => ActivityState::Done,
$booking->contact_requested_at !== null => ActivityState::Waiting,
$hasEmail && $missing === [] => ActivityState::Done,
$asked => ActivityState::Waiting,
default => ActivityState::Open,
};
$activities[] = new Activity('contact', $booking->guest === null ? 'Name und Kontaktdaten des Gastes eintragen' : 'E-Mail-Adresse des Gastes eintragen', $later($state),
$hasEmail ? $booking->guestName() : ($booking->contact_requested_at ? 'beim Gast erfragt am '.$booking->contact_requested_at->format('d.m.Y') : 'fehlt noch'),
$hasEmail ? null : 'provideContact');
$title = match (true) {
$booking->guest === null => 'Name und Kontaktdaten des Gastes eintragen',
! $hasEmail => 'E-Mail-Adresse des Gastes eintragen',
$missing !== [] => $action === CaseRequirements::OFFER ? 'Angaben für das Angebot vervollständigen' : 'Angaben für die Bestätigung vervollständigen',
default => 'Kontaktdaten des Gastes',
};
$detail = match (true) {
$state === ActivityState::Done => $booking->guestName(),
$missing !== [] => 'fehlt: '.implode(', ', CaseRequirements::labels($missing)).($asked ? ' · beim Gast angefragt' : ''),
$booking->contact_requested_at !== null => 'beim Gast erfragt am '.$booking->contact_requested_at->format('d.m.Y'),
default => 'fehlt noch',
};
$activities[] = new Activity('contact', $title, $later($state), $detail, $state === ActivityState::Done ? null : 'provideContact');
}
if ($inquiry && ! $profile->preReservation() && $booking->offer_version === 0) {
@@ -322,6 +337,7 @@ private static function task(BookingTask $task): Activity
BookingTaskKind::BookingWish => 'decideWish',
BookingTaskKind::ArrivalDetails => 'arrivalDetails',
BookingTaskKind::CancellationRequest => 'end',
BookingTaskKind::FactConflict => 'provideContact',
default => $task->kind->isPayment() ? null : 'completeTask',
};
$today = CarbonImmutable::today();
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace App\Process;
use App\Models\Booking;
/**
* The details a case needs before an action (v0.11, G2a / E-032 / CH §1.3). The one place that knows the required
* details: before an own binding offer and before the binding confirmation of a booking wish the contracting party's
* first and last name, e-mail, full postal address including the country, the number of guests and the dates must be
* there. The information "unter Vorbehalt" needs none of them beyond what it needs today (B3). A missing address is
* a blocker that cannot be confirmed away.
*
* A pre-filled country of a form counts only when the guest sent it (B4); an empty field is never assumed.
*/
final class CaseRequirements
{
/** Own binding offer (A1/A2). */
public const OFFER = 'offer';
/** Binding confirmation of a booking wish after an information without hold (package 7). */
public const WISH_CONFIRMATION = 'wish_confirmation';
/** @var array<string, string> field key => label */
public const FIELDS = [
'guest.first_name' => 'Vorname',
'guest.last_name' => 'Nachname',
'guest.email' => 'E-Mail-Adresse',
'guest.street' => 'Straße und Hausnummer',
'guest.postal_code' => 'PLZ',
'guest.city' => 'Ort',
'guest.country' => 'Land',
'booking.guests' => 'Personenzahl',
'booking.arrival' => 'Anreise',
'booking.departure' => 'Abreise',
];
/** Fields the guest can give for a case (contact and stay details beyond the required ones). */
public const OPTIONAL_FIELDS = [
'guest.phone' => 'Telefon',
'booking.arrival_time' => 'Voraussichtliche Anreisezeit',
];
/**
* Required fields of the action that are missing or not valid.
*
* @return list<string> field keys of {@see self::FIELDS}
*/
public static function missing(Booking $booking, string $action = self::OFFER): array
{
$missing = [];
foreach (array_keys(self::FIELDS) as $field) {
if (! self::isValid($field, self::value($booking, $field))) {
$missing[] = $field;
}
}
return $missing;
}
public static function isComplete(Booking $booking, string $action = self::OFFER): bool
{
return self::missing($booking, $action) === [];
}
/**
* The blocker text for the action, or null when nothing is missing.
*/
public static function blocker(Booking $booking, string $action = self::OFFER): ?string
{
$missing = self::missing($booking, $action);
if ($missing === []) {
return null;
}
$what = $action === self::WISH_CONFIRMATION ? 'die verbindliche Bestätigung' : 'ein verbindliches Angebot';
return 'Für '.$what.' fehlen noch Angaben: '.implode(', ', self::labels($missing)).'.';
}
/**
* Whether an incomplete request may get the clarification hold (V1, E-033): property, unambiguous dates and an
* e-mail address that can be written to. The free calendar is checked by the caller.
*/
public static function qualifiesForClarificationHold(Booking $booking): bool
{
return $booking->property_id !== null
&& $booking->arrival !== null && $booking->departure !== null && $booking->departure->greaterThan($booking->arrival)
&& self::isValid('guest.email', $booking->guest?->email);
}
/**
* @param list<string> $fields
* @return list<string>
*/
public static function labels(array $fields): array
{
return array_map(fn (string $field): string => self::FIELDS[$field] ?? self::OPTIONAL_FIELDS[$field] ?? $field, $fields);
}
public static function label(string $field): string
{
return self::labels([$field])[0];
}
/**
* Current value of a field of the case (guest fields from the guest record).
*/
public static function value(Booking $booking, string $field): mixed
{
[$scope, $attribute] = explode('.', $field, 2);
$value = $scope === 'guest' ? $booking->guest?->{$attribute} : $booking->{$attribute};
return $value instanceof \DateTimeInterface ? $value->format('Y-m-d') : $value;
}
/**
* Whether a value is usable for the field.
*/
public static function isValid(string $field, mixed $value): bool
{
if (is_string($value)) {
$value = trim($value);
}
if ($value === null || $value === '') {
return false;
}
return match ($field) {
'guest.email' => filter_var($value, FILTER_VALIDATE_EMAIL) !== false,
'guest.postal_code' => (bool) preg_match('/^[A-Za-z0-9][A-Za-z0-9 \-]{1,9}$/', (string) $value),
'guest.country' => (bool) preg_match('/^[A-Z]{2}$/', (string) $value),
'booking.guests' => is_numeric($value) && (int) $value >= 1,
'booking.arrival', 'booking.departure' => strtotime((string) $value) !== false,
default => mb_strlen((string) $value) >= 1,
};
}
}
+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Process;
use App\Models\CaseFact;
/**
* What became of the details given for a case in one contribution (v0.11, S5).
*/
final class FactContribution
{
/**
* @param list<CaseFact> $facts recorded facts (duplicates of an earlier contribution are not recorded again)
*/
public function __construct(public readonly array $facts = []) {}
/**
* @return list<string> field keys with the given outcome
*/
public function fields(string $outcome): array
{
return array_values(array_map(fn (CaseFact $fact): string => $fact->field, array_filter($this->facts, fn (CaseFact $fact): bool => $fact->outcome === $outcome)));
}
public function anyApplied(): bool
{
return $this->fields(CaseFact::APPLIED) !== [];
}
public function needsReview(): bool
{
return $this->fields(CaseFact::CONFLICT) !== [] || $this->fields(CaseFact::CHANGE_REQUEST) !== [];
}
public function isEmpty(): bool
{
return $this->facts === [];
}
/**
* Plain words for the landlord, e.g. for a notification.
*/
public function summary(): string
{
$parts = [];
foreach ([CaseFact::APPLIED => 'übernommen', CaseFact::CONFIRMED => 'bestätigt', CaseFact::CONFLICT => 'weichen ab (zur Prüfung)', CaseFact::CHANGE_REQUEST => 'Änderungswunsch (zur Prüfung)', CaseFact::REJECTED => 'nicht verwendbar'] as $outcome => $label) {
$fields = $this->fields($outcome);
if ($fields !== []) {
$parts[] = implode(', ', CaseRequirements::labels($fields)).' '.$label;
}
}
return $parts === [] ? 'Keine neuen Angaben.' : implode(' · ', $parts);
}
}