Added Credit CSV download to Invoice/Index
This commit is contained in:
@@ -151,7 +151,11 @@ $pagination_entity_name = "Rechnungen";
|
||||
<td class="<?=($total_gross < 0) ? "text-danger" : ""?>">€ <?=number_format($total_gross,2,",",".")?></td>
|
||||
<td><?=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?></td>
|
||||
<td><?=($invoice->billing_delivery == "email") ? "Email" : "Papier"?></td>
|
||||
<td><a href="<?=self::getUrl("Invoice", "downloadInvoice", ["id" => $invoice->id])?>"><i class="fas fa-download fa-fw"></i></a></td>
|
||||
<td>
|
||||
<?php if($invoice->total < 0): ?>
|
||||
<a class="text-danger" href="<?=self::getUrl("Invoice", "downloadInvoiceCsv", ["id" => $invoice->id])?>"><i class="fas fa-file-csv fa-fw"></i></a>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
@@ -63,7 +63,7 @@ class Contract extends mfBaseModel {
|
||||
$this->linkTo[] = $link;
|
||||
break;
|
||||
case "credit":
|
||||
$this->linkFrom[] = $link;
|
||||
$this->linkTo[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeTo[] = $link;
|
||||
@@ -89,7 +89,7 @@ class Contract extends mfBaseModel {
|
||||
$this->linkFrom[] = $link;
|
||||
break;
|
||||
case "credit":
|
||||
$this->linkTo[] = $link;
|
||||
$this->linkFrom[] = $link;
|
||||
break;
|
||||
case "upgrade":
|
||||
$this->upgradeFrom[] = $link;
|
||||
|
||||
@@ -124,59 +124,33 @@ class InvoiceController extends mfBaseController {
|
||||
|
||||
readfile($pdf_path);
|
||||
exit;
|
||||
}
|
||||
|
||||
/*$vat = [];
|
||||
foreach ($invoice->positions as $p) {
|
||||
if (!array_key_exists($p->vatrate, $vat)) {
|
||||
$vat[$p->vatrate] = 0;
|
||||
}
|
||||
$vat[$p->vatrate] += $p->price_gross - ($p->price * $p->amount);
|
||||
protected function downloadInvoiceCsv() {
|
||||
$id = $this->request->id;
|
||||
if (!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$pdf_vars = [
|
||||
"invoice" => $invoice,
|
||||
"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
|
||||
];
|
||||
$invoice = new Invoice($id);
|
||||
if (!$invoice->id) {
|
||||
$this->layout()->setFlash("Rechnung nicht gefunden", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
// 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 }}", $invoice->company ? $invoice->company : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_2 }}", $invoice->firstname . " " . $invoice->lastname, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_3 }}", nl2br($invoice->street), $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_4 }}", $invoice->zip . " " . $invoice->city, $headerHtml);
|
||||
$headerHtml = str_replace("{{ addressLine_5 }}", $invoice->country != "Österreich" ? $invoice->country : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ customerNumber }}", $invoice->customer_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ billingAccount }}", $invoice->fibu_account_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceNumber }}", $invoice->invoice_number, $headerHtml);
|
||||
$headerHtml = str_replace("{{ invoiceDate }}", date("d.m.Y", $invoice->invoice_date), $headerHtml);
|
||||
$headerHtml = str_replace("{{ vatHtml }}", $invoice->uid ? "<tr><td>Ihre UID:</td><td>" . $invoice->uid . "</td></tr>" : "", $headerHtml);
|
||||
$headerHtml = str_replace("{{ qrCodeSrc }}", $this->getBankQRCode($invoice->invoice_number, round($invoice->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";
|
||||
$pdf->download($invoice->invoice_number . ".pdf", $wkhtmltopdfArgs);*/
|
||||
if(!$invoice->positions) {
|
||||
$this->layout()->setFlash("Keine Rechnungspositionen vorhanden", "error");
|
||||
$this->redirect("Invoice");
|
||||
}
|
||||
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Invoice/invoicepositions.csv");
|
||||
$tpl->set("invoice", $invoice);
|
||||
$tpl->display();
|
||||
//$csv = $tpl->render();
|
||||
//echo $csv;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Invoiceposition extends mfBaseModel {
|
||||
private $invoice;
|
||||
private $contract;
|
||||
|
||||
public function setOption($name, $value) {
|
||||
$options = $this->getOptions;
|
||||
@@ -65,4 +67,52 @@ class Invoiceposition extends mfBaseModel {
|
||||
|
||||
//$this->log->debug("Cloned Invoiceposition $old_id");
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$this->creator = new User($this->create_by);
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
}
|
||||
24
scripts/contract/mark-credit-contracts-as-credit.php
Normal file
24
scripts/contract/mark-credit-contracts-as-credit.php
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/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);
|
||||
|
||||
foreach(ContractLinkModel::getAll() as $link) {
|
||||
if($link->origin->price <= 0) continue;
|
||||
|
||||
if($link->contract->price < 0) {
|
||||
$link->type = "credit";
|
||||
$link->save();
|
||||
echo "fixed link ".$link->id." origin contract ".$link->origin_contract_id."\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user