PreorderBilling: Added optional pdf format for invoice detail file

This commit is contained in:
Frank Schubert
2025-10-21 18:25:49 +02:00
parent 1319876194
commit ab33924031
5 changed files with 355 additions and 48 deletions
@@ -181,7 +181,38 @@ class PreorderBillingInvoiceController extends mfBaseController {
exit;
}
protected function downloadCsv() {
protected function downloadDetailPdf() {
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
$this->redirect("Invoice");
}
$invoice = new PreorderBillingInvoice($id);
if (!$invoice->id) {
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
$this->redirect("Invoice");
}
$csv = $invoice->detailpdf;
if(!$csv) {
$this->layout()->setFlash("Fehler beim PDF Generieren", "error");
}
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$csv->filename.'"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Length: " . filesize($csv->getFullPath()));
if($csv->mimetype) {
header('Content-Type: '.$csv->mimetype);
}
readfile($csv->getFullPath());
exit;
}
protected function downloadDetailCsv() {
$id = $this->request->id;
if (!is_numeric($id) || !$id) {
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
@@ -704,38 +735,6 @@ class PreorderBillingInvoiceController extends mfBaseController {
return ["sent" => $sent, "defer" => $defer];
}
/*$pdf = $invoice->pdf;
$pdf = false;
if(!$pdf || !$pdf->name) {
$ifile = PreorderBillingInvoiceFile::createFromInvoice($invoice);
if(!$ifile) {
$this->layout()->setFlash("Fehler beim PDF erstellen");
$this->redirect("PreorderBillingInvoice");
}
$pdf = $ifile->file;
}
$pdf_file = false;
try {
$pdf_file = $pdf->getFullPath();
} catch (Exception $e) {
$this->log->error(__METHOD__.": File for Invoice ".$invoice->id." not found");
continue;
}
if(!file_exists($pdf_file)) {
$this->log->error(__METHOD__.": Datei ".$pdf->filename." nicht gefunden");
continue;
}
if($invoice->total == 0) {
$this->log->info(__METHOD__.": Skipping ".$invoice->invoice_number." because total is zero");
$invoice->date_delivered = date("U");
$invoice->save();
continue;
}
*/
if(!$invoice->sendByEmail()) {
$this->log->warning(__METHOD__.": Error sending ".$invoice->invoice_number." to ".$invoice->email);
$invoice->date_delivered = date("U");