PreorderstatusJournal & preorder flags -> ADBHausnummer flags sync
This commit is contained in:
@@ -654,12 +654,6 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
#email-log-modal p {
|
|
||||||
margin-top: 8px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div class="modal" tabindex="-1" id="email-log-modal" style="max-height: 100vh;">
|
<div class="modal" tabindex="-1" id="email-log-modal" style="max-height: 100vh;">
|
||||||
<div class="modal-dialog modal-dialog-centered modal-xl">
|
<div class="modal-dialog modal-dialog-centered modal-xl">
|
||||||
<div class="modal-content" style="overflow: auto;">
|
<div class="modal-content" style="overflow: auto;">
|
||||||
@@ -697,7 +691,7 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
</div>
|
</div>
|
||||||
<div class="row mb-2" id="email-log-body-section">
|
<div class="row mb-2" id="email-log-body-section">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div id="email-log-body-view" style="min-height: 48px; width:100%; border: 1px solid #000; padding: 8px; font-family: sans-serif; overflow-y: auto;"></div>
|
<iframe id="email-log-body-view" style="height: 50vh; width:100%; border: 1px solid #000; padding: 8px; font-family: sans-serif; overflow-y: auto;"></iframe>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -779,11 +773,11 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
// do: setStatusFlag, preorder_id, flag_id: 1, value (0 or 1)
|
// do: setStatusFlag, preorder_id, flag_id: 1, value (0 or 1)
|
||||||
|
|
||||||
if (attrib == "inhouse_cabling_supplied") {
|
if (attrib == "inhouse_cabling_supplied") {
|
||||||
var flag_id = 1;
|
const code = 145;
|
||||||
$.post("<?=self::getUrl("Preorder", "Api")?>", {
|
$.post("<?=self::getUrl("Preorder", "Api")?>", {
|
||||||
do: "setStatusFlag",
|
do: "setStatusFlag",
|
||||||
preorder_id: preorder_id,
|
preorder_id: preorder_id,
|
||||||
flag_id: flag_id,
|
code: 145,
|
||||||
value: value
|
value: value
|
||||||
},
|
},
|
||||||
function(success) {
|
function(success) {
|
||||||
@@ -838,6 +832,58 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
$("#attributes_" + attribute + "-" + id).prop("checked", !$("#attributes_" + attribute + "-" + id).is(":checked"));
|
$("#attributes_" + attribute + "-" + id).prop("checked", !$("#attributes_" + attribute + "-" + id).is(":checked"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function submitStatusJournal(pid) {
|
||||||
|
var text = $("#preorder-" + pid + "-status-journal-input").val();
|
||||||
|
if(!text) return;
|
||||||
|
|
||||||
|
// disable elements
|
||||||
|
$("#preorder-" + pid + "-status-journal-input").attr("disabled", "disabled");
|
||||||
|
$("#preorder-" + pid + "-status-journal button").attr("disabled", "disabled");
|
||||||
|
|
||||||
|
// save text
|
||||||
|
await fetch("<?=self::getUrl("Preorder", "Api")?>", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
||||||
|
},
|
||||||
|
body: new URLSearchParams({
|
||||||
|
do: "saveStatusJournal",
|
||||||
|
preorder_id: pid,
|
||||||
|
text: text
|
||||||
|
})
|
||||||
|
}).then(resp => {
|
||||||
|
if(resp.ok) {
|
||||||
|
return resp.json();
|
||||||
|
}
|
||||||
|
}).then((data) => {
|
||||||
|
// enable items
|
||||||
|
$("#preorder-" + pid + "-status-journal-input").attr("disabled", false);
|
||||||
|
$("#preorder-" + pid + "-status-journal button").attr("disabled", false);
|
||||||
|
|
||||||
|
if(data.status == "OK") {
|
||||||
|
$("#preorder-" + pid + "-status-journal-input").val("");
|
||||||
|
// get returned data
|
||||||
|
var new_text = data.result.text;
|
||||||
|
var creator = data.result.creator;
|
||||||
|
var create_date = new Date(data.result.create);
|
||||||
|
var date_ts = create_date.getTime();
|
||||||
|
var date_string = create_date.toLocaleString("de-DE", {year: "numeric", month: "2-digit", day: "2-digit"}) + " " + String(create_date.getHours()).padStart(2, 0) + ":" + String(create_date.getMinutes()).padStart(2, 0);
|
||||||
|
|
||||||
|
// add new journal item
|
||||||
|
$("#preorder-" + pid + "-status-journal-list").prepend('<tr id="preorder-' + pid + '-status-journal-list-' + date_ts + '"><td class="text-monospace"><small style="white-space: nowrap"><i class="fas fa-clock fa-fw"></i> ' + date_string + '</small> <span style="white-space: nowrap">(' + creator + ')<span></span></td> <td class="text-left">' + new_text + '</td></tr>');
|
||||||
|
|
||||||
|
// visual effects
|
||||||
|
$('#preorder-' + pid + '-status-journal-list-' + date_ts).addClass("text-success").fadeOut(10).fadeIn(400);
|
||||||
|
setTimeout(() => {$('#preorder-' + pid + '-status-journal-list-' + date_ts).removeClass("text-success")}, 300)
|
||||||
|
window.notify("success", "Journaleintrag erfolgreich gespeichert.");
|
||||||
|
} else {
|
||||||
|
window.notify("error", "Fehler beim Speichern des Journaleintrags");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1113,6 +1159,7 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
var elem = e.target;
|
var elem = e.target;
|
||||||
var preorder_id = $(elem).data("preorder_id");
|
var preorder_id = $(elem).data("preorder_id");
|
||||||
var flag_id = $(elem).data("flag_id");
|
var flag_id = $(elem).data("flag_id");
|
||||||
|
var flag_code = $(elem).data("flag_code");
|
||||||
var value = $(elem).prop("checked") ? 1 : 0;
|
var value = $(elem).prop("checked") ? 1 : 0;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -1121,7 +1168,7 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
data: {
|
data: {
|
||||||
do: "setStatusFlag",
|
do: "setStatusFlag",
|
||||||
preorder_id: preorder_id,
|
preorder_id: preorder_id,
|
||||||
flag_id: flag_id,
|
code: flag_code,
|
||||||
value: value
|
value: value
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@@ -1129,9 +1176,10 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
elem: elem,
|
elem: elem,
|
||||||
preorder_id: preorder_id,
|
preorder_id: preorder_id,
|
||||||
flag_id: flag_id,
|
flag_id: flag_id,
|
||||||
|
flag_code: flag_code,
|
||||||
},
|
},
|
||||||
success: function (success) {
|
success: function (success) {
|
||||||
var textelem = $("#preorder-" + this.preorder_id + "-statusflag-" + this.flag_id + "-text");
|
var textelem = $("#preorder-" + this.preorder_id + "-statusflag-" + this.flag_code + "-text");
|
||||||
if(success.status != "OK") {
|
if(success.status != "OK") {
|
||||||
notify("error","Fehler beim Speichern des Statusflags");
|
notify("error","Fehler beim Speichern des Statusflags");
|
||||||
$(this.elem).prop("checked", !$(this.elem).prop("checked"));
|
$(this.elem).prop("checked", !$(this.elem).prop("checked"));
|
||||||
@@ -1145,7 +1193,7 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
|
|
||||||
// find all inputs with this data-preorder_id="21969" and data-flag_id="3" and set the text to the new value
|
// find all inputs with this data-preorder_id="21969" and data-flag_id="3" and set the text to the new value
|
||||||
// always with their own fields and then select / unselect the checkbox
|
// always with their own fields and then select / unselect the checkbox
|
||||||
$("input.preorder-statusflag[data-preorder_id='" + this.preorder_id + "'][data-flag_id='" + this.flag_id + "']").each(function() {
|
$("input.preorder-statusflag[data-preorder_id='" + this.preorder_id + "'][data-flag_code='" + this.flag_code + "']").each(function() {
|
||||||
if(value) {
|
if(value) {
|
||||||
$(this).prop("checked", true);
|
$(this).prop("checked", true);
|
||||||
} else {
|
} else {
|
||||||
@@ -1771,7 +1819,9 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
$("#email-log-to-value").text("");
|
$("#email-log-to-value").text("");
|
||||||
$("#email-log-log-sent-value").text("");
|
$("#email-log-log-sent-value").text("");
|
||||||
$("#email-log-subject-value").text("");
|
$("#email-log-subject-value").text("");
|
||||||
$("#email-log-view").empty();
|
document.getElementById("email-log-body-view").contentWindow.document.open();
|
||||||
|
document.getElementById("email-log-body-view").contentWindow.document.write("<html><body> </body></html>");
|
||||||
|
document.getElementById("email-log-body-view").contentWindow.document.close();
|
||||||
$("#email-log-attachments-section").hide();
|
$("#email-log-attachments-section").hide();
|
||||||
$("#email-log-attachment-list").empty();
|
$("#email-log-attachment-list").empty();
|
||||||
hideEmailLogHeaders();
|
hideEmailLogHeaders();
|
||||||
@@ -1816,11 +1866,17 @@ $pagination_entity_name = "Vorbestellungen";
|
|||||||
$("#email-log-attachments-section").show();
|
$("#email-log-attachments-section").show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById("email-log-body-view").contentWindow.document.open();
|
||||||
if(email.bodyIsHtml) {
|
if(email.bodyIsHtml) {
|
||||||
$("#email-log-body-view").html(email.body);
|
document.getElementById("email-log-body-view").contentWindow.document.write(email.body);
|
||||||
} else {
|
} else {
|
||||||
$("#email-logbody-view").text(email.body);
|
var html_body = '<html lang="de"><head><meta charset="utf-8"></head><body><p>';
|
||||||
|
html_body += email.body.replaceAll("\r", "").replaceAll("\n", "<br />");
|
||||||
|
html_body += '</p></body></html>';
|
||||||
|
document.getElementById("email-log-body-view").contentWindow.document.write(html_body);
|
||||||
}
|
}
|
||||||
|
document.getElementById("email-log-body-view").contentWindow.document.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$("#email-log-modal").modal("show");
|
$("#email-log-modal").modal("show");
|
||||||
|
|||||||
@@ -740,6 +740,29 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row mt-2" id="preorder-<?=$preorder->id?>-status-journal">
|
||||||
|
<div class="col">
|
||||||
|
<h3>Journal</h3>
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text">Neuer Journaleintrag:</span>
|
||||||
|
</div>
|
||||||
|
<input type="text" class="form-control preorder-status-journal-input" id="preorder-<?=$preorder->id?>-status-journal-input" />
|
||||||
|
<div class="input-group-append">
|
||||||
|
<button type="button" class="btn btn-primary" onclick="submitStatusJournal(<?=$preorder->id?>)">Speichern</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table class="table table-sm table-striped" id="preorder-<?=$preorder->id?>-status-journal-list">
|
||||||
|
<?php foreach(array_reverse($preorder->statusjournals) as $journal): ?>
|
||||||
|
<tr>
|
||||||
|
<td class="text-monospace"><small style="white-space: nowrap"><i class="fas fa-clock fa-fw"></i> <?=date("d.m.Y H:i", $journal->create)?></small> <span style="white-space: nowrap">(<?=htmlentities($journal->creator->name)?>)<span></span></td>
|
||||||
|
<td class="text-left"><?=htmlentities($journal->text)?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<h3>Statusflags</h3>
|
<h3>Statusflags</h3>
|
||||||
@@ -748,9 +771,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th class="text-right">
|
<th class="text-right">
|
||||||
<input type="checkbox" class="form-control preorder-statusflag"
|
<input type="checkbox" class="form-control preorder-statusflag"
|
||||||
id="preorder-<?=$preorder->id?>-statusflag-<?=$flag->id?>"
|
id="preorder-<?=$preorder->id?>-statusflag-<?=$flag->code?>"
|
||||||
data-preorder_id="<?=$preorder->id?>"
|
data-preorder_id="<?=$preorder->id?>"
|
||||||
data-flag_id="<?=$flag->id?>"
|
data-flag_id="<?=$flag->id?>"
|
||||||
|
data-flag_code="<?=$flag->code?>"
|
||||||
<?=(array_key_exists($flag->id, $preorder->statusflags) && $preorder->statusflags[$flag->id]->value && $preorder->statusflags[$flag->id]->value->value) ? "checked='checked'" : ""?>
|
<?=(array_key_exists($flag->id, $preorder->statusflags) && $preorder->statusflags[$flag->id]->value && $preorder->statusflags[$flag->id]->value->value) ? "checked='checked'" : ""?>
|
||||||
/>
|
/>
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
@@ -146,6 +146,23 @@ class ADBHausnummer extends mfBaseModel {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStatusflag($code, $value) {
|
||||||
|
if(!$code || !$this->id) return false;
|
||||||
|
|
||||||
|
$this->log->debug("[".$this->_ruid."] ".__METHOD__." (Hausnummer $this->id) Setting $code to $value");
|
||||||
|
|
||||||
|
$sflag = ADBStatusflagModel::getFirst(["code" => $code]);
|
||||||
|
$sflag->hausnummer_id = $this->id;
|
||||||
|
|
||||||
|
$sflag->value->value = $value ? 1 : 0;
|
||||||
|
$sflag->value->save();
|
||||||
|
|
||||||
|
//$this->log->ebug(print_r($sflag, true));
|
||||||
|
//$this->log->ebug(print_r($sflag->value, true));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private function getGpsCoords() {
|
private function getGpsCoords() {
|
||||||
$search = [
|
$search = [
|
||||||
'country' => "AT",
|
'country' => "AT",
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class ADBWohneinheit extends mfBaseModel {
|
|||||||
if($hausnummer->netzgebiet_id) {
|
if($hausnummer->netzgebiet_id) {
|
||||||
$netzgebiet = new ADBNetzgebiet($hausnummer->netzgebiet_id);
|
$netzgebiet = new ADBNetzgebiet($hausnummer->netzgebiet_id);
|
||||||
if($netzgebiet->id) {
|
if($netzgebiet->id) {
|
||||||
|
$usable_unit_count = 0;
|
||||||
$unit_count = ADBWohneinheitModel::count(['netzgebiet_id' => $hausnummer->netzgebiet_id]);
|
$unit_count = ADBWohneinheitModel::count(['netzgebiet_id' => $hausnummer->netzgebiet_id]);
|
||||||
if($unit_count) {
|
if($unit_count) {
|
||||||
$unit_count_gda = [
|
$unit_count_gda = [
|
||||||
@@ -101,13 +102,15 @@ class ADBWohneinheit extends mfBaseModel {
|
|||||||
$unit_count_gda[$type] += $hausnummer->unit_count;
|
$unit_count_gda[$type] += $hausnummer->unit_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($unit_count_gda as $type => $count) {
|
foreach($unit_count_gda as $type => $count) {
|
||||||
|
$usable_unit_count += $count;
|
||||||
$netzgebiet->{"unit_count_$type"} = $count;
|
$netzgebiet->{"unit_count_$type"} = $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//var_dump($netzgebiet);
|
//var_dump($netzgebiet);
|
||||||
$netzgebiet->unit_count = $unit_count;
|
$netzgebiet->unit_count = $usable_unit_count;
|
||||||
$netzgebiet->save();
|
$netzgebiet->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,6 +168,23 @@ class ADBWohneinheit extends mfBaseModel {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStatusflag($code, $value) {
|
||||||
|
if(!$code || !$this->id) return false;
|
||||||
|
|
||||||
|
$this->log->debug("[".$this->_ruid."] ".__METHOD__." (Wohneinheit $this->id) Setting $code to $value");
|
||||||
|
|
||||||
|
$sflag = ADBStatusflagModel::getFirst(["code" => $code]);
|
||||||
|
$sflag->wohneinheit_id = $this->id;
|
||||||
|
|
||||||
|
$sflag->value->value = $value ? 1 : 0;
|
||||||
|
$sflag->value->save();
|
||||||
|
|
||||||
|
$this->log->ebug(print_r($sflag, true));
|
||||||
|
$this->log->ebug(print_r($sflag->value, true));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static function parseHausnummerZusatz($text) {
|
public static function parseHausnummerZusatz($text) {
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|||||||
@@ -223,7 +223,9 @@ class AddressDB {
|
|||||||
// seems all criteria match => set new status
|
// seems all criteria match => set new status
|
||||||
|
|
||||||
$log->debug(__METHOD__.": new Preorder Status: ".$matrix["p"]);
|
$log->debug(__METHOD__.": new Preorder Status: ".$matrix["p"]);
|
||||||
|
if(array_key_exists("pf", $matrix)) {
|
||||||
$log->debug(__METHOD__ . ": new Preorder Status flag: " . $matrix["pf"]);
|
$log->debug(__METHOD__ . ": new Preorder Status flag: " . $matrix["pf"]);
|
||||||
|
}
|
||||||
|
|
||||||
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
$preorder = PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
||||||
|
|
||||||
@@ -245,8 +247,16 @@ class AddressDB {
|
|||||||
$preorder->resetSaveNesting();
|
$preorder->resetSaveNesting();
|
||||||
}
|
}
|
||||||
if($preorderstatus_flag) {
|
if($preorderstatus_flag) {
|
||||||
|
$psflag = PreorderStatusflagModel::getFirst(["code" => $preorderstatus_flag]);
|
||||||
$log->debug(__METHOD__.": Setting Preorder Status Flag ".$preorderstatus_flag);
|
$log->debug(__METHOD__.": Setting Preorder Status Flag ".$preorderstatus_flag);
|
||||||
|
if(array_key_exists($psflag->id, $preorder->statusflags)) {
|
||||||
|
if(!$preorder->statusflags[$psflag->id]->value->value) {
|
||||||
$preorder->setStatusFlag($preorderstatus_flag);
|
$preorder->setStatusFlag($preorderstatus_flag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$preorder->setStatusFlag($preorderstatus_flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$sflag = PreorderStatusflagModel::getFirst(["code" => $preorderstatus_flag]);
|
$sflag = PreorderStatusflagModel::getFirst(["code" => $preorderstatus_flag]);
|
||||||
|
|||||||
@@ -53,6 +53,13 @@ class Cif extends Modules\ApiControllerModule {
|
|||||||
$preorder->save();
|
$preorder->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sflag = \PreorderStatusflagModel::getFirst(["code" => 200]);
|
||||||
|
$sflag->preorder_id = $preorder->id;
|
||||||
|
if(!$sflag->value->value) {
|
||||||
|
$sflag->value->value = 1;
|
||||||
|
$sflag->value->save();
|
||||||
|
}
|
||||||
|
|
||||||
return \mfResponse::Ok(["message" => "Status successfully updated."]);
|
return \mfResponse::Ok(["message" => "Status successfully updated."]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class Preorder extends mfBaseModel {
|
|||||||
private $history;
|
private $history;
|
||||||
private $citycomoan; // ONT data
|
private $citycomoan; // ONT data
|
||||||
private $ctags; // network-keyed array of Ctags
|
private $ctags; // network-keyed array of Ctags
|
||||||
|
private $statusjournals;
|
||||||
|
|
||||||
protected function beforeUpdate($data) {
|
protected function beforeUpdate($data) {
|
||||||
if(!array_key_exists("edit_by", $data)) {
|
if(!array_key_exists("edit_by", $data)) {
|
||||||
@@ -532,8 +533,8 @@ class Preorder extends mfBaseModel {
|
|||||||
|
|
||||||
if(is_array($flags) && count($flags)) {
|
if(is_array($flags) && count($flags)) {
|
||||||
foreach($flags as $flag) {
|
foreach($flags as $flag) {
|
||||||
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_MATRIX)) {
|
if(strlen($flag->value->value) && array_key_exists($flag->code, TT_PREORDER_STATUS_FLAG_MATRIX)) {
|
||||||
$flag_matrix_item = TT_PREORDER_STATUS_MATRIX[$flag->code];
|
$flag_matrix_item = TT_PREORDER_STATUS_FLAG_MATRIX[$flag->code];
|
||||||
if(!$flag_matrix_item["flag"]) continue;
|
if(!$flag_matrix_item["flag"]) continue;
|
||||||
|
|
||||||
// set hausnummer flag
|
// set hausnummer flag
|
||||||
@@ -541,19 +542,13 @@ class Preorder extends mfBaseModel {
|
|||||||
$hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]);
|
$hflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["h"]]);
|
||||||
if(!$hflag) {
|
if(!$hflag) {
|
||||||
$this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist");
|
$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
|
// set wohneiheit flag
|
||||||
@@ -561,19 +556,33 @@ class Preorder extends mfBaseModel {
|
|||||||
$wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]);
|
$wflag = ADBStatusflagModel::getFirst(["code" => $flag_matrix_item["w"]]);
|
||||||
if(!$wflag) {
|
if(!$wflag) {
|
||||||
$this->log->warn("[".$this->_ruid."] "."Statusflag Code ".$flag->code." does not exist");
|
$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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$wflagval = ADBWohneinheitStatusflagValueModel::getFirst(["wohneinheit_id" => $this->adb_wohneinheit_id, "flag_id" => $wflag->id]);
|
if(array_key_exists("ws", $flag_matrix_item) && $flag_matrix_item["ws"] && $this->adb_wohneinheit_id) {
|
||||||
if(!$wflagval) {
|
//echo "Setting Wohneinheit status to ".$flag_matrix_item["ws"]." from ".$this->getProperty("adb_wohneinheit")->status->code."\n";
|
||||||
$wflagval = ADBWohneinheitStatusflagValueModel::create([
|
// set new wohneinheit status
|
||||||
"wohneinheit_id" => $this->adb_wohneinheit_id,
|
$new_wohneinheit_status = ADBStatusModel::getFirst(["code" => $flag_matrix_item["ws"]]);
|
||||||
"flag_id" => $wflag->id,
|
if(!$new_wohneinheit_status) {
|
||||||
"value" => 0
|
$this->log->warning("[".$this->_ruid."] ".__METHOD__ . ": new ADBStatus code " . $flag_matrix_item["w"] . " not found!");
|
||||||
]);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
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") {
|
if($name == "creator") {
|
||||||
$user = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
|
$user = mfValuecache::singleton()->get("Worker-id-" . $this->create_by);
|
||||||
if($user) {
|
if($user) {
|
||||||
|
|||||||
@@ -1087,6 +1087,9 @@ class PreorderController extends mfBaseController {
|
|||||||
case "updateBilled":
|
case "updateBilled":
|
||||||
$return = $this->updateBilledApi();
|
$return = $this->updateBilledApi();
|
||||||
break;
|
break;
|
||||||
|
case "saveStatusJournal":
|
||||||
|
$return = $this->saveStatusJournalApi();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$return = false;
|
$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() {
|
protected function getLoggedEmail() {
|
||||||
$preorder_id = $this->request->pid;
|
$preorder_id = $this->request->pid;
|
||||||
$emaillog_id = $this->request->eid;
|
$emaillog_id = $this->request->eid;
|
||||||
@@ -1328,25 +1360,24 @@ class PreorderController extends mfBaseController {
|
|||||||
|
|
||||||
private function setStatusFlagApi() {
|
private function setStatusFlagApi() {
|
||||||
$preorder_id = $this->request->preorder_id;
|
$preorder_id = $this->request->preorder_id;
|
||||||
$flag_id = $this->request->flag_id;
|
$code = $this->request->code;
|
||||||
$value = $this->request->value;
|
$value = $this->request->value;
|
||||||
|
|
||||||
if(!$preorder_id || !$flag_id) {
|
if(!$preorder_id || !$code) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$flag = new PreorderStatusflag($flag_id);
|
|
||||||
if(!$flag->id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($flag_id == 1) {
|
|
||||||
$preorder = new Preorder($preorder_id);
|
$preorder = new Preorder($preorder_id);
|
||||||
if(!$preorder->id) {
|
if(!$preorder->id) return false;
|
||||||
|
|
||||||
|
$sflag = PreorderStatusflagModel::getFirst(["code" => $code]);
|
||||||
|
if(!$sflag) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$sflag->preorder_id = $preorder->id;
|
||||||
|
|
||||||
$attribute = "inhouse_cabling_supplied";
|
if ($code == 145) {
|
||||||
|
$attribute = "inhouse_cabling_supplied"; // = Starterpaket erhalten
|
||||||
$attribs = $preorder->attribute;
|
$attribs = $preorder->attribute;
|
||||||
if(!$attribs) {
|
if(!$attribs) {
|
||||||
$attribs = [];
|
$attribs = [];
|
||||||
@@ -1361,24 +1392,21 @@ class PreorderController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$flagvalue = PreorderStatusflagValueModel::getFirst(["preorder_id" => $preorder_id, "flag_id" => $flag_id]);
|
$sflag->value->value = ($value) ? 1 : 0;
|
||||||
if(!$flagvalue) {
|
|
||||||
$flagvalue = PreorderStatusflagValueModel::create([
|
|
||||||
"preorder_id" => $preorder_id,
|
|
||||||
"flag_id" => $flag_id
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$flagvalue->value = ($value) ? 1 : 0;
|
|
||||||
//var_dump($flagvalue);exit;
|
//var_dump($flagvalue);exit;
|
||||||
try {
|
try {
|
||||||
if(!$flagvalue->save()) {
|
if(!$sflag->value->save()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
$this->log->debug($e->getTraceAsString());
|
$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"];
|
return ["message" => "Statusflag saved successfully"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ class PreorderStatusflagValue extends mfBaseModel {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$history->save();
|
$history->save();
|
||||||
$this->getProperty("preorder")->afterSave();
|
|
||||||
}
|
}
|
||||||
|
$this->getProperty("preorder")->afterSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProperty($name) {
|
public function getProperty($name) {
|
||||||
|
|||||||
203
application/PreorderstatusJournal/PreorderstatusJournal.php
Normal file
203
application/PreorderstatusJournal/PreorderstatusJournal.php
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class PreorderstatusJournal extends mfBaseModel {
|
||||||
|
protected $forcestr = ["text"];
|
||||||
|
private $preorder;
|
||||||
|
private $invoice;
|
||||||
|
private $adb_wohneinheit;
|
||||||
|
private $creator;
|
||||||
|
private $editor;
|
||||||
|
|
||||||
|
|
||||||
|
public function getProperty($name) {
|
||||||
|
if($this->$name == null) {
|
||||||
|
|
||||||
|
|
||||||
|
if($name == "creator") {
|
||||||
|
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||||
|
if($creator) {
|
||||||
|
$this->creator = $creator;
|
||||||
|
return $this->creator;
|
||||||
|
}
|
||||||
|
$this->creator = new User($this->create_by);
|
||||||
|
|
||||||
|
if(!$this->creator->id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||||
|
return $this->creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($name == "editor") {
|
||||||
|
$editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||||
|
if($editor) {
|
||||||
|
$this->editor = $editor;
|
||||||
|
return $this->editor;
|
||||||
|
}
|
||||||
|
$this->editor = new User($this->edit_by);
|
||||||
|
if(!$this->editor->id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||||
|
return $this->editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************
|
||||||
|
* Begin static Model functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function create(Array $data) {
|
||||||
|
$model = new PreorderstatusJournal();
|
||||||
|
|
||||||
|
$table_fields = [
|
||||||
|
"preorder_id", "text",
|
||||||
|
"create_by","edit_by","create","edit"
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach($data as $field => $value) {
|
||||||
|
if(in_array($field, $table_fields)) {
|
||||||
|
$model->$field = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$me = new User();
|
||||||
|
$me->loadMe();
|
||||||
|
|
||||||
|
if($model->create_by === null) {
|
||||||
|
$model->create_by = $me->id;
|
||||||
|
}
|
||||||
|
if($model->edit_by === null) {
|
||||||
|
$model->edit_by = $me->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAll() {
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$res = $db->select("PreorderstatusJournal", "*", "1 = 1 ORDER BY `create`");
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
while($data = $db->fetch_object($res)) {
|
||||||
|
$items[] = new PreorderstatusJournal($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $items;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getFirst($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM PreorderstatusJournal
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY `create` LIMIT 1";
|
||||||
|
//var_dump($sql);exit;
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
$data = $db->fetch_object($res);
|
||||||
|
$item = new PreorderstatusJournal($data);
|
||||||
|
if($item->id) {
|
||||||
|
return $item;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function count($filter) {
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT COUNT(*) as cnt FROM PreorderstatusJournal
|
||||||
|
WHERE $where";
|
||||||
|
|
||||||
|
//mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$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, $order = false) {
|
||||||
|
//var_dump($filter);exit;
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
if(!$order) {
|
||||||
|
$order = "`create` ASC";
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = FronkDB::singleton();
|
||||||
|
|
||||||
|
$where = self::getSqlFilter($filter);
|
||||||
|
$sql = "SELECT * FROM PreorderstatusJournal
|
||||||
|
WHERE $where
|
||||||
|
ORDER BY $order";
|
||||||
|
|
||||||
|
if(is_array($limit) && count($limit)) {
|
||||||
|
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||||
|
} elseif(is_numeric($limit['count'])) {
|
||||||
|
$sql .= " LIMIT ".$limit['count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mfLoghandler::singleton()->debug($sql);
|
||||||
|
|
||||||
|
$res = $db->query($sql);
|
||||||
|
if($db->num_rows($res)) {
|
||||||
|
while($data = $db->fetch_object($res)) {
|
||||||
|
$items[$data->id] = new PreorderstatusJournal($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getSqlFilter($filter) {
|
||||||
|
$where = "1=1 ";
|
||||||
|
|
||||||
|
if(array_key_exists("preorder_id", $filter)) {
|
||||||
|
$preorder_id = $filter['preorder_id'];
|
||||||
|
if(is_numeric($preorder_id)) {
|
||||||
|
$where .= " AND PreorderstatusJournal.preorder_id=$preorder_id";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(array_key_exists("add-where", $filter)) {
|
||||||
|
$where .= " ".$filter['add-where'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//var_dump($filter, $where);exit;
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
db/migrations/20250910114337_preorderstatus_journal.php
Normal file
36
db/migrations/20250910114337_preorderstatus_journal.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Phinx\Migration\AbstractMigration;
|
||||||
|
|
||||||
|
final class PreorderstatusJournal extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$table = $this->table("PreorderstatusJournal");
|
||||||
|
$table->addColumn("preorder_id", "integer", ["null" => false]);
|
||||||
|
$table->addColumn("text", "text", ["null" => false]);
|
||||||
|
$table->addColumn("create_by", "integer", ["null" => false]);
|
||||||
|
$table->addColumn("edit_by", "integer", ["null" => false]);
|
||||||
|
$table->addColumn("create", "integer", ["null" => false]);
|
||||||
|
$table->addColumn("edit", "integer", ["null" => false]);
|
||||||
|
$table->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
if($this->getEnvironment() == "thetool") {
|
||||||
|
$this->table("PreorderstatusJournal")->drop()->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->getEnvironment() == "addressdb") {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user