Added scritp to create Invoice PDFs
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
.customer-details {
|
.customer-details {
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
padding-left: 30pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
.invoice-details {
|
.invoice-details {
|
||||||
|
|||||||
@@ -651,39 +651,50 @@ class InvoiceController extends mfBaseController {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPDFsAction() {
|
public function createPDFs() {
|
||||||
$invoice_path = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER."/";
|
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
|
||||||
foreach(InvoiceModel::getAll() as $invoice) {
|
foreach(InvoiceModel::getAll() as $invoice) {
|
||||||
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
if(InvoiceFileModel::getFirst(["invoice_id" => $invoice->id])) {
|
||||||
continue;
|
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
|
// create PDF
|
||||||
$tmp_filename = $invoice->createPdf();
|
$tmp_filename = $invoice->createPdf();
|
||||||
if(!$tmp_filename) {
|
if(!$tmp_filename) {
|
||||||
$this->layout()->setFlash("Error creating PDF file", "error");
|
echo "Error creating PDF file", "error";
|
||||||
$this->redirect("Invoice");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_filename = $invoice->invoice_number.".pdf";
|
$new_filename = $invoice->invoice_number.".pdf";
|
||||||
|
|
||||||
// move pdf to correct folder
|
// move pdf to correct folder
|
||||||
if(!rename($tmp_filename, $invoice_path.$new_filename)) {
|
if(!rename($tmp_filename, "$invoice_path/$new_filename")) {
|
||||||
$this->layout()->setFlash("Error moving created PDF file", "error");
|
echo "Error moving created PDF file", "error";
|
||||||
$this->redirect("Invoice");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create File
|
// create File
|
||||||
$file = FileModel::create([
|
$file = FileModel::create([
|
||||||
"name" => $invoice->invoice_number,
|
"name" => $invoice->invoice_number,
|
||||||
"filename" => $new_filename,
|
"filename" => $new_filename,
|
||||||
"subfolder" => TT_INVOICE_SAVE_SUBFOLDER,
|
"subfolder" => $invoice_subfolder,
|
||||||
"store_filename" => $new_filename,
|
"store_filename" => $new_filename,
|
||||||
"orig_filename" => $new_filename,
|
"orig_filename" => $new_filename,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if(!$file->save()) {
|
if(!$file->save()) {
|
||||||
$this->layout()->setFlash("Error saving PDF file", "error");
|
echo "Error saving PDF file", "error";
|
||||||
$this->redirect("Invoice");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create InvoiceFile
|
// create InvoiceFile
|
||||||
@@ -695,8 +706,8 @@ class InvoiceController extends mfBaseController {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if(!$ifile->save()) {
|
if(!$ifile->save()) {
|
||||||
$this->layout()->setFlash("Error saving PDF Invoice file", "error");
|
echo "Error saving PDF Invoice file", "error";
|
||||||
$this->redirect("Invoice");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
//require 'vendor/autoload.php';
|
||||||
|
require("../../config/config.php");
|
||||||
|
|
||||||
|
define('FRONKDB_SQLDEBUG',false);
|
||||||
|
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
|
||||||
|
|
||||||
|
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
|
||||||
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
|
||||||
|
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
|
||||||
|
|
||||||
|
$me = new User(1);
|
||||||
|
|
||||||
|
define("INTERNAL_USER_ID", $me->id);
|
||||||
|
define("INTERNAL_USER_USERNAME", $me->username);
|
||||||
|
|
||||||
|
$ic = new InvoiceController(false);
|
||||||
|
$ic->createPDFs();
|
||||||
Reference in New Issue
Block a user