Preorder patchposition can be edited now

This commit is contained in:
Frank Schubert
2023-12-15 18:33:29 +01:00
parent be6907fc55
commit dd07bbede6
8 changed files with 219 additions and 36 deletions

View File

@@ -337,6 +337,58 @@
</div>
<div class="col-6">
<h3>
Patchposition
<?php if($preorder->adb_wohneinheit_id): ?>
<small id="preorder-detail-<?=$preorder->id?>-patchposition-edit"><a href="#" onclick="togglePortdata(<?=$preorder->id?>); return false;"><i class="fas fa-pencil"></i> Bearbeiten</a></small>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-controls" class="hidden">
<button type="button" class="btn btn-sm btn-primary" onclick="savePortdata(<?=$preorder->id?>)"><i class="fas fa-check"></i></button>
<button type="button" class="btn btn-sm btn-secondary" onclick="togglePortdata(<?=$preorder->id?>)"><i class="fas fa-times"></i></button>
</span>
<?php endif; ?>
</h3>
<table class="table table-sm table-striped" id="preorder-detail-<?=$preorder->id?>-patchposition">
<tr>
<th>Equipment Name:</th>
<td>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-string"><?=$preorder->adb_wohneinheit->getPatchEqString()?></span>
<table class="row hidden" id="preorder-detail-<?=$preorder->id?>-patchposition-data-form">
<tr>
<th>Cluster:</td>
<td><input type="text" class="form-control" name="patch_cluster"
data-default="<?=($preorder->adb_wohneinheit->patch_cluster) ? $preorder->adb_wohneinheit->patch_cluster : $preorder->adb_hausnummer->netzgebiet->extref?>"
/></td>
</tr><tr>
<th>Shelf:</td>
<td><input type="text" class="form-control" name="patch_shelf"
data-default="<?=$preorder->adb_wohneinheit->patch_shelf?>"
/></td>
</tr><tr>
<th>Module:</td>
<td><input type="text" class="form-control" name="patch_module"
data-default="<?=$preorder->adb_wohneinheit->patch_module?>"
/></td>
</tr>
</table>
</td>
</tr>
<tr>
<th>Equipment Port:</th>
<td>
<span id="preorder-detail-<?=$preorder->id?>-patchposition-port"><?=$preorder->adb_wohneinheit->patch_port?></span>
<table class="row hidden" id="preorder-detail-<?=$preorder->id?>-patchposition-port-form">
<tr>
<th>Port:</td>
<td><input type="text" class="form-control" name="patch_port" data-default="<?=$preorder->adb_wohneinheit->patch_port?>" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
@@ -351,6 +403,67 @@
</div>
</div>
<script type="text/javascript">
function togglePortdata(pid) {
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").val($("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").data("default"));
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_shelf']").val($("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_shelf']").data("default"));
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_module']").val($("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_module']").data("default"));
$("#preorder-detail-" + pid + "-patchposition-port-form input[name='patch_port']").val($("#preorder-detail-" + pid + "-patchposition-port-form input[name='patch_port']").data("default"));
$("#preorder-detail-" + pid + "-patchposition-data-form").toggle();
$("#preorder-detail-" + pid + "-patchposition-string").toggle();
$("#preorder-detail-" + pid + "-patchposition-port-form").toggle();
$("#preorder-detail-" + pid + "-patchposition-port").toggle();
$("#preorder-detail-" + pid + "-patchposition-edit").toggle();
$("#preorder-detail-" + pid + "-patchposition-controls").toggle();
}
function savePortdata(pid) {
if(!pid) return;
var cluster = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").val();
var shelf = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_shelf']").val();
var module = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_module']").val();
var port = $("#preorder-detail-" + pid + "-patchposition-port-form input[name='patch_port']").val();
$.post("<?=self::getUrl("Preorder", "Api")?>", {
do: "savePatchposition",
id: pid,
cluster: cluster,
shelf: shelf,
module: module,
port: port
},
(success) => {
if(success.status == "OK") {
var pid = success.result.id;
var default_cluster = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").data("default");
var cluster = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").val();
var shelf = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_shelf']").val();
var module = $("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_module']").val();
var port = $("#preorder-detail-" + pid + "-patchposition-port-form input[name='patch_port']").val();
if(!cluster) cluster = default_cluster;
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_cluster']").data("default", cluster);
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_shelf']").data("default", shelf);
$("#preorder-detail-" + pid + "-patchposition-data-form input[name='patch_module']").data("default", module);
$("#preorder-detail-" + pid + "-patchposition-port-form input[name='patch_port']").data("default", port);
$("#preorder-detail-" + pid + "-patchposition-string").text(cluster + "-" + shelf + "-" + module);
$("#preorder-detail-" + pid + "-patchposition-port").text(port);
togglePortdata(pid);
}
},
"json"
);
}
function toggleStatusControl(pid, sid) {
// set select to current status id
$("#preorder-detail-status-" + pid + "-input select").val($("#preorder-detail-status-" + pid + "-text").data("status-id"));

View File

@@ -159,6 +159,20 @@ class ADBWohneinheit extends mfBaseModel {
return false;
}
public function getPatchEqString() {
$patch = "";
if($this->patch_cluster) {
$patch = $this->patch_cluster;
} else {
$patch = $this->getProperty("hausnummer")->netzgebiet->extref;
}
if($this->patch_shelf) $patch .= "-".$this->patch_shelf;
if($this->patch_module) $patch .= "-".$this->patch_module;
return $patch;
}
public function getProperty($name) {
if($this->$name == null) {

View File

@@ -11,6 +11,10 @@ class ADBWohneinheitModel {
public $zusatz;
public $bezeichner;
public $nutzung;
public $patch_cluster;
public $patch_shelf;
public $patch_module;
public $patch_port;
public $create_by = null;
public $edit_by = null;

View File

@@ -693,8 +693,10 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
$preorder_data['extref'] = (trim($this->post['extref'])) ? trim($this->post['extref']) : null;
$preorder_data['technology'] = (trim($this->post['technology'])) ? trim($this->post['technology']) : null;
/*
* patchposition now comes from RIMO
$preorder_data['equipment_name'] = (trim($this->post['equipment_name'])) ? trim($this->post['equipment_name']) : null;
$preorder_data['equipment_port'] = (trim($this->post['equipment_port'])) ? trim($this->post['equipment_port']) : null;
$preorder_data['equipment_port'] = (trim($this->post['equipment_port'])) ? trim($this->post['equipment_port']) : null;*/
/*
* setup price

View File

@@ -433,8 +433,8 @@ class Preorder extends mfBaseModel {
$a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1;
$a['isAdditionalOrder'] = ($this->is_additional_order) ? true : false;
$a['technology'] = ($this->technology) ? $this->technology : null;
$a['equipment_name'] = ($this->equipment_name) ? $this->equipment_name: null;
$a['equipment_port'] = ($this->equipment_port) ? $this->equipment_port: null;
$a['equipment_name'] = ($wohneinheit->getPatchEqString()) ? $wohneinheit->getPatchEqString(): null;
$a['equipment_port'] = ($wohneinheit->patch_port) ? $wohneinheit->patch_port: null;
$a['preorderType'] = $this->type;
$a['acceptMarketing'] = ($this->accept_marketing) ? true : false;
$a['acceptAgb'] = ($this->accept_agb) ? true : false;

View File

@@ -802,6 +802,9 @@ class PreorderController extends mfBaseController {
case "deleteWorkorder":
$return = $this->deleteWorkorderApi();
break;
case "savePatchposition":
$return = $this->savePatchpositionApi();
break;
default:
$return = false;
}
@@ -987,39 +990,43 @@ class PreorderController extends mfBaseController {
$update[] = $up;
}
/* $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, "updates" => $update];
}
private function savePatchpositionApi() {
$preorder_id = $this->request->id;
$cluster = $this->request->cluster;
$shelf = $this->request->shelf;
$module = $this->request->module;
$port = $this->request->port;
if(!is_numeric($preorder_id) || $preorder_id < 1) {
return false;
}
$preorder = new Preorder($preorder_id);
if(!$preorder->id) {
return false;
}
if(!$preorder->adb_wohneinheit_id) {
return false;
}
$we = $preorder->adb_wohneinheit;
if($cluster && $cluster != $we->cluster) {
$we->patch_cluster = $cluster;
}
$we->patch_shelf = $shelf;
$we->patch_module = $module;
$we->patch_port = $port;
$we->save();
return ["message" => "Patchposition saved successfully", "id" => $preorder->id];
}
private function deleteWorkorderApi() {
if(!$this->me->is("Admin")) {
return false;
@@ -1046,7 +1053,7 @@ class PreorderController extends mfBaseController {
}
$workorder->delete();
return ["Message" => "Workorder deleted successfully", "id" => $preorder->id];
return ["message" => "Workorder deleted successfully", "id" => $preorder->id];
}
}

View File

@@ -51,8 +51,6 @@ class PreorderModel {
public $phone;
public $email;
public $technology;
public $equipment_name;
public $equipment_port;
public $is_additional_order;
public $shipping_address;
public $addon_services;

View File

@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class WohneinheitAddPatchdata extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Preorder");
$table->removeColumn("equipment_name");
$table->removeColumn("equipment_port");
$table->save();
}
if($this->getEnvironment() == "addressdb") {
$table = $this->table("Wohneinheit");
$table->addColumn("patch_cluster", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "nutzung"]);
$table->addColumn("patch_shelf", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "patch_cluster"]);
$table->addColumn("patch_module", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "patch_shelf"]);
$table->addColumn("patch_port", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "patch_module"]);
$table->update();
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Preorder");
$table->addColumn("equipment_name", "string", ["null" => true, "default" => null, "limit" => 1024, "after" => "technology"]);
$table->addColumn("equipment_port", "string", ["null" => true, "default" => null, "limit" => 1024, "after" => "equipment_name"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
$table = $this->table("Wohneinheit");
$table->removeColumn("patch_port");
$table->removeColumn("patch_module");
$table->removeColumn("patch_shelf");
$table->removeColumn("patch_cluster");
$table->save();
}
}
}