Added sums to Invoice/Index
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user