booking columns (quote, total, deposit, price_adjustment, ...) */ public function columns(Property $property, StayRequest $stay, int $portalTotal): array { try { $quote = $this->calculator->calculate($property, $stay); } catch (QuoteException) { return $this->columnsOf($this->standalone($property, $stay, $portalTotal), null); } $difference = max($portalTotal - $quote->total(), -$quote->rent()); if ($difference === 0) { return $this->columnsOf($quote, null); } return $this->columnsOf($quote->withLine(new QuoteLine(QuoteLineType::Adjustment, self::LABEL, 1, $difference, $difference)), $difference); } /** * Quote for a stay without a known portal price: our calculation, or an empty quote when it is not possible. * * @return array */ public function unknownColumns(Property $property, StayRequest $stay): array { try { return $this->columnsOf($this->calculator->calculate($property, $stay), null); } catch (QuoteException) { return $this->columnsOf($this->standalone($property, $stay, 0), null); } } private function standalone(Property $property, StayRequest $stay, int $total): PriceQuote { $lines = $total > 0 ? [new QuoteLine(QuoteLineType::Accommodation, 'Preis laut Portal', 1, $total, $total)] : []; return new PriceQuote($stay->arrival, $stay->departure, $stay->guests, $lines, $property->deposit_percent, CarbonImmutable::instance($stay->arrival)->subDays($property->balance_due_days_before_arrival)); } /** * @return array */ private function columnsOf(PriceQuote $quote, ?int $adjustment): array { return [ 'quote' => $quote->toArray(), 'total' => $quote->total(), 'deposit' => $quote->deposit(), 'balance_due_on' => $quote->balanceDueOn->toDateString(), 'price_adjustment' => $adjustment, 'price_adjustment_label' => $adjustment !== null ? self::LABEL : null, ]; } }