- 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.
238 lines
14 KiB
PHP
238 lines
14 KiB
PHP
<?php
|
||
/** @var array $booking */
|
||
/** @var array $reminders */
|
||
/** @var array $doneMap */
|
||
/** @var string $copyText */
|
||
/** @var bool $canDelete */
|
||
/** @var bool $canEdit */
|
||
/** @var bool $canCancel */
|
||
/** @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']);
|
||
$returnTo = '/bookings/' . (int) $booking['id'];
|
||
?>
|
||
<div class="breadcrumb">
|
||
<a href="<?= e(url('/calendar?date=' . $booking['start_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Kalender</a>
|
||
<span>/</span>
|
||
<span>Buchung #<?= (int) $booking['id'] ?></span>
|
||
</div>
|
||
|
||
<div class="page-head page-head--compact">
|
||
<div>
|
||
<p class="eyebrow">
|
||
<?= e(fmt_date_with_time($booking['start_date'], $booking['start_time'] ?? null)) ?> –
|
||
<?= e(fmt_date_with_time($booking['end_date'], $booking['end_time'] ?? null)) ?> ·
|
||
<?= e($booking['trailer_label']) ?> · <?= e(booking_employee_summary($booking)) ?>
|
||
</p>
|
||
<h1><?= e($booking['customer_name']) ?>
|
||
<span class="pill <?= $cancelled ? 'pill--grey' : 'pill--green' ?>"><?= $cancelled ? 'storniert' : 'aktiv' ?></span>
|
||
</h1>
|
||
</div>
|
||
<div class="page-head__actions">
|
||
<?php if (!empty($canEdit)): ?>
|
||
<a class="btn" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Bearbeiten</a>
|
||
<?php endif; ?>
|
||
<?php if ($isAdmin): ?>
|
||
<a class="btn" href="<?= e(url('/bookings/new')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Neue Buchung</a>
|
||
<?php endif; ?>
|
||
<?php if (!empty($canCancel)): ?>
|
||
<?php if (!$cancelled): ?>
|
||
<form method="post" action="<?= e(url($returnTo . '/cancel')) ?>" data-confirm="Buchung von <?= e($booking['customer_name']) ?> wirklich stornieren?">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||
<button class="btn danger" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-close"/></svg> Stornieren</button>
|
||
</form>
|
||
<?php else: ?>
|
||
<form method="post" action="<?= e(url($returnTo . '/restore')) ?>" data-confirm="Buchung wieder aktivieren?">
|
||
<?= csrf_field() ?>
|
||
<button class="btn" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> Wiederherstellen</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($cancelled): ?>
|
||
<div class="alert alert--warning">
|
||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||
<div><strong>Storniert<?= $booking['cancelled_at'] ? ' am ' . e(fmt_datetime($booking['cancelled_at'])) : '' ?>.</strong> Die Erinnerungen für diese Buchung entfallen.</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="detail-grid">
|
||
<div class="detail-main">
|
||
<section class="card card--copy" data-copy-wrap>
|
||
<div class="card__head card__head--row">
|
||
<div>
|
||
<h2>Buchungsinformation</h2>
|
||
<p>Genau diese Reihenfolge wird beim Kopieren übernommen.</p>
|
||
</div>
|
||
<button class="btn primary" type="button" data-copy>
|
||
<svg class="ico" aria-hidden="true"><use href="#i-copy"/></svg> Alles kopieren
|
||
</button>
|
||
</div>
|
||
<textarea class="copy-source" readonly aria-hidden="true" tabindex="-1"><?= e($copyText) ?></textarea>
|
||
<dl class="copy-list">
|
||
<?php foreach ($lines as $line): ?>
|
||
<?php
|
||
$parts = explode(': ', $line, 2);
|
||
$label = $parts[0] ?? $line;
|
||
$value = $parts[1] ?? '';
|
||
?>
|
||
<div class="copy-list__row<?= $label === 'Noch zu zahlen' ? ' is-strong' : '' ?>">
|
||
<dt><?= e($label) ?></dt>
|
||
<dd><?= e($value) ?></dd>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</dl>
|
||
<p class="copy-hint"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Zeilenumbrüche und Formatierung bleiben beim Kopieren erhalten.</p>
|
||
</section>
|
||
|
||
<?php if (trim((string) ($booking['note'] ?? '')) !== ''): ?>
|
||
<section class="card">
|
||
<div class="card__head">
|
||
<h2>Bemerkung</h2>
|
||
<p>Interne Notiz – nicht Teil des kopierten Kundentexts.</p>
|
||
</div>
|
||
<p class="note-text"><?= nl2br(e((string) $booking['note'])) ?></p>
|
||
</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>
|
||
<p>Wird der Termin verschoben, passen sich die Fälligkeiten automatisch an.</p>
|
||
</div>
|
||
<?php if ($cancelled): ?>
|
||
<div class="empty-state small"><p>Diese Buchung ist storniert – es werden keine Erinnerungen erzeugt.</p></div>
|
||
<?php else: ?>
|
||
<ul class="reminder-list">
|
||
<?php foreach ($reminders as $reminder): ?>
|
||
<?php
|
||
$key = reminder_done_key($booking, $reminder['kind'], $reminder['due_date']);
|
||
$done = isset($doneMap[$key]);
|
||
$overdue = !$done && $reminder['due_date'] < today_iso();
|
||
?>
|
||
<li class="reminder-row<?= $done ? ' is-done' : '' ?><?= $overdue ? ' is-overdue' : '' ?>">
|
||
<div class="reminder-row__date">
|
||
<strong><?= e(fmt_date($reminder['due_date'])) ?></strong>
|
||
<span><?= e(relative_day($reminder['due_date'])) ?></span>
|
||
</div>
|
||
<div class="reminder-row__body">
|
||
<strong><?= e($reminder['label']) ?></strong>
|
||
<p><?= e($reminder['message']) ?></p>
|
||
<span class="muted small"><?= e($reminder['short']) ?> · <?= e($reminder['kind'] === 'end_1' ? booking_return_employee_name($booking) : $booking['employee_name']) ?></span>
|
||
</div>
|
||
<div class="reminder-row__action">
|
||
<?php if ($done): ?>
|
||
<span class="pill pill--green"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> erledigt</span>
|
||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
|
||
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
|
||
<input type="hidden" name="done" value="0">
|
||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||
<button class="link-button small" type="submit">rückgängig</button>
|
||
</form>
|
||
<?php else: ?>
|
||
<form method="post" action="<?= e(url('/reminders/done')) ?>">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="booking_id" value="<?= (int) $booking['id'] ?>">
|
||
<input type="hidden" name="kind" value="<?= e($reminder['kind']) ?>">
|
||
<input type="hidden" name="done" value="1">
|
||
<input type="hidden" name="return_to" value="<?= e($returnTo) ?>">
|
||
<button class="btn small" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Erledigt</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</div>
|
||
</li>
|
||
<?php endforeach; ?>
|
||
</ul>
|
||
<?php endif; ?>
|
||
</section>
|
||
</div>
|
||
|
||
<aside class="detail-side">
|
||
<section class="card">
|
||
<h2>Zuordnung</h2>
|
||
<dl class="meta-list">
|
||
<div>
|
||
<dt>Kühlanhänger</dt>
|
||
<dd>
|
||
<span class="trailer-chip" style="--trailer: <?= e($booking['trailer_color']) ?>; --trailer-text: <?= e(contrast_color($booking['trailer_color'])) ?>">
|
||
<span class="trailer-dot" style="--trailer: <?= e($booking['trailer_color']) ?>"></span>
|
||
<?= e($booking['trailer_label']) ?>
|
||
</span>
|
||
</dd>
|
||
</div>
|
||
<div><dt>Übergabe</dt><dd><?= e($booking['employee_name']) ?></dd></div>
|
||
<div><dt>Rücknahme</dt><dd><?= e(booking_return_employee_name($booking)) ?></dd></div>
|
||
<div><dt>Von</dt><dd><?= e(fmt_date_long($booking['start_date'])) ?><?php if (fmt_time($booking['start_time'] ?? null) !== ''): ?> · <?= e(fmt_time($booking['start_time'])) ?> Uhr<?php endif; ?></dd></div>
|
||
<div><dt>Bis</dt><dd><?= e(fmt_date_long($booking['end_date'])) ?><?php if (fmt_time($booking['end_time'] ?? null) !== ''): ?> · <?= e(fmt_time($booking['end_time'])) ?> Uhr<?php endif; ?></dd></div>
|
||
<div><dt>Art</dt><dd><span class="pill pill--blue"><?= e(booking_kind_label((string) $booking['kind'])) ?></span></dd></div>
|
||
<div><dt>Rechnung</dt><dd><span class="pill <?= (int) $booking['invoice'] === 1 ? 'pill--green' : 'pill--grey' ?>"><?= e(booking_invoice_label($booking['invoice'])) ?></span></dd></div>
|
||
<?php if (trim((string) ($booking['invoice_no'] ?? '')) !== ''): ?>
|
||
<div><dt>Rechnungsnummer</dt><dd><?= e((string) $booking['invoice_no']) ?></dd></div>
|
||
<?php endif; ?>
|
||
</dl>
|
||
<hr>
|
||
<dl class="money-list">
|
||
<div><dt>Miete</dt><dd><?= e(fmt_money((int) $booking['rent_cents'])) ?></dd></div>
|
||
<div><dt>Lieferkosten</dt><dd><?= e(fmt_money((int) $booking['delivery_cents'])) ?></dd></div>
|
||
<div><dt>Gesamtbetrag</dt><dd><?= e(fmt_money((int) $booking['total_cents'])) ?></dd></div>
|
||
<div><dt>Anzahlung</dt><dd><?= e(fmt_money((int) $booking['deposit_cents'])) ?></dd></div>
|
||
<div class="is-strong"><dt>Noch zu zahlen</dt><dd><?= e(fmt_money($due)) ?></dd></div>
|
||
</dl>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<h2>Aktionen</h2>
|
||
<div class="stack-actions">
|
||
<?php if (!empty($canEdit)): ?>
|
||
<a class="btn btn--block" href="<?= e(url($returnTo . '/edit')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-edit"/></svg> Buchung bearbeiten</a>
|
||
<?php endif; ?>
|
||
<?php if ($isAdmin): ?>
|
||
<a class="btn btn--block" href="<?= e(url('/bookings/new?trailer=' . (int) $booking['trailer_id'] . '&start=' . $booking['end_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anschlussbuchung anlegen</a>
|
||
<?php endif; ?>
|
||
<?php if ($canDelete): ?>
|
||
<form method="post" action="<?= e(url($returnTo . '/delete')) ?>" data-confirm="Buchung endgültig löschen? Das kann nicht rückgängig gemacht werden.">
|
||
<?= csrf_field() ?>
|
||
<button class="btn danger-ghost btn--block" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Endgültig löschen</button>
|
||
</form>
|
||
<?php elseif ($isAdmin && $deleteBlocked): ?>
|
||
<p class="muted small">
|
||
Diese Buchung ist als Rechnung markiert und unterliegt der gesetzlichen Aufbewahrungspflicht.
|
||
Löschen ist deshalb gesperrt. Wenn keine Rechnung erstellt wurde, kann die Markierung unter
|
||
<strong>Bearbeiten</strong> entfernt werden.
|
||
</p>
|
||
<?php endif; ?>
|
||
</div>
|
||
</section>
|
||
|
||
<p class="muted small detail-meta">
|
||
Angelegt am <?= e(fmt_datetime($booking['created_at'])) ?>.
|
||
Zuletzt geändert am <?= e(fmt_datetime($booking['updated_at'])) ?>.
|
||
</p>
|
||
</aside>
|
||
</div>
|