Merge branch 'preorderstatus-neu' into 'master'

New Preorderstatus handling at import

See merge request fronk/thetool!509
This commit is contained in:
Frank Schubert
2024-07-24 18:39:28 +00:00
6 changed files with 209 additions and 9 deletions

View File

@@ -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() {

View File

@@ -14,7 +14,23 @@ class ADBWohneinheit extends mfBaseModel {
protected function afterSave() {
if(!$this->id) return true;
if(!$this->hausnummer_id) return true;
// prevent potential infinite loop
$nesting_level = mfValuecache::singleton()->get("adbwohneinheit-save-nesting-level-".$this->id);
if(!$nesting_level) {
$nesting_level = 1;
} else {
$nesting_level++;
}
mfValuecache::singleton()->set("adbwohneinheit-save-nesting-level-".$this->id, $nesting_level);
if($nesting_level > 1) {
return true;
}
// Statuschange from Rimo statuschange
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) {
@@ -36,6 +52,20 @@ class ADBWohneinheit extends mfBaseModel {
}
}
public function setNewStatusCode($new_status_code) {
if(!$new_status_code) return false;
$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;
}
return true;
}
public static function parseHausnummerZusatz($text) {

View File

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

View File

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

View File

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