Merge branch 'fronkdev' into 'master'
Added script to create Invoice PDFs See merge request fronk/thetool!461
This commit is contained in:
@@ -1,8 +1,103 @@
|
||||
<?php
|
||||
|
||||
use chillerlan\QRCode\QRCode;
|
||||
use chillerlan\QRCode\QROptions;
|
||||
use chillerlan\QRCode\Output\QROutputInterface;
|
||||
|
||||
class Invoice extends mfBaseModel {
|
||||
private $positions;
|
||||
private $voicenumbers;
|
||||
private $pdf;
|
||||
|
||||
|
||||
public function createPdf() {
|
||||
if($this->id) {
|
||||
$invoice_number = $this->invoice_number;
|
||||
$invoice_date = $this->invoice_date;
|
||||
} else {
|
||||
$invoice_number = "PROFORMA";
|
||||
$invoice_date = 1;
|
||||
}
|
||||
|
||||
$filename = "";
|
||||
$positions = $this->getProperty("positions");
|
||||
|
||||
$vat = [];
|
||||
foreach ($positions as $p) {
|
||||
if (!array_key_exists($p->vatrate, $vat)) {
|
||||
$vat[$p->vatrate] = 0;
|
||||
}
|
||||
$vat[$p->vatrate] += $p->price_gross - ($p->price * $p->amount);
|
||||
}
|
||||
|
||||
$pdf_vars = [
|
||||
"invoice" => $this,
|
||||
"vat" => $vat,
|
||||
"bank_iban" => TT_INVOICE_BANK_IBAN,
|
||||
"bank_bic" => TT_INVOICE_BANK_BIC,
|
||||
"bank_bank"=> TT_INVOICE_BANK_BANK,
|
||||
"bank_owner" => TT_INVOICE_BANK_OWNER
|
||||
];
|
||||
|
||||
// Replace placeholders in header
|
||||
$headerHtml = file_get_contents(BASEDIR . "/Layout/default/Invoice/PDF_HEADER.html");
|
||||
$headerHtml = str_replace("{{ basedir }}", BASEDIR, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_1 }}", $this->company ? $this->company : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_2 }}", $this->firstname . " " . $this->lastname, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_3 }}", nl2br($this->street), $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_4 }}", $this->zip . " " . $this->city, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_5 }}", $this->country != "Österreich" ? $this->country : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ customerNumber }}", $this->customer_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ billingAccount }}", $this->fibu_account_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceNumber }}", $invoice_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceDate }}", date("d.m.Y", $invoice_date), $headerHtml);
|
||||
$headerHtml = str_replace("{{ vatHtml }}", $this->uid ? "<tr><td>Ihre UID:</td><td>" . $this->uid . "</td></tr>" : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ qrCodeSrc }}", $this->getSepaQRCode($invoice_number, round($this->total_gross, 2)), $headerHtml);
|
||||
|
||||
$headerFile = BASEDIR . "/var/temp/invoice_header-" . date("U") . "-" . rand(1000, 9999) . ".html";
|
||||
file_put_contents($headerFile, $headerHtml);
|
||||
|
||||
|
||||
// Replace placeholders in header
|
||||
$footerHtml = file_get_contents(BASEDIR . "/Layout/default/Invoice/PDF_FOOTER.html");
|
||||
$footerHtml = str_replace("{{ bank_iban }}", TT_INVOICE_BANK_IBAN_FORMATTED, $footerHtml);
|
||||
$footerHtml = str_replace("{{ bank_bic }}", TT_INVOICE_BANK_BIC, $footerHtml);
|
||||
$footerHtml = str_replace("{{ bank_bank }}", TT_INVOICE_BANK_BANK, $footerHtml);
|
||||
$footerHtml = str_replace("{{ bank_owner }}", TT_INVOICE_BANK_OWNER, $footerHtml);
|
||||
|
||||
|
||||
$footerFile = BASEDIR . "/var/temp/invoice_footer-" . date("U") . "-" . rand(1000, 9999) . ".html";
|
||||
file_put_contents($footerFile, $footerHtml);
|
||||
|
||||
|
||||
$pdf = new PdfForm("Invoice/PDF_MAIN", $pdf_vars);
|
||||
$wkhtmltopdfArgs = "--header-html $headerFile --footer-html $footerFile";
|
||||
$filename = $pdf->render($wkhtmltopdfArgs);
|
||||
|
||||
return $filename;
|
||||
|
||||
}
|
||||
|
||||
public function getSepaQRCode($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);
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
@@ -24,6 +119,17 @@ class Invoice extends mfBaseModel {
|
||||
return $this->voicenumbers;
|
||||
}
|
||||
|
||||
if($name == "pdf") {
|
||||
$ifile = InvoiceFileModel::getFirst(["invoice_id" => $this->id]);
|
||||
if(!$ifile) return null;
|
||||
|
||||
$file = $ifile->file;
|
||||
if(!$file) return null;
|
||||
|
||||
$this->pdf = $file;
|
||||
return $this->pdf;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
|
||||
@@ -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,128 @@ XINON GmbH";
|
||||
exit;
|
||||
}
|
||||
|
||||
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) {
|
||||
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")) {
|
||||
echo "Error moving created PDF file", "error";
|
||||
return false;
|
||||
}
|
||||
|
||||
// create File
|
||||
$file = FileModel::create([
|
||||
"name" => $invoice->invoice_number,
|
||||
"filename" => $new_filename,
|
||||
"subfolder" => $invoice_subfolder,
|
||||
"store_filename" => $new_filename,
|
||||
"orig_filename" => $new_filename,
|
||||
]);
|
||||
|
||||
if(!$file->save()) {
|
||||
echo "Error saving PDF file", "error";
|
||||
return false;
|
||||
}
|
||||
|
||||
// create InvoiceFile
|
||||
$ifile = InvoiceFileModel::create([
|
||||
"invoice_id" => $invoice->id,
|
||||
"file_id" => $file->id,
|
||||
"name" => $new_filename,
|
||||
"description" => ""
|
||||
]);
|
||||
|
||||
if(!$ifile->save()) {
|
||||
echo "Error saving PDF Invoice file", "error";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ class InvoiceModel {
|
||||
public $total;
|
||||
public $total_gross;
|
||||
public $bmd_export_date;
|
||||
public $date_delivered;
|
||||
public $total_vat;
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
@@ -173,7 +174,7 @@ class InvoiceModel {
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Invoice
|
||||
WHERE $where";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
@@ -220,7 +221,7 @@ class InvoiceModel {
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
//var_dump($filter);exit;
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
@@ -253,6 +254,31 @@ class InvoiceModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("invoice_date>", $filter)) {
|
||||
$invoice_date = $db->escape($filter['invoice_date>']);
|
||||
if($invoice_date) {
|
||||
$where .= " AND Invoice.invoice_date > '$invoice_date'";
|
||||
}
|
||||
}
|
||||
if(array_key_exists("invoice_date>=", $filter)) {
|
||||
$invoice_date = $db->escape($filter['invoice_date>=']);
|
||||
if($invoice_date) {
|
||||
$where .= " AND Invoice.invoice_date >= '$invoice_date'";
|
||||
}
|
||||
}
|
||||
if(array_key_exists("invoice_date<", $filter)) {
|
||||
$invoice_date = $db->escape($filter['invoice_date<']);
|
||||
if($invoice_date) {
|
||||
$where .= " AND Invoice.invoice_date < '$invoice_date'";
|
||||
}
|
||||
}
|
||||
if(array_key_exists("invoice_date<=", $filter)) {
|
||||
$invoice_date = $db->escape($filter['invoice_date<=']);
|
||||
if($invoice_date) {
|
||||
$where .= " AND Invoice.invoice_date <= '$invoice_date'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("bmd_export_date", $filter)) {
|
||||
$bmd_export_date = $filter['bmd_export_date'];
|
||||
if(is_numeric($bmd_export_date)) {
|
||||
@@ -264,6 +290,17 @@ class InvoiceModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("date_delivered", $filter)) {
|
||||
$date_delivered = $filter['date_delivered'];
|
||||
if(is_numeric($date_delivered)) {
|
||||
$where .= " AND Invoice.date_delivered=$date_delivered";
|
||||
} elseif($date_delivered === null || $date_delivered === false) {
|
||||
$where .= " AND Invoice.date_delivered IS NULL";
|
||||
} elseif($date_delivered === true) {
|
||||
$where .= " AND Invoice.date_delivered > 0";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("billingaddress_id", $filter)) {
|
||||
$Invoiceaddress_id = $filter['billingaddress_id'];
|
||||
if(is_numeric($Invoiceaddress_id)) {
|
||||
@@ -353,7 +390,6 @@ class InvoiceModel {
|
||||
$where .= " AND Invoice.Invoice_period = $Invoice_period";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
39
application/InvoiceFile/InvoiceFile.php
Normal file
39
application/InvoiceFile/InvoiceFile.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class InvoiceFile extends mfBaseModel {
|
||||
private $file;
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = new User($this->create_by);
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = new User($this->edit_by);
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
|
||||
if($this->$name->id) {
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
}
|
||||
37
application/InvoiceFile/InvoiceFileController.php
Normal file
37
application/InvoiceFile/InvoiceFileController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class InvoiceFileController extends mfBaseController {
|
||||
/*
|
||||
protected function init() {
|
||||
$this->needlogin=true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me",$me);
|
||||
|
||||
if(!$me->is(["Admin","salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
// internal redirect to File::editAction
|
||||
}
|
||||
|
||||
protected function deleteAction() {
|
||||
$id = $this->request->id;
|
||||
|
||||
$orderfile = new InvoiceFile($id);
|
||||
if(!$orderfile->id || $orderfile->id != $id) {
|
||||
$this->layout()->setFlash("Dokument nicht gefunden.", "error");
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
$order_id = $orderfile->order_id;
|
||||
|
||||
$orderfile->file->delete();
|
||||
$orderfile->delete();
|
||||
$this->redirect("Order", "edit", ["id" => $order_id]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
134
application/InvoiceFile/InvoiceFileModel.php
Normal file
134
application/InvoiceFile/InvoiceFileModel.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
class InvoiceFileModel {
|
||||
public $invoice_id;
|
||||
public $file_id;
|
||||
public $name;
|
||||
public $description;
|
||||
|
||||
public $create_by = null;
|
||||
public $edit_by = null;
|
||||
public $create = null;
|
||||
public $edit = null;
|
||||
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new InvoiceFile();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
$model ->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("InvoiceFile", "*", "1=1 ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new InvoiceFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("InvoiceFile", "*", "$where ORDER BY name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new InvoiceFile($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT InvoiceFile.* FROM InvoiceFile
|
||||
LEFT JOIN File ON (InvoiceFile.file_id = File.id)
|
||||
WHERE $where
|
||||
ORDER BY invoice_id, name";
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new InvoiceFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
if(array_key_exists("file_id", $filter)) {
|
||||
$file_id = $filter['file_id'];
|
||||
if(is_numeric($file_id)) {
|
||||
$where .= " AND file_id=$file_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("invoice_id", $filter)) {
|
||||
$invoice_id = $filter['invoice_id'];
|
||||
if(is_numeric($invoice_id)) {
|
||||
$where .= " AND invoice_id=$invoice_id";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("name", $filter)) {
|
||||
$name = FronkDB::singleton()->escape($filter['name']);
|
||||
if($name) {
|
||||
$where .= " AND name='$name'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("filename", $filter)) {
|
||||
$filename = FronkDB::singleton()->escape($filter['filename']);
|
||||
if($filename) {
|
||||
$where .= " AND File.filename='$filename'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("subfolder", $filter)) {
|
||||
$subfolder = FronkDB::singleton()->escape($filter['subfolder']);
|
||||
if($subfolder) {
|
||||
$where .= " AND File.subfolder='$subfolder'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class IvtCustomerModel {
|
||||
return $items;
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
Reference in New Issue
Block a user