InvoiceFile WIP 2024-07-09
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
<?php
|
||||
|
||||
//use \chillerlan\QRCode;
|
||||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use chillerlan\QRCode\Output\QROutputInterface;
|
||||
|
||||
class InvoiceController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
@@ -97,8 +92,18 @@ class InvoiceController extends mfBaseController {
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$filename = $invoice->createPdf();
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-disposition: attachment; filename="'.$filename.'"');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Content-Type: ' . mime_content_type($filename));
|
||||
header("Content-Length: " . filesize($filename));
|
||||
|
||||
$vat = [];
|
||||
readfile($filename);
|
||||
exit;
|
||||
|
||||
/*$vat = [];
|
||||
foreach ($invoice->positions as $p) {
|
||||
if (!array_key_exists($p->vatrate, $vat)) {
|
||||
$vat[$p->vatrate] = 0;
|
||||
@@ -148,30 +153,11 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
$pdf = new PdfForm("Invoice/PDF_MAIN", $pdf_vars);
|
||||
$wkhtmltopdfArgs = "--header-html $headerFile --footer-html $footerFile";
|
||||
$pdf->download($invoice->invoice_number . ".pdf", $wkhtmltopdfArgs);
|
||||
$pdf->download($invoice->invoice_number . ".pdf", $wkhtmltopdfArgs);*/
|
||||
|
||||
}
|
||||
|
||||
public function getBankQRCode($paymentReference, $amount) {
|
||||
$xinonIBAN = TT_INVOICE_BANK_IBAN;
|
||||
$xinonBIC = TT_INVOICE_BANK_BIC;
|
||||
$xinonOwner = TT_INVOICE_BANK_OWNER;
|
||||
|
||||
$epc = "BCD
|
||||
001
|
||||
1
|
||||
SCT
|
||||
$xinonBIC
|
||||
$xinonOwner
|
||||
$xinonIBAN
|
||||
EUR$amount
|
||||
XINO
|
||||
$paymentReference
|
||||
|
||||
XINON GmbH";
|
||||
|
||||
return (new QRCode)->render($epc);
|
||||
}
|
||||
|
||||
protected function runInvoicingAction() {
|
||||
$i = 0;
|
||||
@@ -665,7 +651,117 @@ XINON GmbH";
|
||||
exit;
|
||||
}
|
||||
|
||||
public function createPDFsAction() {
|
||||
$invoice_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER."/";
|
||||
foreach(InvoiceModel::getAll() as $invoice) {
|
||||
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
||||
continue;
|
||||
}
|
||||
// create PDF
|
||||
$tmp_filename = $invoice->createPdf();
|
||||
if(!$tmp_filename) {
|
||||
$this->layout()->setFlash("Error creating PDF file", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$new_filename = $invoice->invoice_number.".pdf";
|
||||
|
||||
// move pdf to correct folder
|
||||
if(!rename($tmp_filename, $invoice_path.$new_filename)) {
|
||||
$this->layout()->setFlash("Error moving created PDF file", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
// create File
|
||||
$file = FileModel::create([
|
||||
"name" => $invoice->invoice_number,
|
||||
"filename" => $new_filename,
|
||||
"subfolder" => TT_INVOICE_SAVE_SUBFOLDER,
|
||||
"store_filename" => $new_filename,
|
||||
"orig_filename" => $new_filename,
|
||||
]);
|
||||
|
||||
if(!$file->save()) {
|
||||
$this->layout()->setFlash("Error saving PDF file", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
// create InvoiceFile
|
||||
$ifile = InvoiceFileModel::create([
|
||||
"invoice_id" => $invoice->id,
|
||||
"file_id" => $file->id,
|
||||
"name" => $new_filename,
|
||||
"description" => ""
|
||||
]);
|
||||
|
||||
if(!$ifile->save()) {
|
||||
$this->layout()->setFlash("Error saving PDF Invoice file", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function printInvoicesAction() {
|
||||
//$start = $r->
|
||||
$start = $this->request->delivery_start_date;
|
||||
$end = $this->request->delivery_end_date;
|
||||
|
||||
try {
|
||||
$start_date = DateTime::createFromFormat("d.m.Y", $start, new DateTimeZone("Europe/Vienna"));
|
||||
$start_date->setTime(0,0,0);
|
||||
|
||||
$end_date = DateTime::createFromFormat("d.m.Y", $end, new DateTimeZone("Europe/Vienna"));
|
||||
$end_date->setTime(23,59,59);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Von- oder Bisdatum ungültig", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
if(!InvoiceModel::count(["billing_delivery" => "paper", "invoice_date>=" => $start_date->getTimestamp(), "invoice_date<=" => $end_date->getTimestamp()])) {
|
||||
$this->layout()->setFlash("Keine Rechnungen im angegebenen Zeitraum gefunden", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$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_files[] = $filename;
|
||||
}
|
||||
|
||||
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_filepath = "$output_path/$output_filename";
|
||||
|
||||
foreach($pdf_files as $file) {
|
||||
$pdf_unite_cmd = PDFUNITE_BIN_PATH." '$file' '$output_filepath'";
|
||||
shell_exec($pdf_unite_cmd);
|
||||
}
|
||||
|
||||
if(!file_exists($output_filepath)) {
|
||||
$this->layout()->setFlash("Fehler beim PDFs zusammenführen: Ausgabedatei nicht gefunden", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-disposition: attachment; filename="'.$output_filename.'"');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Content-Type: ' . mime_content_type($output_filepath));
|
||||
header("Content-Length: " . filesize($output_filepath));
|
||||
|
||||
readfile($output_filepath);
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user