Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
- Vorlage = kompletter Vertragstext plus Anlage mit Platzhaltern ({{ mieter }}, {{ anreise }}, {{ wohnung.x }}),
eigene Vertrags-PDF, Anzeige auf der Angebotsseite; Text und Wohnungsdaten werden beim Angebot eingefroren
- Wohnungsdaten (WLAN, Codes, ...) als Vertragsdaten der Wohnung statt im Vorlagentext
- Je Portal eigene Vorlage fuer Anfragen und fuer beim Portal verbindliche Buchungen; direkte Bestaetigung
nutzt dieselbe Aufloesung; Bestaetigungsmail ohne Zahlungsanweisung bei Portalzahlung
- Befehl contracts:install-fewo-direkt legt die FeWo-direkt-Vorlage aus dem Vertragstext des Vermieters an
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use App\Models\Concerns\BelongsToTenant;
|
||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
|
||
/**
|
||
* 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'])]
|
||
class ContractTemplate extends Model
|
||
{
|
||
use BelongsToTenant;
|
||
|
||
/** Form/storage key => website text key it replaces in an offer. */
|
||
public const TEXTS = [
|
||
'intro' => 'contract.intro',
|
||
'terms' => 'contract.terms',
|
||
'closing' => 'contract.closing',
|
||
'cancellation' => 'stay.cancellation',
|
||
'house_rules' => 'stay.house_rules',
|
||
'contract_note' => 'offer.contract_note',
|
||
];
|
||
|
||
/**
|
||
* Get the attributes that should be cast.
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
protected function casts(): array
|
||
{
|
||
return ['texts' => 'array', 'version' => 'integer'];
|
||
}
|
||
|
||
/**
|
||
* A complete contract document (text with placeholders) instead of text blocks.
|
||
*/
|
||
public function hasDocument(): bool
|
||
{
|
||
return filled($this->body) && trim(strip_tags((string) $this->body)) !== '';
|
||
}
|
||
|
||
public function label(): string
|
||
{
|
||
return $this->name.' (Version '.$this->version.')';
|
||
}
|
||
|
||
/**
|
||
* Texts by website text key; blank ones fall back to the website texts.
|
||
*
|
||
* @return array<string, string>
|
||
*/
|
||
public function overrides(): array
|
||
{
|
||
$overrides = [];
|
||
foreach (self::TEXTS as $field => $key) {
|
||
$value = $this->texts[$field] ?? null;
|
||
if (filled($value) && trim(strip_tags((string) $value)) !== '') {
|
||
$overrides[$key] = (string) $value;
|
||
}
|
||
}
|
||
|
||
return $overrides;
|
||
}
|
||
|
||
public function isUsed(): bool
|
||
{
|
||
return Booking::query()->where('offer_terms->template->id', $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,
|
||
'texts' => $this->texts,
|
||
'body' => $this->body,
|
||
'annex_title' => $this->annex_title,
|
||
'annex_body' => $this->annex_body,
|
||
'notes' => $this->notes,
|
||
]);
|
||
}
|
||
}
|