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>
56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Documents;
|
|
|
|
use App\Models\Booking;
|
|
use App\Models\Site;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
/**
|
|
* The rental contract as PDF. As a draft it is part of the offer (offer_path, one file per offer version);
|
|
* the final contract is generated at confirmation (contract_path). Both are stored, so later changes of
|
|
* texts or prices do not alter a document the guest already received.
|
|
*/
|
|
class RentalContract
|
|
{
|
|
private const DISK = 'local';
|
|
|
|
public function generate(Booking $booking, bool $draft = false): string
|
|
{
|
|
$booking->loadMissing(['guest', 'property']);
|
|
$filename = $draft
|
|
? "contracts/Angebot-{$booking->reference}-v{$booking->offer_version}.pdf"
|
|
: "contracts/Mietvertrag-{$booking->reference}.pdf";
|
|
$path = "contracts/tenants/{$booking->tenant_id}/bookings/{$booking->id}/".basename($filename);
|
|
|
|
// The logo is embedded as a file: the PDF is rendered on the server and must not depend on
|
|
// fetching anything over the network. Each website has its own (A14).
|
|
$logo = $booking->website()?->brandPath(Site::BRAND_DOCUMENT_LOGO);
|
|
|
|
// The final contract is a document of record: once stored it is never rewritten (confirmation resends reuse it).
|
|
if (! $draft && $booking->contract_path !== null && Storage::disk(self::DISK)->exists($booking->contract_path)) {
|
|
return $booking->contract_path;
|
|
}
|
|
|
|
$document = OfferTerms::document($booking);
|
|
$pdf = Pdf::loadView($document !== null ? 'pdf.contract-document' : 'pdf.contract', [
|
|
'booking' => $booking,
|
|
'draft' => $draft,
|
|
'logo' => $logo,
|
|
'document' => $document,
|
|
])->setPaper('a4')->output();
|
|
Storage::disk(self::DISK)->put($path, $pdf);
|
|
$booking->update([$draft ? 'offer_path' : 'contract_path' => $path, $draft ? 'offer_pdf_sha256' : 'contract_pdf_sha256' => hash('sha256', $pdf)]);
|
|
|
|
return $path;
|
|
}
|
|
|
|
public function absolutePath(Booking $booking, bool $draft = false): ?string
|
|
{
|
|
$path = $draft ? $booking->offer_path : $booking->contract_path;
|
|
|
|
return $path && Storage::disk(self::DISK)->exists($path) ? Storage::disk(self::DISK)->path($path) : null;
|
|
}
|
|
}
|