Changes for Preorder:
- Added OAID to Hausnummer and Wohneinheit - Added format parameter to /addressdb/findAddress - Added additional fields to /addressdb/findAddress - Updated api doc yaml - Updated addressdb import scripts for Liezen
This commit is contained in:
@@ -37,6 +37,40 @@ class ADBHausnummer extends mfBaseModel {
|
||||
return $data;
|
||||
}*/
|
||||
|
||||
public function getNewOAID() {
|
||||
if(!$this->plz_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cc = "AT";
|
||||
$zip = $this->getProperty("plz")->plz;
|
||||
|
||||
for($try = 16; $try > 0; $try--) {
|
||||
$rnd[0] = random_int(0, 255);
|
||||
$rnd[1] = random_int(0, 255);
|
||||
$rnd[2] = random_int(0, 255);
|
||||
$rnd[3] = random_int(0, 255);
|
||||
|
||||
$code = "$cc-$zip-";
|
||||
foreach($rnd as $r) {
|
||||
$code .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
if(ADBHausnummerModel::search(['oaid' => $code])) {
|
||||
$this->log->warn(__FILE__."::getNewObjectCode: New Code already in use. Trying again for a maximum of $try times.");
|
||||
} else {
|
||||
// code is unique
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($try == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
|
||||
@@ -133,6 +133,13 @@ class ADBHausnummerModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("oaid", $filter)) {
|
||||
$oaid = FronkDB::singleton()->escape($filter['oaid']);
|
||||
if($oaid) {
|
||||
$where .= " AND Hausnummer.`oaid` = '$oaid'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("extref", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref']);
|
||||
if($extref) {
|
||||
|
||||
@@ -53,6 +53,49 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNewOAID() {
|
||||
if(!$this->hausnummer_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$bcode = $this->getProperty("hausnummer")->oaid;
|
||||
//var_dump($bcode);
|
||||
if(!$bcode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$codes = [];
|
||||
|
||||
// get existing codes
|
||||
$res = $this->db->select("Wohneinheit", "oaid", "oaid like '$bcode.%'");
|
||||
if($this->db->num_rows($res)) {
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$codes[] = $data->oaid;
|
||||
}
|
||||
} else {
|
||||
return $bcode.".001";
|
||||
}
|
||||
|
||||
if(count($codes)) {
|
||||
sort($codes);
|
||||
}
|
||||
|
||||
$last_code = end($codes);
|
||||
|
||||
$m = [];
|
||||
if(preg_match('/\.(\d+)$/', $last_code, $m)) {
|
||||
if($m[1]) {
|
||||
$last_num = $m[1];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_num = ++$last_num;
|
||||
$code = $bcode.".".sprintf("%03d", $new_num);
|
||||
return $code;
|
||||
}
|
||||
|
||||
public function afterLoad() {
|
||||
//$this->hausnummer = new ADBHausnummer($this->hausnummer_id);
|
||||
//$this->loadStatus();
|
||||
|
||||
@@ -105,7 +105,7 @@ class ADBWohneinheitModel {
|
||||
LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id)
|
||||
WHERE $where
|
||||
GROUP BY Wohneinheit.id
|
||||
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer";
|
||||
ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer,num";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
|
||||
@@ -298,6 +298,10 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
$search_city = $this->db()->escape(trim($get['city']));
|
||||
$search_housenumber = $this->db()->escape(trim($get['housenumber']));
|
||||
|
||||
$format = "flat";
|
||||
if($get['format'] == "tree") {
|
||||
$format = "tree";
|
||||
}
|
||||
|
||||
if(!$search_street) {
|
||||
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
|
||||
@@ -332,51 +336,121 @@ class AddressdbApicontroller extends mfBaseApicontroller {
|
||||
}
|
||||
//echo $where;
|
||||
//var_dump($this->filter_salescluster_ids);exit;
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(tuer), tuer";
|
||||
$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, gemeinde, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(num), num, LENGTH(tuer), tuer";
|
||||
$this->log->debug($sql);
|
||||
$res = $this->db()->query($sql);
|
||||
|
||||
if($this->db()->num_rows($res)) {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
if($format == "flat") {
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
// get unit count
|
||||
$unit_count = ADBWohneinheitModel::count(['hausnummer_id' => $data->hausnummer_id]);
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$addresses[] = [
|
||||
'oaid' => $data->wohneinheit_oaid,
|
||||
'building_oaid' => $data->hausnummer_oaid,
|
||||
'zip' => $data->plz,
|
||||
'city' => ($this->district_is_city) ? $data->ortschaft : $data->gemeinde,
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'lot_number' => $data->grund_nr,
|
||||
'building_unit_count' => (int)$unit_count,
|
||||
'num' => (int)$data->num,
|
||||
'block' => $data->block,
|
||||
'stock' => $data->stock,
|
||||
'stiege' => $data->stiege,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
'gps_lat' => (float)$data->gps_lat,
|
||||
'gps_long' => (float)$data->gps_long,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$tmp_addresses = [];
|
||||
while($data = $this->db()->fetch_object($res)) {
|
||||
$address_key = $data->hausnummer_id."-".$data->zusatz;
|
||||
if(!array_key_exists($address_key, $tmp_addresses)) {
|
||||
|
||||
// get allowed preorderTypes
|
||||
$ptypes = [];
|
||||
if($data->freigabe) {
|
||||
$freigaben = json_decode($data->freigabe);
|
||||
if(is_array($freigaben) && count($freigaben)) {
|
||||
foreach($freigaben as $freigabe) {
|
||||
if(in_array($freigabe, $this->allowed_preordertypes)) {
|
||||
$ptypes[] = $freigabe;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$housenumber = $data->hausnummer;
|
||||
if($this->hausnummer_add_zusatz) {
|
||||
if($data->zusatz) {
|
||||
$housenumber .= " (".$data->zusatz.")";
|
||||
}
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key] = [
|
||||
'oaid' => $data->hausnummer_oaid,
|
||||
'zip' => $data->plz,
|
||||
'city' => ($this->district_is_city) ? $data->ortschaft : $data->gemeinde,
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'lot_number' => $data->grund_nr,
|
||||
'building_unit_count' => 0,
|
||||
'gps_lat' => (float)$data->gps_lat,
|
||||
'gps_long' => (float)$data->gps_long,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes,
|
||||
'units' => []
|
||||
];
|
||||
}
|
||||
|
||||
$tmp_addresses[$address_key]['units'][] = [
|
||||
'oaid' => $data->wohneinheit_oaid,
|
||||
'num' => (int)$data->num,
|
||||
'block' => $data->block,
|
||||
'stiege' => $data->stiege,
|
||||
'stock' => $data->stock,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
];
|
||||
$tmp_addresses[$address_key]['building_unit_count']++;
|
||||
|
||||
}
|
||||
|
||||
foreach($tmp_addresses as $ta) {
|
||||
$addresses[] = $ta;
|
||||
}
|
||||
|
||||
$addresses[] = [
|
||||
'zip' => $data->plz,
|
||||
'city' => ($this->district_is_city) ? $data->ortschaft : $data->gemeinde,
|
||||
'district' => $data->ortschaft,
|
||||
'street' => $data->strasse,
|
||||
'housenumber' => $housenumber,
|
||||
'block' => $data->block,
|
||||
'stock' => $data->stock,
|
||||
'stiege' => $data->stiege,
|
||||
'tuer' => $data->tuer,
|
||||
'zusatz' => $data->zusatz,
|
||||
'gps_lat' => $data->gps_lat,
|
||||
'gps_long' => $data->gps_long,
|
||||
'rollout_year' => ($data->rollout) ? (int)$data->rollout : null,
|
||||
'rollout_info' => $data->rollout_info,
|
||||
'preorderTypes' => $ptypes
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
private $district_is_city = false;
|
||||
private $hausnummer_add_zusatz = false;
|
||||
private $exist_is_error = false;
|
||||
private $require_connectiontype = false;
|
||||
|
||||
protected function init() {
|
||||
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
@@ -55,6 +56,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
if($campaign->exist_is_error == 1) {
|
||||
$this->exist_is_error = true;
|
||||
}
|
||||
if($campaign->require_connectiontype == 1) {
|
||||
$this->require_connectiontype = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +111,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(["message" => "Invalid preorderType"]);
|
||||
}
|
||||
|
||||
$connection_type = false;
|
||||
$connection_type = null;
|
||||
switch($this->post['connectionType']) {
|
||||
case "single-dwelling":
|
||||
$connection_type = "single-dwelling";
|
||||
@@ -125,7 +129,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
$connection_type = "business";
|
||||
break;
|
||||
default:
|
||||
return mfResponse::BadRequest(["message" => "Invalid connectionType"]);
|
||||
if($this->require_connectiontype) {
|
||||
return mfResponse::BadRequest(["message" => "Invalid connectionType"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +154,11 @@ class PreorderApicontroller extends mfBaseApicontroller {
|
||||
return mfResponse::BadRequest(['message' => "Mandatory address fields missing"]);
|
||||
}
|
||||
|
||||
$shipping_address = "customer";
|
||||
if(array_key_exists("is_shipping", $this->post['address']) && $this->post['address']['is_shipping']) {
|
||||
$shipping_address = "address";
|
||||
}
|
||||
|
||||
$address_search = [];
|
||||
$address_search_fields = [
|
||||
'street' => 'strasse',
|
||||
|
||||
@@ -18,7 +18,7 @@ class DashboardController extends mfBaseController {
|
||||
|
||||
|
||||
protected function testAction() {
|
||||
var_dump(ADBHausnummerModel::search(["hausnummer" => 1]));
|
||||
var_dump(ADBWohneinheitModel::count(["hausnummer_id" => 1772369]));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user