$guestData first_name and last_name are required, everything else optional * * @throws QuoteException * @throws ReservationException */ public function handle(Property $property, Channel $channel, StayRequest $stay, array $guestData, string $process = self::CONFIRM, ?string $portalReference = null, ?int $portalTotal = null, ?string $notes = null, bool $guestConfirmed = false): Booking { if ($channel->property_id !== $property->id) { throw new ReservationException('Der Kanal gehört nicht zu dieser Wohnung.'); } if ($process === self::CONTRACT && blank($guestData['email'] ?? null)) { throw new ReservationException('Für den sofortigen Vertragsversand wird die E-Mail-Adresse des Gastes benötigt.'); } $booking = $this->create->handle($property, $stay, $guestData, source: 'portal', sendMails: false); $changes = ['origin_channel_id' => $channel->id, 'portal_reference' => filled($portalReference) ? trim($portalReference) : null, 'internal_notes' => filled($notes) ? trim($notes) : $booking->internal_notes]; if ($guestConfirmed) { $changes['guest_confirmed_at'] = now(); } if ($portalTotal !== null) { $changes += $this->priceOf($property, $stay, $portalTotal); } $booking->update($changes); if ($process === self::RECORD) { return $booking->refresh(); } if ($process === self::CONTRACT) { $this->confirm->handle($booking, notifyGuest: true); } else { DB::transaction(fn () => $this->confirm->bind($booking)); } return $booking->refresh(); } /** * Price columns for a booking whose portal price differs from our own calculation: the difference becomes an * adjustment line, so the quote still adds up to what the portal charged. * * @return array * * @throws QuoteException */ private function priceOf(Property $property, StayRequest $stay, int $portalTotal): array { $quote = $this->calculator->calculate($property, $stay); $difference = $portalTotal - $quote->total(); if ($difference === 0) { return []; } $difference = max($difference, -$quote->rent()); $quote = $quote->withLine(new QuoteLine(QuoteLineType::Adjustment, 'Abweichung Portalpreis', 1, $difference, $difference)); return [ 'price_adjustment' => $difference, 'price_adjustment_label' => 'Abweichung Portalpreis', 'quote' => $quote->toArray(), 'total' => $quote->total(), 'deposit' => $quote->deposit(), ]; } }