Added Credit CSV download to Invoice/Index

This commit is contained in:
Frank Schubert
2024-07-12 18:57:46 +02:00
parent 1ca399786f
commit 5e5e4de27d
5 changed files with 103 additions and 51 deletions

View File

@@ -151,7 +151,11 @@ $pagination_entity_name = "Rechnungen";
<td class="<?=($total_gross < 0) ? "text-danger" : ""?>">€ <?=number_format($total_gross,2,",",".")?></td> <td class="<?=($total_gross < 0) ? "text-danger" : ""?>">€ <?=number_format($total_gross,2,",",".")?></td>
<td><?=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?></td> <td><?=($invoice->billing_type == "sepa") ? "SEPA" : "Überweisung"?></td>
<td><?=($invoice->billing_delivery == "email") ? "Email" : "Papier"?></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> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>

View File

@@ -63,7 +63,7 @@ class Contract extends mfBaseModel {
$this->linkTo[] = $link; $this->linkTo[] = $link;
break; break;
case "credit": case "credit":
$this->linkFrom[] = $link; $this->linkTo[] = $link;
break; break;
case "upgrade": case "upgrade":
$this->upgradeTo[] = $link; $this->upgradeTo[] = $link;
@@ -89,7 +89,7 @@ class Contract extends mfBaseModel {
$this->linkFrom[] = $link; $this->linkFrom[] = $link;
break; break;
case "credit": case "credit":
$this->linkTo[] = $link; $this->linkFrom[] = $link;
break; break;
case "upgrade": case "upgrade":
$this->upgradeFrom[] = $link; $this->upgradeFrom[] = $link;

View File

@@ -124,59 +124,33 @@ class InvoiceController extends mfBaseController {
readfile($pdf_path); readfile($pdf_path);
exit; 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);
} }
$pdf_vars = [ protected function downloadInvoiceCsv() {
"invoice" => $invoice, $id = $this->request->id;
"vat" => $vat, if (!is_numeric($id) || !$id) {
"bank_iban" => TT_INVOICE_BANK_IBAN, $this->layout()->setFlash("Rechnung nicht gefunden", "error");
"bank_bic" => TT_INVOICE_BANK_BIC, $this->redirect("Invoice");
"bank_bank"=> TT_INVOICE_BANK_BANK, }
"bank_owner" => TT_INVOICE_BANK_OWNER
];
// Replace placeholders in header $invoice = new Invoice($id);
$headerHtml = file_get_contents(BASEDIR . "/Layout/default/Invoice/PDF_HEADER.html"); if (!$invoice->id) {
$headerHtml = str_replace("{{ basedir }}", BASEDIR, $headerHtml); $this->layout()->setFlash("Rechnung nicht gefunden", "error");
$headerHtml = str_replace("{{ addressLine_1 }}", $invoice->company ? $invoice->company : "", $headerHtml); $this->redirect("Invoice");
$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"; if(!$invoice->positions) {
file_put_contents($headerFile, $headerHtml); $this->layout()->setFlash("Keine Rechnungspositionen vorhanden", "error");
$this->redirect("Invoice");
}
// 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);*/
$tpl = new Layout();
$tpl->setTemplate("Invoice/invoicepositions.csv");
$tpl->set("invoice", $invoice);
$tpl->display();
//$csv = $tpl->render();
//echo $csv;
exit;
} }

View File

@@ -1,6 +1,8 @@
<?php <?php
class Invoiceposition extends mfBaseModel { class Invoiceposition extends mfBaseModel {
private $invoice;
private $contract;
public function setOption($name, $value) { public function setOption($name, $value) {
$options = $this->getOptions; $options = $this->getOptions;
@@ -65,4 +67,52 @@ class Invoiceposition extends mfBaseModel {
//$this->log->debug("Cloned Invoiceposition $old_id"); //$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;
}
} }

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