diff --git a/Layout/default/Building/Form.php b/Layout/default/Building/Form.php index 68d14444e..31d15bbfc 100644 --- a/Layout/default/Building/Form.php +++ b/Layout/default/Building/Form.php @@ -56,7 +56,7 @@
- +
diff --git a/Layout/default/Building/Index.php b/Layout/default/Building/Index.php index 56d8f9089..b70bd4afc 100644 --- a/Layout/default/Building/Index.php +++ b/Layout/default/Building/Index.php @@ -262,6 +262,7 @@ +

Neuer Anschluss

"> @@ -276,7 +277,7 @@
- + diff --git a/application/Building/BuildingController.php b/application/Building/BuildingController.php index a9ec10d3b..16088c906 100644 --- a/application/Building/BuildingController.php +++ b/application/Building/BuildingController.php @@ -198,25 +198,25 @@ class BuildingController extends mfBaseController { $data['lineworker_id'] = ($r->lineworker_id) ? $r->lineworker_id : null; $data['networksection_id'] = ($r->networksection_id) ? $r->networksection_id : null; - $data['oan_id'] = $r->oan_id; - $data['street'] = $r->street; - $data['zip'] = $r->zip; - $data['city'] = $r->city; + $data['oan_id'] = trim($r->oan_id); + $data['street'] = trim($r->street); + $data['zip'] = trim($r->zip); + $data['city'] = trim($r->city); - $data['contact'] = $r->contact; - $data['phone'] = $r->phone; - $data['email'] = $r->email; - $data['units'] = $r->units; - $data['description'] = $r->description; - $data['note'] = $r->note; + $data['contact'] = trim($r->contact); + $data['phone'] = trim($r->phone); + $data['email'] = trim($r->email); + $data['units'] = trim($r->units); + $data['description'] = trim($r->description); + $data['note'] = trim($r->note); $data['edit_by'] = 1; if($this->me->is("Admin")) { - if($r->gps_lat) $data['gps_lat'] = $r->gps_lat; - if($r->gps_long) $data['gps_long'] = $r->gps_long; - if($r->code) $data['code'] = $r->code; - if($r->laea) $data['laea'] = $r->laea; + if($r->gps_lat) $data['gps_lat'] = trim($r->gps_lat); + if($r->gps_long) $data['gps_long'] = trim($r->gps_long); + if($r->code) $data['code'] = trim($r->code); + if($r->laea) $data['laea'] = trim($r->laea); } if($mode == "add") { @@ -224,13 +224,13 @@ class BuildingController extends mfBaseController { $building = BuildingModel::create($data); // check if building exists already - $checkBuilding = BuildingModel::search(['street' => $data['street'], 'city' => $data['city'], 'zip' => $data['zip']]); + $checkBuilding = BuildingModel::search(['=street' => $data['street'], '=city' => $data['city'], '=zip' => $data['zip']]); + if($checkBuilding) { $this->layout()->setFlash("Objekt ist bereits vorhanden!", "error"); $this->layout()->set("building", $building); return $this->add(); } - } else { $building->update($data); } diff --git a/application/Building/BuildingModel.php b/application/Building/BuildingModel.php index 86d739a7a..734b4937c 100644 --- a/application/Building/BuildingModel.php +++ b/application/Building/BuildingModel.php @@ -109,7 +109,8 @@ class BuildingModel { LEFT JOIN Buildingstatus ON (Buildingstatus.id = Building.status_id) WHERE $where ORDER BY network_id, pop_id, street, zip, city"; - + + 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']; @@ -215,6 +216,13 @@ class BuildingModel { } } + if(array_key_exists("=street", $filter)) { + $street = FronkDB::singleton()->escape($filter["=street"]); + if($street) { + $where .= " AND street like '$street'"; + } + } + if(array_key_exists("zip", $filter)) { $zip = FronkDB::singleton()->escape($filter["zip"]); if($zip) { @@ -222,6 +230,13 @@ class BuildingModel { } } + if(array_key_exists("=zip", $filter)) { + $zip = FronkDB::singleton()->escape($filter["=zip"]); + if($zip) { + $where .= " AND zip like '$zip'"; + } + } + if(array_key_exists("city", $filter)) { $city = FronkDB::singleton()->escape($filter["city"]); if($city) { @@ -229,6 +244,13 @@ class BuildingModel { } } + if(array_key_exists("=city", $filter)) { + $city = FronkDB::singleton()->escape($filter["=city"]); + if($city) { + $where .= " AND city like '$city'"; + } + } + //var_dump($filter, $where);exit; return $where; } diff --git a/application/Patching/PatchingController.php b/application/Patching/PatchingController.php index 63cea82eb..e92b92963 100644 --- a/application/Patching/PatchingController.php +++ b/application/Patching/PatchingController.php @@ -92,8 +92,9 @@ class PatchingController extends mfBaseController { foreach($terms as $term) { $term->order = OrderModel::getFirst(["termination_id" => $term->id]); $terminations[] = $term; - //var_dump($term); } + + $this->layout()->set("terminations", $terms); } @@ -141,12 +142,11 @@ class PatchingController extends mfBaseController { } $r = $this->request; - //var_dump($r);exit; + //var_dump($r); $term_id = $r->termination_id; //var_dump($r);exit; if(is_numeric($term_id) && $term_id > 0) { - $mode = "edit"; $termination = new Termination($term_id); if(!$termination->id) { $this->layout()->setFlash("Anschluss nicht gefunden", "error"); @@ -159,14 +159,6 @@ class PatchingController extends mfBaseController { $patch_data = []; - $patching = PatchingModel::getFirst(["termination_id" => $term_id]); - if($patching) { - $mode = "edit"; - } else { - $mode = "add"; - $patch_data["termination_id"] = $term_id; - } - $patch_data["linework_port"] = $r->linework_port; $patch_data["device_name"] = $r->device_name; @@ -179,6 +171,15 @@ class PatchingController extends mfBaseController { $patch_data["device_type"] = null; } + $patching = PatchingModel::getFirst(["termination_id" => $term_id]); + if($patching) { + $mode = "edit"; + } else { + $mode = "add"; + $patch_data["termination_id"] = $term_id; + } + //var_dump($mode, $patch_data);exit; + if($mode == "add") { $patch_data['create_by'] = 1; $patching = PatchingModel::create($patch_data); diff --git a/application/Patching/PatchingModel.php b/application/Patching/PatchingModel.php index 117ea03db..c41c071b3 100644 --- a/application/Patching/PatchingModel.php +++ b/application/Patching/PatchingModel.php @@ -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; + } + } \ No newline at end of file diff --git a/application/Termination/Termination.php b/application/Termination/Termination.php index 970d4fb74..54230c104 100644 --- a/application/Termination/Termination.php +++ b/application/Termination/Termination.php @@ -38,6 +38,7 @@ class Termination extends mfBaseModel { } $bcode = $this->getProperty("building")->code; + var_dump($bcode); if(!$bcode) { return false; } @@ -50,6 +51,8 @@ class Termination extends mfBaseModel { while($data = $this->db->fetch_object($res)) { $codes[] = $data->code; } + } else { + return $bcode.".001"; } if(count($codes)) { @@ -156,7 +159,7 @@ class Termination extends mfBaseModel { } if($name == "patching") { - $this->patching = PatchingModel::getFirst(["termination_i" => $this->id]); + $this->patching = PatchingModel::getFirst(["termination_id" => $this->id]); return $this->patching; } diff --git a/application/Termination/TerminationController.php b/application/Termination/TerminationController.php index af5d6d800..750dbf188 100644 --- a/application/Termination/TerminationController.php +++ b/application/Termination/TerminationController.php @@ -42,7 +42,6 @@ class TerminationController extends mfBaseController { $data['contact'] = $r->contact; $data['phone'] = $r->phone; $data['email'] = $r->email; - $data['lineworker_id'] = $building->lineworker_id; $data['edit_by'] = $this->me->id; @@ -58,6 +57,7 @@ class TerminationController extends mfBaseController { $this->layout()->setFlash("Fehler beim Speichern", "error"); $this->redirect("Building", "Index", [], "building=".$term->building_id); } + if(!$term->code) { $term->code = $term->getNewObjectCode();