InvoiceFile WIP 2024-07-09
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) {
|
||||
|
||||
Reference in New Issue
Block a user