- 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.
175 lines
9.2 KiB
PHP
175 lines
9.2 KiB
PHP
<?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>
|