46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../src/config.php';
|
|
require_once __DIR__ . '/../src/auth.php';
|
|
require_once __DIR__ . '/../src/db.php';
|
|
require_once __DIR__ . '/../src/invoice_functions.php';
|
|
require_once __DIR__ . '/../src/pdf_functions.php';
|
|
require_login();
|
|
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
if (!$id) {
|
|
header('Location: ' . url_for('invoices.php'));
|
|
exit;
|
|
}
|
|
|
|
$pdo = get_db();
|
|
$stmt = $pdo->prepare("SELECT m.*, i.invoice_number FROM mahnungen m JOIN invoices i ON i.id = m.invoice_id WHERE m.id = :id");
|
|
$stmt->execute([':id' => $id]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$row) {
|
|
header('Location: ' . url_for('invoices.php'));
|
|
exit;
|
|
}
|
|
|
|
// PDF vorhanden?
|
|
if (empty($row['pdf_path'])) {
|
|
archive_mahnung_pdf($id);
|
|
// Neu laden
|
|
$stmt->execute([':id' => $id]);
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
$fullPath = __DIR__ . '/' . ($row['pdf_path'] ?? '');
|
|
if (!file_exists($fullPath)) {
|
|
http_response_code(404);
|
|
echo 'PDF nicht gefunden.';
|
|
exit;
|
|
}
|
|
|
|
$safe_name = 'MAHNUNG-' . preg_replace('/[^A-Za-z0-9\-]/', '_', $row['invoice_number']) . '-L' . $row['level'] . '.pdf';
|
|
header('Content-Type: application/pdf');
|
|
header('Content-Disposition: inline; filename="' . $safe_name . '"');
|
|
header('Content-Length: ' . filesize($fullPath));
|
|
readfile($fullPath);
|
|
exit;
|