Added hausnummer_add_zusatz flag to campaigns
This commit is contained in:
@@ -11,6 +11,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
|
||||
private $allowed_preordertypes = [];
|
||||
private $district_is_city = false;
|
||||
private $hausnummer_add_zusatz = false;
|
||||
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
@@ -46,6 +47,11 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
if($campaign->district_is_city == 1) {
|
||||
$this->district_is_city = true;
|
||||
}
|
||||
|
||||
if($campaign->hausnummer_add_zusatz == 1) {
|
||||
$this->hausnummer_add_zusatz = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -131,12 +137,24 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
}
|
||||
|
||||
$zusatz = false;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
$m = [];
|
||||
if(preg_match('/^(.*) \((.+)\)$/', trim($address_search['hausnummer']), $m)) {
|
||||
$address_search['hausnummer'] = $this->db()->escape($m[1]);
|
||||
$zusatz = $m[2];
|
||||
}
|
||||
}
|
||||
|
||||
$unit_search = [];
|
||||
foreach(['block','stiege','stock','tuer'] as $key) {
|
||||
if(property_exists($this->post['address'], $key) && trim($this->post['address']->$key)) {
|
||||
$unit_search[$key] = trim($this->post['address']->$key);
|
||||
}
|
||||
}
|
||||
if($zusatz) {
|
||||
$unit_search['zusatz'] = $zusatz;
|
||||
}
|
||||
|
||||
/*
|
||||
* check customer
|
||||
@@ -173,13 +191,15 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$address = $this->db()->fetch_object($res);
|
||||
|
||||
//var_dump($address);exit;
|
||||
|
||||
/*
|
||||
* search wohneinheit
|
||||
*/
|
||||
$where = "1=1 ";
|
||||
$unit = false;
|
||||
if(count($unit_search)) {
|
||||
//var_dump($unit_search);exit;
|
||||
foreach($unit_search as $field => $value) {
|
||||
if($field == "stock" || $field == "stiege") continue; // only check for block and tuer
|
||||
$where .= " AND `$field` = '$value'";
|
||||
@@ -191,6 +211,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where AND hausnummer_id=".$address->hausnummer_id;
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
$unit = $this->db()->fetch_object($res);
|
||||
@@ -200,14 +221,19 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
} else {
|
||||
// if all unit values are empty try to find the unit with all empty values
|
||||
// failure is not an error, but must be checked by a human at some point
|
||||
|
||||
$where = "hausnummer_id=".$address->hausnummer_id." AND (block = '' OR block IS NULL) AND (stiege = '' OR stiege IS NULL) AND (stock = '' OR stock IS NULL) AND (tuer = '' OR tuer IS NULL)";
|
||||
if($zusatz) {
|
||||
$where .= " AND zusatz='$zusatz'";
|
||||
} else {
|
||||
$where .= " AND (zusatz = '' OR zusatz IS NULL)";
|
||||
}
|
||||
// filter salesclusters
|
||||
if(count($this->filter_salescluster_ids)) {
|
||||
$where .= " AND netzgebiet_id IN (".implode(',', $this->filter_salescluster_ids).")";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
if($this->db()->num_rows($res)) {
|
||||
$unit = $this->db()->fetch_object($res);
|
||||
|
||||
Reference in New Issue
Block a user