Setting preorder status triggers status update on hausnummer and
wohneinhiet
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
</tr><tr>
|
||||
<th>Status:</th>
|
||||
<td class="text-monospace">
|
||||
<span id="preorder-detail-status-<?=$preorder->id?>-text"><span id="preorder-detail-status-<?=$preorder->id?>-statustext"><?=$preorder->status->code?> - <?=$preorder->status->name?></span> <a href="#" onclick="return toggleStatusControl(<?=$preorder->id?>, <?=$preorder->status_id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
|
||||
<span id="preorder-detail-status-<?=$preorder->id?>-text" data-status-id="<?=$preorder->status_id?>"><span id="preorder-detail-status-<?=$preorder->id?>-statustext"><?=$preorder->status->code?> - <?=$preorder->status->name?></span> <a href="#" onclick="return toggleStatusControl(<?=$preorder->id?>)"><i class="fas fa-fw fa-edit"></i></a></span>
|
||||
<div class="input-group" id="preorder-detail-status-<?=$preorder->id?>-input" style="display:none">
|
||||
<select class="form-control">
|
||||
<?php foreach(PreorderstatusModel::getAll() as $status): ?>
|
||||
@@ -172,7 +172,8 @@
|
||||
<td class="text-monospace text-pink"><?=$preorder->adb_hausnummer->oaid?></td>
|
||||
</tr><tr>
|
||||
<th>Status</th>
|
||||
<td class="text-monospace"><?=$preorder->adb_hausnummer->status->code?> - <?=$preorder->adb_hausnummer->status->name?></td>
|
||||
<td id="preorder-detail-building-status-<?=$preorder->id?>" class="text-monospace"><?=$preorder->adb_hausnummer->status->code?> - <?=$preorder->adb_hausnummer->status->name?></td>
|
||||
|
||||
</tr><tr>
|
||||
<th>Extref</th>
|
||||
<td class="text-monospace"><?=$preorder->adb_hausnummer->extref?></td>
|
||||
@@ -195,7 +196,7 @@
|
||||
<td class="text-monospace"><?=($preorder->adb_wohneinheit_id) ? $preorder->adb_wohneinheit_id : ""?></td>
|
||||
</tr><tr>
|
||||
<th>Status</th>
|
||||
<td class="text-monospace"><?=$preorder->adb_wohneinheit->status->code?> - <?=$preorder->adb_wohneinheit->status->name?></td>
|
||||
<td id="preorder-detail-unit-status-<?=$preorder->id?>" class="text-monospace"><?=$preorder->adb_wohneinheit->status->code?> - <?=$preorder->adb_wohneinheit->status->name?></td>
|
||||
</tr><tr>
|
||||
<th>OAID</th>
|
||||
<td class="text-monospace text-pink"><?=$preorder->adb_wohneinheit->oaid?></td>
|
||||
@@ -345,7 +346,10 @@
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
function toggleStatusControl(pid, sid) {
|
||||
$("#preorder-detail-status-" + pid + "-input select").val(sid);
|
||||
// set select to current status id
|
||||
$("#preorder-detail-status-" + pid + "-input select").val($("#preorder-detail-status-" + pid + "-text").data("status-id"));
|
||||
|
||||
// toggle controls
|
||||
$("#preorder-detail-status-" + pid + "-text").toggle();
|
||||
$("#preorder-detail-status-" + pid + "-input").toggle();
|
||||
|
||||
@@ -367,15 +371,31 @@
|
||||
},
|
||||
function(success) {
|
||||
if(success.status == "OK") {
|
||||
$("#preorder-detail-status-" + pid + "-statustext").text(success.result.status_code + " - " + success.result.status_text);
|
||||
var update = success.result.update;
|
||||
if("preorder" in update) {
|
||||
// update detail status text
|
||||
$("#preorder-detail-status-" + pid + "-statustext").text(update.preorder.status.code + " - " + update.preorder.status.text);
|
||||
$("#preorder-detail-status-" + pid + "-text").addClass("text-success");
|
||||
setTimeout(() => { $("#preorder-detail-status-" + pid + "-text").removeClass("text-success") }, 1500);
|
||||
|
||||
// update list status text
|
||||
$("#preorder-" + pid + " .status").text(update.preorder.status.code + " - " + update.preorder.status.text);
|
||||
$("#preorder-" + pid + " .status").addClass("text-success");
|
||||
setTimeout(() => { $("#preorder-" + pid + " .status").removeClass("text-success") }, 1500);
|
||||
|
||||
// update status id data attribute
|
||||
$("#preorder-detail-status-" + pid + "-text").data("status-id", update.preorder.status.id);
|
||||
}
|
||||
|
||||
$("#preorder-detail-status-" + pid + "-text").addClass("text-success");
|
||||
setTimeout(() => { $("#preorder-detail-status-" + pid + "-text").removeClass("text-success") }, 1500);
|
||||
if("building" in update) {
|
||||
$("#preorder-detail-building-status-" + pid).text(update.building.status.code + " - " + update.building.status.text);
|
||||
}
|
||||
if("unit" in update) {
|
||||
$("#preorder-detail-unit-status-" + pid).text(update.unit.status.code + " - " + update.unit.status.text);
|
||||
}
|
||||
|
||||
$("#preorder-" + pid + " .status").text(success.result.status_code + " - " + success.result.status_text);
|
||||
$("#preorder-" + pid + " .status").addClass("text-success");
|
||||
setTimeout(() => { $("#preorder-" + pid + " .status").removeClass("text-success") }, 1500);
|
||||
toggleStatusControl(pid);
|
||||
|
||||
}
|
||||
},
|
||||
'json');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class StatusModel {
|
||||
class ADBStatusModel {
|
||||
public $code;
|
||||
public $name;
|
||||
|
||||
@@ -10,7 +10,7 @@ class StatusModel {
|
||||
public $edit;
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new Status();
|
||||
$model = new ADBStatus();
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(property_exists(get_called_class(), $field)) {
|
||||
@@ -39,7 +39,7 @@ class StatusModel {
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$res = $db->select("Status", "*");
|
||||
if($db->num_rows($res)) {
|
||||
@@ -52,13 +52,13 @@ class StatusModel {
|
||||
}
|
||||
|
||||
public static function getFirst($filter = false) {
|
||||
$db = FronkDB::singleton();
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("Status", "*", "$where ORDER BY code, name");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new Status($data);
|
||||
$item = new ADBStatus($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ class StatusModel {
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM Status
|
||||
@@ -88,7 +88,7 @@ class StatusModel {
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
@@ -110,7 +110,7 @@ class StatusModel {
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Status($data);
|
||||
$items[] = new ADBStatus($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
@@ -151,7 +151,7 @@ class AdminController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function ivtAdminImportAction() {
|
||||
//exit;
|
||||
exit;
|
||||
$doit = false;
|
||||
if($this->request->doit == 1) {
|
||||
$doit = true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class Admin_IvtAdminImport {
|
||||
$data = [];
|
||||
$data['ignore'] = 0;
|
||||
$data["contracts"] = [];
|
||||
foreach(IvtCustomerProductModel::search(["pid" => 784]) as $ivt_contract) {
|
||||
foreach(IvtCustomerProductModel::getAll() as $ivt_contract) {
|
||||
$ivt_customer = $ivt_contract->customer;
|
||||
$ivt_product = $ivt_contract->product;
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ class Preorder extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// reset auto magic properties
|
||||
$this->status = null;
|
||||
$this->campaign = null;
|
||||
$this->partner = null;
|
||||
$this->building = null;
|
||||
$this->adb_hausnummer = null;
|
||||
$this->adb_wohneinheit = null;
|
||||
$this->services = null;
|
||||
$this->ordered_services = null;
|
||||
$this->creator = null;
|
||||
$this->editor = null;
|
||||
|
||||
// prevent potential infinite loop
|
||||
if($this->in_after_save) return true;
|
||||
$this->in_after_save = true;
|
||||
@@ -35,6 +47,95 @@ class Preorder extends mfBaseModel {
|
||||
if($this->oaid != $old_oaid) {
|
||||
$this->save();
|
||||
}
|
||||
|
||||
// Cascade status changes down to adb_hausnummer and adb_wohneinheit
|
||||
$this->cascadeStatus();
|
||||
}
|
||||
|
||||
/*
|
||||
* Cascade status changes down to adb_hausnummer and adb_wohneinheit
|
||||
*/
|
||||
public function cascadeStatus() {
|
||||
|
||||
/*
|
||||
* defines status alignments of preorder status to hausnummer (h) and wohneinheit (w)
|
||||
* if h or w are greater than defined here, don't change them
|
||||
*
|
||||
* $statusmatrix = [
|
||||
* "preorder_status_code" => [
|
||||
* "h" => adb_status_code,
|
||||
* "w" => adb_status_code
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
|
||||
if(!$this->adb_hausnummer_id && !$this->adb_wohneinheit_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!defined("TT_PREORDER_STATUS_MATRIX") || !is_array(TT_PREORDER_STATUS_MATRIX) || !count(TT_PREORDER_STATUS_MATRIX)) {
|
||||
$this->log->warning(__METHOD__.": TT_PREORDER_STATUS_MATRIX undefined! Cannot cascade Preorder status to Hausnummer and Wohneinheit");
|
||||
return true;
|
||||
}
|
||||
|
||||
$new_status = new Preorderstatus($this->status_id);
|
||||
if(!$new_status->id) {
|
||||
$this->log->warning(__METHOD__.": Preorder has invalid status!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!array_key_exists($new_status->code, TT_PREORDER_STATUS_MATRIX)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$cascade = TT_PREORDER_STATUS_MATRIX[$new_status->code];
|
||||
|
||||
if($cascade["h"] && $this->adb_hausnummer_id) {
|
||||
// set new hausnummer status
|
||||
$new_hausnummer_status = ADBStatusModel::getFirst(["code" => $cascade["h"]]);
|
||||
if(!$new_hausnummer_status) {
|
||||
$this->log->warning(__METHOD__.": new ADBStatus code ".$cascade["h"]." not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
|
||||
if(!$hausnummer->id) {
|
||||
$this->log->warning(__METHOD__.": hausnummer ".$this->adb_hausnummer_id." not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->log->debug(__METHOD__.": new hausnummer status code ".$new_hausnummer_status->code);
|
||||
|
||||
// only update if current status is less than new status
|
||||
if($hausnummer->status->code < $new_hausnummer_status->code) {
|
||||
$this->log->debug(__METHOD__.": Setting new hausnummer status code: ".$new_hausnummer_status->code);
|
||||
$hausnummer->status_id = $new_hausnummer_status->id;
|
||||
$hausnummer->save();
|
||||
}
|
||||
}
|
||||
|
||||
if($cascade["w"] && $this->adb_wohneinheit_id) {
|
||||
// set new wohneinheit status
|
||||
$new_wohneinheit_status = ADBStatusModel::getFirst(["code" => $cascade["w"]]);
|
||||
if(!$new_wohneinheit_status) {
|
||||
$this->log->warning(__METHOD__.": new ADBStatus code ".$cascade["w"]." not found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
$wohneinheit = new ADBWohneinheit($this->adb_wohneinheit_id);
|
||||
if(!$wohneinheit->id) return true;
|
||||
|
||||
$this->log->debug(__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(__METHOD__.": Setting new wohneinheit status code: ".$new_wohneinheit_status->code);
|
||||
$wohneinheit->status_id = $new_wohneinheit_status->id;
|
||||
$wohneinheit->save();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function setOrCreateOaid($oaid_attributes = false) {
|
||||
|
||||
@@ -963,7 +963,38 @@ class PreorderController extends mfBaseController {
|
||||
$preorder->status_id = $status_id;
|
||||
$preorder->save();
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $preorder_id, "status_id" => $status->id, "status_code" => $status->code, "status_text" => $status->name];
|
||||
|
||||
$update = [
|
||||
"preorder" => [
|
||||
"status" => [
|
||||
"id" => $status->id,
|
||||
"code" => $status->code,
|
||||
"text" => $status->name
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
if($preorder->adb_hausnummer_id) {
|
||||
$update["building"] = [
|
||||
"status" => [
|
||||
"id" => $preorder->adb_hausnummer->status->id,
|
||||
"code" => $preorder->adb_hausnummer->status->code,
|
||||
"text" => $preorder->adb_hausnummer->status->name
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
if($preorder->adb_wohneinheit_id) {
|
||||
$update["unit"] = [
|
||||
"status" => [
|
||||
"id" => $preorder->adb_wohneinheit->status->id,
|
||||
"code" => $preorder->adb_wohneinheit->status->code,
|
||||
"text" => $preorder->adb_wohneinheit->status->name
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return ["message" => "Status saved successfully", "id" => $preorder_id, "update" => $update];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user