Fix: PDF-Download liefert gespeicherten Beleg statt neu generierter PDF

This commit is contained in:
fds2610-bot 2026-05-05 16:25:30 +02:00
parent 58806757fa
commit 8c9d109e56

View file

@ -274,7 +274,22 @@ class InvoiceController
$invoice = Invoice::find((int)$params['id']); $invoice = Invoice::find((int)$params['id']);
if (!$invoice) { http_response_code(404); return; } if (!$invoice) { http_response_code(404); return; }
// Bei Stornorechnung Originalrechnung laden für Referenzzeile // Gespeicherte PDF aus dem Beleg ausliefern (GoBD: unveränderlicher Stand)
if (!empty($invoice['beleg_id'])) {
$beleg = Beleg::find((int)$invoice['beleg_id']);
$absPath = $beleg
? dirname(__DIR__, 2) . '/public/' . $beleg['storage_path']
: '';
if ($absPath && file_exists($absPath)) {
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $beleg['filename'] . '"');
header('Content-Length: ' . filesize($absPath));
readfile($absPath);
return;
}
}
// Fallback: PDF on-the-fly generieren (Entwurf oder Beleg noch ohne Datei)
if (!empty($invoice['storno_of_id'])) { if (!empty($invoice['storno_of_id'])) {
$original = Invoice::find((int)$invoice['storno_of_id']); $original = Invoice::find((int)$invoice['storno_of_id']);
if ($original) { if ($original) {