diff --git a/Layout/default/ConstructionConsent/Form.php b/Layout/default/ConstructionConsent/Form.php index df597d02e..5a888459f 100644 --- a/Layout/default/ConstructionConsent/Form.php +++ b/Layout/default/ConstructionConsent/Form.php @@ -90,13 +90,6 @@ -
- -
- " /> -
-
-
@@ -118,6 +111,13 @@
+
+ +
+ " /> +
+
+
@@ -395,13 +395,24 @@ $("#kg").change(updateGstnr); $("#gst").change(updateGstnr); - function updateGstnr() { + async function updateGstnr() { let kg = $("#kg").val(); let gst = $("#gst").val(); if(!kg || !gst) return; $("#gstnr").val(kg + gst); + + // update EZ + + var response = await fetch(' "getEz"])?>&kg=' + kg + '&gst=' + gst); + if (!response.ok) { + return false; + } + var resp_json = await response.json(); + if(resp_json.status == "OK" && resp_json.result.ez) { + $("#ez").val(resp_json.result.ez); + } } $(window).bind("paste", (e) => { diff --git a/application/ADBGwrgst/ADBGwrgst.php b/application/ADBGwrgst/ADBGwrgst.php new file mode 100644 index 000000000..5b57ff3d3 --- /dev/null +++ b/application/ADBGwrgst/ADBGwrgst.php @@ -0,0 +1,266 @@ +db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + $this->table = "Gwrgst"; + } + + public function getProperty($name) { + if($this->$name == null) { + + if(!$this->id) { + return null; + } + + + $classname = ucfirst($name); + $idfield = $name."_id"; + $this->$name = new $classname($this->$idfield); + + if($this->$name->id) { + return $this->$name; + } else { + return null; + } + } + + return $this->$name; + } + + /* + * Static Model function + */ + + /******************************** + * Begin static Model functions + */ + + public static function create(Array $data) { + $model = new ADBGwrgst(); + + $table_fields = [ + "kgnr", "gstnr", "g", "ba", "nu", "tind", "ind", "flaeche", "emz", "gfn", "gft", "kgez", "ez", + "create","edit" + ]; + + foreach($data as $field => $value) { + if(in_array($field, $table_fields)) { + $model->$field = $value; + } + } + + $me = new User(); + $me->loadMe(); + + return $model; + } + + public static function getAll() { + $items = []; + + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + + $res = $db->select("Gwrgst", "*", "1 = 1 ORDER BY id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new Gwrgst($data); + } + } + return $items; + + } + + public static function getFirst($filter) { + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT Gwrgst.* FROM Gwrgst + WHERE $where + ORDER BY id + LIMIT 1"; + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new ADBGwrgst($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function count($filter) { + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT COUNT(*) as cnt FROM Gwrgst + WHERE $where + ORDER BY id + "; + + //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 search($filter, $limit = false, $order = false) { + //var_dump($filter);exit; + $items = []; + + if(!$order) { + $order = "id ASC"; + } + + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT Gwrgst.* FROM Gwrgst + WHERE $where + GROUP BY Gwrgst.id + ORDER BY $order"; + + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['count']; + } + } + + mfLoghandler::singleton()->debug($sql); + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[$data->id] = new ADBGwrgst($data); + } + } + + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); + + + if(array_key_exists("constructionconsent_id", $filter)) { + $constructionconsent_id = $filter["constructionconsent_id"]; + if(is_numeric($constructionconsent_id)) { + $where .= " AND constructionconsent_id='$constructionconsent_id'"; + } + } + + if(array_key_exists("kgnr", $filter)) { + $kgnr = $db->escape($filter["kgnr"]); + if($kgnr) { + $where .= " AND `kgnr`='$kgnr'"; + } + } + + if(array_key_exists("gstnr", $filter)) { + $gstnr = $db->escape($filter["gstnr"]); + if($gstnr) { + $where .= " AND `gstnr`='$gstnr'"; + } + } + + if(array_key_exists("g", $filter)) { + $g = $db->escape($filter["g"]); + if($g) { + $where .= " AND `g`='$g'"; + } + } + + if(array_key_exists("ba", $filter)) { + $ba = $db->escape($filter["ba"]); + if($ba) { + $where .= " AND `ba`='$ba'"; + } + } + + if(array_key_exists("nu", $filter)) { + $nu = $db->escape($filter["nu"]); + if($nu) { + $where .= " AND `nu`='$nu'"; + } + } + + if(array_key_exists("tind", $filter)) { + $tind = $db->escape($filter["tind"]); + if($tind) { + $where .= " AND `tind`='$tind'"; + } + } + + if(array_key_exists("ind", $filter)) { + $ind = $db->escape($filter["ind"]); + if($ind) { + $where .= " AND `ind`='$ind'"; + } + } + + if(array_key_exists("flaeche", $filter)) { + $flaeche = $db->escape($filter["flaeche"]); + if($flaeche) { + $where .= " AND `flaeche`='$flaeche'"; + } + } + + if(array_key_exists("emz", $filter)) { + $emz = $db->escape($filter["emz"]); + if($emz) { + $where .= " AND `emz`='$emz'"; + } + } + + if(array_key_exists("gfn", $filter)) { + $gfn = $db->escape($filter["gfn"]); + if($gfn) { + $where .= " AND `gfn`='$gfn'"; + } + } + + if(array_key_exists("gft", $filter)) { + $gft = $db->escape($filter["gft"]); + if($gft) { + $where .= " AND `gft`='$gft'"; + } + } + + if(array_key_exists("kgez", $filter)) { + $kgez = $db->escape($filter["kgez"]); + if($kgez) { + $where .= " AND `kgez`='$kgez'"; + } + } + + if(array_key_exists("ez", $filter)) { + $ez = $db->escape($filter["ez"]); + if($ez) { + $where .= " AND `ez`='$ez'"; + } + } + + + if(array_key_exists("add-where", $filter)) { + $where .= " ".$filter['add-where']; + } + + //var_dump($filter, $where);exit; + return $where; + } +} diff --git a/application/ConstructionConsent/ConstructionConsentController.php b/application/ConstructionConsent/ConstructionConsentController.php index 7621cea5b..ad68e8145 100644 --- a/application/ConstructionConsent/ConstructionConsentController.php +++ b/application/ConstructionConsent/ConstructionConsentController.php @@ -492,6 +492,9 @@ class ConstructionConsentController extends mfBaseController { case "deleteRimoPlan": $return = $this->deleteRimoPlanApi(); break; + case "getEz": + $return = $this->getEzApi(); + break; default: $this->log->warn(__METHOD__ . ": Called API function '$do' does not exist"); $return = false; @@ -506,6 +509,22 @@ class ConstructionConsentController extends mfBaseController { $this->returnJson($data); } + private function getEzApi() { + $kg = trim($this->request->kg); + $gst = trim($this->request->gst); + + if(!$kg || !$gst) return false; + + $ez = ADBGwrgst::getFirst(["kgnr" => $kg, "gstnr" => $gst]); + //var_dump($ez);exit; + if(!$ez) { + return ["ez" => ""]; + } + + return ["ez" => $ez->ez]; + } + + private function findStreetApi() { $addresses = []; $search = trim($this->request->q); diff --git a/db/migrations/20250226154252_addressdb_create_gwrgst.php b/db/migrations/20250226154252_addressdb_create_gwrgst.php new file mode 100644 index 000000000..581f24cf1 --- /dev/null +++ b/db/migrations/20250226154252_addressdb_create_gwrgst.php @@ -0,0 +1,47 @@ +getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + $table = $this->table('Gwrgst'); + $table->addColumn("kgnr", "integer", ["null" => false]) + ->addColumn("gstnr", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("g", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("ba", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("nu", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("tind", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("ind", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("flaeche", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("emz", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("gfn", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("gft", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("kgez", "string", ["limit" => 255, "null" => true, "default" => null]) + ->addColumn("ez", "string", ["limit" => 255, "null" => true, "default" => null]) + + ->addColumn("create", "integer", ["null" => false]) + ->addColumn("edit", "integer", ["null" => false]) + + ->create(); + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + $this->table("Gwrgst")->drop()->save(); + } + } +}