Merge branch 'fronkdev' into 'master'
Added Sums in Billing/Index See merge request fronk/thetool!449
This commit is contained in:
@@ -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']);
|
||||
|
||||
@@ -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)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user