Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
- Akte anlegen aus einer importierten Portal-Reservierung (Belegung bleibt durchgehend belegt, Kalendereintrag wird Spiegelung) - Akte: Standardprozess (Portal/Vorlage/Storno/Anlagen), Meilensteine mit Aktivitaeten und Aktionshinweis, chronologischer Verlauf - Kanalformular: Abschnitt Standardprozess je Buchungstyp mit Anzeige, was die Vorlage mitbringt - Portalpreis als gemeinsame Logik (PortalPrice) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
75 lines
2.8 KiB
PHP
75 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Pricing;
|
|
|
|
use App\Enums\QuoteLineType;
|
|
use App\Models\Property;
|
|
use Carbon\CarbonImmutable;
|
|
|
|
/**
|
|
* The price a portal charged for a stay as booking columns. Our own calculation is the basis; the difference to the
|
|
* portal price becomes an adjustment line, so the quote adds up to what the portal charged. When our price list does
|
|
* not cover the stay (or the stay breaks a rule the portal did not know), the portal price stands alone as one line.
|
|
*/
|
|
class PortalPrice
|
|
{
|
|
public const LABEL = 'Abweichung Portalpreis';
|
|
|
|
public function __construct(private PriceCalculator $calculator) {}
|
|
|
|
/**
|
|
* @return array<string, mixed> 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<string, mixed>
|
|
*/
|
|
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<string, mixed>
|
|
*/
|
|
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,
|
|
];
|
|
}
|
|
}
|