Files
fewo-stommer/app/Pricing/PrivateStayPrice.php
LarsandClaude Opus 5.5 3bcfc09417
Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m44s
Pakete 8, 5 und 6: Beträge und Zahlungen, Ändern und Stornieren, A6 im Vorgang
- Paket 8: Zahlungsarten (Gast an uns, laut Portal, Auszahlung, Erstattung),
  Portalbeträge als Angaben mit Quelle, Übersicht nach Zuständigkeit (R09).
- Paket 5: Ändern mit Folgenvorschau, vereinbart oder dem Gast vorgeschlagen
  (signierter Link), ein Stornoweg mit Grund und Erstattung, Portalstorno erst
  nach Bestätigung.
- Paket 6: eigene Nutzung, Besuch und Sperre als Vorgang mit Kurabgabe und
  Aufenthaltsbestätigung; Bestandsübernahme der Sperren mit identischem Export.
- Wirksame Einstellungen (Expertenansicht), Abnahmekatalog T01–T14, Ergebnis-,
  Abnahme- und Konfigurationsdokument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 22:16:47 +01:00

68 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Pricing;
use App\Enums\QuoteLineType;
use App\Models\Property;
use Carbon\CarbonImmutable;
/**
* The price of an internal case (A6, package 6): the rent agreed for this stay (often 0 for family), the services
* booked with their usual prices, and the tourist tax (Kurabgabe) as a position of its own – the persons liable ×
* nights × the rate the landlord keeps on the property. Exemptions are noted by hand; there is no municipal rule logic.
*/
class PrivateStayPrice
{
public function __construct(private PriceCalculator $calculator) {}
/**
* @param array<int, int> $extras extra id => quantity
*
* @throws QuoteException
*/
public function quote(Property $property, CarbonImmutable $arrival, CarbonImmutable $departure, ?int $guests, array $extras, int $rent, ?int $taxPersons): PriceQuote
{
$nights = (int) $arrival->diffInDays($departure);
$lines = [new QuoteLine(QuoteLineType::Rent, 'Miete (vereinbart)', 1, $rent, $rent)];
array_push($lines, ...$this->calculator->extraLines($property, $extras, $nights));
$tax = self::touristTax($property, $nights, $taxPersons);
if ($tax !== null) {
$lines[] = $tax;
}
return new PriceQuote($arrival, $departure, (int) $guests, $lines, 0, $arrival);
}
/**
* The tourist tax line, or null when no rate is kept or nobody is liable.
*/
public static function touristTax(Property $property, int $nights, ?int $persons): ?QuoteLine
{
$rate = (int) ($property->tourist_tax_rate ?? 0);
if ($rate <= 0 || (int) $persons <= 0 || $nights <= 0) {
return null;
}
$units = (int) $persons * $nights;
return new QuoteLine(QuoteLineType::TouristTax, 'Kurabgabe ('.$persons.' '.((int) $persons === 1 ? 'Person' : 'Personen').' × '.$nights.' Nächte)', $units, $rate, $units * $rate);
}
/**
* The agreed rent of an existing internal case (its rent line), 0 when none.
*
* @param array<string, mixed>|null $quote
*/
public static function rentOf(?array $quote): int
{
foreach ((array) ($quote['lines'] ?? []) as $line) {
if (($line['type'] ?? null) === QuoteLineType::Rent->value) {
return (int) $line['amount'];
}
}
return 0;
}
}