feat(documents): Mietvertrag digital vom Kunden unterschreiben lassen
- „Unterschrift anfordern“ erzeugt einen persönlichen Link (/unterschrift/<64 Hex>) und mailt ihn an den Kunden; der Link bleibt gültig, bis unterschrieben oder ein neuer erzeugt wird. - Öffentliche Seite ohne Login: Buchungsdaten, Vertrags-PDF zur Ansicht (/unterschrift/<token>/pdf), Unterschriftfeld (Canvas) und Hinweis auf die AGB. Nach der Unterschrift wird der Token entwertet, die Signatur ins PDF gesetzt und der unterschriebene Vertrag automatisch an den Kunden gemailt. - Migration 013 (sign_token, sign_requested_at, Unique-Index), portabel und wiederholbar; schema.sql entsprechend ergänzt. - Booking-Karte zeigt „Unterschrift angefragt“ samt Link zum Kopieren/Öffnen; das Unterschreiben auf dem Tablet bleibt unverändert möglich.
This commit is contained in:
parent
7c0c2c3676
commit
ddc607bff3
12 changed files with 496 additions and 7 deletions
|
|
@ -75,6 +75,15 @@ function page_handle(string $method, string $path): void
|
|||
return;
|
||||
}
|
||||
|
||||
if (preg_match('#^/unterschrift/([a-f0-9]{64})/pdf$#', $path, $m) === 1) {
|
||||
page_signature_public_pdf($m[1]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/unterschrift/([a-f0-9]{64})$#', $path, $m) === 1) {
|
||||
page_signature_public($method, $m[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = auth_user();
|
||||
if ($user !== null && $user['must_change_password'] === 1
|
||||
&& !in_array($path, ['/account', '/logout', '/push/subscribe', '/push/unsubscribe', '/push/test'], true)
|
||||
|
|
@ -155,7 +164,7 @@ function page_handle(string $method, string $path): void
|
|||
page_booking_document_file($user, (int) $m[1], (int) $m[2]);
|
||||
return;
|
||||
}
|
||||
if (preg_match('#^/bookings/(\d+)/documents/(\d+)/(sign|mail|delete)$#', $path, $m) === 1) {
|
||||
if (preg_match('#^/bookings/(\d+)/documents/(\d+)/(sign|request|mail|delete)$#', $path, $m) === 1) {
|
||||
page_booking_document_action($user, $method, (int) $m[1], (int) $m[2], (string) $m[3]);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1136,6 +1145,26 @@ function page_booking_document_action(array $user, string $method, int $bookingI
|
|||
}
|
||||
|
||||
require_post();
|
||||
if ($action === 'request') {
|
||||
if (!auth_can_edit_booking($user)) {
|
||||
abort_page(403, 'Dafür fehlt dir die Berechtigung.');
|
||||
}
|
||||
try {
|
||||
$doc = document_request_signature($doc);
|
||||
$link = document_sign_link($doc);
|
||||
if (mail_is_enabled()) {
|
||||
document_mail_signature_request($booking, $doc)
|
||||
? flash('success', 'Unterschriftslink an ' . $booking['email'] . ' gesendet.')
|
||||
: flash('error', 'Die E-Mail konnte nicht verschickt werden – Link bitte kopieren.');
|
||||
} else {
|
||||
flash('info', 'E-Mail-Versand ist aus. Unterschriftslink zum Kopieren: ' . $link);
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
flash('error', $error->getMessage());
|
||||
}
|
||||
redirect('/bookings/' . $bookingId . '#unterlagen');
|
||||
}
|
||||
|
||||
if ($action === 'mail') {
|
||||
if (!auth_can_edit_booking($user)) {
|
||||
abort_page(403, 'Dafür fehlt dir die Berechtigung.');
|
||||
|
|
@ -1180,6 +1209,69 @@ function page_booking_document_invoice_upload(array $user, int $id): void
|
|||
redirect('/bookings/' . $id . '#unterlagen');
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffentliche Unterschriftsseite des Kunden (/unterschrift/<token>).
|
||||
*
|
||||
* Kein Login: der Token im Link ist der Ausweis. Nach dem Unterschreiben wird
|
||||
* er entwertet und der unterschriebene Vertrag per E-Mail verschickt.
|
||||
*/
|
||||
function page_signature_public(string $method, string $token): void
|
||||
{
|
||||
$doc = document_find_by_sign_token($token);
|
||||
if (!$doc) {
|
||||
abort_page(404, 'Dieser Unterschriftslink ist nicht mehr gültig. Bitte den Betrieb um einen neuen Link bitten.');
|
||||
}
|
||||
$booking = booking_find((int) $doc['booking_id']);
|
||||
if (!$booking) {
|
||||
abort_page(404, 'Zu diesem Link gibt es keine Buchung mehr.');
|
||||
}
|
||||
|
||||
$error = '';
|
||||
if ($method === 'POST') {
|
||||
if (!csrf_valid()) {
|
||||
$error = 'Die Sitzung ist abgelaufen. Bitte die Seite neu laden und erneut unterschreiben.';
|
||||
} else {
|
||||
try {
|
||||
$result = document_sign_by_customer($booking, $doc, post_string('signature'));
|
||||
render_standalone('document_sign_done', [
|
||||
'booking' => $booking,
|
||||
'doc' => $result['doc'],
|
||||
'mailed' => $result['mailed'],
|
||||
], 'Unterschrift gespeichert');
|
||||
return;
|
||||
} catch (Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_standalone('document_sign_customer', [
|
||||
'booking' => $booking,
|
||||
'doc' => $doc,
|
||||
'token' => $token,
|
||||
'error' => $error,
|
||||
], 'Mietvertrag unterschreiben');
|
||||
}
|
||||
|
||||
/** Vertrag als PDF zur Ansicht (nur mit gültigem Unterschriftslink). */
|
||||
function page_signature_public_pdf(string $token): void
|
||||
{
|
||||
$doc = document_find_by_sign_token($token);
|
||||
if (!$doc) {
|
||||
abort_page(404, 'Dieser Unterschriftslink ist nicht mehr gültig.');
|
||||
}
|
||||
$path = document_path($doc);
|
||||
if (!is_file($path)) {
|
||||
abort_page(404, 'Die Datei ist nicht mehr vorhanden.');
|
||||
}
|
||||
header('Content-Type: ' . (string) $doc['mime_type']);
|
||||
header('Content-Length: ' . (string) filesize($path));
|
||||
header('Content-Disposition: inline; filename="' . (string) preg_replace('/[\r\n\"]+/', '', (string) $doc['file_name']) . '"');
|
||||
header('Cache-Control: private, no-store');
|
||||
readfile($path);
|
||||
exit;
|
||||
}
|
||||
|
||||
function api_availability(): void
|
||||
{
|
||||
auth_require_login();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue