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).';
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Process\ProcessProfile;
|
||||
use App\Process\ProcessSettings;
|
||||
use App\Support\Money;
|
||||
@@ -194,6 +195,11 @@ private function commonFindings(Booking $booking, Booking $draft, DocumentKind $
|
||||
} elseif (blank($draft->guest->email)) {
|
||||
$findings[] = DocumentFinding::blocker('Die E-Mail-Adresse des Gastes fehlt.');
|
||||
}
|
||||
// G2a (v0.11, E-032): an own binding offer needs the contracting party's name, e-mail, full address with country,
|
||||
// the number of guests and the dates – a hard blocker, also by hand. The information "unter Vorbehalt" does not (B3).
|
||||
if ($kind === DocumentKind::Offer && $draft->guest !== null && ($missing = CaseRequirements::blocker($draft, CaseRequirements::OFFER)) !== null) {
|
||||
$findings[] = DocumentFinding::blocker($missing);
|
||||
}
|
||||
if (! in_array($kind, [DocumentKind::Offer, DocumentKind::Information], true) && $booking->total === null) {
|
||||
$findings[] = DocumentFinding::blocker($booking->intake === IntakeKind::Booking ? 'Der Gesamtpreis (laut Portal) fehlt.' : 'Der Preis fehlt.');
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ enum BookingTaskKind: string implements HasLabel
|
||||
case FollowUp = 'follow_up';
|
||||
case PayoutCheck = 'payout_check';
|
||||
case OpenClaim = 'open_claim';
|
||||
case FactConflict = 'fact_conflict';
|
||||
case ChangeRequest = 'change_request';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
@@ -51,6 +53,8 @@ public function getLabel(): string
|
||||
self::FollowUp => 'Folgeaufgabe',
|
||||
self::PayoutCheck => 'Auszahlung des Portals prüfen',
|
||||
self::OpenClaim => 'Offenen Betrag nach der Abreise klären',
|
||||
self::FactConflict => 'Abweichende Angabe des Gastes prüfen',
|
||||
self::ChangeRequest => 'Änderungswunsch des Gastes prüfen',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
/**
|
||||
* Where a detail of a case came from (v0.11 common fact intake, S5).
|
||||
*/
|
||||
enum FactSource: string implements HasLabel
|
||||
{
|
||||
case WebsiteForm = 'website_form';
|
||||
case GuestLink = 'guest_link';
|
||||
case Email = 'email';
|
||||
case PortalMail = 'portal_mail';
|
||||
case Extraction = 'llm';
|
||||
case Landlord = 'landlord';
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::WebsiteForm => 'Anfrageformular der Webseite',
|
||||
self::GuestLink => 'Gast über den Ergänzungslink',
|
||||
self::Email => 'E-Mail des Gastes',
|
||||
self::PortalMail => 'Portal-Mail',
|
||||
self::Extraction => 'aus einer Nachricht erkannt (KI)',
|
||||
self::Landlord => 'von Ihnen eingetragen',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The landlord's own entry is authoritative; every other source only completes or is put to the landlord.
|
||||
*/
|
||||
public function isAuthoritative(): bool
|
||||
{
|
||||
return $this === self::Landlord;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Enums\FactSource;
|
||||
use App\Models\Booking;
|
||||
use App\Process\FactContribution;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
|
||||
/**
|
||||
* Details arrived for a case and went through the common fact intake (after the commit). The data request of the
|
||||
* case listens to stop reminders or to plan a follow-up question (CH-17).
|
||||
*/
|
||||
class CaseFactsContributed
|
||||
{
|
||||
use Dispatchable;
|
||||
|
||||
public function __construct(
|
||||
public readonly Booking $booking,
|
||||
public readonly FactContribution $contribution,
|
||||
public readonly FactSource $source,
|
||||
) {}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ protected function handleRecordCreation(array $data): Model
|
||||
$channel = filled($data['channel_id'] ?? null) ? Channel::query()->findOrFail($data['channel_id']) : null;
|
||||
$arrival = CarbonImmutable::parse($data['arrival']);
|
||||
$departure = CarbonImmutable::parse($data['departure']);
|
||||
$guest = Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']);
|
||||
$guest = Arr::only($data, ['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country']);
|
||||
|
||||
if ($data['kind'] === BookingForm::EXTERNAL) {
|
||||
return app(TakeOverExternalBooking::class)->handle($property, $channel, $arrival, $departure, [
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
use App\Process\CaseActivities;
|
||||
use App\Process\CaseAutomation;
|
||||
use App\Process\CaseLog;
|
||||
use App\Support\Countries;
|
||||
use App\Support\Money;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Filament\Actions\Action;
|
||||
@@ -291,10 +292,10 @@ private function provideContactAction(): Action
|
||||
->icon(Heroicon::OutlinedUserPlus)
|
||||
->visible(fn (): bool => $this->record->internal_kind !== InternalKind::Block && ! in_array($this->record->status, [BookingStatus::Cancelled, BookingStatus::Declined, BookingStatus::Expired], true))
|
||||
->modalHeading('Kontaktdaten des Gastes')
|
||||
->modalDescription('Aus Portalnachricht, E-Mail oder Telefonat. Nur eintragen, was bekannt ist.')
|
||||
->modalDescription(fn (): string => 'Aus Portalnachricht, E-Mail oder Telefonat. Nur eintragen, was bekannt ist.'.$this->openFactConflicts())
|
||||
->modalWidth('3xl')
|
||||
->fillForm(fn (): array => [
|
||||
'guest' => $this->record->guest?->only(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city']) ?? [],
|
||||
'guest' => $this->record->guest?->only(['first_name', 'last_name', 'email', 'phone', 'street', 'postal_code', 'city', 'country']) ?? [],
|
||||
'process' => $this->record->processingMode() === ProcessingMode::Automatic ? ProvideGuestContact::AUTOMATIC : ProvideGuestContact::MANUAL,
|
||||
'guest_confirmed' => $this->record->guest_confirmed_at !== null,
|
||||
])
|
||||
@@ -307,6 +308,7 @@ private function provideContactAction(): Action
|
||||
TextInput::make('guest.street')->label('Straße und Hausnummer')->maxLength(150),
|
||||
TextInput::make('guest.postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('guest.city')->label('Ort')->maxLength(100),
|
||||
Select::make('guest.country')->label('Land')->options(Countries::options())->placeholder('nicht bekannt'),
|
||||
]),
|
||||
Section::make('Wie geht es danach weiter?')->schema([
|
||||
Radio::make('process')->hiddenLabel()->options([
|
||||
@@ -331,6 +333,16 @@ private function provideContactAction(): Action
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Details from the guest's side that differ from the stored ones (v0.11 fact intake), for the contact dialog.
|
||||
*/
|
||||
private function openFactConflicts(): string
|
||||
{
|
||||
$notes = $this->record->tasks()->where('kind', BookingTaskKind::FactConflict)->where('status', BookingTaskStatus::Open)->pluck('note')->all();
|
||||
|
||||
return $notes === [] ? '' : ' Abweichende Angaben des Gastes – bitte den richtigen Wert eintragen: '.implode(' · ', $notes);
|
||||
}
|
||||
|
||||
private function requestContactAction(): Action
|
||||
{
|
||||
return Action::make('requestContact')
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
use App\Models\Channel;
|
||||
use App\Models\Extra;
|
||||
use App\Models\Property;
|
||||
use App\Support\Countries;
|
||||
use App\Support\CurrentProperty;
|
||||
use App\Support\Money;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
@@ -140,6 +141,7 @@ public static function configure(Schema $schema): Schema
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
Select::make('country')->label('Land')->options(Countries::options())->placeholder('nicht bekannt'),
|
||||
Toggle::make('guest_confirmed')->label('Der Gast hat die Buchung bereits per E-Mail bestätigt')->visible($is(self::EXTERNAL)),
|
||||
]),
|
||||
Section::make('Wie geht es weiter?')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
use App\Pricing\QuoteException;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\ProcessSettings;
|
||||
use App\Support\Countries;
|
||||
use App\Tenancy\TenantContext;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -64,6 +65,9 @@ class BookingRequest extends Component
|
||||
|
||||
public string $city = '';
|
||||
|
||||
/** Pre-filled but changeable; it only counts because the guest sends it with the form (B4). */
|
||||
public string $country = Countries::DEFAULT;
|
||||
|
||||
public string $message = '';
|
||||
|
||||
public bool $privacyAccepted = false;
|
||||
@@ -105,6 +109,16 @@ public function property(): Property
|
||||
return Property::findOrFail($this->propertyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the full address must be given in the form (channel manager, website entry; default: no – missing
|
||||
* details are asked for afterwards, v0.11 B2).
|
||||
*/
|
||||
#[Computed]
|
||||
public function requiresAddress(): bool
|
||||
{
|
||||
return app(ProcessSettings::class)->forWebsite($this->property)->formRequiresAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a request on the website reserves the dates (else it is answered with an information, package 7).
|
||||
*/
|
||||
@@ -261,6 +275,7 @@ public function submit(CreateReservation $createReservation): void
|
||||
'street' => $this->street ?: null,
|
||||
'postal_code' => $this->postalCode ?: null,
|
||||
'city' => $this->city ?: null,
|
||||
'country' => $this->country ?: null,
|
||||
],
|
||||
$this->message ?: null,
|
||||
attribution: [...$this->utm, 'referral_source' => $this->referralSource ?: null],
|
||||
@@ -328,9 +343,10 @@ protected function rules(): array
|
||||
'lastName' => ['required', 'string', 'max:255', 'not_regex:/https?:|www\.|<|>/i'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'street' => ['nullable', 'string', 'max:255'],
|
||||
'postalCode' => ['nullable', 'string', 'max:20'],
|
||||
'city' => ['nullable', 'string', 'max:255'],
|
||||
'street' => [$this->requiresAddress() ? 'required' : 'nullable', 'string', 'max:255'],
|
||||
'postalCode' => [$this->requiresAddress() ? 'required' : 'nullable', 'string', 'max:20'],
|
||||
'city' => [$this->requiresAddress() ? 'required' : 'nullable', 'string', 'max:255'],
|
||||
'country' => [$this->requiresAddress() ? 'required' : 'nullable', Rule::in(array_keys(Countries::options()))],
|
||||
'message' => ['nullable', 'string', 'max:5000', function (string $attribute, mixed $value, \Closure $fail): void {
|
||||
if (preg_match_all('~https?://|www\.~i', (string) $value) > config('fewo.spam.max_links')) {
|
||||
$fail('Bitte schreiben Sie Ihre Nachricht ohne Links.');
|
||||
@@ -353,6 +369,10 @@ protected function validationAttributes(): array
|
||||
'firstName' => 'Vorname',
|
||||
'lastName' => 'Nachname',
|
||||
'email' => 'E-Mail',
|
||||
'street' => 'Straße & Hausnr.',
|
||||
'postalCode' => 'PLZ',
|
||||
'city' => 'Ort',
|
||||
'country' => 'Land',
|
||||
'privacyAccepted' => 'Datenschutzerklärung',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\FactSource;
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* One detail that arrived for a case, with its source and what became of it (v0.11, S5). Only appended, never
|
||||
* changed: the evidence behind the values in guests and bookings.
|
||||
*/
|
||||
#[Fillable(['booking_id', 'field', 'value', 'previous_value', 'source', 'inbound_message_id', 'evidence', 'confidence', 'outcome', 'fingerprint', 'actor', 'created_at'])]
|
||||
class CaseFact extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
public const APPLIED = 'applied';
|
||||
|
||||
public const CONFIRMED = 'confirmed';
|
||||
|
||||
public const CONFLICT = 'conflict';
|
||||
|
||||
public const CHANGE_REQUEST = 'change_request';
|
||||
|
||||
public const REJECTED = 'rejected';
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'value' => 'encrypted',
|
||||
'previous_value' => 'encrypted',
|
||||
'evidence' => 'encrypted',
|
||||
'source' => FactSource::class,
|
||||
'confidence' => 'float',
|
||||
'created_at' => 'immutable_datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Booking, $this>
|
||||
*/
|
||||
public function booking(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Booking::class);
|
||||
}
|
||||
|
||||
public function outcomeLabel(): string
|
||||
{
|
||||
return match ($this->outcome) {
|
||||
self::APPLIED => 'übernommen',
|
||||
self::CONFIRMED => 'bestätigt (gleicher Wert)',
|
||||
self::CONFLICT => 'weicht ab – zur Prüfung',
|
||||
self::CHANGE_REQUEST => 'Änderungswunsch – zur Prüfung',
|
||||
default => 'nicht verwendbar',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* Countries guests usually come from, as ISO 3166-1 alpha-2 codes (the guest record stores the code). Forms may
|
||||
* pre-select Germany; it counts as given only because the guest or the landlord sends it (v0.11 B4).
|
||||
*/
|
||||
class Countries
|
||||
{
|
||||
public const DEFAULT = 'DE';
|
||||
|
||||
/**
|
||||
* @return array<string, string> code => name
|
||||
*/
|
||||
public static function options(): array
|
||||
{
|
||||
return [
|
||||
'DE' => 'Deutschland',
|
||||
'AT' => 'Österreich',
|
||||
'CH' => 'Schweiz',
|
||||
'NL' => 'Niederlande',
|
||||
'BE' => 'Belgien',
|
||||
'LU' => 'Luxemburg',
|
||||
'DK' => 'Dänemark',
|
||||
'SE' => 'Schweden',
|
||||
'NO' => 'Norwegen',
|
||||
'FI' => 'Finnland',
|
||||
'PL' => 'Polen',
|
||||
'CZ' => 'Tschechien',
|
||||
'FR' => 'Frankreich',
|
||||
'IT' => 'Italien',
|
||||
'ES' => 'Spanien',
|
||||
'GB' => 'Vereinigtes Königreich',
|
||||
'IE' => 'Irland',
|
||||
'US' => 'Vereinigte Staaten',
|
||||
];
|
||||
}
|
||||
|
||||
public static function name(?string $code): ?string
|
||||
{
|
||||
return $code === null ? null : (self::options()[$code] ?? $code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Prozessarchitektur v0.11, common fact intake (S5, CH-03): every detail that arrives for a case – from the website
|
||||
* form, the guest's link, an e-mail, a portal mail, the extraction or the landlord – is recorded with its source and
|
||||
* what became of it (taken over, confirmed, conflict, change request, rejected). The data itself stays in guests and
|
||||
* bookings; this is the evidence. Bookings get the purpose of their hold (offer as before, or clarification).
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('case_facts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_id')->nullable()->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('booking_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('field', 60);
|
||||
$table->text('value')->nullable();
|
||||
$table->text('previous_value')->nullable();
|
||||
$table->string('source', 30);
|
||||
$table->unsignedBigInteger('inbound_message_id')->nullable()->index();
|
||||
$table->text('evidence')->nullable();
|
||||
$table->decimal('confidence', 4, 3)->nullable();
|
||||
$table->string('outcome', 20);
|
||||
$table->string('fingerprint', 64);
|
||||
$table->string('actor')->nullable();
|
||||
$table->dateTime('created_at');
|
||||
|
||||
$table->index(['booking_id', 'field']);
|
||||
$table->index(['booking_id', 'fingerprint']);
|
||||
});
|
||||
|
||||
Schema::table('bookings', function (Blueprint $table) {
|
||||
$table->string('hold_purpose', 20)->default('offer')->after('hold_expires_at');
|
||||
});
|
||||
|
||||
// B4: the country is never assumed. New guests have none until a source names it (existing values stay, they
|
||||
// cannot be told apart from confirmed ones).
|
||||
Schema::table('guests', function (Blueprint $table) {
|
||||
$table->string('country', 2)->nullable()->default(null)->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('guests', function (Blueprint $table) {
|
||||
$table->string('country', 2)->default('DE')->change();
|
||||
});
|
||||
|
||||
Schema::table('bookings', function (Blueprint $table) {
|
||||
$table->dropColumn('hold_purpose');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('case_facts');
|
||||
}
|
||||
};
|
||||
@@ -168,9 +168,9 @@
|
||||
['lastName', 'Nachname', 'text', 'family-name', true],
|
||||
['email', 'E-Mail', 'email', 'email', true],
|
||||
['phone', 'Telefon', 'tel', 'tel', false],
|
||||
['street', 'Straße & Hausnr.', 'text', 'street-address', false],
|
||||
['postalCode', 'PLZ', 'text', 'postal-code', false],
|
||||
['city', 'Ort', 'text', 'address-level2', false],
|
||||
['street', 'Straße & Hausnr.', 'text', 'street-address', $this->requiresAddress],
|
||||
['postalCode', 'PLZ', 'text', 'postal-code', $this->requiresAddress],
|
||||
['city', 'Ort', 'text', 'address-level2', $this->requiresAddress],
|
||||
] as [$field, $label, $type, $autocomplete, $required])
|
||||
<label class="block text-sm" wire:key="field-{{ $field }}">
|
||||
<span class="font-medium text-ink">{{ $label }}@if ($required)<span class="text-rose-600" aria-hidden="true"> *</span>@endif</span>
|
||||
@@ -180,6 +180,15 @@ class="mt-1 w-full rounded-lg border-line">
|
||||
@error($field) <span id="{{ $field }}-error" class="mt-1 block text-xs text-rose-700">{{ $message }}</span> @enderror
|
||||
</label>
|
||||
@endforeach
|
||||
<label class="block text-sm" wire:key="field-country">
|
||||
<span class="font-medium text-ink">Land @if ($this->requiresAddress)<span class="text-rose-600" aria-hidden="true">*</span>@endif</span>
|
||||
<select wire:model="country" autocomplete="country" @error('country') aria-invalid="true" aria-describedby="country-error" @enderror class="mt-1 w-full rounded-lg border-line">
|
||||
@foreach (\App\Support\Countries::options() as $code => $name)
|
||||
<option value="{{ $code }}">{{ $name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('country') <span id="country-error" class="mt-1 block text-xs text-rose-700">{{ $message }}</span> @enderror
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="mt-4 block text-sm">
|
||||
|
||||
@@ -214,7 +214,7 @@ private function request(string $email = 'gast@example.org', string $arrival = '
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2),
|
||||
['first_name' => 'Gast', 'last_name' => 'Test', 'email' => $email],
|
||||
['first_name' => 'Gast', 'last_name' => 'Test', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
)->fresh(['guest', 'property']);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ private function request(string $email = 'gast@example.org', string $arrival = '
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2),
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email],
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
sendMails: false,
|
||||
originChannel: $channel,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Actions\ContributeCaseFacts;
|
||||
use App\Actions\CreateReservation;
|
||||
use App\Actions\DecideBookingWish;
|
||||
use App\Actions\SendInformation;
|
||||
use App\Actions\SendOffer;
|
||||
use App\Actions\SubmitBookingWish;
|
||||
use App\Actions\TakeOverExternalBooking;
|
||||
use App\Documents\DocumentReleases;
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Enums\BookingTaskKind;
|
||||
use App\Enums\DocumentKind;
|
||||
use App\Enums\FactSource;
|
||||
use App\Exceptions\ReservationException;
|
||||
use App\Models\Booking;
|
||||
use App\Models\BookingTask;
|
||||
use App\Models\CaseFact;
|
||||
use App\Models\Channel;
|
||||
use App\Models\Guest;
|
||||
use App\Models\Property;
|
||||
use App\Pricing\StayRequest;
|
||||
use App\Process\CaseRequirements;
|
||||
use App\Support\Content;
|
||||
use App\Support\Settings;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Database\Seeders\PropertySeeder;
|
||||
use Database\Seeders\SiteSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* v0.11 package U2: required details before an own binding offer and before the binding confirmation of a booking wish
|
||||
* (G2a, E-032, B3, B4, M01) and the common fact intake with source, conflict and change request (S5, CH-03, E-038,
|
||||
* M03, M06).
|
||||
*/
|
||||
class CaseFactIntakeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const ADDRESS = ['street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'];
|
||||
|
||||
private Property $property;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
|
||||
$this->seed([PropertySeeder::class, SiteSeeder::class]);
|
||||
$this->property = Property::sole();
|
||||
Mail::fake();
|
||||
Storage::fake('local');
|
||||
Http::fake(['*' => Http::response('', 500)]);
|
||||
Content::save(['contract.terms' => '<p>Echte Bedingungen</p>', 'stay.cancellation' => '<p>Echtes Storno</p>']);
|
||||
Settings::tenant()->update(['bank_iban' => 'DE02120300000000202051']);
|
||||
}
|
||||
|
||||
/** M01 */
|
||||
public function test_a_request_without_address_gets_no_offer_neither_automatically_nor_by_hand(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
|
||||
|
||||
$booking = $this->request(sendMails: true);
|
||||
|
||||
$this->assertSame(0, $booking->fresh()->offer_version);
|
||||
$this->assertSame(['guest.street', 'guest.postal_code', 'guest.city', 'guest.country'], CaseRequirements::missing($booking));
|
||||
try {
|
||||
app(SendOffer::class)->handle($booking->fresh(), ['acknowledged' => true]);
|
||||
$this->fail('An offer without address must not go out.');
|
||||
} catch (ReservationException $exception) {
|
||||
$this->assertStringContainsString('Straße und Hausnummer, PLZ, Ort, Land', $exception->getMessage());
|
||||
}
|
||||
$this->assertSame(BookingStatus::Reserved, $booking->fresh()->status);
|
||||
}
|
||||
|
||||
public function test_with_the_full_address_the_offer_goes_out_automatically(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
|
||||
|
||||
$booking = $this->request(address: self::ADDRESS, sendMails: true);
|
||||
|
||||
$this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status);
|
||||
}
|
||||
|
||||
/** B3: the information "unter Vorbehalt" stays possible, the binding confirmation of the wish does not. */
|
||||
public function test_an_information_needs_no_address_but_the_binding_confirmation_of_the_wish_does(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic', 'pre_reservation' => false]]);
|
||||
DocumentReleases::set(DocumentKind::Information, true, 'Test');
|
||||
|
||||
$booking = $this->request(sendMails: true)->fresh();
|
||||
$this->assertSame(1, $booking->information_version, 'the information went out without address');
|
||||
|
||||
$outcome = app(SubmitBookingWish::class)->handle($booking, 1);
|
||||
$this->assertSame(SubmitBookingWish::PENDING, $outcome);
|
||||
$this->assertStringContainsString('fehlen noch Angaben', implode(' ', $booking->fresh()->wish['findings']));
|
||||
|
||||
$this->expectException(ReservationException::class);
|
||||
app(DecideBookingWish::class)->confirm($booking->fresh());
|
||||
}
|
||||
|
||||
public function test_the_wish_is_confirmed_once_the_address_is_there(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['pre_reservation' => false]]);
|
||||
$booking = $this->request();
|
||||
app(SendInformation::class)->handle($booking->fresh(), ['acknowledged' => true]);
|
||||
app(SubmitBookingWish::class)->handle($booking->fresh(), 1);
|
||||
|
||||
app(ContributeCaseFacts::class)->handle($booking->fresh(), $this->prefixed(self::ADDRESS), FactSource::Landlord);
|
||||
app(DecideBookingWish::class)->confirm($booking->fresh());
|
||||
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->fresh()->status);
|
||||
}
|
||||
|
||||
/** B4 */
|
||||
public function test_an_empty_country_is_missing_and_never_assumed(): void
|
||||
{
|
||||
$booking = $this->request(address: [...self::ADDRESS, 'country' => null]);
|
||||
|
||||
$this->assertSame(['guest.country'], CaseRequirements::missing($booking));
|
||||
$this->assertNull($booking->guest->fresh()->country);
|
||||
}
|
||||
|
||||
public function test_missing_values_are_taken_over_equal_ones_confirmed_and_different_ones_put_to_the_landlord(): void
|
||||
{
|
||||
$booking = $this->request(address: ['street' => 'Strandweg 1']);
|
||||
|
||||
$result = app(ContributeCaseFacts::class)->handle($booking, ['guest.street' => 'Am Deich 7', 'guest.postal_code' => '18225', 'guest.city' => 'Kühlungsborn', 'guest.first_name' => 'gesa', 'guest.phone' => 'kein Telefon?'], FactSource::Email, ['reference' => 'mail-1']);
|
||||
|
||||
$guest = $booking->guest->fresh();
|
||||
$this->assertSame('Strandweg 1', $guest->street, 'the guest record is not written over');
|
||||
$this->assertSame('18225', $guest->postal_code);
|
||||
$this->assertSame(['guest.postal_code', 'guest.city', 'guest.phone'], $result->fields(CaseFact::APPLIED));
|
||||
$this->assertSame(['guest.first_name'], $result->fields(CaseFact::CONFIRMED));
|
||||
$this->assertSame(['guest.street'], $result->fields(CaseFact::CONFLICT));
|
||||
$task = BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::FactConflict)->sole();
|
||||
$this->assertStringContainsString('Am Deich 7', $task->note);
|
||||
$this->assertStringContainsString('Strandweg 1', $task->note);
|
||||
|
||||
$landlord = app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.street' => 'Am Deich 7'], FactSource::Landlord);
|
||||
$this->assertSame(['guest.street'], $landlord->fields(CaseFact::APPLIED));
|
||||
$this->assertSame('Am Deich 7', $booking->guest->fresh()->street);
|
||||
$this->assertSame('Strandweg 1', CaseFact::query()->where('source', FactSource::Landlord)->sole()->previous_value);
|
||||
}
|
||||
|
||||
/** M03 */
|
||||
public function test_the_same_contribution_twice_is_recorded_once(): void
|
||||
{
|
||||
$booking = $this->request();
|
||||
|
||||
app(ContributeCaseFacts::class)->handle($booking, ['guest.phone' => '038293 1234'], FactSource::GuestLink, ['reference' => 'link-v1']);
|
||||
$again = app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.phone' => '038293 1234'], FactSource::GuestLink, ['reference' => 'link-v1']);
|
||||
|
||||
$this->assertTrue($again->isEmpty());
|
||||
$this->assertSame(1, CaseFact::query()->where('field', 'guest.phone')->count());
|
||||
$this->assertSame(2, $booking->events()->where('type', 'facts')->count(), 'the form and the first link contribution, not the repeated one');
|
||||
}
|
||||
|
||||
/** M06 core: a binding booking gets administrative details, a change of the stay is only a request. */
|
||||
public function test_a_binding_booking_takes_administrative_details_but_a_new_date_is_only_a_change_request(): void
|
||||
{
|
||||
$booking = $this->portalBooking(guest: ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.org']);
|
||||
|
||||
$result = app(ContributeCaseFacts::class)->handle($booking, ['guest.phone' => '0171 555', 'booking.departure' => '2026-12-12', 'booking.guests' => '3'], FactSource::Email, ['reference' => 'mail-2']);
|
||||
|
||||
$booking->refresh();
|
||||
$this->assertSame(BookingStatus::Confirmed, $booking->status);
|
||||
$this->assertSame('2026-12-08', $booking->departure->toDateString(), 'nothing about the booking changed');
|
||||
$this->assertNull($booking->guests);
|
||||
$this->assertSame('0171 555', $booking->guest->phone);
|
||||
$this->assertSame(['booking.departure', 'booking.guests'], $result->fields(CaseFact::CHANGE_REQUEST));
|
||||
$this->assertSame(2, BookingTask::query()->where('booking_id', $booking->id)->where('kind', BookingTaskKind::ChangeRequest)->count());
|
||||
|
||||
$portal = app(ContributeCaseFacts::class)->handle($booking, ['booking.guests' => '3'], FactSource::PortalMail, ['reference' => 'portal-1']);
|
||||
$this->assertSame(['booking.guests'], $portal->fields(CaseFact::APPLIED), 'the portal itself may complete an unknown number of guests');
|
||||
}
|
||||
|
||||
public function test_a_case_without_guest_gets_one_from_a_name_but_never_joins_a_known_address_silently(): void
|
||||
{
|
||||
Guest::factory()->create(['email' => 'bekannt@example.org']);
|
||||
$booking = $this->portalBooking();
|
||||
|
||||
$known = app(ContributeCaseFacts::class)->handle($booking, ['guest.first_name' => 'Kai', 'guest.last_name' => 'Kurz', 'guest.email' => 'bekannt@example.org'], FactSource::Email, ['reference' => 'mail-3']);
|
||||
$this->assertNull($booking->fresh()->guest_id);
|
||||
$this->assertSame(['guest.first_name', 'guest.last_name', 'guest.email'], $known->fields(CaseFact::CONFLICT));
|
||||
|
||||
app(ContributeCaseFacts::class)->handle($booking->fresh(), ['guest.first_name' => 'Kai', 'guest.last_name' => 'Kurz', 'guest.email' => 'kai@example.org'], FactSource::PortalMail, ['reference' => 'mail-4']);
|
||||
$this->assertSame('kai@example.org', $booking->fresh()->guest->email);
|
||||
}
|
||||
|
||||
/** S6: once the details are complete the existing process carries on by itself. */
|
||||
public function test_completing_the_address_continues_an_automatic_case(): void
|
||||
{
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
|
||||
$booking = $this->request(sendMails: true);
|
||||
$this->assertSame(0, $booking->fresh()->offer_version);
|
||||
|
||||
app(ContributeCaseFacts::class)->handle($booking->fresh(), $this->prefixed(self::ADDRESS), FactSource::GuestLink, ['reference' => 'link-v1']);
|
||||
|
||||
$this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ?string> $address
|
||||
*/
|
||||
private function request(array $address = [], bool $sendMails = false): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', ...$address],
|
||||
sendMails: $sendMails,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ?string>|null $guest
|
||||
*/
|
||||
private function portalBooking(?array $guest = null): Booking
|
||||
{
|
||||
$portal = Channel::factory()->for($this->property)->create(['name' => 'FeWo-direkt', 'booking_model' => 'portal_booking']);
|
||||
|
||||
return app(TakeOverExternalBooking::class)->handle($this->property, $portal, CarbonImmutable::parse('2026-12-05'), CarbonImmutable::parse('2026-12-08'), ['portal_reference' => 'HA-7', 'guest' => $guest]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, ?string> $address
|
||||
* @return array<string, ?string>
|
||||
*/
|
||||
private function prefixed(array $address): array
|
||||
{
|
||||
return collect($address)->mapWithKeys(fn (?string $value, string $key): array => ['guest.'.$key => $value])->all();
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ private function request(bool $sendMails = false): Booking
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'],
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
sendMails: $sendMails,
|
||||
);
|
||||
}
|
||||
@@ -358,7 +358,7 @@ private function portalBooking(): Booking
|
||||
$this->portal,
|
||||
CarbonImmutable::parse('2026-12-05'),
|
||||
CarbonImmutable::parse('2026-12-12'),
|
||||
['portal_total' => 97951, 'portal_reference' => 'HA-77', 'guest' => ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.org']],
|
||||
['portal_total' => 97951, 'portal_reference' => 'HA-77', 'guest' => ['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public function test_t01_own_request_handled_automatically(): void
|
||||
$this->releaseTexts();
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
|
||||
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org']);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
|
||||
$this->assertSame([BookingStatus::OfferSent, CaseType::A1], [$booking->status, $booking->case_type]);
|
||||
Mail::assertSent(OfferMade::class, 1);
|
||||
@@ -120,7 +120,7 @@ public function test_t01_own_request_handled_automatically(): void
|
||||
public function test_t02_own_request_released_by_hand_and_accepted_by_the_guest(): void
|
||||
{
|
||||
Livewire::test(CreateBooking::class)
|
||||
->fillForm(['kind' => BookingForm::INQUIRY, 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'send_mails' => false])
|
||||
->fillForm(['kind' => BookingForm::INQUIRY, 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE', 'send_mails' => false])
|
||||
->call('create')->assertHasNoFormErrors();
|
||||
$booking = Booking::query()->sole();
|
||||
$this->assertSame('Angebot prüfen und senden', WorkList::items()[0]['title']);
|
||||
@@ -145,13 +145,13 @@ public function test_t03_missing_guest_data_becomes_a_task_and_the_case_continue
|
||||
$this->releaseTexts();
|
||||
Settings::tenant()->update(['process_defaults' => ['processing' => 'automatic']]);
|
||||
Livewire::test(CreateBooking::class)
|
||||
->fillForm(['kind' => BookingForm::INQUIRY, 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Paul', 'last_name' => 'Telefon', 'send_mails' => true])
|
||||
->fillForm(['kind' => BookingForm::INQUIRY, 'property_id' => $this->property->id, 'guests' => 2, 'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Paul', 'last_name' => 'Telefon', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE', 'send_mails' => true])
|
||||
->call('create')->assertHasNoFormErrors();
|
||||
$booking = Booking::query()->sole();
|
||||
|
||||
$this->assertSame('E-Mail-Adresse des Gastes eintragen', WorkList::items()[0]['title']);
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
|
||||
->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Paul', 'last_name' => 'Telefon', 'email' => 'paul@example.org'], 'process' => ProvideGuestContact::AUTOMATIC, 'guest_confirmed' => false])
|
||||
->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Paul', 'last_name' => 'Telefon', 'email' => 'paul@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], 'process' => ProvideGuestContact::AUTOMATIC, 'guest_confirmed' => false])
|
||||
->assertNotified('Kontaktdaten gespeichert, Angebot gesendet');
|
||||
|
||||
$this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status);
|
||||
@@ -258,7 +258,7 @@ public function test_t08_cancellation_takes_the_right_way(): void
|
||||
->assertNotified('Buchung storniert');
|
||||
$this->assertSame(BookingStatus::Cancelled, $portal->fresh()->status);
|
||||
|
||||
$request = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-28'), CarbonImmutable::parse('2026-12-01'), 2), ['first_name' => 'Ina', 'last_name' => 'Anfrage', 'email' => 'ina@example.org'], sendMails: false);
|
||||
$request = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-28'), CarbonImmutable::parse('2026-12-01'), 2), ['first_name' => 'Ina', 'last_name' => 'Anfrage', 'email' => 'ina@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], sendMails: false);
|
||||
Livewire::test(ViewBooking::class, ['record' => $request->getRouteKey()])
|
||||
->callAction('end', ['reason' => 'Hund nicht erlaubt', 'notify' => false])
|
||||
->assertNotified('Vorgang beendet');
|
||||
@@ -385,7 +385,7 @@ public function test_t12_settings_hierarchy_is_applied_and_visible(): void
|
||||
$this->assertSame([ProcessingMode::Automatic, 'tenant'], [$portalBooking->processing(), $portalBooking->source(ProcessSetting::Processing)], 'the booking intake inherits the default');
|
||||
$this->assertSame(CaseType::A4, $portalBooking->caseType);
|
||||
|
||||
$case = app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'], sendMails: false, originChannel: $fewo);
|
||||
$case = app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], sendMails: false, originChannel: $fewo);
|
||||
$this->assertSame(ProcessingMode::Manual, $case->processingMode());
|
||||
Livewire::test(ViewBooking::class, ['record' => $case->getRouteKey()])->callAction('automation', ['mode' => ProcessingMode::Automatic->value]);
|
||||
$this->assertSame(ProcessingMode::Automatic, $case->fresh()->processingMode(), 'the case decision wins');
|
||||
@@ -412,7 +412,7 @@ public function test_t13_test_operation_redirects_every_outgoing_message(): void
|
||||
Settings::tenant()->update(['operating_mode' => Settings::MODE_TEST, 'test_recipient' => 'test@example.com']);
|
||||
app(TenantContext::class)->set(Settings::tenant()->fresh());
|
||||
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@gast.example']);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@gast.example', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])->callAction(TestAction::make('sendOffer')->arguments([]));
|
||||
$booking->refresh();
|
||||
$this->post(URL::temporarySignedRoute('offers.accept', $booking->hold_expires_at, ['booking' => $booking, 'v' => $booking->offer_version]), ['terms' => '1']);
|
||||
@@ -483,7 +483,7 @@ public function test_existing_manual_blocks_become_cases_without_changing_the_po
|
||||
|
||||
private function confirmedOwnBooking(): Booking
|
||||
{
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'], sendMails: false);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], sendMails: false);
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])->callAction('confirm', ['notify' => false]);
|
||||
|
||||
return $booking->fresh();
|
||||
|
||||
@@ -449,7 +449,7 @@ public function test_t24_settings_of_every_level_are_effective_in_the_whole_run(
|
||||
$this->assertSame(BookingStatus::OfferSent, $direct->fresh()->status, 'landlord level: automatic offer with hold');
|
||||
$this->assertNotNull($direct->fresh()->hold_expires_at);
|
||||
|
||||
$viaPortal = app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-21'), CarbonImmutable::parse('2026-11-24'), 2), ['first_name' => 'Pia', 'last_name' => 'Portal', 'email' => 'pia@example.org'], originChannel: $this->manualPortal->fresh());
|
||||
$viaPortal = app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse('2026-11-21'), CarbonImmutable::parse('2026-11-24'), 2), ['first_name' => 'Pia', 'last_name' => 'Portal', 'email' => 'pia@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], originChannel: $this->manualPortal->fresh());
|
||||
$this->assertSame([0, 0, null], [$viaPortal->fresh()->information_version, $viaPortal->fresh()->offer_version, $viaPortal->fresh()->hold_expires_at], 'portal level: no hold, manual');
|
||||
$this->assertSame('sendInformation', CaseActivities::next($viaPortal->fresh())?->action);
|
||||
|
||||
@@ -516,7 +516,7 @@ public function test_special_cases_of_preparation_and_closing(): void
|
||||
$this->assertContains('Der Gesamtpreis laut FeWo-direkt fehlt.', CaseClosure::commercialPoints($portal), 'an unknown portal price is no invented 0');
|
||||
|
||||
// Cancellation two days before arrival: preparation is dropped, costs keep the case open commercially.
|
||||
$own = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-05'), CarbonImmutable::parse('2026-11-08'), 2), ['first_name' => 'Kurt', 'last_name' => 'Kurzfristig', 'email' => 'kurt@example.org'], sendMails: false);
|
||||
$own = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-05'), CarbonImmutable::parse('2026-11-08'), 2), ['first_name' => 'Kurt', 'last_name' => 'Kurzfristig', 'email' => 'kurt@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], sendMails: false);
|
||||
Livewire::test(ViewBooking::class, ['record' => $own->getRouteKey()])->callAction('confirm', ['notify' => false]);
|
||||
app(SendBookingReminders::class)->handle();
|
||||
$this->assertTrue(BookingTask::query()->where('booking_id', $own->id)->where('kind', BookingTaskKind::Service)->exists());
|
||||
@@ -569,7 +569,7 @@ public function test_existing_payment_statuses_are_only_corrected_on_request():
|
||||
|
||||
private function request(string $email = 'gesa@example.org', string $arrival = '2026-11-07', string $departure = '2026-11-10'): Booking
|
||||
{
|
||||
return app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email]);
|
||||
return app(CreateReservation::class)->handle($this->property->fresh(), new StayRequest(CarbonImmutable::parse($arrival), CarbonImmutable::parse($departure), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
}
|
||||
|
||||
private function sendInformation(Booking $booking): void
|
||||
@@ -593,7 +593,7 @@ private function automaticWithoutHold(): void
|
||||
|
||||
private function confirmedOwnBooking(): Booking
|
||||
{
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org'], sendMails: false);
|
||||
$booking = app(CreateReservation::class)->handle($this->property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], sendMails: false);
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])->callAction('confirm', ['notify' => false]);
|
||||
|
||||
return $booking->fresh();
|
||||
|
||||
@@ -104,7 +104,7 @@ public function test_missing_data_stops_the_case_with_a_task_and_it_continues_au
|
||||
Livewire::test(CreateBooking::class)
|
||||
->fillForm([
|
||||
'kind' => BookingForm::INQUIRY, 'property_id' => $this->property->id, 'guests' => 2,
|
||||
'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Paul', 'last_name' => 'Telefon', 'send_mails' => true,
|
||||
'arrival' => '2026-11-07', 'departure' => '2026-11-10', 'first_name' => 'Paul', 'last_name' => 'Telefon', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE', 'send_mails' => true,
|
||||
])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
@@ -116,7 +116,7 @@ public function test_missing_data_stops_the_case_with_a_task_and_it_continues_au
|
||||
Mail::assertNotSent(OfferMade::class);
|
||||
|
||||
Livewire::test(ViewBooking::class, ['record' => $booking->getRouteKey()])
|
||||
->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Paul', 'last_name' => 'Telefon', 'email' => 'paul@example.org'], 'process' => ProvideGuestContact::AUTOMATIC, 'guest_confirmed' => false])
|
||||
->callAction(TestAction::make('provideContact')->arguments([]), ['guest' => ['first_name' => 'Paul', 'last_name' => 'Telefon', 'email' => 'paul@example.org', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'], 'process' => ProvideGuestContact::AUTOMATIC, 'guest_confirmed' => false])
|
||||
->assertNotified('Kontaktdaten gespeichert, Angebot gesendet');
|
||||
|
||||
$this->assertSame(BookingStatus::OfferSent, $booking->fresh()->status);
|
||||
@@ -202,7 +202,7 @@ public function test_nationality_is_never_a_reason_to_stop(): void
|
||||
$foreign = app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
|
||||
['first_name' => 'Ayşe', 'last_name' => 'Yılmaz', 'email' => 'ayse@example.com.tr', 'country' => 'TR', 'city' => 'İzmir'],
|
||||
['first_name' => 'Ayşe', 'last_name' => 'Yılmaz', 'email' => 'ayse@example.com.tr', 'country' => 'TR', 'city' => 'İzmir', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
);
|
||||
|
||||
$this->assertSame(BookingStatus::OfferSent, $foreign->status);
|
||||
@@ -243,7 +243,7 @@ private function request(string $email = 'gesa@example.org', bool $sendMails = f
|
||||
return app(CreateReservation::class)->handle(
|
||||
$this->property->fresh(),
|
||||
new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2),
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email],
|
||||
['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => $email, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
sendMails: $sendMails,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public function test_every_mail_along_the_booking_path_renders_in_its_state(): v
|
||||
$booking = app(CreateReservation::class)->handle(
|
||||
Property::sole(),
|
||||
new StayRequest(CarbonImmutable::parse('2026-12-01'), CarbonImmutable::parse('2026-12-05'), 2),
|
||||
['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.com', 'street' => 'Seeweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn'],
|
||||
['first_name' => 'Erika', 'last_name' => 'Muster', 'email' => 'erika@example.com', 'street' => 'Seeweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE'],
|
||||
'Wir kommen mit Hund – ist das in Ordnung?',
|
||||
sendMails: false,
|
||||
);
|
||||
|
||||
@@ -108,7 +108,7 @@ public function test_real_guest_mails_of_the_booking_process_go_to_the_test_reci
|
||||
$property->tenant->update(['operating_mode' => Settings::MODE_TEST, 'test_recipient' => 'test@example.com']);
|
||||
app(TenantContext::class)->set($property->tenant->fresh());
|
||||
|
||||
$booking = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@gast.example']);
|
||||
$booking = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => 'gesa@gast.example', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
app(SendOffer::class)->handle($booking);
|
||||
|
||||
$sent = $this->sent();
|
||||
|
||||
@@ -106,7 +106,7 @@ public function test_t23_every_message_goes_only_to_the_test_address_over_real_s
|
||||
$property = Property::sole();
|
||||
|
||||
// Automatic: request → information; guest: booking wish → confirmation; scheduled: arrival information.
|
||||
$booking = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => self::GUEST]);
|
||||
$booking = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-07'), CarbonImmutable::parse('2026-11-10'), 2), ['first_name' => 'Gesa', 'last_name' => 'Gast', 'email' => self::GUEST, 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
$booking->refresh();
|
||||
$this->post(URL::temporarySignedRoute('information.wish', $booking->information_valid_until, ['booking' => $booking, 'v' => $booking->information_version]), ['terms' => '1'])->assertRedirect();
|
||||
$this->assertTrue($booking->fresh()->isBinding());
|
||||
@@ -114,7 +114,7 @@ public function test_t23_every_message_goes_only_to_the_test_address_over_real_s
|
||||
app(SendBookingReminders::class)->handle();
|
||||
|
||||
// Manual: the landlord resends the information of a second request; with Cc and Bcc to outside addresses.
|
||||
$second = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-21'), CarbonImmutable::parse('2026-11-24'), 2), ['first_name' => 'Ole', 'last_name' => 'Zweit', 'email' => 'ole@gast.example']);
|
||||
$second = app(CreateReservation::class)->handle($property, new StayRequest(CarbonImmutable::parse('2026-11-21'), CarbonImmutable::parse('2026-11-24'), 2), ['first_name' => 'Ole', 'last_name' => 'Zweit', 'email' => 'ole@gast.example', 'street' => 'Strandweg 1', 'postal_code' => '18225', 'city' => 'Kühlungsborn', 'country' => 'DE']);
|
||||
Livewire::test(ViewBooking::class, ['record' => $second->getRouteKey()])->callAction(TestAction::make('sendInformation')->arguments([]), ['acknowledged' => true])->assertNotified('Auskunft gesendet');
|
||||
Mail::to('ole@gast.example')->cc('cc@aussen.example')->bcc('bcc@aussen.example')->send(new BookingWishNotice($second->fresh(), 'pending'));
|
||||
|
||||
|
||||
Reference in new issue
Block a user