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:
1 parent
799869c6a4
commit
ccac78a6c9
33 files changed
+1041
-47
No files matched your search
@@ -41,7 +41,7 @@ public function handle(Booking|BlockedPeriod $occupation, ?int $guestId, array $
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:255'],
|
||||
])->validate();
|
||||
$guest = new Guest([...$data, 'last_name' => $data['last_name'] ?? '', 'email' => filled($data['email'] ?? null) ? mb_strtolower(trim($data['email'])) : null, 'country' => $data['country'] ?? 'DE']);
|
||||
$guest = new Guest([...$data, 'last_name' => $data['last_name'] ?? '', 'email' => filled($data['email'] ?? null) ? mb_strtolower(trim($data['email'])) : null, 'country' => $data['country'] ?? null]);
|
||||
$guest->forceFill(['tenant_id' => $record->tenant_id])->save();
|
||||
}
|
||||
$record->forceFill(['guest_id' => $guest->id])->save();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
|
||||
@@ -58,6 +59,8 @@ public function blockers(Booking $booking): array
|
||||
}
|
||||
if (blank($booking->guest?->email)) {
|
||||
$reasons[] = 'Die E-Mail-Adresse des Gastes fehlt.';
|
||||
} elseif (! $information && ($missing = CaseRequirements::blocker($booking, CaseRequirements::OFFER)) !== null) {
|
||||
$reasons[] = $missing;
|
||||
}
|
||||
if (! $this->availability->isAvailable($property, $booking->arrival, $booking->departure, ignore: $booking)) {
|
||||
$reasons[] = 'Der Zeitraum ist inzwischen belegt.';
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\BookingTaskStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Events\CaseFactsContributed;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\CaseFact;
|
||||
use App\Models\Guest;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\CaseLog;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Process\FactContribution;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* The common fact intake of v0.11 (S5, CH-03, E-038). Every source – website form, the guest's link, an e-mail,
|
||||
* a portal mail, the extraction, the landlord – hands its details for a case to this one place:
|
||||
*
|
||||
* - a missing value is taken over, an equal one confirmed;
|
||||
* - a different contact or address value from the guest's side is never written over the stored one: it becomes a
|
||||
* conflict for the landlord (the guest record may belong to other cases too);
|
||||
* - the landlord's own entry is authoritative and replaces the value, the previous one stays in the evidence;
|
||||
* - dates and the number of guests are stay details: a differing value (and in a binding case also a missing one from
|
||||
* the guest's side) is only a change request for the landlord – nothing about the booking changes here;
|
||||
* - invalid values are rejected.
|
||||
*
|
||||
* Every detail is recorded with source and outcome. The same contribution again is harmless (idempotent). Afterwards
|
||||
* the existing process is asked once to carry on (S6); this intake decides nothing about offers or bookings.
|
||||
*/
|
||||
class ContributeCaseFacts
|
||||
{
|
||||
/** Stay details: never changed through the intake once known (P02/P03: change requests). */
|
||||
public const STAY_FIELDS = ['booking.guests', 'booking.arrival', 'booking.departure'];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $facts field key ({@see CaseRequirements::FIELDS} or OPTIONAL_FIELDS) => value
|
||||
* @param array{reference?: string, inbound_message_id?: int, evidence?: array<string, string>, confidence?: array<string, float>, actor?: string, advance?: bool} $options
|
||||
*/
|
||||
public function handle(Booking $booking, array $facts, FactSource $source, array $options = []): FactContribution
|
||||
{
|
||||
$known = [...CaseRequirements::FIELDS, ...CaseRequirements::OPTIONAL_FIELDS];
|
||||
$facts = array_filter(array_map(fn (mixed $value): mixed => is_string($value) ? trim($value) : $value, array_intersect_key($facts, $known)), fn (mixed $value): bool => $value !== null && $value !== '');
|
||||
if (isset($facts['guest.email'])) {
|
||||
$facts['guest.email'] = mb_strtolower((string) $facts['guest.email']);
|
||||
}
|
||||
if ($facts === []) {
|
||||
return new FactContribution;
|
||||
}
|
||||
|
||||
$actor = $options['actor'] ?? ($source === FactSource::Landlord ? (auth()->user()?->name ?? 'Vermieter') : CaseLog::GUEST);
|
||||
$reference = (string) ($options['reference'] ?? $options['inbound_message_id'] ?? '');
|
||||
|
||||
$contribution = DB::transaction(function () use ($booking, $facts, $source, $options, $actor, $reference): FactContribution {
|
||||
$booking->lockForTransition();
|
||||
$booking->load('guest');
|
||||
|
||||
$recorded = [];
|
||||
$guestChanges = [];
|
||||
$bookingChanges = [];
|
||||
foreach ($facts as $field => $value) {
|
||||
$value = is_scalar($value) ? (string) $value : json_encode($value);
|
||||
$fingerprint = hash('sha256', implode('|', [$booking->id, $source->value, $reference, $field, mb_strtolower($value)]));
|
||||
if (CaseFact::query()->withoutGlobalScopes()->where('booking_id', $booking->id)->where('fingerprint', $fingerprint)->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$current = CaseRequirements::value($booking, $field);
|
||||
$outcome = $this->outcome($booking, $field, $value, $current, $source);
|
||||
if ($outcome === CaseFact::APPLIED) {
|
||||
[$scope, $attribute] = explode('.', $field, 2);
|
||||
if ($scope === 'guest') {
|
||||
$guestChanges[$attribute] = $value;
|
||||
} else {
|
||||
$bookingChanges[$attribute] = $field === 'booking.guests' ? (int) $value : $value;
|
||||
}
|
||||
}
|
||||
|
||||
$recorded[] = new CaseFact([
|
||||
'booking_id' => $booking->id,
|
||||
'field' => $field,
|
||||
'value' => $value,
|
||||
'previous_value' => filled($current) ? (string) $current : null,
|
||||
'source' => $source,
|
||||
'inbound_message_id' => $options['inbound_message_id'] ?? null,
|
||||
'evidence' => $options['evidence'][$field] ?? null,
|
||||
'confidence' => $options['confidence'][$field] ?? null,
|
||||
'outcome' => $outcome,
|
||||
'fingerprint' => $fingerprint,
|
||||
'actor' => $actor,
|
||||
'created_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->applyGuest($booking, $guestChanges, $recorded, $source);
|
||||
if ($bookingChanges !== []) {
|
||||
$booking->update($bookingChanges);
|
||||
}
|
||||
|
||||
foreach ($recorded as $fact) {
|
||||
$fact->tenant_id = $booking->tenant_id;
|
||||
$fact->save();
|
||||
}
|
||||
|
||||
$contribution = new FactContribution($recorded);
|
||||
if (! $contribution->isEmpty()) {
|
||||
$this->openTasks($booking, $contribution, $source);
|
||||
CaseLog::record($booking, 'facts', 'Angaben von '.$source->getLabel().': '.$contribution->summary(), data: ['fields' => array_map(fn (CaseFact $fact): array => ['field' => $fact->field, 'outcome' => $fact->outcome], $recorded)], actor: $actor);
|
||||
}
|
||||
|
||||
return $contribution;
|
||||
});
|
||||
|
||||
if (! $contribution->isEmpty()) {
|
||||
$booking->refresh()->load('guest');
|
||||
event(new CaseFactsContributed($booking, $contribution, $source));
|
||||
|
||||
if ($contribution->anyApplied() && ($options['advance'] ?? true)) {
|
||||
app(CaseAutomation::class)->advance($booking);
|
||||
}
|
||||
}
|
||||
|
||||
return $contribution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase of the case for the rules (CH §1.4): binding (P3) or not.
|
||||
*/
|
||||
public static function isBinding(Booking $booking): bool
|
||||
{
|
||||
return in_array($booking->status, BookingStatus::occupying(), true);
|
||||
}
|
||||
|
||||
private function outcome(Booking $booking, string $field, string $value, mixed $current, FactSource $source): string
|
||||
{
|
||||
if (! CaseRequirements::isValid($field, $value)) {
|
||||
return CaseFact::REJECTED;
|
||||
}
|
||||
|
||||
$known = CaseRequirements::isValid($field, $current);
|
||||
if ($known && $this->same($field, $value, $current)) {
|
||||
return CaseFact::CONFIRMED;
|
||||
}
|
||||
|
||||
if (in_array($field, self::STAY_FIELDS, true)) {
|
||||
// A stay detail never changes through the intake. Only an unknown number of guests may be completed – by the
|
||||
// landlord or the portal's own message, or on a request that binds nobody yet.
|
||||
$completes = ! $known && ($source->isAuthoritative() || $source === FactSource::PortalMail || ! self::isBinding($booking));
|
||||
|
||||
return $completes ? CaseFact::APPLIED : CaseFact::CHANGE_REQUEST;
|
||||
}
|
||||
|
||||
if (! $known || $source->isAuthoritative()) {
|
||||
return CaseFact::APPLIED;
|
||||
}
|
||||
|
||||
return CaseFact::CONFLICT;
|
||||
}
|
||||
|
||||
private function same(string $field, string $value, mixed $current): bool
|
||||
{
|
||||
if ($field === 'booking.guests') {
|
||||
return (int) $value === (int) $current;
|
||||
}
|
||||
|
||||
return mb_strtolower(preg_replace('/\s+/', ' ', $value)) === mb_strtolower(preg_replace('/\s+/', ' ', trim((string) $current)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the taken-over guest details. A case without a guest gets a new guest record once a name is known; a
|
||||
* known e-mail address never joins another person's record silently (the landlord assigns it).
|
||||
*
|
||||
* @param array<string, string> $changes
|
||||
* @param list<CaseFact> $recorded
|
||||
*/
|
||||
private function applyGuest(Booking $booking, array $changes, array $recorded, FactSource $source): void
|
||||
{
|
||||
if ($changes === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($booking->guest !== null) {
|
||||
$booking->guest->update($changes);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$email = $changes['email'] ?? '';
|
||||
// The landlord knows whom he enters; any other source must not attach the case to somebody else's record.
|
||||
$taken = ! $source->isAuthoritative() && $email !== '' && Guest::query()->where('email', $email)->exists();
|
||||
if (blank($changes['first_name'] ?? null) || blank($changes['last_name'] ?? null) || $taken) {
|
||||
foreach ($recorded as $fact) {
|
||||
if ($fact->outcome === CaseFact::APPLIED && str_starts_with($fact->field, 'guest.')) {
|
||||
$fact->outcome = CaseFact::CONFLICT;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$guest = Guest::query()->create([...$changes, 'email' => $email, 'tenant_id' => $booking->tenant_id]);
|
||||
$booking->update(['guest_id' => $guest->id]);
|
||||
$booking->setRelation('guest', $guest);
|
||||
}
|
||||
|
||||
private function openTasks(Booking $booking, FactContribution $contribution, FactSource $source): void
|
||||
{
|
||||
if ($source->isAuthoritative()) {
|
||||
// The landlord's entry settles what was put to him for these details.
|
||||
BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::FactConflict)->where('status', BookingTaskStatus::Open)
|
||||
->whereIn('subject', array_map(fn (CaseFact $fact): string => $fact->field, $contribution->facts))
|
||||
->get()->each(fn (BookingTask $task): bool => $task->forceFill(['status' => BookingTaskStatus::Done, 'completed_at' => now(), 'completed_by' => auth()->user()?->name, 'note' => trim($task->note.' · von Ihnen entschieden')])->save());
|
||||
}
|
||||
|
||||
foreach ($contribution->facts as $fact) {
|
||||
if ($fact->outcome === CaseFact::CONFLICT) {
|
||||
BookingTask::openOnce($booking, BookingTaskKind::FactConflict, $fact->field, [
|
||||
'due_on' => today(),
|
||||
'note' => CaseRequirements::label($fact->field).' laut '.$source->getLabel().': „'.$fact->value.'“'.($fact->previous_value ? ' (bisher „'.$fact->previous_value.'“)' : ' (noch nicht eingetragen – Zuordnung prüfen)'),
|
||||
]);
|
||||
}
|
||||
if ($fact->outcome === CaseFact::CHANGE_REQUEST) {
|
||||
BookingTask::openOnce($booking, BookingTaskKind::ChangeRequest, $fact->field.':'.substr($fact->fingerprint, 0, 12), [
|
||||
'due_on' => today(),
|
||||
'note' => 'Gewünscht laut '.$source->getLabel().': '.CaseRequirements::label($fact->field).' „'.$fact->value.'“'.($fact->previous_value ? ' (gebucht: „'.$fact->previous_value.'“)' : '').'. Nichts wurde geändert – bitte über „Buchung ändern“ bzw. ein neues Angebot entscheiden.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Availability\AvailabilityChecker;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Mail\NewReservation;
|
||||
@@ -103,6 +104,16 @@ private function create(Property $property, StayRequest $stay, array $guestData,
|
||||
]);
|
||||
});
|
||||
|
||||
if ($source === 'website') {
|
||||
// Evidence of what the guest typed (v0.11, S5): completed fields are confirmed, differing ones go to the
|
||||
// landlord as a conflict instead of only a note. The guest record itself was already handled above.
|
||||
$facts = collect(Arr::only($guestData, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country']))
|
||||
->filter(fn (?string $value): bool => filled($value))
|
||||
->mapWithKeys(fn (string $value, string $field): array => ['guest.'.$field => $value])->all();
|
||||
app(ContributeCaseFacts::class)->handle($booking, $facts, FactSource::WebsiteForm, ['advance' => false, 'reference' => 'request']);
|
||||
$booking->refresh();
|
||||
}
|
||||
|
||||
if ($sendMails) {
|
||||
$this->sendMails($booking);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
use App\Models\BookingTask;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseLog;
|
||||
use App\Process\CaseRequirements;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -43,6 +44,10 @@ public function confirm(Booking $booking, bool $useTodaysPrice = false, bool $no
|
||||
if ($booking->status !== BookingStatus::Reserved || $booking->wish_at === null) {
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'als Buchungswunsch bestätigt');
|
||||
}
|
||||
// G2a also before the binding confirmation of a wish (v0.11, B3), by hand as well.
|
||||
if (($missing = CaseRequirements::blocker($booking->load('guest'), CaseRequirements::WISH_CONFIRMATION)) !== null) {
|
||||
throw new ReservationException($missing);
|
||||
}
|
||||
|
||||
if ($useTodaysPrice) {
|
||||
$quote = $this->offer->quoteFor($booking, new StayRequest($booking->arrival, $booking->departure, $booking->guests, $booking->extras ?? [], $booking->promo_code), (int) $booking->price_adjustment, (string) ($booking->price_adjustment_label ?: 'Zuschlag'));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\FactSource;
|
||||
use App\Enums\IntakeKind;
|
||||
use App\Enums\ProcessingMode;
|
||||
use App\Exceptions\ReservationException;
|
||||
@@ -41,15 +42,13 @@ public function handle(Booking $booking, array $contact, string $process = self:
|
||||
throw new ReservationException('Für den automatischen Ablauf wird die E-Mail-Adresse des Gastes benötigt.');
|
||||
}
|
||||
|
||||
if ($booking->guest === null) {
|
||||
if (blank($contact['first_name'] ?? null) || blank($contact['last_name'] ?? null)) {
|
||||
throw new ReservationException('Bitte Vor- und Nachnamen des Gastes angeben.');
|
||||
}
|
||||
$guest = Guest::query()->create([...array_filter($contact, fn ($value) => $value !== null), 'email' => $contact['email'] ?? '']);
|
||||
$booking->update(['guest_id' => $guest->id]);
|
||||
} else {
|
||||
$booking->guest->update(array_filter($contact, fn ($value) => $value !== null));
|
||||
if ($booking->guest === null && (blank($contact['first_name'] ?? null) || blank($contact['last_name'] ?? null))) {
|
||||
throw new ReservationException('Bitte Vor- und Nachnamen des Gastes angeben.');
|
||||
}
|
||||
|
||||
// The landlord's entry goes through the common fact intake (v0.11, S5): taken over with its source, the previous
|
||||
// value kept as evidence. Carrying on stays with the choice below.
|
||||
app(ContributeCaseFacts::class)->handle($booking, collect($contact)->mapWithKeys(fn (?string $value, string $field): array => ['guest.'.$field => $value])->all(), FactSource::Landlord, ['advance' => false, 'reference' => 'landlord:'.now()->getTimestampMs()]);
|
||||
if ($guestConfirmed) {
|
||||
$booking->forceFill(['guest_confirmed_at' => $booking->guest_confirmed_at ?? now()])->save();
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
use App\Pricing\QuoteLine;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseLog;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Support\Inbox;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -65,6 +66,11 @@ public function handle(Booking $booking, array $changes = [], bool $sendMail = t
|
||||
throw ReservationException::invalidTransition($booking->status->getLabel(), 'als Angebot versendet');
|
||||
}
|
||||
|
||||
// G2a (v0.11): never an own binding offer without the required details – not even confirmed by hand.
|
||||
if (($missing = CaseRequirements::blocker($booking->loadMissing('guest'), CaseRequirements::OFFER)) !== null) {
|
||||
throw new ReservationException($missing);
|
||||
}
|
||||
|
||||
$toConfirm = app(DocumentComposer::class)->compose($booking, DocumentKind::Offer, $changes)->toConfirm();
|
||||
if ($toConfirm !== [] && ! ($changes['acknowledged'] ?? false)) {
|
||||
throw new ReservationException('Bitte die Hinweise prüfen und ausdrücklich bestätigen: '.implode(' ', $toConfirm));
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\CaseLog;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Support\Inbox;
|
||||
use App\Support\Money;
|
||||
use App\Support\Settings;
|
||||
@@ -198,6 +199,9 @@ public function findings(Booking $booking, array $stale = []): array
|
||||
}
|
||||
|
||||
$findings = [...$findings, ...app(CaseAutomation::class)->documentBlockers($booking)];
|
||||
if (($missing = CaseRequirements::blocker($booking, CaseRequirements::WISH_CONFIRMATION)) !== null) {
|
||||
$findings[] = $missing;
|
||||
}
|
||||
if (! app(AutoOffer::class)->contractTextsReleased()) {
|
||||
$findings[] = 'Mietbedingungen, Stornobedingungen oder Bankverbindung sind noch nicht vom Betreiber freigegeben (leer oder Mustertext).';
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user