Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
- Stornoregel (Stufen nach Tagen vor Anreise, Mietpreis oder Gesamtpreis, Ersatzmieter-Gebuehr), je Vertragsvorlage, beim Angebot eingefroren, als Platzhalter im Vertrag - Stornierung (Gast-Link oder Verwaltung) berechnet die Kosten, legt einen Stornofall an; Verwaltung Stornierungen mit Vorschlag, Festlegung, Saldo, Abrechnung und Erlass; Gast sieht die Kosten vorab auf der Storno-Seite - Vertragsanlagen als eigene versionierte Dokumente mit Bedingung (immer, Zusatzleistung, Portal, von Hand), je Angebot ausgewaehlt und eingefroren; Zusatzleistungen in der Buchung erfassbar - FeWo-direkt-Installation legt die Stornoregel aus Paragraf 13 an Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5baf39441f
commit
0c4187edaf
37 files changed
+1440
-10
No files matched your search
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Enums\QuoteLineType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\CancellationPolicy;
|
||||
use Carbon\CarbonInterface;
|
||||
|
||||
/**
|
||||
* Calculates what a cancellation costs according to the cancellation rule frozen in the offer. Returns null when
|
||||
* the booking has no rule (then the landlord decides by hand). The result is a proposal: the landlord can adjust it.
|
||||
*/
|
||||
class CancellationCost
|
||||
{
|
||||
/**
|
||||
* @return array{policy: string, base: string, days_before: int, percent: int, base_amount: int, fee: int, free: bool, tier_text: string}|null
|
||||
*/
|
||||
public static function calculate(Booking $booking, ?CarbonInterface $on = null): ?array
|
||||
{
|
||||
$policy = $booking->offer_terms['cancellation_policy'] ?? null;
|
||||
if (! is_array($policy) || empty($policy['tiers'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$on ??= today();
|
||||
$daysBefore = max(0, (int) $on->copy()->startOfDay()->diffInDays($booking->arrival, false));
|
||||
$tier = CancellationPolicy::tierFor($policy, $daysBefore);
|
||||
$baseAmount = $policy['base'] === CancellationPolicy::BASE_TOTAL ? (int) $booking->total : self::rent($booking);
|
||||
$fee = (int) round($baseAmount * $tier['percent'] / 100);
|
||||
|
||||
return [
|
||||
'policy' => (string) $policy['name'],
|
||||
'base' => (string) $policy['base'],
|
||||
'days_before' => $daysBefore,
|
||||
'percent' => $tier['percent'],
|
||||
'base_amount' => $baseAmount,
|
||||
'fee' => $fee,
|
||||
'free' => $fee === 0,
|
||||
'tier_text' => $tier['percent'].' % '.($policy['base'] === CancellationPolicy::BASE_TOTAL ? 'des Gesamtpreises' : 'des Mietpreises').' ('.$daysBefore.' Tage vor Anreise)',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The rent: accommodation, extra guests, discounts and manual adjustments – without cleaning, services and extras.
|
||||
*/
|
||||
public static function rent(Booking $booking): int
|
||||
{
|
||||
$rentTypes = [QuoteLineType::Accommodation->value, QuoteLineType::ExtraGuest->value, QuoteLineType::Discount->value, QuoteLineType::Adjustment->value];
|
||||
|
||||
return (int) collect($booking->quote['lines'] ?? [])->filter(fn (array $line): bool => in_array($line['type'] ?? null, $rentTypes, true))->sum('amount');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user