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
90
app/migrate.php
Normal file
90
app/migrate.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Schema-Migrationen anwenden.
|
||||
*
|
||||
* Wird von tools/migrate.php (CLI) und von der Route /migrate?token=… genutzt.
|
||||
* Letztere gibt es, weil auf dem netcup-Webhosting kein SSH zur Verfügung
|
||||
* steht: Nach `tools/deploy.sh --target netcup --sync` zieht
|
||||
* curl -sS "https://drinkitcold.com/migrate?token=<app.cron_token>"
|
||||
* die ausstehenden Migrationen nach.
|
||||
*
|
||||
* Migrationen sind additiv und werden über schema_migrations genau einmal
|
||||
* ausgeführt; ein erneuter Aufruf ist gefahrlos.
|
||||
*/
|
||||
|
||||
/** @return list<int> */
|
||||
function migrations_applied(): array
|
||||
{
|
||||
return array_map('intval', db()->query('SELECT version FROM schema_migrations')->fetchAll(PDO::FETCH_COLUMN));
|
||||
}
|
||||
|
||||
/** @return array<string, string> Dateiname => SQL (nur ausstehende) */
|
||||
function migrations_pending(): array
|
||||
{
|
||||
db()->exec(
|
||||
'CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
version INT UNSIGNED NOT NULL,
|
||||
applied_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (version)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
|
||||
);
|
||||
$applied = migrations_applied();
|
||||
$files = glob(DIC_ROOT . '/sql/migrations/*.sql') ?: [];
|
||||
sort($files, SORT_STRING);
|
||||
|
||||
$pending = [];
|
||||
foreach ($files as $file) {
|
||||
$name = basename($file);
|
||||
if (!preg_match('/^(\d+)_/', $name, $match)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array((int) $match[1], $applied, true)) {
|
||||
continue;
|
||||
}
|
||||
$pending[$name] = (string) file_get_contents($file);
|
||||
}
|
||||
return $pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt alle ausstehenden Migrationen aus.
|
||||
*
|
||||
* @return array{applied: list<string>, skipped: list<string>}
|
||||
*/
|
||||
function migrations_run(): array
|
||||
{
|
||||
$result = ['applied' => [], 'skipped' => []];
|
||||
foreach (migrations_pending() as $name => $sql) {
|
||||
preg_match('/^(\d+)_/', $name, $match);
|
||||
$version = (int) $match[1];
|
||||
// Kommentare entfernen und an Semikola trennen (wie tools/migrate.php).
|
||||
$clean = (string) preg_replace('/^\s*--.*$/m', '', $sql);
|
||||
$statements = array_filter(array_map('trim', explode(';', $clean)));
|
||||
if ($statements === []) {
|
||||
$result['skipped'][] = $name;
|
||||
continue;
|
||||
}
|
||||
foreach ($statements as $statement) {
|
||||
if ($statement === '') {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
db()->exec($statement);
|
||||
} catch (PDOException $error) {
|
||||
// "Gibt es schon": Bei einem frisch installierten Schema sind
|
||||
// Spalten/Tabellen früherer Migrationen bereits vorhanden
|
||||
// (install.php spielt schema.sql ein). Das gilt als erledigt.
|
||||
if (in_array((int) ($error->errorInfo[1] ?? 0), [1050, 1060, 1061, 1091], true)) {
|
||||
continue;
|
||||
}
|
||||
throw new RuntimeException($name . ': ' . $error->getMessage(), 0, $error);
|
||||
}
|
||||
}
|
||||
db()->prepare('INSERT IGNORE INTO schema_migrations (version, applied_at) VALUES (?, ?)')
|
||||
->execute([$version, utc_now()]);
|
||||
$result['applied'][] = $name;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue