Various Bugfixes

This commit is contained in:
Frank Schubert
2021-10-07 19:54:28 +02:00
parent e27da7ec55
commit d150b4e7b5
8 changed files with 167 additions and 39 deletions

View File

@@ -66,10 +66,11 @@ class PatchingModel {
}
public static function getFirst() {
public static function getFirst($filter = false) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$where = self::getPatchingSqlFilter($filter);
//var_dump($where);exit;
$res = $db->select("Patching", "*", "$where ORDER BY termination_id");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -83,11 +84,47 @@ class PatchingModel {
return null;
}
public static function getFirstByTermination($filter = false) {
$db = FronkDB::singleton();
$where = self::getTerminationSqlFilter($filter);
$sql = "SELECT Termination.id as termination_id FROM `Order`
LEFT JOIN OrderProduct ON (OrderProduct.order_id = `Order`.id)
LEFT JOIN Product ON (Product.id = OrderProduct.product_id)
LEFT JOIN Termination ON (Termination.id = OrderProduct.termination_id)
LEFT JOIN Building ON (Building.id = Termination.building_id)
LEFT JOIN Terminationstatus ON (Terminationstatus.id = Termination.status_id)
LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id)
LEFT JOIN Patching ON (Patching.Termination_id = OrderProduct.termination_id)
LEFT JOIN Workflowitem ON (Workflowitem.object_type = 'Termination')
LEFT JOIN Workflowvalue ON (Workflowvalue.item_id = Workflowitem.id)
WHERE Workflowitem.name = 'customer_passive_finished'
AND Workflowvalue.object_id = OrderProduct.termination_id
AND Workflowvalue.value_int = 1
AND $where
GROUP BY Termination.id
ORDER BY Termination.id ASC";
// AND (Patching.patched IS NULL OR Patching.patched = 0)
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = PatchingModel::getFirst(["termination_id" => $data->termination_id]);
//$item = new Patching($data->termination_id);
return $item;
}
return null;
}
public static function searchByTerminationCount($filter = false) {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$where = self::getTerminationSqlFilter($filter);
$sql = "SELECT COUNT(Termination.id) as cnt FROM `Order`
LEFT JOIN OrderProduct ON (OrderProduct.order_id = `Order`.id)
@@ -122,7 +159,7 @@ class PatchingModel {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$where = self::getTerminationSqlFilter($filter);
$sql = "SELECT Termination.id as termination_id FROM `Order`
LEFT JOIN OrderProduct ON (OrderProduct.order_id = `Order`.id)
@@ -167,7 +204,7 @@ class PatchingModel {
$items = [];
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$where = self::getPatchingSqlFilter($filter);
$res = $db->select("Patching", "*", "$where ORDER BY termination_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
@@ -177,7 +214,7 @@ class PatchingModel {
return $items;
}
private function getSqlFilter($filter = []) {
private function getTerminationSqlFilter($filter = []) {
$where = "1=1 ";
if(!is_array($filter) || !count($filter)) {
return $where;
@@ -187,7 +224,7 @@ class PatchingModel {
if(array_key_exists("termination_id", $filter)) {
$termination_id = $filter['termination_id'];
if(is_numeric($termination_id)) {
$where .= " AND termination_id=$termination_id";
$where .= " AND Patching.termination_id=$termination_id";
}
}
@@ -244,4 +281,68 @@ class PatchingModel {
return $where;
}
private function getPatchingSqlFilter($filter = []) {
$where = "1=1 ";
if(!is_array($filter) || !count($filter)) {
return $where;
}
//var_dump($filter);exit;
if(array_key_exists("termination_id", $filter)) {
$termination_id = $filter['termination_id'];
if(is_numeric($termination_id)) {
$where .= " AND Patching.termination_id=$termination_id";
}
}
if(array_key_exists("patched", $filter)) {
$patched = $filter["patched"];
if($patched) {
$where .= " AND Patching.patched=1";
} else {
$where .= " AND (Patching.patched IS NULL OR Patching.patched = 0)";
}
}
if(array_key_exists("hide_delayed_finish", $filter)) {
$hide_delayed_finish = $filter["hide_delayed_finish"];
if($hide_delayed_finish) {
$where .= " AND (`Order`.finish_after IS NULL OR `Order`.finish_after <= ".(date("U") + (31 * 86400))." )";
}
}
if(array_key_exists("network_id", $filter)) {
$network_id = $filter['network_id'];
if(is_numeric($network_id)) {
$where .= " AND Building.network_id=$network_id";
} elseif(is_array($network_id) && count($network_id)) {
$where .= " AND Building.network_id IN (". implode(",", $network_id).")";
}
}
if(array_key_exists("pop_id", $filter)) {
$pop_id = $filter['pop_id'];
if(is_numeric($pop_id)) {
$where .= " AND Building.pop_id=$pop_id";
}
}
if(array_key_exists("code", $filter)) {
$code = FronkDB::singleton()->escape($filter['code']);
if($code) {
$where .= " AND Building.`code` like '%$code%'";
}
}
if(array_key_exists("street", $filter)) {
$street = FronkDB::singleton()->escape($filter["street"]);
if($street) {
$where .= " AND Building.street like '%$street%'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
}