Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
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:
LarsandClaude Sonnet 5.5 committed 2026-10-30 16:32:48 +01:00
1 parent 5baf39441f
commit 0c4187edaf
37 files changed
+1440 -10

No files matched your search

+15 -1
View File
@@ -8,6 +8,7 @@
use App\Enums\ChannelBookingModel;
use App\Models\Booking;
use App\Models\BookingTask;
use App\Models\Cancellation;
use Carbon\CarbonImmutable;
/**
@@ -91,6 +92,19 @@ public static function steps(Booking $booking): array
return $steps;
}
private static function cancelledText(Booking $booking, bool $open): string
{
$cancellation = Cancellation::query()->where('booking_id', $booking->id)->first();
if ($cancellation === null) {
return $open ? 'Stornokosten bzw. Rückzahlung sind noch zu klären (siehe Aufgaben).' : 'Nichts mehr zu tun. Die Buchung bleibt zur Historie erhalten.';
}
$balance = $cancellation->balance();
$text = 'Storniert am '.$cancellation->cancelled_on->format('d.m.Y').' ('.($cancellation->days_before ?? '?').' Tage vor Anreise). Stornokosten '.Money::format($cancellation->fee()).', bezahlt '.Money::format($cancellation->paid_amount).'.';
return $text.($cancellation->status === Cancellation::OPEN ? ($balance > 0 ? ' Noch einzufordern: '.Money::format($balance).'.' : ($balance < 0 ? ' Zu erstatten: '.Money::format(-$balance).'.' : ' Ausgeglichen – bitte als abgerechnet markieren.')) : ' Erledigt.');
}
/**
* @return array{title: string, text: string, color: string}
*/
@@ -109,7 +123,7 @@ public static function next(Booking $booking): array
}
return match (true) {
$booking->status === BookingStatus::Cancelled => ['title' => 'Storniert', 'text' => $costs !== null || $wish !== null ? 'Stornokosten bzw. Rückzahlung sind noch zu klären (siehe Aufgaben).' : 'Nichts mehr zu tun. Die Buchung bleibt zur Historie erhalten.', 'color' => $costs !== null ? 'warning' : 'gray'],
$booking->status === BookingStatus::Cancelled => ['title' => 'Storniert', 'text' => self::cancelledText($booking, $costs !== null || $wish !== null), 'color' => $costs !== null ? 'warning' : 'gray'],
$booking->status === BookingStatus::Declined => ['title' => 'Abgelehnt', 'text' => 'Der Zeitraum ist wieder frei.', 'color' => 'gray'],
$booking->status === BookingStatus::Expired => ['title' => 'Abgelaufen', 'text' => 'Die Haltefrist ist verstrichen. Sie können die Anfrage trotzdem noch bestätigen, solange der Zeitraum frei ist.', 'color' => 'gray'],
$booking->status === BookingStatus::Reserved => ['title' => 'Anfrage prüfen', 'text' => $kind === self::PORTAL_BOOKING
+53
View File
@@ -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');
}
}