Added Preorder attributes and checkboxes in list

This commit is contained in:
Frank Schubert
2023-03-08 14:49:47 +01:00
parent 835d9b1b58
commit 9d02064aa2
5 changed files with 142 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ ob_end_flush();
header("Content-type: text/csv");
header('Content-disposition: attachment; filename="addressdb-export-'.date('Y-m-d_H-i-s').'.csv"');
?>
AddressDB_ID;Extref;Adrcd;OAID;Netzgebiet_Extref;Netzgebiet;GKZ;Gemeinde;OKZ;Ortschaft;PLZ;SKZ;Strasse;Hausnummer;Grundstueck;GPS Breite; GPS Laenge;Rollout;Rollout_Info;Freigabe;Nutzungseinheiten;GDA-Eingenschaft;Meridian;RW;HW
AddressDB_ID;Extref;Adrcd;OAID;Netzgebiet_Extref;Netzgebiet;GKZ;Gemeinde;OKZ;Ortschaft;PLZ;SKZ;Strasse;Hausnummer;Grundstueck;GPS Breite; GPS Laenge;Rollout;Rollout_Info;Freigabe;Nutzungseinheiten;GDA-Eigenschaft;Meridian;RW;HW
<?php
$line = 0;

View File

@@ -137,7 +137,7 @@
<th>Kunde</th>
<th>Kontakt</th>
<th>Partner</th>
<th>Anschluss</th>
<th>Attribute</th>
<th>Erstellt</th>
<th>Zuletzt bearbeitet</th>
<th></th>
@@ -173,7 +173,10 @@
</td>
<td><?=($preorder->partner_id) ? $preorder->partner->getCompanyOrName() : ""?></td>
<td><?=($preorder->termination) ? $preorder->termination->code : ""?></td>
<td>
<label><input type="checkbox" name="attributes_bep_specified" id="attributes_bep_specified-<?=$preorder->id?>" data-preorder-id="<?=$preorder->id?>" value="1" <?=(is_array($preorder->attribute) && array_key_exists("bep_specified", $preorder->attribute) && $preorder->attribute["bep_specified"]) ? "checked='checked'" : ""?> /> Borderpoint festgelegt</label><br />
<label><input type="checkbox" name="attributes_inhouse_cabling_supplied" id="attributes_inhouse_cabling_supplied-<?=$preorder->id?>" data-preorder-id="<?=$preorder->id?>" value="1" <?=(is_array($preorder->attribute) && array_key_exists("inhouse_cabling_supplied", $preorder->attribute) && $preorder->attribute["inhouse_cabling_supplied"]) ? "checked='checked'" : ""?> /> Starterpaket erhalten</label>
</td>
<td><?=date('d.m.Y H:i', $preorder->create)?></td>
<td><?=date('d.m.Y H:i', $preorder->edit)?></td>
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
@@ -195,7 +198,56 @@
<script type="text/javascript">
$("#filter_type").select2({closeOnSelect: false});
$("#filter_status").select2({closeOnSelect: false});
$(document).ready(function() {
$("#filter_type").select2({closeOnSelect: false});
$("#filter_status").select2({closeOnSelect: false});
var attributes = ["bep_specified", "inhouse_cabling_supplied"];
attributes.forEach(function(attrib) {
$("input[name=attributes_" + attrib + "]").change(function(ev) {
// save new value
//console.log(ev);
var cb = $("#" + ev.currentTarget.id);
//console.log($(cb).is(":checked"));
var value = $(cb).is(":checked") ? 1 : 0;
var preorder_id = $(cb).data("preorder-id");
//console.log(preorder_id);
$.post("<?=self::getUrl("Preorder", "Api")?>", {
do: "saveAttribute",
id: preorder_id,
attribute: attrib,
value: value
},
function(success) {
if(success.status == "OK") {
attributeSuccess(success.result.id, success.result.attribute);
} else {
attributeError(success.result.id, success.result.attribute);
}
},
"json"
);
});
});
});
function attributeSuccess(id, attribute) {
$("#attributes_" + attribute + "-" + id).parent().removeClass("text-danger");
$("#attributes_" + attribute + "-" + id).parent().addClass("text-success");
setTimeout(function() {
$("#attributes_" + attribute + "-" + id).parent().removeClass("text-success");
}, 2000, id, attribute);
}
function attributeError(id, attribute) {
$("#attributes_" + attribute + "-" + id).parent().addClass("text-danger");
$("#attributes_" + attribute + "-" + id).prop("checked", !$("#attributes_" + attribute + "-" + id).is(":checked"));
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -8,6 +8,7 @@ class Preorder extends mfBaseModel {
private $building;
private $adb_hausnummer;
private $adb_wohneinheit;
private $attribute = [];
public function afterLoad() {
@@ -184,6 +185,14 @@ class Preorder extends mfBaseModel {
}
if($name == "attribute") {
if(!$this->attributes) {
return null;
}
$this->attribute = json_decode($this->attributes, true);
return $this->attribute;
}
if($name == "creator") {
$user = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($user) {

View File

@@ -126,6 +126,9 @@ class PreorderController extends mfBaseController {
}
}
if(array_key_exists("attributes", $filter) && count($filter['attributes'])) {
}
if(is_array($filter) && count($filter)) {
foreach($filter as $name => $value) {
@@ -586,4 +589,60 @@ class PreorderController extends mfBaseController {
}
protected function apiAction() {
if(!$this->me->is(["Admin","netowner","salespartner"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
case "saveAttribute":
$return = $this->saveAttributeApi();
break;
default:
$return = false;
}
if(!is_array($return) || !count($return)) {
$data = ["status" => "error"];
$this->returnJson($data);
}
$data['status'] = "OK";
$data['result'] = $return;
$this->returnJson($data);
}
private function saveAttributeApi() {
$preorder_id = $this->request->id;
if(!is_numeric($preorder_id) || $preorder_id < 1) {
return false;
}
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
$attribute = $this->request->attribute;
if(!$attribute) {
return false;
}
$value = $this->request->value;
$attribs = $preorder->attribute;
if(!$attribs) {
$attribs = [];
}
$attribs[$attribute] = $value ? 1 : 0;
$preorder->attributes = json_encode($attribs);
if($preorder->save()) {
return ["id" => $preorder_id, "attribute" => $attribute];
} else {
$this->returnJson(["status" => "error", "result" => ["id" => $preorder_id, "attribute" => $attribute]]);
}
}
}

View File

@@ -51,6 +51,7 @@ class PreorderModel {
public $shipping_address;
public $addon_services;
public $addon_data;
public $attributes;
public $submit_type;
public $submit_request;
@@ -442,6 +443,22 @@ class PreorderModel {
}
}
if(array_key_exists("attributes", $filter)) {
$attributes = FronkDB::singleton()->escape($filter['attributes']);
if(is_array($attributes) && count($attributes)) {
if(array_key_exists("bep_specified", $attributes)) {
if($attributes['bep_specified']) {
$where .= " AND JSON_EXTRACT(attributes, \"$.bep_specified\") = 1";
}
}
if(array_key_exists("inhouse_cabling_supplied", $attributes)) {
if($attributes['inhouse_cabling_supplied']) {
$where .= " AND JSON_EXTRACT(attributes, \"$.inhouse_cabling_supplied\") = 1";
}
}
}
}
// custom where clause
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];