*/ 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)', 'storno_regel' => 'Die Stornoregel dieser Vorlage als Aufzählung (Stufen und Prozent)', 'wohnung.' => 'Eigene Wohnungsdaten (Wohnung bearbeiten › Vertragsdaten), z. B. wohnung.wlan_passwort', ]; } /** * @param array $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]); if (! array_key_exists($key, $values) || $values[$key] === null) { return '['.e($key).'?]'; } return in_array($key, self::RAW, true) ? (string) $values[$key] : e((string) $values[$key]); }, $html); } /** * Placeholders in the text that have no value for this booking. * * @param array $propertyData * @return list */ 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 $propertyData * @return array */ 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 ?? '', ]; $policy = $booking->offer_terms['cancellation_policy'] ?? null; if (is_array($policy) && ! empty($policy['tiers'])) { $values['storno_regel'] = '
    '.collect(CancellationPolicy::describe($policy))->map(fn (string $line): string => '
  • '.e($line).'
  • ')->implode('').'
'; } foreach ($propertyData as $name => $value) { $values['wohnung.'.strtolower((string) $name)] = is_scalar($value) ? (string) $value : null; } return $values; } }