feat(settings): eigene Unterschrift hinterlegen, Datum im Unterschriftenfeld
- Neue Seite Verwaltung → Einstellungen (/admin/settings): Unterschrift mit Maus/Finger zeichnen, Vorschau, Speichern und Entfernen; Bild über die geschützte Route /admin/settings/signature - owner_signature_*() in app/documents.php speichert die Unterschrift als JPEG unter storage/signature/ (0600) und liefert Pfad/Zeitpunkt - Auftragsbestätigung: Unterschrift des Vermieters im rechten Feld, links vorbelegt „Ort, Datum“ (z. B. „Neuss, 30.11.2026“); beide Felder wandern zusammen auf Seite 2, wenn kein Platz bleibt - Zahlungs- und Schlusstext zu einem Absatz zusammengefasst, damit die Bestätigung mit Anzahlung und Unterschrift einseitig bleibt - CSS .signature-preview, Anleitung, README und ROADMAP (Feature 26)
This commit is contained in:
parent
a45a159f9e
commit
e4be5831e1
6 changed files with 226 additions and 17 deletions
|
|
@ -50,6 +50,14 @@ function admin_handle(string $path, array $user): void
|
|||
admin_accounts();
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/settings') {
|
||||
admin_settings($user);
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/settings/signature') {
|
||||
admin_settings_signature();
|
||||
return;
|
||||
}
|
||||
if ($path === '/admin/backups') {
|
||||
admin_backups($user);
|
||||
return;
|
||||
|
|
@ -916,3 +924,54 @@ function admin_accounts(): void
|
|||
'rowValues' => $rowValues,
|
||||
], 'Konten');
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------- Einstellungen */
|
||||
|
||||
function admin_settings(array $user): void
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
if (is_post()) {
|
||||
require_post();
|
||||
$action = post_string('action');
|
||||
try {
|
||||
if ($action === 'save_signature') {
|
||||
owner_signature_save((string) ($_POST['signature'] ?? ''));
|
||||
error_log('Einstellungen: Unterschrift des Vermieters gespeichert (Benutzer ' . (int) $user['id'] . ')');
|
||||
flash('success', 'Unterschrift gespeichert – sie erscheint in allen neu erzeugten Auftragsbestätigungen.');
|
||||
redirect('/admin/settings');
|
||||
}
|
||||
if ($action === 'delete_signature') {
|
||||
owner_signature_delete();
|
||||
error_log('Einstellungen: Unterschrift des Vermieters entfernt (Benutzer ' . (int) $user['id'] . ')');
|
||||
flash('success', 'Unterschrift entfernt.');
|
||||
redirect('/admin/settings');
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
error_log('Einstellungen: ' . $error->getMessage());
|
||||
$errors['general'] = $error->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
render_page('admin_settings', [
|
||||
'signatureTime' => owner_signature_time(),
|
||||
'hasSignature' => owner_signature_path() !== null,
|
||||
'errors' => $errors,
|
||||
'legal' => legal_data(),
|
||||
'depositDueDays' => deposit_due_working_days(),
|
||||
], 'Einstellungen');
|
||||
}
|
||||
|
||||
/** Liefert die hinterlegte Unterschrift als Bild (nur angemeldete Admins). */
|
||||
function admin_settings_signature(): void
|
||||
{
|
||||
$file = owner_signature_path();
|
||||
if ($file === null) {
|
||||
abort_page(404, 'Es ist keine Unterschrift hinterlegt.');
|
||||
}
|
||||
header('Content-Type: image/jpeg');
|
||||
header('Content-Length: ' . (string) filesize($file));
|
||||
header('Cache-Control: private, no-store');
|
||||
readfile($file);
|
||||
exit;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,6 +473,62 @@ function deposit_account_label(array $account): string
|
|||
return (string) $account['label'] . ($iban !== '' ? ' (…' . substr($iban, -4) . ')' : '');
|
||||
}
|
||||
|
||||
/** Verzeichnis für die hinterlegte Unterschrift des Vermieters. */
|
||||
function owner_signature_dir(): string
|
||||
{
|
||||
$storage = rtrim((string) config('app.storage_path', DIC_ROOT . '/storage'), '/');
|
||||
return $storage . '/signature';
|
||||
}
|
||||
|
||||
/** Pfad der hinterlegten Unterschrift (JPEG) oder null. */
|
||||
function owner_signature_path(): ?string
|
||||
{
|
||||
$file = owner_signature_dir() . '/unterschrift-vermieter.jpg';
|
||||
return is_file($file) ? $file : null;
|
||||
}
|
||||
|
||||
function owner_signature_time(): ?string
|
||||
{
|
||||
$file = owner_signature_path();
|
||||
if ($file === null) {
|
||||
return null;
|
||||
}
|
||||
return gmdate('Y-m-d H:i:s', (int) filemtime($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert die im Browser gezeichnete Unterschrift (data:image/jpeg;base64,…).
|
||||
* Gilt für alle neu erzeugten Auftragsbestätigungen.
|
||||
*/
|
||||
function owner_signature_save(string $dataUrl): void
|
||||
{
|
||||
if (!preg_match('#^data:image/jpeg;base64,([A-Za-z0-9+/=\s]+)$#', trim($dataUrl), $match)) {
|
||||
throw new RuntimeException('Die Unterschrift konnte nicht gelesen werden.');
|
||||
}
|
||||
$binary = base64_decode((string) preg_replace('/\s+/', '', $match[1]), true);
|
||||
if (!is_string($binary) || strlen($binary) < 500 || strncmp($binary, "\xFF\xD8", 2) !== 0) {
|
||||
throw new RuntimeException('Bitte zuerst unterschreiben.');
|
||||
}
|
||||
if (strlen($binary) > 1500000) {
|
||||
throw new RuntimeException('Die Unterschrift ist zu groß.');
|
||||
}
|
||||
$dir = owner_signature_dir();
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0700, true) && !is_dir($dir)) {
|
||||
throw new RuntimeException('Das Verzeichnis für die Unterschrift fehlt.');
|
||||
}
|
||||
$file = $dir . '/unterschrift-vermieter.jpg';
|
||||
if (@file_put_contents($file, $binary) === false) {
|
||||
throw new RuntimeException('Die Unterschrift konnte nicht gespeichert werden.');
|
||||
}
|
||||
@chmod($file, 0600);
|
||||
}
|
||||
|
||||
function owner_signature_delete(): bool
|
||||
{
|
||||
$file = owner_signature_path();
|
||||
return $file !== null && @unlink($file);
|
||||
}
|
||||
|
||||
/** Eingabewerte eines Anzahlungskontos normalisieren. */
|
||||
function deposit_account_input(array $source): array
|
||||
{
|
||||
|
|
@ -876,31 +932,38 @@ function document_confirmation_pdf(array $booking, string $variant): string
|
|||
$y = $pdf->paragraph(50, $y + 4, $pdf->pageWidth() - 100, 9.5, $warning, false, 13);
|
||||
}
|
||||
|
||||
// Mit Anzahlung steht das Zahlungsziel schon oben; dann genügt der Hinweis zur Kaution.
|
||||
$note = $account !== null
|
||||
? 'Die Kaution von ' . fmt_money($deposit) . ' wird bei ordnungsgemäßer Rückgabe vollständig erstattet. '
|
||||
. 'Der Restbetrag von ' . fmt_money(max(0, $grand - $paid)) . ' ist bei der Übergabe fällig.'
|
||||
: 'Der Gesamtbetrag ist bei der Übergabe in bar zu zahlen. Nach Absprache ist auch eine '
|
||||
. 'Überweisung möglich – das Geld muss dann spätestens am Montag der Terminwoche eingegangen sein. '
|
||||
. 'Die Kaution wird bei ordnungsgemäßer Rückgabe vollständig erstattet.';
|
||||
$y = document_pdf_note($pdf, $y + 6, 'Zahlung', $note);
|
||||
|
||||
// Zahlungshinweis und Schlusstext in einem Block – hält die Seite einseitig.
|
||||
$payment = $account !== null
|
||||
? 'Der Restbetrag von ' . fmt_money(max(0, $grand - $paid)) . ' ist bei der Übergabe fällig. '
|
||||
. 'Die Kaution von ' . fmt_money($deposit) . ' wird bei ordnungsgemäßer Rückgabe vollständig erstattet. '
|
||||
: 'Der Gesamtbetrag ist bei der Übergabe in bar zu zahlen; nach Absprache auch per Überweisung '
|
||||
. '(Geld bis spätestens Montag der Terminwoche). Die Kaution wird bei ordnungsgemäßer Rückgabe '
|
||||
. 'vollständig erstattet. ';
|
||||
$closing = 'Vielen Dank für die Buchung. Diese Auftragsbestätigung bestätigt den vereinbarten Termin und '
|
||||
. 'die genannten Beträge. Es gelten die Allgemeinen Geschäftsbedingungen des Vermieters. '
|
||||
. 'die genannten Beträge. ' . $payment
|
||||
. 'Es gelten die Allgemeinen Geschäftsbedingungen des Vermieters. '
|
||||
. 'Bitte prüfen Sie die Angaben und melden Sie sich bei Abweichungen.';
|
||||
$y = $pdf->paragraph(50, $y + 4, $pdf->pageWidth() - 100, 9, $closing, false, 12.5);
|
||||
$y = $pdf->paragraph(50, $y + 8, $pdf->pageWidth() - 100, 9, $closing, false, 12.5);
|
||||
|
||||
// Unterschriftenfelder: links Ort/Datum, rechts die Unterschrift des Vermieters.
|
||||
// Nur wenn kein Platz mehr bleibt, wandern sie auf eine neue Seite.
|
||||
$signatureTop = $y + 18;
|
||||
if ($signatureTop > 755) {
|
||||
// Unterschriftenfelder: links Ort/Datum (vorbelegt), rechts die hinterlegte
|
||||
// Unterschrift des Vermieters. Nur bei Platzmangel auf eine neue Seite.
|
||||
$owner = trim((string) ($legal['owner'] ?? '')) !== '' ? (string) $legal['owner'] : (string) $legal['business_name'];
|
||||
$signatureFile = owner_signature_path();
|
||||
$signatureTop = $y + ($signatureFile !== null ? 52 : 18);
|
||||
if ($signatureTop > 762) {
|
||||
document_pdf_footer($pdf, 'Auftragsbestätigung · Buchung #' . (int) $booking['id']);
|
||||
$pdf->newPage();
|
||||
$signatureTop = 150;
|
||||
$signatureTop = 190;
|
||||
}
|
||||
$owner = trim((string) ($legal['owner'] ?? '')) !== '' ? (string) $legal['owner'] : (string) $legal['business_name'];
|
||||
|
||||
$place = trim((string) ($legal['city'] ?? ''));
|
||||
$pdf->text(50, $signatureTop - 7, 9.5, trim($place . ', ' . fmt_date(today_iso()), ', '));
|
||||
$pdf->line(50, $signatureTop, 300, $signatureTop, 0.7);
|
||||
$pdf->text(50, $signatureTop + 13, 7.5, 'Ort, Datum');
|
||||
|
||||
if ($signatureFile !== null) {
|
||||
$pdf->image($signatureFile, 326, $signatureTop - 46, 130, 43.3);
|
||||
}
|
||||
$pdf->line(320, $signatureTop, 545, $signatureTop, 0.7);
|
||||
$pdf->text(320, $signatureTop + 13, 7.5, 'Unterschrift Vermieter – ' . $owner);
|
||||
document_pdf_footer($pdf, 'Auftragsbestätigung · Buchung #' . (int) $booking['id']);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ $items = [
|
|||
'/admin/trailers' => ['label' => 'Anhänger', 'icon' => 'i-truck'],
|
||||
'/admin/mailings' => ['label' => 'Rundmail', 'icon' => 'i-mail'],
|
||||
'/admin/accounts' => ['label' => 'Konten', 'icon' => 'i-bank'],
|
||||
'/admin/settings' => ['label' => 'Einstellungen', 'icon' => 'i-settings'],
|
||||
'/admin/backups' => ['label' => 'Sicherungen', 'icon' => 'i-database'],
|
||||
];
|
||||
?>
|
||||
|
|
|
|||
81
views/admin_settings.php
Normal file
81
views/admin_settings.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/** @var string|null $signatureTime */
|
||||
/** @var bool $hasSignature */
|
||||
/** @var array<string, string> $errors */
|
||||
/** @var array<string, mixed> $legal */
|
||||
/** @var int $depositDueDays */
|
||||
$error = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
||||
$place = trim((string) ($legal['city'] ?? ''));
|
||||
$owner = trim((string) ($legal['owner'] ?? '')) !== '' ? (string) $legal['owner'] : (string) ($legal['business_name'] ?? '');
|
||||
?>
|
||||
<div class="page-head page-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">Verwaltung</p>
|
||||
<h1>Einstellungen</h1>
|
||||
<p class="page-head__lede">Unterschrift des Vermieters für die Auftragsbestätigung. Sie wird einmal
|
||||
hinterlegt und in jede neu erzeugte Auftragsbestätigung eingesetzt – zusammen mit Ort und Datum.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
||||
|
||||
<?php if ($error('general') !== ''): ?>
|
||||
<div class="alert alert--error" role="alert">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
||||
<div><strong>Das hat nicht geklappt.</strong><p><?= e($error('general')) ?></p></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel__head">
|
||||
<div>
|
||||
<h2>Unterschrift des Vermieters</h2>
|
||||
<p><?= $hasSignature
|
||||
? 'Hinterlegt' . ($signatureTime !== null ? ' seit ' . e(fmt_datetime($signatureTime)) : '') . '. Neue Auftragsbestätigungen enthalten sie im Feld „Unterschrift Vermieter“.'
|
||||
: 'Noch keine Unterschrift hinterlegt – die Auftragsbestätigung bleibt im Unterschriftenfeld leer.' ?></p>
|
||||
</div>
|
||||
<?php if ($hasSignature): ?>
|
||||
<div class="panel__actions">
|
||||
<form method="post" action="<?= e(url('/admin/settings')) ?>" data-confirm="Hinterlegte Unterschrift entfernen?">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="delete_signature">
|
||||
<button class="btn small danger-ghost" type="submit">
|
||||
<svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Unterschrift entfernen
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="form-grid">
|
||||
<div class="field">
|
||||
<span>Aktuell hinterlegt</span>
|
||||
<?php if ($hasSignature): ?>
|
||||
<img class="signature-preview" src="<?= e(url('/admin/settings/signature')) ?>" alt="Hinterlegte Unterschrift von <?= e($owner) ?>">
|
||||
<?php else: ?>
|
||||
<p class="muted small">– keine –</p>
|
||||
<?php endif; ?>
|
||||
<em class="muted small">Ort und Datum setzt die Auftragsbestätigung automatisch:
|
||||
<strong><?= e(trim($place . ', ' . fmt_date(today_iso()), ', ')) ?></strong>.</em>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span>Neue Unterschrift zeichnen</span>
|
||||
<form method="post" action="<?= e(url('/admin/settings')) ?>" data-signature-form>
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="action" value="save_signature">
|
||||
<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">Hier mit Maus oder Finger unterschreiben</p>
|
||||
</div>
|
||||
<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 speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
<em class="muted small">Gilt ab sofort für alle <strong>neu</strong> erzeugten Auftragsbestätigungen;
|
||||
bereits erzeugte PDFs bleiben unverändert.</em>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -74,6 +74,7 @@ $navActive = static function (string $area) use ($path): string {
|
|||
<symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M4.5 6.8l15 10.4M19.5 6.8 4.5 17.2M12 6.4 9.6 4M12 6.4 14.4 4M12 17.6 9.6 20M12 17.6l2.4 2.4"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M19.1 4.9 17 7M7 17l-2.1 2.1"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 24 24"><path d="M12 3v12M7 10l5 5 5-5"/><path d="M5 20h14"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3.2"/><path d="M19.4 14.5a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.2a1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.2a1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.2a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.2a1.6 1.6 0 0 0-1.4 1z"/></symbol>
|
||||
<symbol id="i-bank" viewBox="0 0 24 24"><path d="M3 9.5 12 4l9 5.5"/><path d="M5 10v9M9.5 10v9M14.5 10v9M19 10v9"/><path d="M3 21h18"/></symbol>
|
||||
<symbol id="i-database" viewBox="0 0 24 24"><ellipse cx="12" cy="5.5" rx="8" ry="3"/><path d="M4 5.5v13c0 1.7 3.6 3 8 3s8-1.3 8-3v-13"/><path d="M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3"/></symbol>
|
||||
</defs>
|
||||
|
|
|
|||
|
|
@ -1283,6 +1283,10 @@ a .ico, button .ico { pointer-events: none; }
|
|||
touch-action: none;
|
||||
}
|
||||
.sign-pad canvas { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
|
||||
.signature-preview {
|
||||
display: block; width: 100%; max-width: 320px; height: auto;
|
||||
background: #fff; border: 1px solid var(--line-soft); border-radius: 10px; padding: 8px 10px;
|
||||
}
|
||||
.sign-pad__hint {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue