Added Credit CSV download to Invoice/Index

This commit is contained in:
Frank Schubert
2024-07-12 18:57:46 +02:00
parent 1ca399786f
commit 5e5e4de27d
5 changed files with 103 additions and 51 deletions

View File

@@ -124,59 +124,33 @@ class InvoiceController extends mfBaseController {
readfile($pdf_path);
exit;
}
/*$vat = [];
foreach ($invoice->positions as $p) {
if (!array_key_exists($p->vatrate, $vat)) {
$vat[$p->vatrate] = 0;
}
$vat[$p->vatrate] += $p->price_gross - ($p->price * $p->amount);
protected function downloadInvoiceCsv() {
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
$this->redirect("Invoice");
}
$pdf_vars = [
"invoice" => $invoice,
"vat" => $vat,
"bank_iban" => TT_INVOICE_BANK_IBAN,
"bank_bic" => TT_INVOICE_BANK_BIC,
"bank_bank"=> TT_INVOICE_BANK_BANK,
"bank_owner" => TT_INVOICE_BANK_OWNER
];
$invoice = new Invoice($id);
if (!$invoice->id) {
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
$this->redirect("Invoice");
}
// Replace placeholders in header
$headerHtml = file_get_contents(BASEDIR . "/Layout/default/Invoice/PDF_HEADER.html");
$headerHtml = str_replace("{{ basedir }}", BASEDIR, $headerHtml);
$headerHtml = str_replace("{{ addressLine_1 }}", $invoice->company ? $invoice->company : "", $headerHtml);
$headerHtml = str_replace("{{ addressLine_2 }}", $invoice->firstname . " " . $invoice->lastname, $headerHtml);
$headerHtml = str_replace("{{ addressLine_3 }}", nl2br($invoice->street), $headerHtml);
$headerHtml = str_replace("{{ addressLine_4 }}", $invoice->zip . " " . $invoice->city, $headerHtml);
$headerHtml = str_replace("{{ addressLine_5 }}", $invoice->country != "Österreich" ? $invoice->country : "", $headerHtml);
$headerHtml = str_replace("{{ customerNumber }}", $invoice->customer_number, $headerHtml);
$headerHtml = str_replace("{{ billingAccount }}", $invoice->fibu_account_number, $headerHtml);
$headerHtml = str_replace("{{ invoiceNumber }}", $invoice->invoice_number, $headerHtml);
$headerHtml = str_replace("{{ invoiceDate }}", date("d.m.Y", $invoice->invoice_date), $headerHtml);
$headerHtml = str_replace("{{ vatHtml }}", $invoice->uid ? "<tr><td>Ihre UID:</td><td>" . $invoice->uid . "</td></tr>" : "", $headerHtml);
$headerHtml = str_replace("{{ qrCodeSrc }}", $this->getBankQRCode($invoice->invoice_number, round($invoice->total_gross, 2)), $headerHtml);
$headerFile = BASEDIR . "/var/temp/invoice_header-" . date("U") . "-" . rand(1000, 9999) . ".html";
file_put_contents($headerFile, $headerHtml);
// Replace placeholders in header
$footerHtml = file_get_contents(BASEDIR . "/Layout/default/Invoice/PDF_FOOTER.html");
$footerHtml = str_replace("{{ bank_iban }}", TT_INVOICE_BANK_IBAN_FORMATTED, $footerHtml);
$footerHtml = str_replace("{{ bank_bic }}", TT_INVOICE_BANK_BIC, $footerHtml);
$footerHtml = str_replace("{{ bank_bank }}", TT_INVOICE_BANK_BANK, $footerHtml);
$footerHtml = str_replace("{{ bank_owner }}", TT_INVOICE_BANK_OWNER, $footerHtml);
$footerFile = BASEDIR . "/var/temp/invoice_footer-" . date("U") . "-" . rand(1000, 9999) . ".html";
file_put_contents($footerFile, $footerHtml);
$pdf = new PdfForm("Invoice/PDF_MAIN", $pdf_vars);
$wkhtmltopdfArgs = "--header-html $headerFile --footer-html $footerFile";
$pdf->download($invoice->invoice_number . ".pdf", $wkhtmltopdfArgs);*/
if(!$invoice->positions) {
$this->layout()->setFlash("Keine Rechnungspositionen vorhanden", "error");
$this->redirect("Invoice");
}
$tpl = new Layout();
$tpl->setTemplate("Invoice/invoicepositions.csv");
$tpl->set("invoice", $invoice);
$tpl->display();
//$csv = $tpl->render();
//echo $csv;
exit;
}