Fix: Rechnungs-PDF beim Finalisieren unveränderlich speichern (GoBD)
This commit is contained in:
parent
81682841a8
commit
58806757fa
1 changed files with 19 additions and 4 deletions
|
|
@ -434,16 +434,31 @@ class InvoiceController
|
||||||
|
|
||||||
private function createBeleg(array $invoice): string
|
private function createBeleg(array $invoice): string
|
||||||
{
|
{
|
||||||
$id = (int)$invoice['id'];
|
$id = (int)$invoice['id'];
|
||||||
|
$lines = Invoice::lines($id);
|
||||||
|
$settings = Setting::get();
|
||||||
|
|
||||||
|
// PDF zum Zeitpunkt der Finalisierung unveränderlich generieren und speichern (GoBD)
|
||||||
|
$svc = new PdfInvoiceService();
|
||||||
|
$pdf = $svc->renderToString($invoice, $lines, $settings);
|
||||||
|
|
||||||
$belegNr = Beleg::generateBelegNr();
|
$belegNr = Beleg::generateBelegNr();
|
||||||
|
$year = date('Y', strtotime($invoice['rechnungs_datum']));
|
||||||
|
$relDir = "static/uploads/{$year}/{$belegNr}";
|
||||||
|
$absDir = dirname(__DIR__, 2) . "/public/{$relDir}";
|
||||||
|
if (!is_dir($absDir)) mkdir($absDir, 0755, true);
|
||||||
|
|
||||||
|
$filename = $invoice['rechnungs_nr'] . '.pdf';
|
||||||
|
$storagePath = "{$relDir}/original.pdf";
|
||||||
|
file_put_contents(dirname(__DIR__, 2) . "/public/{$storagePath}", $pdf);
|
||||||
|
|
||||||
$belegId = Beleg::create([
|
$belegId = Beleg::create([
|
||||||
'invoice_id' => $id,
|
'invoice_id' => $id,
|
||||||
'beleg_nr' => $belegNr,
|
'beleg_nr' => $belegNr,
|
||||||
'filename' => $invoice['rechnungs_nr'] . '.pdf',
|
'filename' => $filename,
|
||||||
'storage_path' => '',
|
'storage_path' => $storagePath,
|
||||||
'mime_type' => 'application/pdf',
|
'mime_type' => 'application/pdf',
|
||||||
'file_hash' => hash('sha256', $invoice['rechnungs_nr']),
|
'file_hash' => hash('sha256', $pdf),
|
||||||
'beleg_datum' => $invoice['rechnungs_datum'],
|
'beleg_datum' => $invoice['rechnungs_datum'],
|
||||||
'rechnungs_nr' => $invoice['rechnungs_nr'],
|
'rechnungs_nr' => $invoice['rechnungs_nr'],
|
||||||
'betrag_brutto' => $invoice['betrag_brutto'],
|
'betrag_brutto' => $invoice['betrag_brutto'],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue