Added Sums in Billing/Index
This commit is contained in:
@@ -63,6 +63,25 @@ $pagination_entity_name = "Billingrecords";
|
||||
<option value="12" <?=(array_key_exists("billing_period", $filter) &&$filter['billing_period'] == 12 ) ? "selected='selected'" : ""?>>Jährlich</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!--div class="col-1">
|
||||
<label class="form-label" for="filter_start_month">Zeitraum Monat</label>
|
||||
<input type="text" class="form-control" name="filter[start_month]" id="filter_start_month" value="<?=(array_key_exists("start_month", $filter)) ? $filter['start_month'] : ""?>"/>
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_start_year">Zeitraum Jahr</label>
|
||||
<input type="text" class="form-control" name="filter[start_year]" id="filter_start_year" value="<?=(array_key_exists("start_year", $filter)) ? $filter['start_year'] : ""?>"/>
|
||||
</div-->
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_status">Status</label>
|
||||
<select class="form-control" name="filter[status]" id="filter_status">
|
||||
<option value="open" <?=(array_key_exists("status", $filter) && $filter['status'] == "open") ? "selected='selected'" : ""?>>Nur offene</option>
|
||||
<option value="billed" <?=(array_key_exists("status", $filter) && $filter['status'] == "billed" ) ? "selected='selected'" : ""?>>Nur verrechnete</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
@@ -81,7 +100,7 @@ $pagination_entity_name = "Billingrecords";
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Fertiggestellte Bestellungen</h4>
|
||||
<h4 class="header-title">Verrechnungsdatensätze</h4>
|
||||
<!--button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-check"></i> Markierte Elemente als Contract übernehmen</button-->
|
||||
</div>
|
||||
<div class="float-right">
|
||||
@@ -92,6 +111,31 @@ $pagination_entity_name = "Billingrecords";
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<div>
|
||||
<h4>Summen</h4>
|
||||
<table class="table table-striped table-bordered">
|
||||
<tr>
|
||||
<th class="text-right">Summe Rechnungen Periodisch:</th>
|
||||
<td><?=$sum_price?></td>
|
||||
</tr><tr>
|
||||
<th class="text-right">Summe Rechnungen Einmalig:</th>
|
||||
<td><?=$sum_price_setup?></td>
|
||||
</tr><tr>
|
||||
<th class="text-right">Summe Gutschriften Periodisch:</th>
|
||||
<td><?=$sum_credit_price?></td>
|
||||
</tr><tr>
|
||||
<th class="text-right">Summe Gutschriften Einmalig:</th>
|
||||
<td><?=$sum_credit_price_setup?></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.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']);
|
||||
|
||||
@@ -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