Added generating/downloading Print Invoices
This commit is contained in:
@@ -670,7 +670,7 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
public function createPDFs() {
|
||||
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||
foreach(InvoiceModel::getAll() as $invoice) {
|
||||
foreach(InvoiceModel::search(["billing_delivery" => "paper"]) as $invoice) {
|
||||
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
||||
continue;
|
||||
}
|
||||
@@ -751,7 +751,6 @@ class InvoiceController extends mfBaseController {
|
||||
}
|
||||
|
||||
public function printInvoices() {
|
||||
return false;
|
||||
$start = $this->request->delivery_start_date;
|
||||
$end = $this->request->delivery_end_date;
|
||||
|
||||
@@ -774,28 +773,62 @@ class InvoiceController extends mfBaseController {
|
||||
$pdf_files = [];
|
||||
|
||||
foreach(InvoiceModel::search(["billing_delivery" => "paper", "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()]) as $invoice) {
|
||||
$filename = $invoice->createPdf();
|
||||
if(!$filename) {
|
||||
$this->layout()->setFlash("Fehler beim PDF erstellen (".$invoice->invoice_number.")", "error");
|
||||
$this->redirect("Invoice");
|
||||
$pdf = $invoice->pdf;
|
||||
|
||||
if(!$pdf || !$pdf->name) {
|
||||
die("PDF für ".$invoice->invoice_number." noch nicht generiert\n");
|
||||
}
|
||||
|
||||
$pdf_files[] = $filename;
|
||||
$pdf_file = $pdf->getFullPath();
|
||||
if(!file_exists($pdf_file)) {
|
||||
die("Datei ".$pdf->filename." nicht gefunden\n");
|
||||
}
|
||||
|
||||
$pdf_files[] = $pdf_file;
|
||||
}
|
||||
|
||||
//var_dump($pdf_files);exit;
|
||||
if(!count($pdf_files)) {
|
||||
$this->layout()->setFlash("Fehler beim PDF erstellen: Keine PDFs zum zusammenführen", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$output_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||
$output_filename = "invoices-print-".date("Y-m-d-H-i-s").".pdf";
|
||||
$output_filename = "print-invoices-".date("Y-m-d_H-i-s").".pdf";
|
||||
$output_filepath = "$output_path/$output_filename";
|
||||
//var_dump($pdf_files);exit;
|
||||
$i = 0;
|
||||
|
||||
$first = true;
|
||||
$tmp_file1 = "$output_filepath.tmp1";
|
||||
$tmp_file2 = "$output_filepath.tmp2";
|
||||
$tmp_file = "";
|
||||
foreach($pdf_files as $file) {
|
||||
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$file' '$output_filepath'";
|
||||
if($i % 2 == 1) {
|
||||
$tmp_file = $tmp_file1;
|
||||
$src_file = $tmp_file2;
|
||||
} else {
|
||||
$tmp_file = $tmp_file2;
|
||||
$src_file = $tmp_file1;
|
||||
}
|
||||
|
||||
if($first) {
|
||||
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$file' '$tmp_file'";
|
||||
$first = false;
|
||||
} else {
|
||||
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$src_file' '$file' '$tmp_file'";
|
||||
}
|
||||
|
||||
|
||||
//echo "$pdf_unite_cmd\n<br />";
|
||||
shell_exec($pdf_unite_cmd);
|
||||
|
||||
$i++;
|
||||
}
|
||||
//exit;
|
||||
rename($tmp_file, $output_filepath);
|
||||
|
||||
//exit;
|
||||
|
||||
if(!file_exists($output_filepath)) {
|
||||
$this->layout()->setFlash("Fehler beim PDFs zusammenführen: Ausgabedatei nicht gefunden", "error");
|
||||
|
||||
Reference in New Issue
Block a user