From 3284b6c42f9107ecde4c7c098478ff2ebaaeae1c Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 7 Aug 2024 20:38:29 +0200 Subject: [PATCH] Added sums to Invoice/Index --- Layout/default/Billing/Index.php | 8 +- Layout/default/Invoice/Index.php | 57 ++++++++++ application/Invoice/InvoiceController.php | 23 ++++ application/Invoice/InvoiceModel.php | 124 ++++++++++++++++++++++ 4 files changed, 208 insertions(+), 4 deletions(-) diff --git a/Layout/default/Billing/Index.php b/Layout/default/Billing/Index.php index f2dffa09d..759810e5f 100644 --- a/Layout/default/Billing/Index.php +++ b/Layout/default/Billing/Index.php @@ -125,16 +125,16 @@ $pagination_entity_name = "Billingrecords"; - + - + - + - + diff --git a/Layout/default/Invoice/Index.php b/Layout/default/Invoice/Index.php index 93f11902e..aef0d47cb 100644 --- a/Layout/default/Invoice/Index.php +++ b/Layout/default/Invoice/Index.php @@ -122,6 +122,63 @@ $pagination_entity_name = "Rechnungen"; +
+
+
+
Summe Rechnungen Periodisch:
Summe Rechnungen Einmalig:
Summe Gutschriften Periodisch:
Summe Gutschriften Einmalig:
+ + + + + + + + + + + + + + + + +
+ Summe Rechnungen Netto:
+ Summe Rechnungen Brutto: +
+ €
+ € +
+ Summe Rechnungen Bankeinzug Netto:
+ Summe Rechnungen Bankeinzug Brutto: +
+ €
+ € +
+ Summe Gutschriften Netto:
+ Summe Gutschriften Brutto: +
+ €
+ € +
+ Summe Gesprächsgebühren Netto:
+ Summe Gesprächsgebühren Brutto: +
+ €
+ € +
+ Summe Gesprächsgebühren Bankeinzug Netto:
+ Summe Gesprächsgebühren Bankeinzug Brutto: +
+ €
+ € +
+ + + + + +
diff --git a/application/Invoice/InvoiceController.php b/application/Invoice/InvoiceController.php index 00debe869..275029377 100644 --- a/application/Invoice/InvoiceController.php +++ b/application/Invoice/InvoiceController.php @@ -56,6 +56,29 @@ class InvoiceController extends mfBaseController { $this->layout()->set("invoices", $billings); $this->layout()->set("pagination", $pagination); + + $sum_price = InvoiceModel::getSumPrice($filter); + $sum_price_gross = InvoiceModel::getSumGrossPrice($filter); + $sum_price_sepa = InvoiceModel::getSumPrice(array_merge($filter, ["billing_type" => "sepa"])); + $sum_price_sepa_gross = InvoiceModel::getSumGrossPrice(array_merge($filter, ["billing_type" => "sepa"])); + $sum_credit_price = InvoiceModel::getSumCreditPrice($filter); + $sum_credit_price_gross = InvoiceModel::getSumCreditGrossPrice(); + + $sum_voicecalls_price = InvoiceModel::getSumVoicecallsPrice($filter); + $sum_voicecalls_price_gross = InvoiceModel::getSumVoicecallsGrossPrice($filter); + $sum_voicecalls_price_sepa = InvoiceModel::getSumVoicecallsPrice(array_merge($filter, ["billing_type" => "sepa"])); + $sum_voicecalls_price_sepa_gross = InvoiceModel::getSumVoicecallsGrossPrice(array_merge($filter, ["billing_type" => "sepa"])); + + $this->layout()->set("sum_price", $sum_price); + $this->layout()->set("sum_price_sepa", $sum_price_sepa); + $this->layout()->set("sum_price_gross", $sum_price_gross); + $this->layout()->set("sum_price_sepa_gross", $sum_price_sepa_gross); + $this->layout()->set("sum_credit_price", $sum_credit_price); + $this->layout()->set("sum_credit_price_gross", $sum_credit_price_gross); + $this->layout()->set("sum_voicecalls_price", $sum_voicecalls_price); + $this->layout()->set("sum_voicecalls_price_gross", $sum_voicecalls_price_gross); + $this->layout()->set("sum_voicecalls_price_sepa", $sum_voicecalls_price_sepa); + $this->layout()->set("sum_voicecalls_price_sepa_gross", $sum_voicecalls_price_sepa_gross); } private function getPreparedFilter($filter) { diff --git a/application/Invoice/InvoiceModel.php b/application/Invoice/InvoiceModel.php index 04af23caa..eddef131f 100644 --- a/application/Invoice/InvoiceModel.php +++ b/application/Invoice/InvoiceModel.php @@ -109,6 +109,130 @@ class InvoiceModel { return $last_invoice->invoice_number; } + public static function getSumPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(total) as p FROM Invoice WHERE total > 0 AND $where"; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + public static function getSumGrossPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(total_gross) as p FROM Invoice WHERE total_gross > 0 AND $where"; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + public static function getSumCreditPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(total) as p FROM Invoice WHERE total < 0 AND $where"; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + public static function getSumCreditGrossPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(total_gross) as p FROM Invoice WHERE total_gross < 0 AND $where"; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + public static function getSumVoicecallsPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(Invoiceposition.price) as p FROM Invoiceposition + LEFT JOIN Invoice ON (Invoice.id = Invoiceposition.invoice_id) + WHERE Invoiceposition.product_name LIKE 'Gesprächsgebühren %' + AND $where + "; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + public static function getSumVoicecallsGrossPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(Invoiceposition.price_gross) as p FROM Invoiceposition + LEFT JOIN Invoice ON (Invoice.id = Invoiceposition.invoice_id) + WHERE Invoiceposition.product_name LIKE 'Gesprächsgebühren %' + AND $where + "; + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + return $data->p; + } + } + + return 0; + } + + + public static function getAll() { $items = [];