From 3cc3f3f50cfbafbb98da1c860aa39ebea46c2bb2 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 21 Sep 2021 23:12:53 +0200 Subject: [PATCH] Patching readonly --- Layout/default/Patching/Index.php | 152 ++++++++++++++++ Layout/default/menu.php | 1 + application/Dashboard/DashboardController.php | 7 +- application/Order/OrderModel.php | 19 +- application/Patching/Patching.php | 5 + application/Patching/PatchingController.php | 34 ++++ application/Patching/PatchingModel.php | 164 ++++++++++++++++++ application/Termination/Termination.php | 50 ++++++ 8 files changed, 428 insertions(+), 4 deletions(-) create mode 100644 Layout/default/Patching/Index.php create mode 100644 application/Patching/Patching.php create mode 100644 application/Patching/PatchingController.php create mode 100644 application/Patching/PatchingModel.php diff --git a/Layout/default/Patching/Index.php b/Layout/default/Patching/Index.php new file mode 100644 index 000000000..aa4109c11 --- /dev/null +++ b/Layout/default/Patching/Index.php @@ -0,0 +1,152 @@ + + + +
+
+
+
+ +
+

Patchungen

+
+
+
+ + +
+
+ + + + +
+
+
+

Patchungen

+
+ + $pagination['count']): ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
StandortODFAbschluss POP/Device
NetzgebietPOPKundeStandortPatchposition ODFODF PortTypGerätPortsGepatched
building->network->name?>order->owner->customer_number?>order->owner->getCompanyOrName()?> + building->street?>
+ building->zip?> building->city?> +
+ workflowitems["schrank"]->value->value_string?> / + workflowitems["baugruppe"]->value->value_string?> / + workflowitems["modul"]->value->value_string?> / + workflowitems["ports"]->value->value_string?> / + + + + +
+ + $pagination['count']): ?> + + + +
+
+ +
+
+ + diff --git a/Layout/default/menu.php b/Layout/default/menu.php index 0addfa0c5..8fba78213 100644 --- a/Layout/default/menu.php +++ b/Layout/default/menu.php @@ -39,6 +39,7 @@ is(["Admin","netowner","pipeplanner"])): ?>
  • ">Objekte & Anschlüsse
  • is(["Admin","netowner","pipeplanner","pipeworker","lineplanner","lineworker"])): ?>
  • ">Tiefbau
  • is(["Admin","netowner","lineplanner","lineworker"])): ?>
  • ">Leitungsbau
  • + is(["Admin", "netowner", "netoperator", "lineworker"])): ?>
  • ">Patchungen
  • diff --git a/application/Dashboard/DashboardController.php b/application/Dashboard/DashboardController.php index fad37dc34..0e7c2ed63 100644 --- a/application/Dashboard/DashboardController.php +++ b/application/Dashboard/DashboardController.php @@ -23,9 +23,14 @@ class DashboardController extends mfBaseController { /*$address = AddressModel::getOne(5); var_dump($address->types);exit;*/ - + /* $a = new Address(1); var_dump($a->generateServicePin());exit; + */ + + $t = new Termination(45); + $ports = $t->getLineworkportPairs(); + var_dump($ports);exit; } protected function pdfAction() { diff --git a/application/Order/OrderModel.php b/application/Order/OrderModel.php index b81341176..c98ba5088 100644 --- a/application/Order/OrderModel.php +++ b/application/Order/OrderModel.php @@ -74,11 +74,24 @@ class OrderModel { } - public static function getFirst() { + public static function getFirst($filter = false) { $db = FronkDB::singleton(); $where = self::getSqlFilter($filter); - $res = $db->select("Order", "*", "$where ORDER BY order_date, owner_id"); + + $sql = "SELECT `Order`.id as order_id, `Order`.* 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) + + WHERE $where + GROUP BY `Order`.id + ORDER BY `Order`.order_date ASC"; + $res = $db->query($sql); + if($db->num_rows($res)) { $data = $db->fetch_object($res); $item = new Order($data); @@ -260,7 +273,7 @@ class OrderModel { if(array_key_exists("termination_id", $filter)) { $termination_id = $filter['termination_id']; if(is_numeric($termination_id)) { - $where .= " AND Product.termination_id=$termination_id"; + $where .= " AND OrderProduct.termination_id=$termination_id"; } } diff --git a/application/Patching/Patching.php b/application/Patching/Patching.php new file mode 100644 index 000000000..7025ded6f --- /dev/null +++ b/application/Patching/Patching.php @@ -0,0 +1,5 @@ +needlogin=true; + $me = new User(); + $me->loadMe(); + $this->me = $me; + $this->layout()->set("me",$me); + + if(!$me->is(["Admin", "netowner", "netoperator", "lineworker"])) { + $this->redirect("Dashboard"); + } + } + + protected function indexAction() { + $this->layout()->setTemplate("Patching/Index"); + + $terminations = PatchingModel::searchByTermination(); + $terms = []; + foreach($terminations as $term) { + $term->order = OrderModel::getFirst(["termination_id" => $term->id]); + $terms[] = $term; + //var_dump($term); + } + //exit; + + $this->layout()->set("terminations", $terms); + + } + + +} \ No newline at end of file diff --git a/application/Patching/PatchingModel.php b/application/Patching/PatchingModel.php new file mode 100644 index 000000000..752ba8fba --- /dev/null +++ b/application/Patching/PatchingModel.php @@ -0,0 +1,164 @@ + $value) { + if(property_exists(get_called_class(), $field)) { + $model ->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + if($model->create_by === null) { + $model->create_by = $me->id; + } + if($model->edit_by === null) { + $model->edit_by = $me->id; + } + + return $model; + } + + public static function getOne($id) { + if(!is_numeric($id) || !$id) { + throw new Exception("Invalid number", 400); + } + $item = []; + $db = FronkDB::singleton(); + + $res = $db->select("Patching", "*", "id=$id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Patching($data); + } + return $item; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(); + + $res = $db->select("Patching", "*"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Patching($data); + } + } + return $items; + + } + + public static function getFirst() { + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Patching", "*", "$where ORDER BY termination_id"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new Patching($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function searchByTermination($filter = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($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 (Patching.termination_id IS NULL OR Patching.patched = 0) + GROUP BY Termination.id + ORDER BY Termination.id ASC"; + + //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; + } + + public static function search($filter = false) { + $items = []; + $db = FronkDB::singleton(); + + $where = self::getSqlFilter($filter); + $res = $db->select("Patching", "*", "$where ORDER BY termination_id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Patching($data); + } + } + return $items; + } + + private function getSqlFilter($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 termination_id=$termination_id"; + } + } + + + + //var_dump($filter, $where);exit; + return $where; + } + +} \ No newline at end of file diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php index 0831fd6a0..2273644e7 100644 --- a/application/Termination/Termination.php +++ b/application/Termination/Termination.php @@ -72,6 +72,56 @@ class Termination extends mfBaseModel { return $code; } + public function getLineworkportPairs() { + $ports = $this->getProperty("workflowitems")["ports"]->value->value_string; + if(!$ports) { + return []; + } + + $return = []; + $return["range"] = []; + $return["pairs"] = []; + + $ports = preg_replace('/[^0-9-]+/', "", $ports); + if(strpos($ports, "-") !== false) { + // port range + $this->log->debug("is range"); + $port_parts = explode("-", $ports); + if(is_array($port_parts) && count($port_parts) == 2) { + $from = $port_parts[0]; + $to = $port_parts[1]; + + if($port_parts[0] > $port_parts[1]) { + $from = $port_parts[1]; + $to = $port_parts[0]; + } + + $range = []; + $pairs = []; + + $mod = $from % 2; + + for($i = $from; $i <= $to; $i++) { + $range[] = intval($i); + if($i % 2 == $mod && $i + 1 <= $to) { + $pairs[] = $i."-".($i+1); + } + } + + $return["range"] = $range; + $return["pairs"] = $pairs; + } + } else { + // single port + $this->log->debug("not a range"); + $return["range"] = $ports; + } + + //var_dump($return);exit; + return $return; + + } + public function resetProperties() { $this->building = null; $this->status = null;