diff --git a/Layout/default/Invoice/PDF_HEADER.html b/Layout/default/Invoice/PDF_HEADER.html index cf9cd2221..5603d20b0 100644 --- a/Layout/default/Invoice/PDF_HEADER.html +++ b/Layout/default/Invoice/PDF_HEADER.html @@ -19,6 +19,7 @@ .customer-details { vertical-align: bottom; font-size: 14px; + padding-left: 30pt; } .invoice-details { diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index 9597dc64a..3810813f9 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -651,39 +651,50 @@ class InvoiceController extends mfBaseController { exit; } - public function createPDFsAction() { - $invoice_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER."/"; + public function createPDFs() { + $invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER; foreach(InvoiceModel::getAll() as $invoice) { if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) { continue; } + + $invoice_date = new DateTime("@".$invoice->invoice_date); + $year = $invoice_date->format("Y"); + $invoice_subfolder = TT_INVOICE_SAVE_SUBFOLDER."/$year"; + $invoice_path = "$invoice_path_base/$year"; + + + if(!file_exists($invoice_path)) { + mkdir($invoice_path, 0777, true); + } + // create PDF $tmp_filename = $invoice->createPdf(); if(!$tmp_filename) { - $this->layout()->setFlash("Error creating PDF file", "error"); - $this->redirect("Invoice"); + echo "Error creating PDF file", "error"; + return false; } $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"); + if(!rename($tmp_filename, "$invoice_path/$new_filename")) { + echo "Error moving created PDF file", "error"; + return false; } // create File $file = FileModel::create([ "name" => $invoice->invoice_number, "filename" => $new_filename, - "subfolder" => TT_INVOICE_SAVE_SUBFOLDER, + "subfolder" => $invoice_subfolder, "store_filename" => $new_filename, "orig_filename" => $new_filename, ]); if(!$file->save()) { - $this->layout()->setFlash("Error saving PDF file", "error"); - $this->redirect("Invoice"); + echo "Error saving PDF file", "error"; + return false; } // create InvoiceFile @@ -695,8 +706,8 @@ class InvoiceController extends mfBaseController { ]); if(!$ifile->save()) { - $this->layout()->setFlash("Error saving PDF Invoice file", "error"); - $this->redirect("Invoice"); + echo "Error saving PDF Invoice file", "error"; + return false; } } diff --git a/scripts/invoice/send-invoice-emails.php b/scripts/invoice/send-invoice-emails.php new file mode 100644 index 000000000..8e79498d4 --- /dev/null +++ b/scripts/invoice/send-invoice-emails.php @@ -0,0 +1,20 @@ +#!/usr/bin/php +id); +define("INTERNAL_USER_USERNAME", $me->username); + +$ic = new InvoiceController(false); +$ic->createPDFs();