- 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>
139 lines
5.0 KiB
PHP
139 lines
5.0 KiB
PHP
<?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,
|
|
};
|
|
}
|
|
}
|