Added scritp to create Invoice PDFs
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
.customer-details {
|
||||
vertical-align: bottom;
|
||||
font-size: 14px;
|
||||
padding-left: 30pt;
|
||||
}
|
||||
|
||||
.invoice-details {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
20
scripts/invoice/send-invoice-emails.php
Normal file
20
scripts/invoice/send-invoice-emails.php
Normal file
@@ -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