Merge branch 'fronkdev' into 'master'
PreorderstatusJournal & preorder flags -> ADBHausnummer flags sync See merge request fronk/thetool!1739
This commit is contained in:
@@ -23,6 +23,7 @@ class Preorder extends mfBaseModel {
|
||||
private $history;
|
||||
private $citycomoan; // ONT data
|
||||
private $ctags; // network-keyed array of Ctags
|
||||
private $statusjournals;
|
||||
|
||||
protected function beforeUpdate($data) {
|
||||
if(!array_key_exists("edit_by", $data)) {
|
||||
@@ -532,8 +533,8 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
if(is_array($flags) && count($flags)) {
|
||||
foreach($flags as $flag) {
|
||||
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_MATRIX)) {
|
||||
$flag_matrix_item = TT_PREORDER_STATUS_MATRIX[$flag->code];
|
||||
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_FLAG_MATRIX)) {
|
||||
$flag_matrix_item = TT_PREORDER_STATUS_FLAG_MATRIX[$flag->code];
|
||||
if(!$flag_matrix_item["flag"]) continue;
|
||||
|
||||
// set hausnummer flag
|
||||
@@ -541,19 +542,13 @@ class Preorder extends mfBaseModel {
|
||||
$hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]);
|
||||
if(!$hflag) {
|
||||
$this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist");
|
||||
} else {
|
||||
//var_dump($hflag);exit;
|
||||
$hflag->hausnummer_id = $hausnummer->id;
|
||||
$hflag->value->value = $flag->value->value;
|
||||
$hflag->save();
|
||||
$this->log->debug("[" . $this->_ruid . "] " . __METHOD__ . ": Hausnummer flag " . $hflag->code . " value '" . $hflag->value->value . "' gespeichert");
|
||||
}
|
||||
|
||||
$hflagval = ADBHausnummerStatusflagValueModel::getFirst(["hausnummer_id" => $this->adb_hausnummer_id, "flag_id" => $hflag->id]);
|
||||
if(!$hflagval) {
|
||||
$hflagval = ADBHausnummerStatusflagValueModel::create([
|
||||
"hausnummer_id" => $this->adb_hausnummer_id,
|
||||
"flag_id" => $hflag->id,
|
||||
"value" => 0
|
||||
]);
|
||||
}
|
||||
$hflagval->value = $flag->value->value;
|
||||
$hflagval->save();
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": Hausnummer flag ".$hflag->code." value '".$hflagval->value."' gespeichert");
|
||||
}
|
||||
|
||||
// set wohneiheit flag
|
||||
@@ -561,19 +556,33 @@ class Preorder extends mfBaseModel {
|
||||
$wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]);
|
||||
if(!$wflag) {
|
||||
$this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist");
|
||||
} else {
|
||||
$wflag->wohneinheit_id = $wohneinheit->id;
|
||||
$wflag->value->value = $flag->value->value;
|
||||
$wflag->value->save();
|
||||
$this->log->debug("[" . $this->_ruid . "] " . __METHOD__ . ": Wohneinheit flag " . $hflag->code . " value '" . $wflag->value->value . "' gespeichert");
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("ws", $flag_matrix_item) && $flag_matrix_item["ws"] && $this->adb_wohneinheit_id) {
|
||||
//echo "Setting Wohneinheit status to ".$flag_matrix_item["ws"]." from ".$this->getProperty("adb_wohneinheit")->status->code."\n";
|
||||
// set new wohneinheit status
|
||||
$new_wohneinheit_status = ADBStatusModel::getFirst(["code" => $flag_matrix_item["ws"]]);
|
||||
if(!$new_wohneinheit_status) {
|
||||
$this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": new ADBStatus code " . $flag_matrix_item["w"] . " not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
$wflagval = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->adb_wohneinheit_id, "flag_id" => $wflag->id]);
|
||||
if(!$wflagval) {
|
||||
$wflagval = ADBWohneinheitStatusflagValueModel::create([
|
||||
"wohneinheit_id" => $this->adb_wohneinheit_id,
|
||||
"flag_id" => $wflag->id,
|
||||
"value" => 0
|
||||
]);
|
||||
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->id) return true;
|
||||
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": new wohneinheit status code " . $new_wohneinheit_status->code);
|
||||
// only update if current status is less than new status
|
||||
if($wohneinheit->status->code < $new_wohneinheit_status->code) {
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__ . ": Setting new wohneinheit status code: " . $new_wohneinheit_status->code);
|
||||
$wohneinheit->status_id = $new_wohneinheit_status->id;
|
||||
$wohneinheit->save();
|
||||
}
|
||||
$wflagval->value = $flag->value->value;
|
||||
$wflagval->save();
|
||||
$this->log->debug("[".$this->_ruid."] ".__METHOD__.": Wohneinheit flag ".$hflag->code." gespeichert");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1554,6 +1563,16 @@ class Preorder extends mfBaseModel {
|
||||
return $this->attribute;
|
||||
}
|
||||
|
||||
if($name == "statusjournals") {
|
||||
$journals = PreorderstatusJournal::search(["preorder_id" => $this->id]);
|
||||
if($journals) {
|
||||
$this->statusjournals = $journals;
|
||||
return $this->statusjournals;
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
if($name == "creator") {
|
||||
$user = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
|
||||
if($user) {
|
||||
|
||||
@@ -1087,6 +1087,9 @@ class PreorderController extends mfBaseController {
|
||||
case "updateBilled":
|
||||
$return = $this->updateBilledApi();
|
||||
break;
|
||||
case "saveStatusJournal":
|
||||
$return = $this->saveStatusJournalApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
@@ -1105,6 +1108,35 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveStatusJournalApi() {
|
||||
$preorder_id = $this->request->preorder_id;
|
||||
$text = $this->request->text;
|
||||
|
||||
if(!$preorder_id || !$text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$journal = PreorderstatusJournal::create([
|
||||
"preorder_id" => $preorder_id,
|
||||
"text" => $text,
|
||||
]);
|
||||
if(!$journal->save()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [
|
||||
"preorder_id" => $preorder_id,
|
||||
"create" => (new DateTime("@".$journal->create))->setTimezone(new DateTimeZone("Europe/Vienna"))->format("Y-m-d H:i:s"),
|
||||
"creator" => $journal->creator->name,
|
||||
"text" => $journal->text,
|
||||
];
|
||||
|
||||
}
|
||||
protected function getLoggedEmail() {
|
||||
$preorder_id = $this->request->pid;
|
||||
$emaillog_id = $this->request->eid;
|
||||
@@ -1328,25 +1360,24 @@ class PreorderController extends mfBaseController {
|
||||
|
||||
private function setStatusFlagApi() {
|
||||
$preorder_id = $this->request->preorder_id;
|
||||
$flag_id = $this->request->flag_id;
|
||||
$code = $this->request->code;
|
||||
$value = $this->request->value;
|
||||
|
||||
if(!$preorder_id || !$flag_id) {
|
||||
if(!$preorder_id || !$code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$flag = new PreorderStatusflag($flag_id);
|
||||
if(!$flag->id) {
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) return false;
|
||||
|
||||
$sflag = PreorderStatusflagModel::getFirst(["code" => $code]);
|
||||
if(!$sflag) {
|
||||
return false;
|
||||
}
|
||||
$sflag->preorder_id = $preorder->id;
|
||||
|
||||
if ($flag_id == 1) {
|
||||
$preorder = new Preorder($preorder_id);
|
||||
if(!$preorder->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$attribute = "inhouse_cabling_supplied";
|
||||
if ($code == 145) {
|
||||
$attribute = "inhouse_cabling_supplied"; // = Starterpaket erhalten
|
||||
$attribs = $preorder->attribute;
|
||||
if(!$attribs) {
|
||||
$attribs = [];
|
||||
@@ -1361,24 +1392,21 @@ class PreorderController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
$flagvalue = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder_id, "flag_id" => $flag_id]);
|
||||
if(!$flagvalue) {
|
||||
$flagvalue = PreorderStatusflagValueModel::create([
|
||||
"preorder_id" => $preorder_id,
|
||||
"flag_id" => $flag_id
|
||||
]);
|
||||
}
|
||||
|
||||
$flagvalue->value = ($value) ? 1 : 0;
|
||||
$sflag->value->value = ($value) ? 1 : 0;
|
||||
//var_dump($flagvalue);exit;
|
||||
try {
|
||||
if(!$flagvalue->save()) {
|
||||
if(!$sflag->value->save()) {
|
||||
return false;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->log->debug($e->getTraceAsString());
|
||||
}
|
||||
|
||||
$this->log->debug("===== Setting Hausnummer Flag Value $code -> ".($value ? 1 : 0));
|
||||
if($preorder->adb_hausnummer_id) {
|
||||
$preorder->adb_hausnummer->setStatusflag($code, ($value ? 1 : 0));
|
||||
}
|
||||
|
||||
return ["message" => "Statusflag saved successfully"];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user