From 9f9ba3f8062472f7159fefb13fb1e21c229862e4 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Fri, 31 Mar 2023 15:06:52 +0200 Subject: [PATCH] SubmitPreorder: city now optional; cutting cityname from street --- application/Api/v1/PreorderApicontroller.php | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/application/Api/v1/PreorderApicontroller.php b/application/Api/v1/PreorderApicontroller.php index bf2e49999..1b4a7036d 100644 --- a/application/Api/v1/PreorderApicontroller.php +++ b/application/Api/v1/PreorderApicontroller.php @@ -341,6 +341,7 @@ class PreorderApicontroller extends mfBaseApicontroller { */ $where = "1=1 "; foreach($address_search as $field => $value) { + if($field == "ortschaft" || $field == "gemeinde") continue; $where .= " AND `$field` = '$value'"; } @@ -353,7 +354,35 @@ class PreorderApicontroller extends mfBaseApicontroller { $this->log->debug($sql); $res = $this->db()->query($sql); if(!$this->db()->num_rows($res)) { - return mfResponse::NotFound(['message' => "Adresse nicht gefunden"]); + // try with Ortschaft in front of strasse (liezen gwr issue) + $where = "1=1 "; + foreach($address_search as $field => $value) { + if($field == "ortschaft" || $field == "gemeinde") continue; + + if($field == "strasse") { + $prefix = ($address_search['ortschaft']) ? $address_search['ortschaft'] : $address_search['gemeinde']; + if(strpos($value, "$prefix ") === 0) { + $str = substr($value, strlen($prefix)+1); + } else { + $str = $value; + } + $where .= " AND `strasse` = '$str'"; + } else { + $where .= " AND `$field` = '$value'"; + } + } + + // filter salesclusters + if(count($this->filter_salescluster_ids)) { + $where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")"; + } + + $sql = "SELECT * FROM view_hausnummer WHERE $where"; + $this->log->debug($sql); + $res = $this->db()->query($sql); + if(!$this->db()->num_rows($res)) { + return mfResponse::NotFound(['message' => "Adresse nicht gefunden"]); + } } $address = $this->db()->fetch_object($res);