InvoiceFile WIP 2024-07-09

This commit is contained in:
Frank Schubert
2024-07-10 10:06:06 +02:00
parent 43e28847a4
commit 72c89aa97c
12 changed files with 849 additions and 56 deletions

View File

@@ -25,6 +25,9 @@ $pagination_entity_name = "Rechnungen";
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<div class="row">
<div class="col-6">
<div class="card"> <div class="card">
<div class="card-body mb-3"> <div class="card-body mb-3">
<h4 class="header-title mb-3">Filter</h4> <h4 class="header-title mb-3">Filter</h4>
@@ -32,15 +35,15 @@ $pagination_entity_name = "Rechnungen";
<form method="get" action="<?=self::getUrl("Invoice")?>"> <form method="get" action="<?=self::getUrl("Invoice")?>">
<div class="row"> <div class="row">
<div class="col-1"> <div class="col-2">
<label class="form-label" for="filter_customer_number">Kundennummer</label> <label class="form-label" for="filter_customer_number">Kundennummer</label>
<input type="text" class="form-control" name="filter[customer_number]" id="filter_customer_number" value="<?=(array_key_exists("customer_number", $filter)) ? $filter['customer_number'] : ""?>"/> <input type="text" class="form-control" name="filter[customer_number]" id="filter_customer_number" value="<?=(array_key_exists("customer_number", $filter)) ? $filter['customer_number'] : ""?>"/>
</div> </div>
<div class="col-1"> <div class="col-2">
<label class="form-label" for="filter_customer">Kunde</label> <label class="form-label" for="filter_customer">Kunde</label>
<input type="text" class="form-control" name="filter[customer]" id="filter_customer" value="<?=(array_key_exists("customer", $filter)) ? $filter['customer'] : ""?>"/> <input type="text" class="form-control" name="filter[customer]" id="filter_customer" value="<?=(array_key_exists("customer", $filter)) ? $filter['customer'] : ""?>"/>
</div> </div>
<div class="col-1"> <div class="col-2">
<label class="form-label" for="filter_address">Adresse</label> <label class="form-label" for="filter_address">Adresse</label>
<input type="text" class="form-control" name="filter[address]" id="filter_address" value="<?=(array_key_exists("address", $filter)) ? $filter['address'] : ""?>"/> <input type="text" class="form-control" name="filter[address]" id="filter_address" value="<?=(array_key_exists("address", $filter)) ? $filter['address'] : ""?>"/>
</div> </div>
@@ -56,6 +59,56 @@ $pagination_entity_name = "Rechnungen";
</div> </div>
</div> </div>
</div>
<div class="col-6">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-6">
<h4>PDF Dokumente generieren</h4>
<form method="post" action="<?=self::getUrl("Invoice","createPDFs")?>">
<div class="row mt-2">
<div class="col">
<button name="type" value="paper" class="btn btn-lg btn-info"><i class="far fa-fw fa-file-pdf"></i> Fehlende PDF-Dateien generieren</button>
</div>
</div>
</form>
</div>
<div class="col-6">
<h4>Rechnungsversand</h4>
<form method="post" action="<?=self::getUrl("Invoice","printInvoices")?>">
<div class="row">
<div class="col-6">
<label class="form-label" for="delivery_start_date">Rechungsdatum von</label>
<input type="text" class="form-control" name="delivery_start_date" id="delivery_start_date" value="" />
</div>
<div class="col-6">
<label class="form-label" for="delivery_end_date">Rechungsdatum bis</label>
<input type="text" class="form-control" name="delivery_end_date" id="delivery_end_date" value="" />
</div>
</div>
<div class="row mt-2">
<div class="col-6">
<button name="type" value="paper" class="btn btn-lg btn-purple"><i class="far fa-fw fa-print"></i> Rechnungen für Postversand drucken</button>
</div>
<div class="col-6">
<button name="type" value="email" class="btn btn-lg btn-danger" onclick="if(!confirm('Wirklich alle noch nicht versendeten Rechnungen per Email verschicken?')) return false;"><i class="far fa-fw fa-envelope"></i> Rechnungen per Email verschicken</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card"> <div class="card">
<div class="card-body mb-3"> <div class="card-body mb-3">
@@ -64,6 +117,7 @@ $pagination_entity_name = "Rechnungen";
<h4 class="header-title">Rechnungen</h4> <h4 class="header-title">Rechnungen</h4>
<div class="float-right"> <div class="float-right">
<a href="<?=self::getUrl("Invoice", "exportBmd")?>" class="btn btn-outline-primary"><i class="far fa-fw fa-file-export"></i> Rechnungsexport für BMD</a> <a href="<?=self::getUrl("Invoice", "exportBmd")?>" class="btn btn-outline-primary"><i class="far fa-fw fa-file-export"></i> Rechnungsexport für BMD</a>
</div> </div>
</div> </div>
</div> </div>
@@ -90,7 +144,12 @@ $pagination_entity_name = "Rechnungen";
<?php $total = $invoice->total + $invoice->total_setup; ?> <?php $total = $invoice->total + $invoice->total_setup; ?>
<?php $total_gross = $invoice->total_gross + $invoice->total_setup_gross; ?> <?php $total_gross = $invoice->total_gross + $invoice->total_setup_gross; ?>
<tr> <tr>
<td><a href="<?=self::getUrl("Invoice", "downloadInvoice", ["id" => $invoice->id])?>"><i class="fas fa-download fa-fw"></i> <?=$invoice->invoice_number?></a></td> <td>
<a href="<?=self::getUrl("Invoice", "downloadInvoice", ["id" => $invoice->id])?>"><i class="fas fa-download fa-fw"></i> <?=$invoice->invoice_number?></a>
<?php if($invoice->pdf): ?>
<i class="fas fa-fw fa-check"></i>
<?php endif; ?>
</td>
<td><?=date("d.m.Y", $invoice->invoice_date)?></td> <td><?=date("d.m.Y", $invoice->invoice_date)?></td>
<td><?=$invoice->customer_number?></td> <td><?=$invoice->customer_number?></td>
<td> <td>
@@ -126,5 +185,23 @@ $pagination_entity_name = "Rechnungen";
</div> </div>
<script>
$('#delivery_start_date').datepicker({
orientation: "bottom",
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$('#delivery_end_date').datepicker({
orientation: "bottom",
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
</script>
<?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?> <?php include(realpath(dirname(__FILE__) . "/../../$mfLayoutPackage") . "/footer.php"); ?>

View File

@@ -1,8 +1,103 @@
<?php <?php
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Output\QROutputInterface;
class Invoice extends mfBaseModel { class Invoice extends mfBaseModel {
private $positions; private $positions;
private $voicenumbers; 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) { public function getProperty($name) {
if($this->$name == null) { if($this->$name == null) {
@@ -24,6 +119,17 @@ class Invoice extends mfBaseModel {
return $this->voicenumbers; 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") { if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by); $this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) { if($this->creator === null) {

View File

@@ -1,10 +1,5 @@
<?php <?php
//use \chillerlan\QRCode;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Output\QROutputInterface;
class InvoiceController extends mfBaseController { class InvoiceController extends mfBaseController {
protected function init() { protected function init() {
@@ -97,8 +92,18 @@ class InvoiceController extends mfBaseController {
$this->redirect("Invoice"); $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) { foreach ($invoice->positions as $p) {
if (!array_key_exists($p->vatrate, $vat)) { if (!array_key_exists($p->vatrate, $vat)) {
$vat[$p->vatrate] = 0; $vat[$p->vatrate] = 0;
@@ -148,30 +153,11 @@ class InvoiceController extends mfBaseController {
$pdf = new PdfForm("Invoice/PDF_MAIN", $pdf_vars); $pdf = new PdfForm("Invoice/PDF_MAIN", $pdf_vars);
$wkhtmltopdfArgs = "--header-html $headerFile --footer-html $footerFile"; $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() { protected function runInvoicingAction() {
$i = 0; $i = 0;
@@ -665,7 +651,117 @@ XINON GmbH";
exit; 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() { 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;
} }
} }

View File

@@ -33,6 +33,7 @@ class InvoiceModel {
public $total; public $total;
public $total_gross; public $total_gross;
public $bmd_export_date; public $bmd_export_date;
public $date_delivered;
public $total_vat; public $total_vat;
public $create_by; public $create_by;
public $edit_by; public $edit_by;
@@ -173,7 +174,7 @@ class InvoiceModel {
$sql = "SELECT COUNT(*) as cnt FROM Invoice $sql = "SELECT COUNT(*) as cnt FROM Invoice
WHERE $where"; WHERE $where";
//mfLoghandler::singleton()->debug($sql); mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql); $res = $db->query($sql);
if($db->num_rows($res)) { if($db->num_rows($res)) {
@@ -220,7 +221,7 @@ class InvoiceModel {
private static function getSqlFilter($filter) { private static function getSqlFilter($filter) {
$where = "1=1 "; $where = "1=1 ";
//var_dump($filter);exit;
$db = FronkDB::singleton(); $db = FronkDB::singleton();
//var_dump($filter);exit; //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)) { if(array_key_exists("bmd_export_date", $filter)) {
$bmd_export_date = $filter['bmd_export_date']; $bmd_export_date = $filter['bmd_export_date'];
if(is_numeric($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)) { if(array_key_exists("billingaddress_id", $filter)) {
$Invoiceaddress_id = $filter['billingaddress_id']; $Invoiceaddress_id = $filter['billingaddress_id'];
if(is_numeric($Invoiceaddress_id)) { if(is_numeric($Invoiceaddress_id)) {
@@ -353,7 +390,6 @@ class InvoiceModel {
$where .= " AND Invoice.Invoice_period = $Invoice_period"; $where .= " AND Invoice.Invoice_period = $Invoice_period";
} }
} }
//var_dump($filter, $where);exit; //var_dump($filter, $where);exit;
return $where; return $where;
} }

View 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;
}
}

View 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]);
}
*/
}

View 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;
}
}

View File

@@ -20,7 +20,7 @@ class IvtCustomerModel {
return $items; return $items;
} }
public static function getFirst() { public static function getFirst($filter = []) {
$db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
$where = self::getSqlFilter($filter); $where = self::getSqlFilter($filter);

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class InvoiceAddDateDelivered extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Invoice");
$table->addColumn("date_delivered", "integer", ["null" => true, "default" => null, "after" => "bmd_export_date"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("Invoice")->removeColumn("date_delivered")->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class CreateInvoiceFile extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("InvoiceFile");
$table->addColumn("invoice_id", "integer", ["null" => false]);
$table->addColumn("file_id", "integer", ["null" => false]);
$table->addColumn("name", "string", ["null" => false, "limit" => 1024]);
$table->addColumn("description", "string", ["null" => true, "default" => null, "limit" => 1024]);
$table->addColumn("create_by", "integer", ["null" => false]);
$table->addColumn("edit_by", "integer", ["null" => false]);
$table->addColumn("create", "integer", ["null" => false]);
$table->addColumn("edit", "integer", ["null" => false]);
$table->create();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("InvoiceFile")->drop()->save();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -0,0 +1,79 @@
#!/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);
$folder = __DIR__."/files/";
$csvname = "tt-rech-export-bmd-2024-07-09_19-42-04.csv";
$filename = $folder.$csvname;
$db = FronkDB::singleton();
$log = mfLoghandler::singleton();
$input = fopen($filename, "r");
$i = 0;
$l = 0;
while($csv = fgetcsv($input, false, ";")) {
$l++;
if($l == 1) continue;
if(!trim($csv[1])) {
continue;
}
$fibu_account_number = trim($csv[1]);
$text = trim($csv[11]);
$iban = strtoupper(trim($csv[13]));
$bic = strtoupper(trim($csv[14]));
if(!$iban || !$bic) continue;
$customer_number = false;
$m = [];
if(preg_match('/\[(\d+)\]/', $text, $m)) {
if(count($m)) {
$customer_number = $m[1];
}
}
if(!$customer_number) {
die("Konnte Kundennummer nicht extrahieren\n");
}
/*if(in_array($customer_number, [3171])) {
continue;
}
echo "$customer_number\n";
*/
$ivt_customer = new IvtCustomer($customer_number);
if(!$ivt_customer->id) {
die("Kunde $customer_number nicht im ivt gefunden\n");
}
$ivt_iban = strtoupper(str_replace(" ","", $ivt_customer->IBAN));
$ivt_bic = strtoupper(str_replace(" ","", $ivt_customer->BIC));
if($ivt_iban != $iban) {
echo "$customer_number | iban: $iban <> $ivt_iban\n";
}
if($ivt_bic != $bic) {
echo "$customer_number | bic: $bic <> $ivt_bic\n";
}
$i++;
}
echo "\n$i Zeilen verarbeitet\n";

View File

@@ -0,0 +1,117 @@
#!/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);
$folder = __DIR__."/files/";
$csvname = "NTCS_Bankeinzug DT.xml";
$filename = $folder.$csvname;
$db = FronkDB::singleton();
$log = mfLoghandler::singleton();
$input = file_get_contents($filename);
$i = 0;
$l = 0;
$in_tx = false;
$rechnum = false;
$iban = false;
$bic = false;
$data = [];
foreach(explode("\n", $input) as $line) {
$line = trim($line);
if(preg_match('@</DrctDbtTxInf>@i', $line, $m)) {
$in_tx = false;
$rechnum = false;
$iban = false;
$bic = false;
$i++;
continue;
}
$m = [];
if(preg_match('@<DrctDbtTxInf>@i', $line, $m)) {
$in_tx = true;
continue;
}
if($in_tx) {
$m = [];
if(preg_match('@<EndToEndId>([a-z0-9-]+)</EndToEndId>@i', $line, $m)) {
$rechnum = $m[1];
}
if(preg_match('@<BIC>([a-z0-9-]+)</BIC>@i', $line, $m)) {
$bic = $m[1];
}
if(preg_match('@<IBAN>([a-z0-9-]+)</IBAN>@i', $line, $m)) {
$iban = $m[1];
}
if($rechnum && $bic && $iban) {
if(!array_key_exists($rechnum, $data)) {
$data[$rechnum] = [
"iban" => $iban,
"bic" => $bic
];
}
}
}
}
echo "$i input datensätze\n";
exit;
$i = 0;
foreach($data as $r => $d) {
//echo "$r ".$d["iban"]." ".$d["bic"]."\n";
$m = [];
if(!preg_match('/(RN2024-.+)/', $r, $m)) {
die("error");
}
$rechnum = $m[1];
$sepa_iban = strtoupper(str_replace(" ","", $d["iban"]));
$sepa_bic = strtoupper(str_replace(" ","", $d["bic"]));
$invoice = InvoiceModel::getFirst(["invoice_number" => $rechnum]);
if(!$invoice) {
die("$rechnum not found\n");
}
$address = new Address($invoice->billingaddress_id);
if(!$address) {
die("not billingaddress\n");
}
$tiban = strtoupper(str_replace(" ","", $address->bank_account_iban));
$tbic = strtoupper(str_replace(" ","", $address->bank_account_bic));
if($sepa_iban != $tiban) {
echo "$rechnum | tool iban: $tiban <> $sepa_iban\n";
}
if($sepa_bic != $tbic) {
echo "$rechnum | tool bic: $tbic <> $sepa_bic\n";
}
$i++;
}
echo "$i sepa daten verglichen\n";