New Preorderstatus handling at import
This commit is contained in:
@@ -16,9 +16,47 @@ class ADBHausnummer extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
if($this->netzgebiet_id && !$this->gps_long && !$this->gps_lat) {
|
||||
$this->getGpsCoords();
|
||||
}
|
||||
// prevent potential infinite loop
|
||||
$nesting_level = mfValuecache::singleton()->get("adbhausnummer-save-nesting-level-".$this->id);
|
||||
if(!$nesting_level) {
|
||||
$nesting_level = 1;
|
||||
} else {
|
||||
$nesting_level++;
|
||||
}
|
||||
mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$this->id, $nesting_level);
|
||||
|
||||
if($nesting_level > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if($this->netzgebiet_id && !$this->gps_long && !$this->gps_lat) {
|
||||
$this->getGpsCoords();
|
||||
}
|
||||
|
||||
|
||||
// Statuschange from Rimo statuschange for all units
|
||||
foreach(ADBWohneinheitModel::search(["hausnummer_id" => $this->id]) as $wohneinheit) {
|
||||
AddressDB::handleRimoStatusUpdate($wohneinheit->id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function setNewStatusCode($new_status_code) {
|
||||
if(!$new_status_code) return false;
|
||||
|
||||
$this->log->debug(__METHOD__.": Want new Hausnummer (".$this->id.") Status ".$new_status_code);
|
||||
|
||||
$new_status = ADBStatusModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$new_status) return false;
|
||||
|
||||
$old_status = $this->getProperty("status");
|
||||
if($old_status->code < $new_status->code) {
|
||||
$this->log->debug(__METHOD__.": Setting Hausnummer (".$this->id.") Status from ".$old_status->code." to ".$new_status->code);
|
||||
$this->status_id = $new_status->id;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getGpsCoords() {
|
||||
|
||||
@@ -22,15 +22,15 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
} else {
|
||||
$nesting_level++;
|
||||
}
|
||||
mfValuecache::singleton()->set("dbwohneinheit-save-nesting-level-".$this->id, $nesting_level);
|
||||
mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$this->id, $nesting_level);
|
||||
|
||||
if($nesting_level > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Statuschange from Rimo statuschange
|
||||
$this->setStatusFromRimo();
|
||||
|
||||
AddressDB::handleRimoStatusUpdate($this->id);
|
||||
|
||||
// ADBWohneinheit_onSave_noAutoUnitCount can be defined if doing bulk
|
||||
// operations where unit count is calculated seperately
|
||||
if(!defined("ADBWohneinheit_onSave_noAutoUnitCount") || !ADBWohneinheit_onSave_noAutoUnitCount) {
|
||||
@@ -53,53 +53,18 @@ class ADBWohneinheit extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
private function setStatusFromRimo() {
|
||||
return true; // XXX disabled for now
|
||||
if(!$this->id) return true;
|
||||
if(!$this->rimo_id) return true;
|
||||
public function setNewStatusCode($new_status_code) {
|
||||
if(!$new_status_code) return false;
|
||||
|
||||
if(!$this->hausnummer->netzgebiet->getOption("statuschange")) {
|
||||
return true;
|
||||
$new_status = ADBStatusModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$new_status) return false;
|
||||
|
||||
$old_status = $this->getProperty("status");
|
||||
if($old_status->code < $new_status->code) {
|
||||
$this->status_id = $new_status->id;
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $this->id]);
|
||||
if(!$preorder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$b_ex_state = strtolower($this->hausnummer->rimo_ex_state);
|
||||
$b_op_state = strtolower($this->hausnummer->rimo_op_state);
|
||||
|
||||
$h_ex_state = strtolower($this->rimo_ex_state);
|
||||
$h_op_state = strtolower($this->rimo_op_state);
|
||||
|
||||
$workorder = $this->getProperty("rimo_workorder");
|
||||
$wo_state = strtolower($workorder->rimo_status);
|
||||
|
||||
foreach(TT_PREORDER_RIMO_STATUS_MATRIX as $matrix) {
|
||||
if($matrix["rbop"] && $matrix["rbop"] != $b_op_state) continue;
|
||||
if($matrix["rbex"] && $matrix["rbex"] != $b_ex_state) continue;
|
||||
|
||||
if($matrix["rhop"] && $matrix["rhop"] != $h_op_state) continue;
|
||||
if($matrix["rhex"] && $matrix["rhex"] != $h_ex_state) continue;
|
||||
|
||||
if($matrix["rwo"] && (!$workorder || $matrix["rwo"] != $wo_state)) continue;
|
||||
|
||||
// seems all criteria match => set new status
|
||||
|
||||
$preorderstatus = $matrix["p"];
|
||||
if(!$preorderstatus) continue;
|
||||
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $preorderstatus]);
|
||||
if(!$new_status) continue;
|
||||
if($preorderstatus->status->code < $new_status->code) {
|
||||
$preorder->status_id = $new_status->id;
|
||||
$preorder->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function parseHausnummerZusatz($text) {
|
||||
|
||||
@@ -70,7 +70,83 @@ class AddressDB {
|
||||
$this->db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$this->log = mfLoghandler::singleton();
|
||||
}
|
||||
|
||||
|
||||
public static function handleRimoStatusUpdate($wohneinheit_id) {
|
||||
if(!$wohneinheit_id) return true;
|
||||
|
||||
$log = mfLoghandler::singleton();
|
||||
//echo "in handleRimoStatusUpdate\n";
|
||||
|
||||
$wohneinheit = new ADBWohneinheit($wohneinheit_id);
|
||||
if(!$wohneinheit->id) return false;
|
||||
|
||||
$hausnummer = $wohneinheit->hausnummer;
|
||||
if(!$hausnummer->netzgebiet->getOption("statuschange")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
||||
if(!$preorder) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$b_ex_state = strtolower($hausnummer->rimo_ex_state);
|
||||
$b_op_state = strtolower($hausnummer->rimo_op_state);
|
||||
|
||||
$h_ex_state = strtolower($wohneinheit->rimo_ex_state);
|
||||
$h_op_state = strtolower($wohneinheit->rimo_op_state);
|
||||
|
||||
$wo_state = false;
|
||||
$workorder = $wohneinheit->rimo_workorder;
|
||||
if($workorder) {
|
||||
$wo_state = strtolower($workorder->rimo_status);
|
||||
}
|
||||
|
||||
|
||||
$order_type = $preorder->type;
|
||||
|
||||
foreach(TT_PREORDER_RIMO_STATUS_MATRIX as $matrix) {
|
||||
//echo "wohneinheit ".$wohneinheit->id."\n";
|
||||
//var_dump($matrix);
|
||||
if($matrix["rbop"] && $matrix["rbop"] != $b_op_state) continue;
|
||||
if($matrix["rbex"] && $matrix["rbex"] != $b_ex_state) continue;
|
||||
|
||||
if($matrix["rhop"] && $matrix["rhop"] != $h_op_state) continue;
|
||||
if($matrix["rhex"] && $matrix["rhex"] != $h_ex_state) continue;
|
||||
|
||||
if($matrix["rwo"] && (!$workorder || $matrix["rwo"] != $wo_state)) continue;
|
||||
|
||||
if($matrix["pt"] && $matrix["pt"] != $order_type) continue;
|
||||
// seems all criteria match => set new status
|
||||
|
||||
$log->debug(__METHOD__.": new Preorder Status: ".$matrix["p"]);
|
||||
|
||||
$preorderstatus = $matrix["p"];
|
||||
if(!$preorderstatus) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$preorder->setNewStatusCode($preorderstatus);
|
||||
$preorder->save();
|
||||
|
||||
$hausnummer_status = $matrix["h"];
|
||||
if($hausnummer_status) {
|
||||
$log->debug(__METHOD__.": new Hausnummer (".$hausnummer->id.") status: ".$matrix["h"]);
|
||||
$hausnummer->setNewStatusCode($hausnummer_status);
|
||||
$hausnummer->save();
|
||||
}
|
||||
|
||||
$wohneinheit_status = $matrix["w"];
|
||||
if($wohneinheit_status) {
|
||||
$wohneinheit->setNewStatusCode($wohneinheit_status);
|
||||
$wohneinheit->save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function import($input) {
|
||||
$path = __DIR__."/Importer/";
|
||||
$dir = opendir($path);
|
||||
|
||||
@@ -235,7 +235,7 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
}
|
||||
|
||||
private function cascadeStatusToPreorders() {
|
||||
public function cascadeStatusToPreorders() {
|
||||
$status = new Preorderstatus($this->status_id);
|
||||
if(!$status->id) {
|
||||
return false;
|
||||
@@ -427,6 +427,18 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setNewStatusCode($new_status_code) {
|
||||
if(!$new_status_code) return false;
|
||||
|
||||
$new_status = PreorderstatusModel::getFirst(["code" => $new_status_code]);
|
||||
if(!$new_status) return false;
|
||||
|
||||
$status = $this->getProperty("status");
|
||||
if($status->code < $new_status->code) {
|
||||
$this->status_id = $new_status->id;
|
||||
}
|
||||
}
|
||||
|
||||
public function createUcode() {
|
||||
$ucode = $this->generateNewUcode();
|
||||
|
||||
@@ -3,7 +3,27 @@
|
||||
class RimoWorkorder extends mfBaseModel {
|
||||
private $adb_wohneinheit;
|
||||
private $termination;
|
||||
|
||||
|
||||
public function afterSave() {
|
||||
// prevent potential infinite loop
|
||||
$nesting_level = mfValuecache::singleton()->get("rimoworkorder-save-nesting-level-".$this->id);
|
||||
if(!$nesting_level) {
|
||||
$nesting_level = 1;
|
||||
} else {
|
||||
$nesting_level++;
|
||||
}
|
||||
mfValuecache::singleton()->set("rimoworkorder-save-nesting-level-".$this->id, $nesting_level);
|
||||
|
||||
if($nesting_level > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Statuschange from Rimo statuschange for all units
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
if($wohneinheit) {
|
||||
AddressDB::handleRimoStatusUpdate($wohneinheit->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -243,6 +243,7 @@ foreach ($clusters as $cluster_data) {
|
||||
}
|
||||
$hausnummer_found_count++;
|
||||
|
||||
$hausnummer_id = $hausnummer->id;
|
||||
/*
|
||||
* Set Building Status based on Operational-/Executionstate
|
||||
*/
|
||||
@@ -254,18 +255,23 @@ foreach ($clusters as $cluster_data) {
|
||||
if($b_executionstate_label != $hausnummer->rimo_ex_state) {
|
||||
$hausnummer->rimo_ex_state = $b_executionstate_label;
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
if($b_operationalstate_label != $hausnummer->rimo_op_state) {
|
||||
$hausnummer->rimo_op_state = $b_operationalstate_label;
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
|
||||
if($b_executionstate_id == "99" && $hausnummer->visibility != "private") {
|
||||
echo "== Setting visibility to private because execution state $b_executionstate_id ($b_executionstate_label) [".$hausnummer->id."]\n";
|
||||
$hausnummer->visibility = "private";
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
|
||||
$last_unit_num = 0;
|
||||
$existing_units = [];
|
||||
$existing_units_extref = [];
|
||||
@@ -300,6 +306,7 @@ foreach ($clusters as $cluster_data) {
|
||||
$rimo_home_count = count($building->homes->item);
|
||||
|
||||
foreach ($building->homes->item as $home) {
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
//print_r($home);exit;
|
||||
$homes_count++;
|
||||
$home_rimo_id = $home->id;
|
||||
@@ -325,6 +332,8 @@ foreach ($clusters as $cluster_data) {
|
||||
if (!$unit->save()) {
|
||||
die("Error saving new unit\n" . print_r($home, true));
|
||||
}
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
}
|
||||
|
||||
if ($unit->extref != $home_rimo_id) {
|
||||
@@ -332,19 +341,27 @@ foreach ($clusters as $cluster_data) {
|
||||
if (!$unit->save()) {
|
||||
die("Error saving new extref on unit\n" . print_r($home, true));
|
||||
}
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Status based on execution-/operational-state
|
||||
* TODO: Status based on execution-/operationalstate
|
||||
*/
|
||||
|
||||
if($home->executionState->userLabel != $unit->rimo_ex_state) {
|
||||
$unit->rimo_ex_state = $home->executionState->userLabel;
|
||||
$unit->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
}
|
||||
if($home->operationalState->userLabel != $unit->rimo_op_state) {
|
||||
$unit->rimo_op_state = $home->operationalState->userLabel;
|
||||
$unit->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -523,6 +540,8 @@ foreach ($clusters as $cluster_data) {
|
||||
if ($wo) {
|
||||
//echo "Updating Workorder $rimo_workorder_id ($workorder_home_id)\n";
|
||||
if ($workorder_status != $wo->rimo_status) {
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
$wo->rimo_status = $workorder_status;
|
||||
$wo->save();
|
||||
}
|
||||
@@ -544,6 +563,8 @@ foreach ($clusters as $cluster_data) {
|
||||
continue;
|
||||
}
|
||||
|
||||
\mfValuecache::singleton()->set("adbhausnummer-save-nesting-level-".$hausnummer->id, 0);
|
||||
\mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$unit->id, 0);
|
||||
//echo "Creating Workorder $rimo_workorder_id ($workorder_home_id)\n";
|
||||
$wo = \RimoWorkorderModel::create([
|
||||
"adb_wohneinheit_id" => $wo_home->id,
|
||||
@@ -595,6 +616,7 @@ foreach ($clusters as $cluster_data) {
|
||||
if ($hausnummer->home_trench != $home_trench) {
|
||||
$hausnummer->home_trench = json_encode($home_trench);
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -611,6 +633,7 @@ foreach ($clusters as $cluster_data) {
|
||||
$hausnummer->borderpoint_lat = $lat;
|
||||
$hausnummer->borderpoint_long = $long;
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -631,6 +654,7 @@ foreach ($clusters as $cluster_data) {
|
||||
//var_dump($trenches);exit;
|
||||
$hausnummer->trenches = json_encode($trenches);
|
||||
$hausnummer->save();
|
||||
$hausnummer = new \ADBHausnummer($hausnummer_id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user