diff --git a/Layout/default/Admin/Index.php b/Layout/default/Admin/Index.php
index e5a6cca0b..ec2ada089 100644
--- a/Layout/default/Admin/Index.php
+++ b/Layout/default/Admin/Index.php
@@ -37,7 +37,7 @@
-
@@ -51,11 +51,15 @@
+
\ No newline at end of file
diff --git a/Layout/default/Admin/IvtAdminImport.php b/Layout/default/Admin/IvtContractImport.php
similarity index 100%
rename from Layout/default/Admin/IvtAdminImport.php
rename to Layout/default/Admin/IvtContractImport.php
diff --git a/Layout/default/Admin/IvtCreditImport.php b/Layout/default/Admin/IvtCreditImport.php
new file mode 100644
index 000000000..1e69bbcc2
--- /dev/null
+++ b/Layout/default/Admin/IvtCreditImport.php
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Kunde
+ IVT Produkt
+ Produkt
+ Preis Setup
+ Preis
+ Rech. Interval
+ Aktion
+
+
+
+
+
+ =$d["customer"]->getCompanyOrName()?>
+ =$d["ivtproduct"]->name?>
+ =$d["product"]->name?>
+ =$d["contract"]->price_setup?>
+ =$d["contract"]->price?>
+
+ =$d["contract"]->billing_period?> (=($d["contract"]->billing_period == 1) ? "Monatlich" : ""?>=($d["contract"]->billing_period == 12) ? "Jährlich" : ""?>=($d["contract"]->billing_period == 24) ? "Zweijährlich" : ""?>=($d["contract"]->billing_period == 36) ? "Dreijährlich" : ""?>)
+
+ =$d["action"]?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Layout/default/User/Form.php b/Layout/default/User/Form.php
index 4853b9091..0887e373b 100644
--- a/Layout/default/User/Form.php
+++ b/Layout/default/User/Form.php
@@ -68,6 +68,10 @@
is("employee")) ? "selected='selected'" : ""?>>Yes
+ " id="employee-number-container">
+ X inon Mitarbeiternummer:
+ value()?>" />
+
Techniker:
@@ -299,6 +303,13 @@
}
});
+ $("#employee").change(function() {
+ if($("#employee").val() == "true") {
+ $("#employee-number-container").show(400);
+ } else {
+ $("#employee-number-container").hide(400);
+ }
+ });
});
diff --git a/application/ADBHausnummer/ADBHausnummerModel.php b/application/ADBHausnummer/ADBHausnummerModel.php
index c6afd930c..819a3cfaf 100644
--- a/application/ADBHausnummer/ADBHausnummerModel.php
+++ b/application/ADBHausnummer/ADBHausnummerModel.php
@@ -209,6 +209,12 @@ class ADBHausnummerModel {
}
}
+ if(array_key_exists("rimo_id", $filter)) {
+ $rimo_id = FronkDB::singleton()->escape($filter['rimo_id']);
+ if($rimo_id) {
+ $where .= " AND Hausnummer.rimo_id = '$rimo_id'";
+ }
+ }
if(array_key_exists("plz", $filter)) {
$plz = FronkDB::singleton()->escape($filter['plz']);
diff --git a/application/ADBStrasse/ADBStrasseModel.php b/application/ADBStrasse/ADBStrasseModel.php
index 4a51a0fde..ff32fec7d 100644
--- a/application/ADBStrasse/ADBStrasseModel.php
+++ b/application/ADBStrasse/ADBStrasseModel.php
@@ -6,8 +6,6 @@ class ADBStrasseModel {
public $kennziffer;
public $name;
- public $create_by = null;
- public $edit_by = null;
public $create = null;
public $edit = null;
diff --git a/application/Admin/AdminController.php b/application/Admin/AdminController.php
index 310515260..7d9acd6bb 100644
--- a/application/Admin/AdminController.php
+++ b/application/Admin/AdminController.php
@@ -150,20 +150,20 @@ class AdminController extends mfBaseController {
$this->layout()->set("products", $products);
}
- protected function ivtAdminImportAction() {
+ protected function ivtContractImportAction() {
exit;
$doit = false;
if($this->request->doit == 1) {
$doit = true;
}
- require_once(realpath(dirname(__FILE__)."/functions")."/IvtAdminImport.php");
+ require_once(realpath(dirname(__FILE__)."/functions")."/IvtContractImport.php");
- if(class_exists("Admin_IvtAdminImport")) {
- $import = new Admin_IvtAdminImport($this->request);
+ if(class_exists("Admin_IvtContractImport")) {
+ $import = new Admin_IvtContractImport($this->request);
$data = $import->run($doit);
- $this->layout()->setTemplate("Admin/IvtAdminImport");
+ $this->layout()->setTemplate("Admin/IvtContractImport");
$this->layout()->set("data", $data);
if($doit) {
@@ -173,4 +173,26 @@ class AdminController extends mfBaseController {
}
}
+ protected function ivtCreditImportAction() {
+ $doit = false;
+ if($this->request->doit == 1) {
+ $doit = true;
+ }
+
+ require_once(realpath(dirname(__FILE__)."/functions")."/IvtCreditImport.php");
+
+ if(class_exists("Admin_IvtCreditImport")) {
+ $import = new Admin_IvtCreditImport($this->request);
+ $data = $import->run($doit);
+
+ $this->layout()->setTemplate("Admin/IvtCreditImport");
+ $this->layout()->set("data", $data);
+
+ if($doit) {
+ $this->layout()->setFlash((count($data['contracts']) - $data['ignore'])." Gutschriften aus IVT importiert!", "success");
+ }
+
+ }
+ }
+
}
\ No newline at end of file
diff --git a/application/Admin/functions/IvtAdminImport.php b/application/Admin/functions/IvtContractImport.php
similarity index 99%
rename from application/Admin/functions/IvtAdminImport.php
rename to application/Admin/functions/IvtContractImport.php
index 83cc34e81..5cf184fec 100644
--- a/application/Admin/functions/IvtAdminImport.php
+++ b/application/Admin/functions/IvtContractImport.php
@@ -1,6 +1,6 @@
request = $request;
+ }
+
+ public function run($doit = false) {
+ $i = 0;
+ foreach(IvtCustomerCreditingModel::getAll() as $cust_cred) {
+ if($i<200) {$i++; continue;}
+ var_dump($cust_cred);
+ var_dump($cust_cred->netowner);
+ var_dump($cust_cred->customer);
+ var_dump($cust_cred->crediting_product);
+ exit;
+
+ if(!$cust_cred->customer) continue;
+
+
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/application/IvtCreditingProduct/IvtCreditingProduct.php b/application/IvtCreditingProduct/IvtCreditingProduct.php
new file mode 100644
index 000000000..12f36d556
--- /dev/null
+++ b/application/IvtCreditingProduct/IvtCreditingProduct.php
@@ -0,0 +1,74 @@
+log = mfLoghandler::singleton();
+ $this->data = new stdClass();
+ $this->table = "crediting_products";
+
+ $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ if(is_numeric($_)) {
+ $this->fetch($_);
+ } elseif(is_object($_)) {
+ $this->load($_);
+ }
+ }
+
+ public function save() {
+ return true;
+ }
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ if($name == "product") {
+ $ivtproduct = new IvtProduct($this->pid);
+ if($ivtproduct->id) {
+ $this->ivtproduct = $ivtproduct;
+ }
+ return $this->ivtproduct;
+ }
+
+ if($name == "customer") {
+ $ivtcustomer = new IvtCustomer($this->cid);
+ if($ivtcustomer->id) {
+ $this->ivtcustomer = $ivtcustomer;
+ }
+ return $this->ivtcustomer;
+ }
+
+ $classname = ucfirst($name);
+ $idfield = $name."_id";
+ $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
+ if(!$this->$name) {
+ $this->$name = new $classname($this->$idfield);
+ }
+
+ if($this->$name->id) {
+ mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
+ return $this->$name;
+ } else {
+ return null;
+ }
+
+ }
+
+ return $this->$name;
+ }
+
+
+ public function __debugInfo() {
+ $vars = get_object_vars($this);
+ if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
+ if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
+ return $vars;
+ }
+
+}
\ No newline at end of file
diff --git a/application/IvtCreditingProduct/IvtCreditingProductModel.php b/application/IvtCreditingProduct/IvtCreditingProductModel.php
new file mode 100644
index 000000000..f95e09dc1
--- /dev/null
+++ b/application/IvtCreditingProduct/IvtCreditingProductModel.php
@@ -0,0 +1,105 @@
+select("crediting_products", "*");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCreditingProduct($data);
+ }
+ }
+ return $items;
+ }
+
+ public static function getFirst($filter = []) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("crediting_products", "*", "$where LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCreditingProduct($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) cnt FROM crediting_products WHERE $where";
+
+ $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) {
+ $items = [];
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM crediting_products WHERE $where";
+
+ mfLoghandler::singleton()->debug($sql);
+ if(is_array($limit) && count($limit)) {
+ if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
+ $sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
+ } elseif(is_numeric($count)) {
+ $sql .= " LIMIT ".$limit['count'];
+ }
+ }
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCreditingProduct($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ /*
+ if(array_key_exists("cid", $filter)) {
+ $cid = $filter['cid'];
+ if(is_numeric($cid)) {
+ $where .= " AND cid=$cid";
+ }
+ }
+
+ if(array_key_exists("pid", $filter)) {
+ $pid = $filter['pid'];
+ if(is_numeric($pid)) {
+ $where .= " AND pid=$pid";
+ }
+ }
+
+ if(array_key_exists("sid", $filter)) {
+ $sid = $filter['sid'];
+ if(is_numeric($sid)) {
+ $where .= " AND sid=$sid";
+ }
+ }
+ */
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/IvtCustomerCrediting/IvtCustomerCrediting.php b/application/IvtCustomerCrediting/IvtCustomerCrediting.php
new file mode 100644
index 000000000..b7e3560a2
--- /dev/null
+++ b/application/IvtCustomerCrediting/IvtCustomerCrediting.php
@@ -0,0 +1,94 @@
+log = mfLoghandler::singleton();
+ $this->data = new stdClass();
+ $this->table = "customer_crediting";
+
+ $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ if(is_numeric($_)) {
+ $this->fetch($_);
+ } elseif(is_object($_)) {
+ $this->load($_);
+ }
+ }
+
+ public function save() {
+ return true;
+ }
+
+ private function getCustomerId() {
+ $customer_id = false;
+
+ $m = [];
+ if(preg_match('/(\d+)\s*$/', $this->comment, $m)) {
+ $customer_id = $m[1];
+ }
+ if(!$customer_id) {
+ $this->log->warn(__METHOD__.": Cannot extract customer id from comment");
+ }
+ return $customer_id;
+ }
+
+ public function getProperty($name) {
+ if($this->$name == null) {
+
+ if($name == "crediting_product") {
+ $cred_prod = new IvtCreditingProduct($this->cred_id);
+ if($cred_prod->id) {
+ $this->crediting_product = $cred_prod;
+ }
+ return $this->crediting_product;
+ }
+
+ if($name == "netowner") {
+ $netowner = new IvtCustomer($this->cust_id);
+ if($netowner->id) {
+ $this->netowner = $netowner;
+ }
+ return $this->netowner;
+ }
+
+ if($name == "customer") {
+ $customer_id = $this->getCustomerId();
+ $customer = new IvtCustomer($customer_id);
+ if($customer->id) {
+ $this->customer = $customer;
+ }
+ return $this->customer;
+ }
+
+ $classname = ucfirst($name);
+ $idfield = $name."_id";
+ $this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
+ if(!$this->$name) {
+ $this->$name = new $classname($this->$idfield);
+ }
+
+ if($this->$name->id) {
+ mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
+ return $this->$name;
+ } else {
+ return null;
+ }
+
+ }
+
+ return $this->$name;
+ }
+
+
+ public function __debugInfo() {
+ $vars = get_object_vars($this);
+ if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)";
+ if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)';
+ return $vars;
+ }
+}
\ No newline at end of file
diff --git a/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php
new file mode 100644
index 000000000..3189194c5
--- /dev/null
+++ b/application/IvtCustomerCrediting/IvtCustomerCreditingModel.php
@@ -0,0 +1,107 @@
+select("customer_crediting", "*", "1=1 ORDER BY id");
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCustomerCrediting($data);
+ }
+ }
+ return $items;
+ }
+
+ public static function getFirst($filter = []) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $res = $db->select("customer_crediting", "*", "$where ORDER BY id LIMIT 1");
+ if($db->num_rows($res)) {
+ $data = $db->fetch_object($res);
+ $item = new IvtCustomerCrediting($data);
+ if($item->id) {
+ return $item;
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static function count($filter) {
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT COUNT(*) cnt FROM customer_crediting WHERE $where ORDER by id";
+
+ $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) {
+ $items = [];
+ $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME);
+
+ $where = self::getSqlFilter($filter);
+ $sql = "SELECT * FROM customer_crediting WHERE $where ORDER by cid,pid,sid,id";
+
+ mfLoghandler::singleton()->debug($sql);
+ if(is_array($limit) && count($limit)) {
+ if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
+ $sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
+ } elseif(is_numeric($count)) {
+ $sql .= " LIMIT ".$limit['count'];
+ }
+ }
+
+ $res = $db->query($sql);
+ if($db->num_rows($res)) {
+ while($data = $db->fetch_object($res)) {
+ $items[] = new IvtCustomerCrediting($data);
+ }
+ }
+ return $items;
+ }
+
+ private static function getSqlFilter($filter) {
+ $where = "1=1 ";
+
+ /*
+ if(array_key_exists("status_id", $filter)) {
+ $status_id = $filter['status_id'];
+ if(is_numeric($status_id)) {
+ $where .= " AND IvtCustomerCrediting.status_id=$status_id";
+ }
+ }
+
+
+ if(array_key_exists("street", $filter)) {
+ $street = FronkDB::singleton()->escape($filter["street"]);
+ if($street) {
+ $where .= " AND street like '%$street%'";
+ }
+ }
+ */
+
+ if(array_key_exists("cust_id", $filter)) {
+ $cust_id = $filter['cust_id'];
+ if(is_numeric($cust_id)) {
+ $where .= " AND cust_id=$cust_id";
+ }
+ }
+
+ //var_dump($filter, $where);exit;
+ return $where;
+ }
+
+}
diff --git a/application/User/UserController.php b/application/User/UserController.php
index eb6a396d6..e8a51163b 100644
--- a/application/User/UserController.php
+++ b/application/User/UserController.php
@@ -250,6 +250,15 @@ class UserController extends mfBaseController
}
+ // employee number
+ $enum = new WorkerFlag($user->id, "employee_number");
+ if($r->employee_number && $user->permissions->employee == "true") {
+ $enum->value($r->employee_number);
+ $enum->save();
+ } else {
+ $enum->delete();
+ }
+
}
$this->layout()->setFlash("Benutzer gespeichert.", "success");
diff --git a/db/migrations/20240108200100_hausnummer_add_index_rimoid.php b/db/migrations/20240108200100_hausnummer_add_index_rimoid.php
new file mode 100644
index 000000000..066e86b55
--- /dev/null
+++ b/db/migrations/20240108200100_hausnummer_add_index_rimoid.php
@@ -0,0 +1,31 @@
+getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+ $table = $this->table("Hausnummer");
+ $table->addIndex("rimo_id", ["limit" => 18]);
+ $table->update();
+ }
+ }
+
+ public function down(): void
+ {
+ if($this->getEnvironment() == "thetool") {
+
+ }
+
+ if($this->getEnvironment() == "addressdb") {
+
+ }
+ }
+}
diff --git a/scripts/adb-rimo-import/ADBAddressHelper/Network/Network-60670-1-prem-sued.php b/scripts/adb-rimo-import/ADBAddressHelper/Network/Network-60670-1-prem-sued.php
new file mode 100644
index 000000000..684904748
--- /dev/null
+++ b/scripts/adb-rimo-import/ADBAddressHelper/Network/Network-60670-1-prem-sued.php
@@ -0,0 +1,32 @@
+$type = $dependencies[$type];
+ }
+ }
+
+ // load network helper
+ if($this->netzgebiet && $this->netzgebiet->extref) {
+ // get netzgebiet extref and make classname
+ $network_extref = $this->netzgebiet->extref;
+ $network_id = preg_replace('/[^a-zA-Z0-9]/', '_', $network_extref);
+ $network_helper_name = "ADBRimoImport\\ADBAddressHelper\\Network\\Network_$network_id";
+
+ // find network helper class
+ $network_helper_dir = __DIR__."/Network";
+ $network_helper_filename = "Network-$network_extref";
+
+ $dir = opendir($network_helper_dir);
+ while($filename = readdir($dir)) {
+ if(preg_match('/^'.$network_helper_filename.'-/', $filename)) {
+ require_once($network_helper_dir."/$filename");
+ }
+ }
+
+ $network_helper = new $network_helper_name();
+ $this->NetworkHelper = $network_helper;
+ } else {
+ die("Netzgebiet hat keine extref (".$this->netzgebiet->id.": ".$this->netzgebiet->name.")");
+ }
+
+ }
+
+
+ public function splitStreetHausnummer($strasse_hausnummer) {
+ $strasse_name = "";
+ $hausnummer_name = "";
+ $addresszusatz = "";
+
+ $m = [];
+ if(preg_match('/^(\D+)\s+(\d+[a-z0-9\/._-]*)(?:\s+((?:gesch(?:ae|ä)ft|werkstatt|betrieb und wohnungen|stg|paketlogistik|cafe|pavillon|pfarrheim|[^ ]*haus|[^ ]*geb(?:ae|ä)ude|[^ ]*halle|[^ ]*schule|Öhlmühle)(?:\s+[a-z0-9]+)?))?/i', $strasse_hausnummer, $m)) {
+ $strasse_name = trim($m[1]);
+ $hausnummer_name = trim($m[2]);
+ if(array_key_exists(3, $m)) {
+ $addresszusatz = trim($m[3]);
+ }
+ } elseif(preg_match('/^(.+)\s+(\d+[a-z0-9\/._-]*)(.+)?/i', $strasse_hausnummer, $m)) {
+ $strasse_name = trim($m[1]);
+ $hausnummer_name = trim($m[2]);
+ if(array_key_exists(3, $m)) {
+ $addresszusatz = trim($m[3]);
+ }
+ } elseif(preg_match('/^(.+)/i', $strasse_hausnummer, $m)) {
+ // ignore GST objects
+ return false;
+ $strasse_name = trim($m[1]);
+ }
+
+ return [$strasse_name, $hausnummer_name, $addresszusatz];
+ }
+
+ public function findAddressFromRimoBuilding($building) {
+ $hausnummer = false;
+
+ echo "===================================\n";
+
+ $rimo_id = trim($building->id);
+
+ if(!$rimo_id) {
+ return false;
+ }
+
+ $name = trim($building->name);
+
+ $strasse_hausnummer = trim($building->address->name);
+ [$strasse_name, $hausnummer_name, $addresszusatz] = $this->splitStreetHausnummer($strasse_hausnummer);
+ $strasse_name = $this->db->escape($strasse_name);
+ $hausnummer_name = $this->db->escape($hausnummer_name);
+ $addresszusatz = $this->db->escape($addresszusatz);
+
+ $gem_kz = $this->db->escape(trim($building->municipality->name));
+ $gem_name = $this->db->escape(trim($building->municipality->userLabel));
+
+ $ort_name = $this->db->escape(trim($building->address->city));
+ $plz_name = $this->db->escape(trim($building->address->zipCode));
+
+ $lat = $building->address->latitude;
+ $long = $building->address->longitude;
+ $unit_count = $building->homesCount;
+ $lot_num = $building->address->lotNumber;
+ $fcp_name = false;
+
+ $addr_dbg_str = "strasse: $strasse_name | hausnummer: $hausnummer_name | zusatz: $addresszusatz | gemkz: $gem_kz | gem_name: $gem_name | ort_name: $ort_name | plz_name: $plz_name";
+ echo "$addr_dbg_str\n";
+
+ // pass variables by ref, so they can be manipulated directly
+ $this->NetworkHelper->checkAddress([
+ "strasse_name" => &$strasse_name,
+ "hausnummer_name" => &$hausnummer_name,
+ "addresszusatz" => &$addresszusatz,
+ "gem_kz" => &$gem_kz,
+ "gem_name" => &$gem_name,
+ "ort_name" => &$ort_name,
+ "plz_name" => &$plz_name
+ ]);
+
+
+ $gemeinde = \ADBGemeindeModel::getFirst(["kennziffer" => $gem_kz]);
+ if(!$gemeinde) {
+ $this->log->warning("[WW] ($addr_dbg_str) Gemeinde nicht gefunden");
+ echo "Gemeinde $gem_name $gem_kz nicht gefunden\n";
+ return false;
+ }
+ $gemeinde_id = $gemeinde->id;
+
+ $adrcd = false;
+ $adr = trim($building->foreignId2);
+ $adr_parts = explode("-", $adr);
+ if(count($adr_parts)) {
+ $adrcd = $adr_parts[0];
+ }
+
+ $hausnummer = \ADBHausnummerModel::getFirst(["rimo_id" => $rimo_id]);
+
+ if($hausnummer) {
+ echo "found hausnummer from rimo_id $rimo_id\n";
+ }
+
+ if($adrcd && !$hausnummer) {
+ // get Hausnummer to update
+ $hausnummer = \ADBHausnummerModel::getFirst(['adrcd' => $adrcd]);
+ if(!$hausnummer) {
+ //echo "Hausnummer adrcd $adrcd not found\n";
+ } else {
+ echo "found hausnummer from adrcd $adrcd\n";
+ //echo "Hausnummer adrcd $adrcd gefunden!\n";
+ }
+ }
+
+ if(!$hausnummer) {
+ $hausnummer = $this->findHausnummerByStreet($strasse_name, $hausnummer_name, $gemeinde_id);
+ if(!$hausnummer) {
+ // hausnummer anlegen
+
+ $strasse = \ADBStrasseModel::getFirst(["gemeinde_id" => $gemeinde_id, "name" => $strasse_name]);
+ //if(!$strasse) die("Strasse $strasse_name (gemeinde_id $gemeinde_id; gem_kz $gem_kz) nicht gefunden\n");
+ if(!$strasse) {
+ $strasse = $this->createStreet($gemeinde_id, $strasse_name);
+ echo "[EE] Konnte Strasse $strasse_name in Gemeinde $gemeinde_id nicht anlegen\n";
+ if(!$strasse) return false;
+ }
+
+ $plz = \ADBPlzModel::getFirst(["gemeinde_id" => $gemeinde_id, "plz" => $plz_name]);
+ if(!$plz) die("PLZ $plz_name nicht gefunden\n");
+
+ $ortschaft = \ADBOrtschaftModel::getFirst(["gemeinde_id" => $gemeinde_id, "name" => $ort_name]);
+ if(!$ortschaft) die("$strasse_hausnummer: ortschaft $ort_name nicht gefunden\n");
+
+ $hausnummer_data = [
+ "netzgebiet_id" => $this->netzgebiet->id,
+ "adrcd" => ($adrcd) ? $adrcd : null,
+ "extref" => $name,
+ "ortschaft_id" => $ortschaft->id,
+ "plz_id" => $plz->id,
+ "strasse_id" => $strasse->id,
+ "hausnummer" => $hausnummer_name,
+ "zusatz" => ($addresszusatz) ? $addresszusatz : null,
+ "grund_nr" => ($lot_num) ? $lot_num : null,
+ "gps_lat" => $lat,
+ "gps_long" => $long,
+ "unit_count" => ($unit_count) ? $unit_count : 1,
+ "freigabe" => $this->netzgebiet->default_freigabe,
+ "rimo_id" => $rimo_id,
+ "rimo_fcp_name" => ($fcp_name) ? $fcp_name : null
+ ];
+ $hausnummer = \ADBHausnummerModel::create($hausnummer_data);
+ //var_dump($hausnummer);exit;
+ //echo "----------------------\ncreating hausnummer:\n";
+ //print_r($hausnummer);
+ $hausnummer->save();
+ }
+ }
+
+ // update hausnummer
+ if($hausnummer->netzgebiet_id != $this->netzgebiet->id) {
+ $hausnummer->netzgebiet_id = $this->netzgebiet->id;
+ //$hausnummer->save();
+ }
+ if($hausnummer->extref != $this->netzgebiet->extref) {
+ $hausnummer->extref = $this->netzgebiet->extref;
+ //$hausnummer->save();
+ }
+ if($lat && $long) {
+ $hausnummer->gps_lat = (float)$lat;
+ $hausnummer->gps_long = (float)$long;
+ }
+ if($rimo_id) $hausnummer->rimo_id = $rimo_id;
+ if($fcp_name) $hausnummer->rimo_fcp_name = $fcp_name;
+ //$hausnummer->freigabe = $this->netzgebiet->default_freigabe;
+ $hausnummer->save();
+ //echo ">>>>>>>>>>>>>>>>>>>\nupdating hausnummer:";
+ //print_r($hausnummer);exit;
+ return $hausnummer;
+
+ }
+
+
+ public function findHausnummerByStreet($strasse_name, $hausnummer_name, $gemeinde_id) {
+ $strasse_search = [$strasse_name];
+
+ if(strpos($strasse_name, ' ') !== false) $strasse_search[] = str_replace(' ', '-', $strasse_name);
+ if(strpos($strasse_name, '-') !== false) $strasse_search[] = str_replace('-', ' ', $strasse_name);
+ if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.', '. ', $strasse_name);
+ if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.', '.-', $strasse_name);
+ if(strpos($strasse_name, '. ') !== false) $strasse_search[] = str_replace('. ', '.', $strasse_name);
+ if(strpos($strasse_name, '. ') !== false) $strasse_search[] = str_replace('. ', '.-', $strasse_name);
+ if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.-', '.', $strasse_name);
+ if(strpos($strasse_name, '.') !== false) $strasse_search[] = str_replace('.-', '. ', $strasse_name);
+
+ foreach($strasse_search as $search) {
+ if(strpos($search, 'ß') !== false) $strasse_search[] = str_replace('ß', 'ss', $search);
+ if(strpos($search, 'ä') !== false) $strasse_search[] = str_replace('ä', 'ae', $search);
+ if(strpos($search, 'ö') !== false) $strasse_search[] = str_replace('ö', 'oe', $search);
+ if(strpos($search, 'ü') !== false) $strasse_search[] = str_replace('ü', 'ue', $search);
+
+ if(strpos($search, 'ss') !== false) $strasse_search[] = str_replace('ss', 'ß', $search);
+ if(strpos($search, 'ae') !== false) $strasse_search[] = str_replace('ae', 'ä', $search);
+ if(strpos($search, 'oe') !== false) $strasse_search[] = str_replace('oe', 'ö', $search);
+ if(strpos($search, 'ue') !== false) $strasse_search[] = str_replace('ue', 'ü', $search);
+ }
+
+ $sql = "SELECT * FROM view_hausnummer WHERE gemeinde_id = $gemeinde_id AND strasse IN ('". implode("', '", $strasse_search)."') AND hausnummer='$hausnummer_name'";
+ //echo "$sql\n";
+ /*if(preg_match('/^Tobelbader/i',$strasse_name)) {
+ echo "$sql\n";
+ }*/
+ $res = $this->db->query($sql);
+
+ if($this->db->num_rows($res)) {
+ // get Hausnummer to update
+ //echo "Hausnummer per Suche gefunden\n";
+ $data = $this->db->fetch_object($res);
+ return new \ADBHausnummer($data->hausnummer_id);
+ }
+ return false;
+ }
+
+ private function createStreet($gemeinde_id, $strasse_name) {
+ if(!$gemeinde_id || !$strasse_name) return null;
+
+ $strasse = \ADBStrasseModel::create([
+ "gemeinde_id" => $gemeinde_id,
+ "name" => $strasse_name
+ ]);
+
+ if(!$strasse->save()) {
+ return null;
+ }
+ return $strasse;
+
+ }
+
+ public function createHausnummer($hausnummer_data = []) {
+ $hausnummer = \ADBHausnummerModel::create($hausnummer_data);
+ //var_dump($hausnummer);exit;
+ return $hausnummer->save();
+ }
+}
\ No newline at end of file
diff --git a/scripts/adb-rimo-import/rimo-import-test.php b/scripts/adb-rimo-import/rimo-import-test.php
index a4d3a5e9d..47d0f032f 100755
--- a/scripts/adb-rimo-import/rimo-import-test.php
+++ b/scripts/adb-rimo-import/rimo-import-test.php
@@ -1,8 +1,12 @@
#!/usr/bin/php
id);
define("INTERNAL_USER_USERNAME", $me->username);
-$mainlog = mfLoghandler::singleton();
-$log = new mfLog_File();
+$mainlog = \mfLoghandler::singleton();
+$log = new \mfLog_File();
$log->init(BASEDIR."/var/log/rimo-import.log");
$apiOwner = "estmk";
@@ -53,6 +57,9 @@ $ctxOptsGet = [
]
];
+$adb = \FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
+
+
/*
* Get RIMO Sales Clusters
*/
@@ -73,58 +80,72 @@ if($responseText === false) {
$clustersResponse = json_decode($responseText);
//var_dump($clustersResponse);
//exit;
-if(is_object($clustersResponse) && property_exists($clustersResponse, "item") && is_array($clustersResponse->item) && count($clustersResponse->item)) {
-
- foreach($clustersResponse->item as $cluster) {
- $cluster_rimo_id = $cluster->id;
- echo "$cluster_rimo_id | name: ".$cluster->name."; label: ".$cluster->userLabel."\n";
+if(!is_object($clustersResponse) || !property_exists($clustersResponse, "item") || !is_array($clustersResponse->item) || !count($clustersResponse->item)) {
+ die("Invalid GetClusters Response\n");
+}
+
+foreach($clustersResponse->item as $cluster) {
+ $cluster_rimo_id = $cluster->id;
+ echo "$cluster_rimo_id | name: ".$cluster->name."; label: ".$cluster->userLabel."\n";
+ //continue;
+ $adb_netzgebiet = \ADBNetzgebietModel::getFirst(['rimo_id' => $cluster_rimo_id]);
+ if(!$adb_netzgebiet) {
+ echo "Kein Netzgebiet für Salescluster $cluster_rimo_id (".$cluster->name.")\n";
continue;
- $adb_netzgebiet = ADBNetzgebietModel::getFirst(['rimo_id' => $cluster_rimo_id]);
- if(!$adb_netzgebiet) {
- echo "Kein Netzgebiet für Salescluster $cluster_rimo_id (".$cluster->name.")\n";
- continue;
- }
-
- /*
- * Get Buildings per SalesCluster
- */
- $params = $baseParams;
- $params["clusterId"] = $cluster_rimo_id;
- $qs = http_build_query($params);
-
- $req_url = $epGetBuildings."?".$qs;
- $req_ctx = stream_context_create($ctxOptsGet);
-
- echo $req_url."\n";
- $responseText = file_get_contents($req_url, false, $req_ctx);
-
- if($responseText === false) {
- echo "Error fetching Buildings in cluster $cluster_rimo_id (".$cluster->name.")\n";
- exit;
- }
-
- $buildingsResponse = json_decode($responseText);
-
- if(is_object($buildingsResponse) && property_exists($buildingsResponse, "item") && is_array($buildingsResponse->item) && count($buildingsResponse->item)) {
- foreach($buildingsResponse->item as $building) {
- //var_dump($building);
- if($building->buildingType && $building->buildingType->userLabel != "Greenfield") {
- //var_dump($building);
- } else {
- continue;
- }
- if($building->buildingType && $building->buildingType->userLabel != "Greenfield" && $building->homesCount > 0 && property_exists($building->homes, "item") && is_array($building->homes->item) && count($building->homes->item)) {
- print_r($building);exit;
- foreach($building->homes->item as $home) {
-
- //vaR_dump($home->ftus->item);
- }
- exit;
- }
- }
- }
}
+ $AddressHelper = new ADBAddressHelper\AddressHelper(["log" => $log, "db" => $adb, "netzgebiet" => $adb_netzgebiet]);
+
+ /*
+ * Get Buildings per SalesCluster
+ */
+ $params = $baseParams;
+ $params["clusterId"] = $cluster_rimo_id;
+ $qs = http_build_query($params);
+
+ $req_url = $epGetBuildings."?".$qs;
+ $req_ctx = stream_context_create($ctxOptsGet);
+
+ echo $req_url."\n";
+ $responseText = file_get_contents($req_url, false, $req_ctx);
+
+ if($responseText === false) {
+ echo "Error fetching Buildings in cluster $cluster_rimo_id (".$cluster->name.")\n";
+ exit;
+ }
+
+ $buildingsResponse = json_decode($responseText);
+
+ if(is_object($buildingsResponse) && property_exists($buildingsResponse, "item") && is_array($buildingsResponse->item) && count($buildingsResponse->item)) {
+ foreach($buildingsResponse->item as $building) {
+ //var_dump($building);
+ if($building->buildingType && $building->buildingType->userLabel != "Greenfield") {
+ //var_dump($building);
+ } else {
+ continue;
+ }
+ // ignore buildings without units
+ if(!$building->plannedTU) {
+ continue;
+ }
+ if($building->buildingType && $building->buildingType->userLabel != "Greenfield" && $building->homesCount > 0 && property_exists($building->homes, "item") && is_array($building->homes->item) && count($building->homes->item)) {
+ //print_r($building);exit;
+
+ $rimo_building_id = $building->id;
+ $hausnummer = $AddressHelper->findAddressFromRimoBuilding($building);
+ if(!$hausnummer) {
+ echo "Adresse nicht gefunden: $rimo_building_id\n";
+ }
+
+ /*foreach($building->homes->item as $home) {
+ var_dump($home->ftus->item);exit;
+ }*/
+ //exit;
+ }
+
+ }
+ }
}
+
//echo $response;
echo "\n";
\ No newline at end of file