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,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* The record of a cancelled booking: when, how many days before arrival, the cost proposed by the cancellation rule
|
||||
* and the amount the landlord finally charges. Cancelled bookings stay in the system for this history.
|
||||
*/
|
||||
#[Fillable(['booking_id', 'cancelled_on', 'initiated_by', 'has_policy', 'policy_name', 'days_before', 'percent', 'base_amount', 'calculated_fee', 'final_fee', 'paid_amount', 'status', 'note', 'settled_at'])]
|
||||
class Cancellation extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
public const OPEN = 'open';
|
||||
|
||||
public const SETTLED = 'settled';
|
||||
|
||||
public const WAIVED = 'waived';
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['cancelled_on' => 'immutable_date', 'has_policy' => 'boolean', 'settled_at' => 'immutable_datetime'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Booking, $this>
|
||||
*/
|
||||
public function booking(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Booking::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* What the guest owes: the final fee, else the proposal; nothing when waived.
|
||||
*/
|
||||
public function fee(): int
|
||||
{
|
||||
return $this->status === self::WAIVED ? 0 : (int) ($this->final_fee ?? $this->calculated_fee ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Positive: the guest still has to pay; negative: the landlord has to refund.
|
||||
*/
|
||||
public function balance(): int
|
||||
{
|
||||
return $this->fee() - $this->paid_amount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use App\Support\Money;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* A cancellation rule: stepped percentages by the days left before arrival, calculated from the rent (accommodation
|
||||
* without cleaning, service and tourist tax) or from the total price, plus an optional fee for a replacement tenant.
|
||||
* Used by contract templates; an offer freezes a copy ({@see snapshot()}), so later edits never change it.
|
||||
*/
|
||||
#[Fillable(['name', 'base', 'tiers', 'replacement_fee', 'notes'])]
|
||||
class CancellationPolicy extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
public const BASE_RENT = 'rent';
|
||||
|
||||
public const BASE_TOTAL = 'total';
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['tiers' => 'array', 'replacement_fee' => 'integer'];
|
||||
}
|
||||
|
||||
/**
|
||||
* The frozen form stored in an offer.
|
||||
*
|
||||
* @return array{name: string, base: string, tiers: list<array{min_days: int, percent: int}>, replacement_fee: ?int}
|
||||
*/
|
||||
public function snapshot(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->name,
|
||||
'base' => $this->base,
|
||||
'tiers' => self::normalise((array) $this->tiers),
|
||||
'replacement_fee' => $this->replacement_fee,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tiers sorted from the earliest to the latest cancellation: "from N days before arrival: P %".
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $tiers
|
||||
* @return list<array{min_days: int, percent: int}>
|
||||
*/
|
||||
public static function normalise(array $tiers): array
|
||||
{
|
||||
$clean = array_map(fn (array $tier): array => ['min_days' => max(0, (int) ($tier['min_days'] ?? 0)), 'percent' => min(100, max(0, (int) ($tier['percent'] ?? 0)))], $tiers);
|
||||
usort($clean, fn (array $a, array $b): int => $b['min_days'] <=> $a['min_days']);
|
||||
|
||||
return array_values($clean);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tier that applies when cancelling this many days before arrival (the last tier covers everything later).
|
||||
*
|
||||
* @param array{tiers: list<array{min_days: int, percent: int}>} $policy
|
||||
* @return array{min_days: int, percent: int}
|
||||
*/
|
||||
public static function tierFor(array $policy, int $daysBefore): array
|
||||
{
|
||||
foreach ($policy['tiers'] as $tier) {
|
||||
if ($daysBefore >= $tier['min_days']) {
|
||||
return $tier;
|
||||
}
|
||||
}
|
||||
|
||||
return $policy['tiers'][array_key_last($policy['tiers'])] ?? ['min_days' => 0, 'percent' => 100];
|
||||
}
|
||||
|
||||
/**
|
||||
* The rule as readable lines for contracts and pages, e.g. "Rücktritt bis 60 Tage vor Mietbeginn: 0 % …".
|
||||
*
|
||||
* @param array{base: string, tiers: list<array{min_days: int, percent: int}>, replacement_fee: ?int} $policy
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function describe(array $policy): array
|
||||
{
|
||||
$base = $policy['base'] === self::BASE_TOTAL ? 'des Gesamtpreises' : 'des Mietpreises';
|
||||
$lines = [];
|
||||
$tiers = $policy['tiers'];
|
||||
foreach ($tiers as $index => $tier) {
|
||||
$next = $tiers[$index + 1] ?? null;
|
||||
$when = match (true) {
|
||||
$index === 0 => 'Rücktritt bis '.$tier['min_days'].' Tage vor Mietbeginn',
|
||||
$next === null => 'Rücktritt ab '.($tiers[$index - 1]['min_days'] - 1).' Tage vor Mietbeginn bis Mietbeginn',
|
||||
default => 'Rücktritt '.($tiers[$index - 1]['min_days'] - 1).' bis '.$tier['min_days'].' Tage vor Mietbeginn',
|
||||
};
|
||||
$lines[] = $when.': '.$tier['percent'].' % '.$base;
|
||||
}
|
||||
if (($policy['replacement_fee'] ?? null) !== null) {
|
||||
$lines[] = 'Stellung eines Ersatzmieters: Bearbeitungsgebühr '.Money::format((int) $policy['replacement_fee']);
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* An annex of the rental contract as a document of its own (e.g. WLAN terms, linen package, key pick-up). A contract
|
||||
* template lists the annexes it may use; the condition decides per booking whether an annex is attached. An offer freezes
|
||||
* a copy; a version used in an offer is never edited – a new version is made instead.
|
||||
*/
|
||||
#[Fillable(['name', 'version', 'title', 'body', 'condition_type', 'condition_id', 'notes'])]
|
||||
class ContractAnnex extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
public const ALWAYS = 'always';
|
||||
|
||||
public const EXTRA = 'extra';
|
||||
|
||||
public const CHANNEL = 'channel';
|
||||
|
||||
public const MANUAL = 'manual';
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['version' => 'integer', 'condition_id' => 'integer'];
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return $this->name.' (Version '.$this->version.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this annex belongs to the booking by its condition (manual annexes are only added by hand).
|
||||
*/
|
||||
public function appliesTo(Booking $booking): bool
|
||||
{
|
||||
$channelId = $booking->import_channel_id ?? $booking->origin_channel_id;
|
||||
|
||||
return match ($this->condition_type) {
|
||||
self::ALWAYS => true,
|
||||
self::EXTRA => $this->condition_id !== null && (int) ($booking->extras[$this->condition_id] ?? 0) > 0,
|
||||
self::CHANNEL => $this->condition_id !== null && (int) $channelId === $this->condition_id,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
public function isUsed(): bool
|
||||
{
|
||||
return Booking::query()->whereJsonContains('offer_terms->annex_ids', $this->id)->exists();
|
||||
}
|
||||
|
||||
public function newVersion(): self
|
||||
{
|
||||
$latest = static::query()->where('name', $this->name)->max('version');
|
||||
|
||||
return static::query()->create([
|
||||
'name' => $this->name,
|
||||
'version' => $latest + 1,
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
'condition_type' => $this->condition_type,
|
||||
'condition_id' => $this->condition_id,
|
||||
'notes' => $this->notes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,15 @@
|
||||
use App\Models\Concerns\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* A version of contract texts for offers (e.g. conditions demanded by a portal). The texts replace the website
|
||||
* texts of the same meaning when an offer is made; the offer then freezes a copy. A version that has been used in
|
||||
* an offer is never edited – a new version is created instead.
|
||||
*/
|
||||
#[Fillable(['name', 'version', 'texts', 'body', 'annex_title', 'annex_body', 'notes'])]
|
||||
#[Fillable(['name', 'version', 'texts', 'body', 'annex_title', 'annex_body', 'cancellation_policy_id', 'annex_ids', 'notes'])]
|
||||
class ContractTemplate extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
@@ -33,7 +35,7 @@ class ContractTemplate extends Model
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['texts' => 'array', 'version' => 'integer'];
|
||||
return ['texts' => 'array', 'version' => 'integer', 'annex_ids' => 'array'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +46,24 @@ public function hasDocument(): bool
|
||||
return filled($this->body) && trim(strip_tags((string) $this->body)) !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<CancellationPolicy, $this>
|
||||
*/
|
||||
public function cancellationPolicy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CancellationPolicy::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The annexes of this template whose condition fits the booking.
|
||||
*
|
||||
* @return Collection<int, ContractAnnex>
|
||||
*/
|
||||
public function annexesFor(Booking $booking): Collection
|
||||
{
|
||||
return ContractAnnex::query()->whereIn('id', (array) ($this->annex_ids ?? []))->orderBy('name')->get()->filter(fn (ContractAnnex $annex): bool => $annex->appliesTo($booking))->values();
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return $this->name.' (Version '.$this->version.')';
|
||||
@@ -83,6 +103,8 @@ public function newVersion(): self
|
||||
'body' => $this->body,
|
||||
'annex_title' => $this->annex_title,
|
||||
'annex_body' => $this->annex_body,
|
||||
'cancellation_policy_id' => $this->cancellation_policy_id,
|
||||
'annex_ids' => $this->annex_ids,
|
||||
'notes' => $this->notes,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user