processingMode() === ProcessingMode::Automatic; } /** * @return list reasons why the offer cannot be sent automatically (empty = may be sent) */ public function blockers(Booking $booking): array { $property = $booking->property; $reasons = []; $information = ! $booking->process()->preReservation(); if ($information && ($booking->status !== BookingStatus::Reserved || $booking->information_version > 0)) { $reasons[] = 'Die Anfrage ist bereits beantwortet oder nicht mehr offen.'; } if (! $information && ($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).'; } // Status, e-mail and dates are checked above; the composition adds what concerns the document. $reasons = [...$reasons, ...app(DocumentComposer::class)->compose($booking, $information ? DocumentKind::Information : DocumentKind::Offer)->toConfirm(except: [DocumentFinding::HOLD_ZERO])]; // An information reserves nothing and binds nobody: the calendar is checked again when the guest asks for the booking. return $information ? $reasons : [...$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 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 { if (! $booking->process()->preReservation()) { $this->sendInformation->handle($booking->fresh(), ['expected_version' => 0, 'acknowledged' => true]); } else { $this->sendOffer->handle($booking->fresh(), ['expected_version' => 0]); } } 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 []; } /** * Whether the landlord's own contract terms, cancellation terms and bank account are in place (always true while * mails only go to the test recipient). */ public 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')); } }