- Buchung ist der einheitliche Vorgang: Eingangsart, Vorgangsart A1–A6, eingefrorenes Abwicklungsprofil, gespeicherter Verlauf (booking_events); Gast, Personen und Beträge dürfen unbekannt sein, Platzhalter-Gäste werden migriert und nicht mehr angelegt - Einstellungen in Ebenen: Vermieterstandard (So arbeite ich), Abweichung der Wohnung (Experte), Abweichung je Portal und Eingangsart; ersetzt booking_model als Steuergröße - Ein Weg für extern verbindliche Buchungen (TakeOverExternalBooking) statt RecordPortalBooking und "Akte anlegen"; Portalpreis als belegte Gesamtposition - Startseite "Zu erledigen", neue Vorgangsseite mit nächstem Schritt, Automatik-Schalter, "Beenden" mit Storno statt Statusumschaltung; Status von Hand nur im Expertenmodus - Migration übernimmt bisheriges Verhalten unverändert (abweichende Wohnungswerte bleiben als Abweichung), Bericht: php artisan process:settings-report Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.7 KiB
PHP
104 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Availability\AvailabilityChecker;
|
|
use App\Availability\CalendarClearance;
|
|
use App\Enums\BookingStatus;
|
|
use App\Enums\ProcessingMode;
|
|
use App\Exceptions\ReservationException;
|
|
use App\Models\Booking;
|
|
use App\Pricing\QuoteException;
|
|
use App\Support\Content;
|
|
use App\Support\Settings;
|
|
|
|
/**
|
|
* Automatic offer processing (property setting "Automatisch"): sends the offer without the landlord when every
|
|
* release rule is met, otherwise leaves the request untouched for manual processing and says why.
|
|
*
|
|
* Rules: pre-reservation active (the dates are really blocked), guest e-mail known, dates still free, contract
|
|
* texts released by the landlord (not the sample text; skipped while mails only go to the test recipient),
|
|
* and the calendar clearance of {@see CalendarClearance} (fresh imports, instant-booking portals fetched our feed).
|
|
*/
|
|
class AutoOffer
|
|
{
|
|
public function __construct(
|
|
private SendOffer $sendOffer,
|
|
private CalendarClearance $clearance,
|
|
private AvailabilityChecker $availability,
|
|
) {}
|
|
|
|
public function applies(Booking $booking): bool
|
|
{
|
|
return $booking->processingMode() === ProcessingMode::Automatic;
|
|
}
|
|
|
|
/**
|
|
* @return list<string> reasons why the offer cannot be sent automatically (empty = may be sent)
|
|
*/
|
|
public function blockers(Booking $booking): array
|
|
{
|
|
$property = $booking->property;
|
|
$reasons = [];
|
|
|
|
if (! $booking->process()->preReservation()) {
|
|
$reasons[] = 'Anfragen reservieren den Zeitraum nicht (Einstellung „Vorreservierung“); ohne Sperre im Kalender wird kein Angebot automatisch erteilt.';
|
|
}
|
|
if ($booking->status !== BookingStatus::Reserved || ! $booking->isHoldActive()) {
|
|
$reasons[] = 'Die Anfrage ist nicht mehr vorgemerkt (Frist abgelaufen oder bereits bearbeitet).';
|
|
}
|
|
if (blank($booking->guest?->email)) {
|
|
$reasons[] = 'Die E-Mail-Adresse des Gastes fehlt.';
|
|
}
|
|
if (! $this->availability->isAvailable($property, $booking->arrival, $booking->departure, ignore: $booking)) {
|
|
$reasons[] = 'Der Zeitraum ist inzwischen belegt.';
|
|
}
|
|
if (! $this->contractTextsReleased()) {
|
|
$reasons[] = 'Mietbedingungen, Stornobedingungen oder Bankverbindung sind noch nicht vom Betreiber freigegeben (leer oder Mustertext).';
|
|
}
|
|
|
|
return [...$reasons, ...$this->clearance->reasons($property, $booking->created_at)];
|
|
}
|
|
|
|
/**
|
|
* Tries to send the offer. Imports of stale channels are refreshed first (network access, outside transactions).
|
|
*
|
|
* @return list<string> reasons for the manual fallback; empty when the offer was sent
|
|
*/
|
|
public function handle(Booking $booking): array
|
|
{
|
|
$booking->loadMissing(['property', 'guest']);
|
|
|
|
if ($booking->process()->preReservation()) {
|
|
$this->clearance->refresh($booking->property);
|
|
}
|
|
|
|
$reasons = $this->blockers($booking);
|
|
if ($reasons !== []) {
|
|
return $reasons;
|
|
}
|
|
|
|
try {
|
|
$this->sendOffer->handle($booking->fresh());
|
|
} catch (QuoteException|ReservationException $exception) {
|
|
// A mail failure keeps the saved offer (SendOffer reports it in the inbox); the landlord can resend the link.
|
|
return [$exception->getMessage()];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
private function contractTextsReleased(): bool
|
|
{
|
|
if (! Settings::isLive()) {
|
|
return true;
|
|
}
|
|
|
|
$terms = (string) Content::get('contract.terms');
|
|
|
|
return filled($terms) && ! str_contains($terms, '[MUSTER')
|
|
&& filled(Content::get('stay.cancellation'))
|
|
&& filled(config('fewo.bank.iban'));
|
|
}
|
|
}
|