From ac1d2772ef7ad50e0003a0f256a59c6218904199 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 8 Jul 2024 21:11:11 +0200 Subject: [PATCH] Added Sums in Billing/Index --- Layout/default/Billing/Index.php | 46 ++++++++++++- application/Billing/BillingController.php | 22 +++++++ application/Billing/BillingModel.php | 78 +++++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-) diff --git a/Layout/default/Billing/Index.php b/Layout/default/Billing/Index.php index 43676214c..2992d8227 100644 --- a/Layout/default/Billing/Index.php +++ b/Layout/default/Billing/Index.php @@ -63,6 +63,25 @@ $pagination_entity_name = "Billingrecords"; + + + +
+ + +
+
@@ -81,7 +100,7 @@ $pagination_entity_name = "Billingrecords";
-

Fertiggestellte Bestellungen

+

Verrechnungsdatensätze

@@ -92,6 +111,31 @@ $pagination_entity_name = "Billingrecords";
+
+
+
+

Summen

+ + + + + + + + + + + + + + +
Summe Rechnungen Periodisch:
Summe Rechnungen Einmalig:
Summe Gutschriften Periodisch:
Summe Gutschriften Einmalig:
+ + +
+
+
+
diff --git a/application/Billing/BillingController.php b/application/Billing/BillingController.php index a83028959..06a5f18fa 100644 --- a/application/Billing/BillingController.php +++ b/application/Billing/BillingController.php @@ -51,6 +51,18 @@ class BillingController extends mfBaseController { $this->layout()->set("billings", $billings); $this->layout()->set("pagination", $pagination); + // summen berechnen + $sum_price = BillingModel::getSumPrice($filter); + $sum_price_setup = BillingModel::getSumPriceSetup($filter); + $sum_credit_price = BillingModel::getSumCreditPrice($filter); + $sum_credit_price_setup = BillingModel::getSumCreditPriceSetup($filter); + + $this->layout()->set("sum_price", $sum_price); + $this->layout()->set("sum_price_setup", $sum_price_setup); + $this->layout()->set("sum_credit_price", $sum_credit_price); + $this->layout()->set("sum_credit_price_setup", $sum_credit_price_setup); + + } private function getPreparedFilter($filter) @@ -66,6 +78,16 @@ class BillingController extends mfBaseController { $new_filter["price>="] = 0; } + if(array_key_exists("status", $filter)) { + if($filter["status"] == "billed") { + $new_filter["invoice_id"] = true; + } else { + $new_filter["invoice_id"] = null; + } + } else { + $new_filter["invoice_id"] = null; + } + if(array_key_exists("customer", $filter)) { if(array_key_exists("customer", $filter) && $filter["customer"]) { $kunde = $this->db()->escape($filter['customer']); diff --git a/application/Billing/BillingModel.php b/application/Billing/BillingModel.php index f1d164438..cd8c990c0 100644 --- a/application/Billing/BillingModel.php +++ b/application/Billing/BillingModel.php @@ -66,6 +66,82 @@ class BillingModel { return $model; } + public static function getSumPrice($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(price) as p FROM Billing WHERE price > 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 getSumPriceSetup($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(price_setup) as p FROM Billing WHERE price_setup > 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(price) as p FROM Billing WHERE price < 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 getSumCreditPriceSetup($filter = []) { + $db = FronkDB::singleton(); + + if(array_key_exists("price>=", $filter)) unset($filter["price>="]); + + $where = self::getSqlFilter($filter); + $sql = "SELECT SUM(price_setup) as p FROM Billing WHERE price_setup < 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 getAll() { $items = []; @@ -229,6 +305,8 @@ class BillingModel { $where .= " AND Billing.invoice_id=$invoice_id"; } elseif($invoice_id === null || $invoice_id === false) { $where .= " AND (Billing.invoice_id IS NULL OR Billing.invoice_id=0)"; + } elseif($invoice_id === true) { + $where .= " AND (Billing.invoice_id IS NOT NULL AND Billing.invoice_id > 0)"; } }