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