Files
fewo-stommer/app/Models/ContractAnnex.php
LarsandClaude Sonnet 5.5 0c4187edaf
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m34s
Stornoregeln mit automatischer Kostenberechnung, Storno-Verwaltung, Vertragsanlagen
- 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>
2026-10-30 16:32:48 +01:00

77 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\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,
]);
}
}