Vertragsvorlagen als ganzes Dokument mit Platzhaltern, Wohnungsdaten, Portal-Zuordnung
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m38s
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>
This commit is contained in:
1 parent
a73b164ea1
commit
89d569b6c8
17 files changed
+648
-28
No files matched your search
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Documents;
|
||||
|
||||
use App\Models\Booking;
|
||||
use App\Support\Money;
|
||||
|
||||
/**
|
||||
* Placeholders of contract documents, written as {{ name }} in the template text. Values are taken from the
|
||||
* booking and the facts of the property ({{ wohnung.wlan_passwort }}); they are HTML-escaped. A placeholder that
|
||||
* cannot be filled stays visible as [name?] so that it is never silently missing in a contract.
|
||||
*/
|
||||
class ContractPlaceholders
|
||||
{
|
||||
private const PATTERN = '/\{\{\s*([a-z][a-z0-9_]*(?:\.[a-z0-9_]+)?)\s*\}\}/i';
|
||||
|
||||
/**
|
||||
* Placeholders with their meaning, for the template editor.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function catalog(): array
|
||||
{
|
||||
return [
|
||||
'mieter' => 'Name des Gastes',
|
||||
'mieter_anschrift' => 'Anschrift des Gastes',
|
||||
'mieter_email' => 'E-Mail des Gastes',
|
||||
'anreise' => 'Anreisetag mit Wochentag, z. B. Samstag, 07.11.2026',
|
||||
'abreise' => 'Abreisetag mit Wochentag',
|
||||
'anreise_datum' => 'Anreisedatum, z. B. 07.11.2026',
|
||||
'abreise_datum' => 'Abreisedatum',
|
||||
'naechte' => 'Anzahl der Nächte',
|
||||
'personen' => 'Anzahl der Personen',
|
||||
'gesamtpreis' => 'Gesamtpreis, z. B. 1.234,00 €',
|
||||
'anzahlung' => 'Anzahlung',
|
||||
'restzahlung' => 'Restzahlung',
|
||||
'restzahlung_faellig' => 'Fälligkeit der Restzahlung',
|
||||
'buchungsnummer' => 'Buchungs-/Angebotsnummer',
|
||||
'datum' => 'Datum des Vertrags',
|
||||
'vermieter' => 'Name des Vermieters',
|
||||
'vermieter_anschrift' => 'Anschrift des Vermieters',
|
||||
'wohnung' => 'Name der Wohnung',
|
||||
'wohnung_adresse' => 'Adresse der Wohnung',
|
||||
'checkin' => 'Anreisezeit (Uhr)',
|
||||
'checkout' => 'Abreisezeit (Uhr)',
|
||||
'portal' => 'Name des Portals (leer bei eigener Buchung)',
|
||||
'wohnung.<name>' => 'Eigene Wohnungsdaten (Wohnung bearbeiten › Vertragsdaten), z. B. wohnung.wlan_passwort',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $propertyData facts of the property as frozen in the offer
|
||||
*/
|
||||
public static function render(string $html, Booking $booking, array $propertyData = []): string
|
||||
{
|
||||
$values = self::values($booking, $propertyData);
|
||||
|
||||
return (string) preg_replace_callback(self::PATTERN, function (array $match) use ($values): string {
|
||||
$key = strtolower($match[1]);
|
||||
|
||||
return array_key_exists($key, $values) && $values[$key] !== null ? e((string) $values[$key]) : '[<b>'.e($key).'?</b>]';
|
||||
}, $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Placeholders in the text that have no value for this booking.
|
||||
*
|
||||
* @param array<string, mixed> $propertyData
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function missing(string $html, Booking $booking, array $propertyData = []): array
|
||||
{
|
||||
$values = self::values($booking, $propertyData);
|
||||
preg_match_all(self::PATTERN, $html, $found);
|
||||
|
||||
return array_values(array_unique(array_filter(array_map('strtolower', $found[1]), fn (string $key): bool => ! isset($values[$key]))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $propertyData
|
||||
* @return array<string, ?string>
|
||||
*/
|
||||
private static function values(Booking $booking, array $propertyData): array
|
||||
{
|
||||
$booking->loadMissing(['guest', 'property', 'importChannel', 'originChannel']);
|
||||
$guest = $booking->guest;
|
||||
$owner = OfferTerms::owner($booking);
|
||||
$property = $booking->property;
|
||||
$address = trim(implode(', ', array_filter([$guest?->street, trim(($guest?->postal_code ?? '').' '.($guest?->city ?? ''))])));
|
||||
|
||||
$values = [
|
||||
'mieter' => $guest?->full_name,
|
||||
'mieter_anschrift' => $address ?: null,
|
||||
'mieter_email' => $guest?->email,
|
||||
'anreise' => $booking->arrival->translatedFormat('l, d.m.Y'),
|
||||
'abreise' => $booking->departure->translatedFormat('l, d.m.Y'),
|
||||
'anreise_datum' => $booking->arrival->format('d.m.Y'),
|
||||
'abreise_datum' => $booking->departure->format('d.m.Y'),
|
||||
'naechte' => (string) $booking->nights(),
|
||||
'personen' => (string) $booking->guests,
|
||||
'gesamtpreis' => Money::format($booking->total),
|
||||
'anzahlung' => Money::format($booking->deposit),
|
||||
'restzahlung' => Money::format($booking->total - $booking->deposit),
|
||||
'restzahlung_faellig' => $booking->balance_due_on?->format('d.m.Y'),
|
||||
'buchungsnummer' => $booking->reference,
|
||||
'datum' => ($booking->confirmed_at ?? $booking->offer_sent_at ?? now())->format('d.m.Y'),
|
||||
'vermieter' => $owner['name'] ?? null,
|
||||
'vermieter_anschrift' => trim(($owner['street'] ?? '').', '.($owner['city'] ?? ''), ', ') ?: null,
|
||||
'wohnung' => $property->name,
|
||||
'wohnung_adresse' => $property->address,
|
||||
'checkin' => $property->check_in_time ? substr((string) $property->check_in_time, 0, 5) : null,
|
||||
'checkout' => $property->check_out_time ? substr((string) $property->check_out_time, 0, 5) : null,
|
||||
'portal' => ($booking->importChannel ?? $booking->originChannel)?->name ?? '',
|
||||
];
|
||||
|
||||
foreach ($propertyData as $name => $value) {
|
||||
$values['wohnung.'.strtolower((string) $name)] = is_scalar($value) ? (string) $value : null;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user