feat(documents): Mietvertrag, Auftragsbestätigung und Rechnung zur Buchung
- Mietvertrag als PDF in drei Varianten (Mit Lieferung, Selbstabholer, Truhe), Seite 2+ mit der AGB aus app/agb.php – derselbe Text wie /agb. - Auftragsbestätigung als PDF, ebenfalls in drei Varianten. - PDF-Erzeuger ohne Fremdbibliothek (app/pdf.php, Helvetica + JPEG für die Unterschrift); Layout in app/documents.php. - Unterschrift auf dem Tablet (views/document_sign.php, Canvas -> JPEG) wird ins PDF gesetzt; Unterlagen lassen sich ansehen, drucken und per Mail an den Kunden senden (mail_send_attachment()). - Rechnung aus Lexware als PDF-Upload; Ablage unter storage/documents/<booking_id>/ (per .htaccess gesperrt). - Aufbewahrung: documents_cleanup() im Cron löscht einen Monat nach Mietende (app.document_retention_days), inklusive verwaister Dateien. - Migrationen per HTTP (/migrate?token=…, app/migrate.php), weil das Hosting kein SSH hat; deploy.sh ruft die Route nach dem Sync auf. - Schema: booking_documents (Migration 012, auch in schema.sql), Doku in README/ROADMAP/docs/todo_kundenemail_2026-11-30-unterlagen.md. Enthält außerdem die bislang nicht committeten Anpassungen in bootstrap.php und app.js/pages.php, die im selben Arbeitsstand lagen.
This commit is contained in:
parent
3e34a6c839
commit
2de8e95c15
24 changed files with 2412 additions and 49 deletions
|
|
@ -9,6 +9,13 @@
|
|||
/** @var bool $canEditBilling */
|
||||
/** @var bool $deleteBlocked */
|
||||
/** @var bool $isAdmin */
|
||||
/** @var list<array<string, mixed>> $documents */
|
||||
/** @var array<string, string> $documentVariants */
|
||||
/** @var string $documentVariantDefault */
|
||||
/** @var bool $canManageDocuments */
|
||||
/** @var bool $canDeleteDocuments */
|
||||
/** @var bool $documentsMailEnabled */
|
||||
/** @var int $documentsRetentionDays */
|
||||
$cancelled = $booking['status'] === 'cancelled';
|
||||
$lines = explode("\n", $copyText);
|
||||
$due = due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents']);
|
||||
|
|
@ -101,6 +108,17 @@ $returnTo = '/bookings/' . (int) $booking['id'];
|
|||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?= render_partial('booking_documents', [
|
||||
'booking' => $booking,
|
||||
'documents' => $documents ?? [],
|
||||
'documentVariants' => $documentVariants ?? document_variants(),
|
||||
'documentVariantDefault' => $documentVariantDefault ?? document_variant_default($booking),
|
||||
'canManageDocuments' => $canManageDocuments ?? false,
|
||||
'canDeleteDocuments' => $canDeleteDocuments ?? false,
|
||||
'documentsMailEnabled' => $documentsMailEnabled ?? false,
|
||||
'documentsRetentionDays' => $documentsRetentionDays ?? 30,
|
||||
]) ?>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__head">
|
||||
<h2>Automatische Erinnerungen</h2>
|
||||
|
|
|
|||
175
views/booking_documents.php
Normal file
175
views/booking_documents.php
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/**
|
||||
* Karte "Unterlagen" auf der Buchungsseite: Mietvertrag, Auftragsbestätigung,
|
||||
* Rechnung. Wird aus views/booking_detail.php eingebunden.
|
||||
*
|
||||
* @var array $booking
|
||||
* @var list<array<string, mixed>> $documents
|
||||
* @var array<string, string> $documentVariants
|
||||
* @var string $documentVariantDefault
|
||||
* @var bool $canManageDocuments
|
||||
* @var bool $canDeleteDocuments
|
||||
* @var bool $documentsMailEnabled
|
||||
* @var int $documentsRetentionDays
|
||||
*/
|
||||
$returnTo = '/bookings/' . (int) $booking['id'];
|
||||
$customerMail = trim((string) $booking['email']);
|
||||
$hasMail = filter_var($customerMail, FILTER_VALIDATE_EMAIL) !== false;
|
||||
$hasContract = false;
|
||||
$hasConfirmation = false;
|
||||
$hasInvoice = false;
|
||||
foreach ($documents as $doc) {
|
||||
$hasContract = $hasContract || $doc['kind'] === 'contract';
|
||||
$hasConfirmation = $hasConfirmation || $doc['kind'] === 'confirmation';
|
||||
$hasInvoice = $hasInvoice || $doc['kind'] === 'invoice';
|
||||
}
|
||||
$docKindLabel = static fn (string $kind): string => match ($kind) {
|
||||
'contract' => 'Mietvertrag',
|
||||
'confirmation' => 'Auftragsbestätigung',
|
||||
'invoice' => 'Rechnung',
|
||||
default => $kind,
|
||||
};
|
||||
?>
|
||||
<section class="card" id="unterlagen">
|
||||
<div class="card__head">
|
||||
<h2>Unterlagen für den Termin</h2>
|
||||
<p>Mietvertrag und Auftragsbestätigung erzeugt die App als PDF – zum Ausdrucken oder direkt per E-Mail an den Kunden.
|
||||
Die Rechnung aus Lexware lässt sich hier als PDF ablegen, damit jeder Fahrer alles in der Buchung findet.</p>
|
||||
</div>
|
||||
|
||||
<?php if ($documentsRetentionDays > 0): ?>
|
||||
<p class="docs-hint">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
Unterlagen werden automatisch <?= (int) $documentsRetentionDays ?> Tage nach dem Mietende gelöscht.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($canManageDocuments)): ?>
|
||||
<form class="docs-create" method="post" action="<?= e(url($returnTo . '/documents')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<label class="field">
|
||||
<span>Variante</span>
|
||||
<select name="variant">
|
||||
<?php foreach ($documentVariants as $key => $label): ?>
|
||||
<option value="<?= e($key) ?>"<?= $key === $documentVariantDefault ? ' selected' : '' ?>><?= e($label) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<div class="docs-create__actions">
|
||||
<button class="btn primary" type="submit" name="kind" value="contract">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg>
|
||||
<?= $hasContract ? 'Mietvertrag neu erzeugen' : 'Mietvertrag erzeugen' ?>
|
||||
</button>
|
||||
<button class="btn" type="submit" name="kind" value="confirmation">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg>
|
||||
<?= $hasConfirmation ? 'Auftragsbestätigung neu erzeugen' : 'Auftragsbestätigung erzeugen' ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form class="docs-upload" method="post" enctype="multipart/form-data" action="<?= e(url($returnTo . '/documents/rechnung')) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<label class="field">
|
||||
<span>Rechnung aus Lexware (PDF)</span>
|
||||
<input type="file" name="invoice" accept="application/pdf,.pdf" required>
|
||||
</label>
|
||||
<button class="btn" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg>
|
||||
Rechnung ablegen
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($documents === []): ?>
|
||||
<div class="empty-state small"><p>Noch keine Unterlagen zu dieser Buchung.</p></div>
|
||||
<?php else: ?>
|
||||
<div class="table-wrap">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Unterlage</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Status</th>
|
||||
<th class="table-actions">Aktionen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($documents as $doc): ?>
|
||||
<?php
|
||||
$docId = (int) $doc['id'];
|
||||
$fileUrl = url($returnTo . '/documents/' . $docId);
|
||||
$isContract = $doc['kind'] === 'contract';
|
||||
$signed = trim((string) ($doc['signed_at'] ?? '')) !== '';
|
||||
$mailed = trim((string) ($doc['mailed_at'] ?? '')) !== '';
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="table-person">
|
||||
<span>
|
||||
<strong><?= e($docKindLabel((string) $doc['kind'])) ?></strong>
|
||||
<small class="muted">
|
||||
<?= e((string) $doc['file_name']) ?>
|
||||
<?php if ((string) $doc['variant'] !== ''): ?>
|
||||
· <?= e($documentVariants[(string) $doc['variant']] ?? (string) $doc['variant']) ?>
|
||||
<?php endif; ?>
|
||||
· <?= e(number_format(((int) $doc['size_bytes']) / 1024, 0, ',', '.')) ?> kB
|
||||
</small>
|
||||
</span>
|
||||
</span>
|
||||
</td>
|
||||
<td><?= e(fmt_datetime((string) $doc['created_at'])) ?></td>
|
||||
<td>
|
||||
<?php if ($signed): ?>
|
||||
<span class="pill pill--green">unterschrieben</span>
|
||||
<?php elseif ($isContract): ?>
|
||||
<span class="pill pill--grey">offen</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($mailed): ?>
|
||||
<span class="pill pill--blue">per Mail gesendet</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="table-actions">
|
||||
<a class="btn small" href="<?= e($fileUrl) ?>" target="_blank" rel="noopener">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-search"/></svg> Ansehen / Drucken
|
||||
</a>
|
||||
<a class="btn small" href="<?= e($fileUrl . '?download=1') ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> PDF
|
||||
</a>
|
||||
<?php if ($isContract && !empty($canManageDocuments)): ?>
|
||||
<a class="btn small" href="<?= e(url($returnTo . '/documents/' . $docId . '/sign')) ?>">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg>
|
||||
<?= $signed ? 'Neu unterschreiben' : 'Unterschreiben' ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($documentsMailEnabled) && $hasMail && !empty($canManageDocuments)): ?>
|
||||
<form method="post" action="<?= e(url($returnTo . '/documents/' . $docId . '/mail')) ?>"
|
||||
data-confirm="Unterlage an <?= e($customerMail) ?> senden?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn small" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-mail"/></svg> Mailen
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($canDeleteDocuments)): ?>
|
||||
<form method="post" action="<?= e(url($returnTo . '/documents/' . $docId . '/delete')) ?>"
|
||||
data-confirm="Unterlage wirklich löschen?">
|
||||
<?= csrf_field() ?>
|
||||
<button class="btn small danger" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-close"/></svg> Löschen
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($documentsMailEnabled) && !$hasMail): ?>
|
||||
<p class="docs-hint muted">Für den Mailversand fehlt in der Buchung eine gültige E-Mail-Adresse des Kunden.</p>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
54
views/document_sign.php
Normal file
54
views/document_sign.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Unterschrift auf dem Tablet. Wird ohne Layout ausgeliefert, damit auf dem
|
||||
* Tablet nur die Unterschriftfläche zu sehen ist.
|
||||
*
|
||||
* @var array $booking
|
||||
* @var array $doc
|
||||
* @var string $title
|
||||
*/
|
||||
$back = '/bookings/' . (int) $booking['id'] . '#unterlagen';
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
|
||||
<meta name="theme-color" content="#196abc">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title><?= e($title) ?> · Drink it cold</title>
|
||||
<link rel="icon" type="image/svg+xml" href="<?= e(asset('favicon.svg')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
|
||||
<script src="<?= e(asset('app.js')) ?>" defer></script>
|
||||
</head>
|
||||
<body class="app sign-page">
|
||||
<main class="sign-shell">
|
||||
<header class="sign-head">
|
||||
<p class="eyebrow">Drink it cold · <?= e((string) $doc['file_name']) ?></p>
|
||||
<h1>Unterschrift Mietvertrag</h1>
|
||||
<p class="muted">
|
||||
<?= e((string) $booking['customer_name']) ?> ·
|
||||
<?= e(fmt_date_short((string) $booking['start_date'])) ?> –
|
||||
<?= e(fmt_date_short((string) $booking['end_date'])) ?> ·
|
||||
<?= e((string) $booking['trailer_label']) ?>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<form method="post" action="<?= e(url('/bookings/' . (int) $booking['id'] . '/documents/' . (int) $doc['id'] . '/sign')) ?>"
|
||||
data-signature-form>
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="signature" value="" data-signature-input>
|
||||
<div class="sign-pad" data-signature-pad>
|
||||
<canvas width="900" height="300" data-signature-canvas aria-label="Unterschriftfläche"></canvas>
|
||||
<p class="sign-pad__hint">Bitte hier unterschreiben</p>
|
||||
</div>
|
||||
<p class="muted small">Mit dem Speichern bestätigt der Mieter, den Mietvertrag gelesen und angenommen zu haben.</p>
|
||||
<div class="sign-actions">
|
||||
<button type="button" class="btn" data-signature-clear>Leeren</button>
|
||||
<button type="submit" class="btn primary" data-signature-submit disabled>Unterschrift übernehmen</button>
|
||||
<a class="btn" href="<?= e(url($back)) ?>">Abbrechen</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
45
views/legal_agb.php
Normal file
45
views/legal_agb.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/** @var array $info */
|
||||
$owner = trim((string) $info['owner']) !== '' ? trim((string) $info['owner']) : (string) $info['business_name'];
|
||||
$sections = agb_sections();
|
||||
?>
|
||||
<p class="legal-eyebrow">Mietbedingungen</p>
|
||||
<h1>Allgemeine Geschäftsbedingungen (AGB)</h1>
|
||||
<p class="legal-lead">
|
||||
für die Vermietung von Kühlanhängern & Kühltrühen –
|
||||
<?= e($owner) ?> – „<?= e((string) $info['business_name']) ?>“ (nachfolgend „Vermieter“).
|
||||
</p>
|
||||
|
||||
<nav class="legal-toc" aria-label="Inhalt dieser Bedingungen">
|
||||
<ol>
|
||||
<?php foreach ($sections as $section): ?>
|
||||
<li><a href="#<?= e((string) $section['id']) ?>"><?= e((string) $section['title']) ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<?php foreach ($sections as $index => $section): ?>
|
||||
<section class="legal-section" id="<?= e((string) $section['id']) ?>">
|
||||
<h2><?= e(agb_heading((int) $index, $section)) ?></h2>
|
||||
<?php foreach (agb_plain_blocks($section) as $block): ?>
|
||||
<?php if ($block['type'] === 'p'): ?>
|
||||
<p><?= e($block['text']) ?></p>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php
|
||||
$items = [];
|
||||
foreach ($section['blocks'] as $raw) {
|
||||
foreach ((array) ($raw['ul'] ?? []) as $item) {
|
||||
$items[] = (string) $item;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($items !== []): ?>
|
||||
<ul>
|
||||
<?php foreach ($items as $item): ?>
|
||||
<li><?= e($item) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
|
|
@ -287,6 +287,7 @@ $rememberDays = (int) $info['remember_days'];
|
|||
<li><strong>Buchungen:</strong> bis zur Beendigung des Mietverhältnisses und vollständigen Abwicklung; danach werden die Daten gelöscht oder anonymisiert, sobald keine gesetzlichen Aufbewahrungspflichten entgegenstehen.</li>
|
||||
<li><strong>Rechnungs- und Buchhaltungsdaten:</strong> <?= $invoiceYears ?> Jahre (§ 147 Abgabenordnung, § 257 Handelsgesetzbuch).</li>
|
||||
<li><strong>Sonstige Buchungsdaten:</strong> bis zum Ablauf der regelmäßigen Verjährungsfrist von <?= $limitationYears ?> Jahren zum Jahresende (§§ 195, 199 BGB), soweit sie zur Geltendmachung oder Abwehr von Ansprüchen erforderlich sind.</li>
|
||||
<li><strong>Buchungsunterlagen (Mietvertrag, Auftragsbestätigung, Rechnung als PDF):</strong> Löschung einen Monat nach dem Mietende, sofern keine gesetzliche Aufbewahrungspflicht entgegensteht.</li>
|
||||
<li><strong>Stornierte Buchungen:</strong> Löschung, sobald kein Aufbewahrungsgrund mehr besteht.</li>
|
||||
<li><strong>Mitarbeiterkonten:</strong> für die Dauer des Beschäftigungsverhältnisses; danach Löschung, sobald keine gesetzlichen Aufbewahrungspflichten entgegenstehen.</li>
|
||||
<li><strong>Login-Fehlversuche:</strong> 24 Stunden.</li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue