From cbac36e96a5dc7d19a7b2daeb4ab6d98f00701ad Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 23 Nov 2021 20:11:35 +0100 Subject: [PATCH] Added Prepatching --- Layout/default/Patching/Index.php | 3 +- application/Linework/LineworkController.php | 22 ++++++ application/Patching/PatchingController.php | 23 ++++-- application/Patching/PatchingModel.php | 86 +++++++++++++++++++-- 4 files changed, 121 insertions(+), 13 deletions(-) diff --git a/Layout/default/Patching/Index.php b/Layout/default/Patching/Index.php index f07ab8b7c..18f1b0f3d 100644 --- a/Layout/default/Patching/Index.php +++ b/Layout/default/Patching/Index.php @@ -54,8 +54,9 @@
diff --git a/application/Linework/LineworkController.php b/application/Linework/LineworkController.php index 72a3de1a5..82139fa4c 100644 --- a/application/Linework/LineworkController.php +++ b/application/Linework/LineworkController.php @@ -323,6 +323,28 @@ class LineworkController extends mfBaseController { } } + //var_dump(strlen($termination->workflowitems['pop_id']->value->value_string));exit; + + // set patching enabled for termination + if( + (strlen($termination->workflowitems['pop_id']->value->value_string) || strlen($termination->workflowitems['ist_pop_id']->value->value_string)) && + (strlen($termination->workflowitems['schrank']->value->value_string) || strlen($termination->workflowitems['ist_schrank']->value->value_string)) && + (strlen($termination->workflowitems['baugruppe']->value->value_string) || strlen($termination->workflowitems['ist_baugruppe']->value->value_string)) && + (strlen($termination->workflowitems['modul']->value->value_string) || strlen($termination->workflowitems['ist_modul']->value->value_string)) && + (strlen($termination->workflowitems['ports']->value->value_string) || strlen($termination->workflowitems['ist_ports']->value->value_string)) + ) { + $this->log->debug("Linework::save: All items needed for patching set"); + if($termination->patching_enabled != 1) { + $termination->patching_enabled = 1; + $termination->save(); + } + } else { + $this->log->debug("Linework::save: Not all items needed for patching set"); + if($termination->patching_enabled == 1) { + $termination->patching_enabled = 0; + $termination->save(); + } + } // file upload //var_dump($_FILES);exit; diff --git a/application/Patching/PatchingController.php b/application/Patching/PatchingController.php index bfe217ed6..43cc7ea96 100644 --- a/application/Patching/PatchingController.php +++ b/application/Patching/PatchingController.php @@ -78,10 +78,20 @@ class PatchingController extends mfBaseController { } //var_dump($terms_search);exit; - $pagination['maxItems'] = PatchingModel::searchByTerminationCount($terms_search); - foreach(PatchingModel::searchByTermination($terms_search, $pagination) as $t) { - if(!array_key_exists($t->id, $terms)) { - $terms[$t->id] = $t; + + if($filter["prepatched"]) { + $pagination['maxItems'] = PatchingModel::searchByEnabledPatchingCount($terms_search); + foreach(PatchingModel::searchByEnabledPatching($terms_search, $pagination) as $t) { + if(!array_key_exists($t->id, $terms)) { + $terms[$t->id] = $t; + } + } + } else { + $pagination['maxItems'] = PatchingModel::searchByFinishedLineworkCount($terms_search); + foreach(PatchingModel::searchByFinishedLinework($terms_search, $pagination) as $t) { + if(!array_key_exists($t->id, $terms)) { + $terms[$t->id] = $t; + } } } @@ -117,16 +127,15 @@ class PatchingController extends mfBaseController { if($filter["patched"] == "1") { $new_filter["patched"] = true; $new_filter["hide_delayed_finish"] = false; - } else { + } elseif ($filter["patched"] == "2") { $new_filter["patched"] = false; + $new_filter["prepatched"] = true; } unset($filter["patched"]); } else { $new_filter["patched"] = false; } - - foreach($filter as $name => $value) { $new_filter[$name] = $value; } diff --git a/application/Patching/PatchingModel.php b/application/Patching/PatchingModel.php index b78c8396c..b9b93a1c1 100644 --- a/application/Patching/PatchingModel.php +++ b/application/Patching/PatchingModel.php @@ -122,12 +122,12 @@ class PatchingModel { return null; } - public static function searchByTerminationCount($filter = false) { + public static function searchByFinishedLineworkCount($filter = false) { $items = []; $db = FronkDB::singleton(); $where = self::getTerminationSqlFilter($filter); - + $sql = "SELECT COUNT(Termination.id) as cnt FROM `Order` LEFT JOIN OrderProduct ON (OrderProduct.order_id = `Order`.id) LEFT JOIN Product ON (Product.id = OrderProduct.product_id) @@ -152,16 +152,15 @@ class PatchingModel { return $data->cnt; } - return 0; } - public static function searchByTermination($filter = false, $limit = false) { + public static function searchByFinishedLinework($filter = false, $limit = false) { $items = []; $db = FronkDB::singleton(); $where = self::getTerminationSqlFilter($filter); - +// TEMP: vorpatchen $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) @@ -197,6 +196,83 @@ class PatchingModel { } } + return $items; + } + + public static function searchByEnabledPatchingCount($filter = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getTerminationSqlFilter($filter); + + $sql = "SELECT COUNT(Termination.id) as cnt 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 Terminationstatus ON (Terminationstatus.id = Termination.status_id) + LEFT JOIN Building ON (Building.id = Termination.building_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 Termination.patching_enabled = 1 + AND Workflowitem.name = 'customer_passive_finished' + AND Workflowvalue.object_id = OrderProduct.termination_id + AND Workflowvalue.value_int <> 1 + AND $where"; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + return $data->cnt; + } + + return 0; + } + + public static function searchByEnabledPatching($filter = false, $limit = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getTerminationSqlFilter($filter); +// TEMP: vorpatchen + $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 Terminationstatus ON (Terminationstatus.id = Termination.status_id) + LEFT JOIN Building ON (Building.id = Termination.building_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 Termination.patching_enabled = 1 + AND 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); + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($count)) { + $sql .= " LIMIT ".$limit['count']; + } + } + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Termination($data->termination_id); + } + } return $items; }