SubmitPreorder: city now optional; cutting cityname from street

This commit is contained in:
Frank Schubert
2023-03-31 15:06:52 +02:00
parent 6cf4e1b64a
commit 9f9ba3f806

View File

@@ -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);