WIP Contractqueue & snopp api

This commit is contained in:
Frank Schubert
2024-04-05 12:21:54 +02:00
parent e69b271295
commit 059b26ba33
13 changed files with 795 additions and 89 deletions

View File

@@ -35,7 +35,12 @@
<label class="form-label" for="filter_owner">Kundennummer</label>
<input type="text" class="form-control" name="filter[customer_number]" id="filter_street" value="<?=(array_key_exists("customer_number", $filter)) ? $filter['customer_number'] : ""?>" />
</div>
<div class="col-1">
<label class="form-label" for="filter_owner">Order ID</label>
<input type="text" class="form-control" name="filter[order_id]" id="filter_order_id" value="<?=(array_key_exists("order_id", $filter)) ? $filter['order_id'] : ""?>" />
</div>
<div class="col-1">
<label class="form-label" for="filter_owner">Inhaber Name</label>
<input type="text" class="form-control" name="filter[owner]" id="filter_street" value="<?=(array_key_exists("owner", $filter)) ? $filter['owner'] : ""?>" />
@@ -105,34 +110,79 @@
<div class="row">
<div class="col-6">
<div class="card">
<div class="card" id="owner-<?=$order_id?>">
<div class="card-body">
<div>
<span class="float-right"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('owner', <?=$order_id?>, false)"></i></span>
<h5 class="m-0">Inhaber</h5>
</div>
<hr class="mt-1" />
<span class="text-monospace"><?=$order->owner->customer_number?></span><br />
<strong><?=$order->owner->getCompanyOrName()?></strong><br />
<?=$order->owner->street?><br />
<?=$order->owner->zip?> <?=$order->owner->city?><br />
<div class="text">
<span class="text-monospace"><?=$order->owner->customer_number?></span><br />
<strong><?=$order->owner->getCompanyOrName()?></strong><br />
<?=$order->owner->street?><br />
<?=$order->owner->zip?> <?=$order->owner->city?><br />
</div>
<div class="edit hidden">
<div class="input-group mb-3">
<select
name="owner_id-<?=$order_id?>"
class="form-control basicAutoComplete"
autocomplete="off"
id="owner_id-<?=$order_id?>"
data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1"
placeholder="Tippen zum Suchen... (Bestandskunden)"
data-noresults-text="Keine Suchergebnisse"
data-val="<?=$order->owner_id?>"
data-ov="<?=$order->owner_id?>"
>
<option></option>
</select>
<div class="input-group-append">
<button class="btn btn-primary" onclick="saveAddress('owner', <?=$order_id?>)"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('owner', <?=$order_id?>, false)"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card" id="billingaddress-<?=$order_id?>">
<div class="card-body">
<div>
<span class="float-right"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('billingaddress', <?=$order_id?>, false)"></i></span>
<h5 class="m-0">Rechnungsempfänger</h5>
<hr class="mt-1" />
</div>
<?php if($order->billingaddress_id): ?>
<?=($order->billingaddress->customer_number) ? $order->billingaddress->customer_number."<br />" : ""?>
<?=$order->billingaddress->getCompanyOrName()?><br />
<?=$order->billingaddress->street?><br />
<?=$order->billingaddress->zip?> <?=$order->billingaddress->city?><br />
<?php endif; ?>
<hr class="mt-1" />
<div class="text">
<?php if($order->billingaddress_id): ?>
<?=($order->billingaddress->customer_number) ? $order->billingaddress->customer_number."<br />" : ""?>
<?=$order->billingaddress->getCompanyOrName()?><br />
<?=$order->billingaddress->street?><br />
<?=$order->billingaddress->zip?> <?=$order->billingaddress->city?><br />
<?php endif; ?>
</div>
<div class="edit hidden">
<div class="input-group mb-3">
<select
name="billingaddress_id-<?=$order_id?>"
class="form-control basicAutoComplete"
autocomplete="off"
id="billingaddress_id-<?=$order_id?>"
data-url="<?=self::getUrl('Address','api')?>?do=findAddress&autocomplete=1"
placeholder="Tippen zum Suchen... (Bestandskunden)"
data-noresults-text="Keine Suchergebnisse"
data-val="<?=$order->billingaddress_id?>"
data-ov="<?=$order->billingaddress_id?>"
>
<option></option>
</select>
<div class="input-group-append">
<button class="btn btn-primary" onclick="saveAddress('billingaddress', <?=$order_id?>)"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('billingaddress', <?=$order_id?>, false)"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -199,7 +249,7 @@
<td><input type="checkbox" class="form-control pointer" id="approve-order-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'order')" <?=($contract->approved) ? "checked='checked'" : ""?> /></td>
<td class="text-wrap product">
<div class="text">
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"></i> <?=$contract->product_name?>
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"></i> <span class="value"><?=$contract->product_name?></span>
<?php if($contract->termination_id && $contract->termination): ?>
<br /><small class="text-pink"><?=$contract->termination->code?> - <?= str_replace("\n", " - ", $contract->termination->getAddress())?></small>
<?php endif ?>
@@ -208,7 +258,7 @@
<div class="input-group mb-3">
<select class="edit-control form-control" data-val="<?=$contract->product_id?>" data-ov="<?=$contract->product_id?>"></select>
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'product')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'product')"><i class="fas fa-times"></i></button>
</div>
</div>
@@ -216,37 +266,37 @@
</td>
<td class="matchcode">
<div class="text">
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'matchcode')"></i> <?= htmlentities($contract->matchcode)?>
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'matchcode')"></i> <span class="value"><?=htmlentities($contract->matchcode)?></span>
</div>
<div class="edit hidden">
<div class="input-group mb-3">
<input type="text" class="form-control edit-control" value="<?=$contract->matchcode?>" data-val="<?=htmlentities($contract->matchcode)?>" data-ov="<?=htmlentities($contract->matchcode)?>" />
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'matchcode')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'matchcode')"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</td>
<td class="price">
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price')"></i> € <?=$contract->price?></div>
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price')"></i> € <span class="value"><?=$contract->price?></span></div>
<div class="edit hidden">
<div class="input-group mb-3">
<input type="text" class="form-control edit-control" value="<?=$contract->price?>" data-val="<?=$contract->price?>" data-ov="<?=$contract->price?>" />
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'price')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price')"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</td>
<td class="price_setup">
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price_setup')"></i> € <?=$contract->price_setup?></div>
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price_setup')"></i> € <span class="value"><?=$contract->price_setup?></span></div>
<div class="edit hidden">
<div class="input-group mb-3">
<input type="text" class="form-control edit-control" value="<?=$contract->price_setup?>" data-val="<?=$contract->price_setup?>" data-ov="<?=$contract->price_setup?>" />
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'price_setup')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'price_setup')"><i class="fas fa-times"></i></button>
</div>
</div>
@@ -255,15 +305,19 @@
<td class="billing_period">
<div class="text">
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_period')"></i>
<?php if($contract->billing_period == 1): ?>
monatlich
<?php elseif($contract->billing_period == 24): ?>
biennal
<?php elseif($contract->billing_period == 36): ?>
triennal
<?php else: ?>
<?=(12 / $contract->billing_period)?>x Jährlich
<?php endif; ?>
<span class="value">
<?php if($contract->billing_period == 1): ?>
monatlich
<?php elseif($contract->billing_period == 12): ?>
Jährlich
<?php elseif($contract->billing_period == 24): ?>
2-jährlich
<?php elseif($contract->billing_period == 36): ?>
3-jährlich
<?php else: ?>
<?=(12 / $contract->billing_period)?>x Jährlich
<?php endif; ?>
</span>
</div>
<div class="edit hidden">
<div class="input-group mb-3">
@@ -274,19 +328,19 @@
<option value="36" <?=($contract->billing_period == 36) ? "selected='selected'" : ""?>>3-Jährlich</option>
</select>
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'billing_period')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_period')"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</td>
<td class="billing_delay">
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_delay')"></i> <?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></div>
<div class="text"><i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_delay')"></i> <span class="value"><?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></span></div>
<div class="edit hidden">
<div class="input-group mb-3">
<input type="text" class="form-control edit-control" value="<?=$contract->billing_delay?>" data-val="<?=$contract->billing_delay?>" data-ov="<?=$contract->billing_delay?>" />
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="saveEdit('contract', <?=$contract->id?>, 'billing_delay')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('contract', <?=$contract->id?>, 'billing_delay')"><i class="fas fa-times"></i></button>
</div>
</div>
@@ -309,45 +363,50 @@
<th>Rechnungsperiode</th>
<th>Verz. Verrechnungsstart</th>
</tr>
<?php foreach($contracts as $contract): ?>
<?php $credit = $contract->getCredit(); if(!$credit) continue; ?>
<tr id="credit-<?=$contract->id?>">
<td><input type="checkbox" class="form-control pointer" id="approve-credit-<?=$order_id?>-contract-<?=$contract->id?>" onclick="toggleApproval(<?=$order_id?>, 'credit')" <?=($contract->approved) ? "checked='checked'" : ""?> /></td>
<td><?=($credit["partner"]) ? $credit["partner"]->getCompanyOrName() : ""?></td>
<td class="text-wrap">
<?=$contract->product_name?>
<td class="crediting_partner_name text value"><?=($credit["partner"]) ? $credit["partner"]->getCompanyOrName() : ""?></td>
<td class="text-wrap product text">
<span class="value"><?=$contract->product_name?></span>
<?php if($contract->termination_id && $contract->termination): ?>
<br /><small class="text-pink"><?=$contract->termination->code?> - <?= str_replace("\n", " - ", $contract->termination->getAddress())?></small>
<?php endif ?>
<?php endif; ?>
</td>
<td class="matchcode">
<td class="crediting_matchcode">
<div class="text">
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"></i> <?=$contract->matchcode?>
<i class="fas fa-fw fa-pencil pointer text-primary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"></i> <span class="value"><?=$contract->crediting_matchcode?></span>
</div>
<div class="edit hidden">
<div class="input-group mb-3">
<input type="text" class="form-control edit-control" value="<?=$contract->matchcode?>" data-val="<?=$contract->matchcode?>" data-ov="<?=$contract->matchcode?>" />
<input type="text" class="form-control edit-control" value="<?=$contract->matchcode?>" data-val="<?=$contract->crediting_matchcode?>" data-ov="<?=$contract->crediting_matchcode?>" />
<div class="input-group-append">
<button class="btn btn-primary"><i class="fas fa-check"></i></button>
<button class="btn btn-primary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"><i class="fas fa-check"></i></button>
<button class="btn btn-secondary" onclick="toggleEdit('credit', <?=$contract->id?>, 'matchcode')"><i class="fas fa-times"></i></button>
</div>
</div>
</div>
</td>
<td><?=($credit["rate_source"] == "rate") ? "€ ".$credit["rate"] : "€ ".$contract->price_nne?> <?=($credit["rate_source"] == "rate") ? "(Prozentrate)" : "(NNE)"?></td>
<td>
<td class="crediting_partner_rate text value">
<?=($credit["rate_source"] == "rate") ? "€ ".$credit["rate"] : "€ ".$contract->price_nne?> <?=($credit["rate_source"] == "rate") ? "(Prozentrate)" : "(NNE)"?>
</td>
<td class="billing_period text value">
<?php if($contract->billing_period == 1): ?>
monatlich
monatlich
<?php elseif($contract->billing_period == 24): ?>
biennal
3-jährlich
<?php elseif($contract->billing_period == 36): ?>
triennal
3-jährlich
<?php else: ?>
<?=(12 / $contract->billing_period)?>x Jährlich
<?php endif; ?>
</td>
<td class=""><?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></td>
<td class="billing_delay text value"><?=($contract->billing_delay) ? $contract->billing_delay." Monate" : ""?></td>
</tr>
<?php endforeach; ?>
</table>
@@ -383,7 +442,9 @@
?>
var products = <?=json_encode($prods)?>;
function toggleOrderApproval(cbox, order_id, type) {
if(!parseInt(order_id) || !order_id) return;
@@ -413,39 +474,207 @@
$("#" + type + "-products-" + order_id + " .checkbox-toggle").prop("checked", false);
}
}
function toggleEdit(type, id, control_name) {
var textBlock = $("#" + type + "-" + id + " ." + control_name + " .text");
var editBlock = $("#" + type + "-" + id + " ." + control_name + " .edit");
var control = $("#" + type + "-" + id + " ." + control_name + " .edit .edit-control");
var current_val = control.data("val");
var original_val = control.data("ov");
textBlock.toggle();
editBlock.toggle();
if(type == "owner" || type == "billingaddress") {
return;
}
if(control_name == "product") {
if(!control.children().length) {
products.forEach((product) => {
var opt = document.createElement("option");
opt.text = product.name;
opt.value = product.id;
control.append(opt);
function toggleEdit(type, id, control_name) {
if(type === "owner" || type === "billingaddress") {
$("#" + type + "-" + id + " .text").toggle();
$("#" + type + "-" + id + " .edit").toggle();
if($("#" + type + "-" + id + " .edit").is(":visible")) {
console.log("visible");
$("#" + type + "-" + id + " .edit select").autoComplete();
}
return;
}
var textBlock = $("#" + type + "-" + id + " ." + control_name + " .text");
var editBlock = $("#" + type + "-" + id + " ." + control_name + " .edit");
var control = $("#" + type + "-" + id + " ." + control_name + " .edit .edit-control");
var current_val = control.data("val");
var original_val = control.data("ov");
textBlock.toggle();
editBlock.toggle();
if(control_name == "product") {
if(!control.children().length) {
products.forEach((product) => {
var opt = document.createElement("option");
opt.text = product.name;
opt.value = product.id;
control.append(opt);
});
console.log(current_val);
control.val(current_val);
}
}
}
function saveEdit(type, id, control_name) {
var textBlock = $("#" + type + "-" + id + " ." + control_name + " .text");
var editBlock = $("#" + type + "-" + id + " ." + control_name + " .edit");
var control = $("#" + type + "-" + id + " ." + control_name + " .edit .edit-control");
control.removeClass("invalid");
var current_val = control.data("val");
var original_val = control.data("ov");
var new_value = control.val();
console.log(new_value);
if(!new_value.length && control_name !== "billing_delay") {
control.addClass("invalid");
return;
}
var action = "saveContract";
if(type === "credit") {
var action = "saveCredit";
}
var data = {};
data["do"] = action;
data["id"] = id;
data[control_name] = new_value;
console.log(data);
var ctx = {id: id, control_name: control_name};
// save
$.ajax({
url: "<?=self::getUrl("Contractqueue", "api")?>",
type: "POST",
data: data,
context: ctx,
success: function (success) {
console.log(ctx);
const id = ctx.id;
const control_name = ctx.control_name;
var textBlock = $("#" + type + "-" + id + " ." + control_name + " .text");
var editBlock = $("#" + type + "-" + id + " ." + control_name + " .edit");
//console.log(success);
if(success.status != "OK") {
$("#" + type + "-" + id + " ." + control_name + " .edit .edit-control").addClass("invalid");
return;
}
Object.entries(success.result.contract).forEach(item => {
const [key, value] = item;
console.log(key + ": " + value);
var text = $("#contract-" + id + " ." + key + " .text .value");
var control = $("#contract-" + id + " ." + key + " .edit .edit-control");
if (text.length && control.length) {
if(key === "billing_period") {
switch (parseInt(value)) {
case 1:
text.text("Monatlich");
$("#credit-" + id + " .billing_period.text.value").text("Monatlich");
break;
case 12:
text.text("Jährlich");
$("#credit-" + id + " .billing_period.text.value").text("Jährlich");
break;
case 24:
text.text("2-Jährlich");
$("#credit-" + id + " .billing_period.text.value").text("2-Jährlich");
break;
case 36:
text.text("3-Jährlich");
$("#credit-" + id + " .billing_period.text.value").text("3-Jährlich");
break;
}
} else if(key === "billing_delay") {
if (value > 0) {
text.text(value + " Monate");
$("#credit-" + id + " .billing_delay.text.value").text(value + " Monate");
} else {
text.text("");
$("#credit-" + id + " .billing_delay.text.value").text("");
}
} else if(key === "product") {
var product_name = success.result.contract.product_name;
text.text(product_name);
$("#credit-" + id + " .product.text .value").text(product_name);
} else {
text.text(value);
}
control.data("val", value);
control.data("ov", value);
}
});
Object.entries(success.result.credit).forEach(item => {
const [key, value] = item;
console.log(key + ": " + value);
var text = $("#credit-" + id + " ." + key + " .text .value");
//var control = $("#credit-" + id + " ." + key + " .edit .edit-control");
if(key === "crediting_rate") {
console.log(success.result.credit.crediting_partner_text);
$("#credit-" + id + " .crediting_partner_rate.text.value").text(success.result.credit.crediting_partner_text);
} /*else if(key === "crediting_partner_id") {
if(!value) {
$("#credit-" + id + " .crediting_partner_text.text.value").text("");
}
$("#credit-" + id + " .crediting_partner_text.text.value").text(value);
}*/ else {
text.text(value);
}
});
editBlock.hide();
textBlock.show();
},
dataType: "json"
});
console.log(current_val);
control.val(current_val);
}
return;
}
}
function saveAddress(type, id) {
var new_value = $("input[name='" + type + "_id-" + id + "'").val();
$.ajax({
url: "<?=self::getUrl("Address", "api")?>",
type: "GET",
context: id,
data: {
do: "getAddress",
id: new_value
},
success: function(success) {
if(success.status !== "OK") {
return;
}
address = success.result.address;
$("#" + type + "-" + id + " .text").html(
`<span class="text-monospace">${address.customer_number}</span><br />
<strong>${address.name}</strong><br />
${address.street}<br />
${address.zip} ${address.city}<br />`
);
$("#" + type + "-" + id + " .text").toggle();
$("#" + type + "-" + id + " .edit").toggle();
},
dataType: "json"
});
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>

View File

@@ -21,7 +21,7 @@
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<div class="card-body bg-">
<h4 class="header-title mb-2"><?=($network->id) ? "Netzbereich bearbeiten" : "Neuer Netzbereich"?></h4>
<form class="form-horizontal" method="post" action="<?=self::getUrl("Network", "save")?>">
@@ -74,6 +74,19 @@
</select>
</div>
</div>
<hr />
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="opsystem"></label>
<div class="col-lg-10">
<label class="form-check-label">
<input type="checkbox" name="opsystem" class="form-check-input" value="snopp" id="opsystem" <?=($network->opsystem == "snopp") ? "checked='checked'" : ""?> />
Für Betrieb in SNOPP freischalten
</label>
</div>
</div>
</div>
</div>

View File

@@ -481,6 +481,7 @@ class AddressController extends mfBaseController {
}
$a = $address->toArray();
$a['name'] = $address->getCompanyOrName();
return ['address' => $a];
}

View File

@@ -0,0 +1,265 @@
<?php
use application\Api\v1\Modules;
class OperationaldataApicontroller extends mfBaseApicontroller
{
//private $filter_gemeinde_ids = [];
//private $campaign;
private $campaign;
private $campaigns = [];
private $filter_salescluster_ids = [];
private $campaigns_by_scluster = [];
private $allowed_preordertypes = [];
private $district_is_city = false;
private $hausnummer_add_zusatz = false;
private $exist_is_error = false;
protected function init()
{
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
}
protected function registerRoutes()
{
/*
* TODO: Load Api Modules automatically in mfBaseApiController
*/
/*$modules = [];
foreach (["Cif", "Activation"] as $moduleName) {
$classname = "application\\Api\\v1\\Modules\\Preorder\\" . $moduleName;
$modules[$moduleName] = new $classname([
"get" => $this->get,
"post" => $this->post,
"db" => $this->db(),
"me" => $this->me
]);
}*/
$this->addRoute("/operationaldata/networks", "getNetworks", "GET");
$this->addRoute("/operationaldata/preordercampaigns", "getPreorderCampaigns", "GET");
$this->addRoute("/operationaldata/buildings", "getBuildingsByCampaign", "GET");
/*$this->addRoute("/preorder/open", "getOpenPreorders", "GET");
$this->addRoute("/preorder/customerInstallationFeedback", [$modules["Cif"], "getCifData"], "GET");
$this->addRoute("/preorder/customerInstallationFeedback", [$modules["Cif"], "userSetCif"], "POST");
$this->addRoute("/preorder/:code/clientInstallationFinished", [$modules["Cif"], "providerSetCif"], "POST");
$this->addRoute("/preorder/:code/serviceActivated", [$modules["Activation"], "setServiceActive"], "POST");
$this->addRoute("/preorder/:code", "getPreorder", "GET");
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
*/
}
/*
* is called after User is authenticated by API Key
*/
protected function authenticated()
{
$this->registerRoutes();
if ($this->me->is("preorderaddressreporting")) {
return mfResponse::Forbidden();
}
$campaignApiusers = PreordercampaignApiuserModel::search(["worker_id" => $this->me->id]);
foreach ($campaignApiusers as $campaignApiuser) {
$campaign = new Preordercampaign($campaignApiuser->preordercampaign_id);
if ($campaign->id) {
foreach (PreordercampaignSalesclusterModel::search(['preordercampaign_id' => $campaign->id]) as $campain_scluster) {
if (!in_array($campain_scluster->salescluster_id, $this->filter_salescluster_ids)) {
$this->filter_salescluster_ids[] = $campain_scluster->salescluster_id;
}
$this->campaigns_by_scluster[$campain_scluster->salescluster_id] = $campaign->id;
}
$this->campaigns[$campaign->id] = $campaign;
// get allowed preordertypes
if (is_array($campaign->types) && count($campaign->types)) {
foreach ($campaign->types as $type) {
$this->allowed_preordertypes[] = $type->type;
}
}
if ($campaign->district_is_city == 1) {
$this->district_is_city = true;
}
if ($campaign->hausnummer_add_zusatz == 1) {
$this->hausnummer_add_zusatz = true;
}
if ($campaign->exist_is_error == 1) {
$this->exist_is_error = true;
}
if ($campaign->require_connectiontype == 1) {
$this->require_connectiontype = true;
}
if ($campaign->allow_unit_update == 1) {
$this->allow_unit_update = true;
}
} else {
$this->log->debug(__METHOD__ . ": campaign not found (PreordercampaignApiuser::preordercampaign_id " . $campaignApiuser->preordercampaign_id . ")");
$this->log->debug(print_r($campaignApiuser, true));
}
foreach (PreordercampaignOriginhostnameModel::search(['preordercampaign_id' => $campaign->id]) as $origin) {
$this->addAllowedOrigin($origin->hostname);
}
}
$this->allowed_preordertypes = array_unique($this->allowed_preordertypes);
}
protected function getNetworks() {
$return = [];
$my_network_ids = [];
foreach($this->me->my_networks as $network) {
if($network->id && !in_array($network->id, $my_network_ids)) {
$my_network_ids[] = $network->id;
}
}
$networks = NetworkModel::search(["opsystem" => "snopp"]);
foreach($networks as $network) {
if(!in_array($network->id, $my_network_ids)) continue;
$name = $network->name;
if($network->adb_netzgebiet_id) {
$cityname = preg_replace('/^Liezen\s+-\s+/', '', $network->adb_netzgebiet->name);
$name = "ROC_".$network->adb_netzgebiet->extref."_".$cityname;
}
$net = [];
$net["id"] = $network->id;
$net["name"] = $name;
$net["created"] = $network->create;
$net["updated"] = $network->edit;
$return[] = $net;
}
return mfResponse::Ok(["networks" => $return]);
}
protected function getPreorderCampaigns() {
$return = [];
foreach($this->campaigns as $campaign) {
$c = [];
$c["id"] = $campaign->id;
$c["name"] = $campaign->name;
$c["created"] = $campaign->create;
$c["updated"] = $campaign->edit;
$return[] = $c;
}
return mfResponse::Ok(["preordercampaigns" => $return]);
}
protected function getBuildingsByCampaign() {
$buildings = [];
if(!array_key_exists("campaign_id", $this->get) || !$this->get["campaign_id"]) {
return mfResponse::BadRequest(["message" => "mandatory parameter campaign_id is missing."]);
}
$campaign_id = $this->get["campaign_id"];
if(!is_numeric($campaign_id) || $campaign_id < 1) {
return mfResponse::BadRequest(["message" => "Invalid value for campaign_id"]);
}
$campaign = new Preordercampaign($campaign_id);
if(!$campaign) {
return mfResponse::NotFound(["message" => "Network not found"]);
}
$adb_netzgebiet_id = $campaign->adb_netzgebiet->id;
if(!$adb_netzgebiet_id) {
return mfResponse::NotFound(["message" => "Network not found"]);
}
$db = $this->db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$sql = AddressDB::$wohneinheit_query;
$sql .= " WHERE Hausnummer.netzgebiet_id=$adb_netzgebiet_id AND Hausnummer.visibility = 'public'";
$res = $db->query($sql);
if(!$db->num_rows($res)) {
return mfResponse::Ok(["buildings" => []]);
}
$b = [];
while($data = $db->fetch_object($res)) {
if(!array_key_exists($data->hausnummer_id, $b)) {
$housenumber = $data->hausnummer;
if($this->hausnummer_add_zusatz) {
if($data->zusatz) {
$housenumber .= " (".$data->zusatz.")";
}
}
$b[$data->hausnummer_id] = [
'id' => $data->hausnummer_id,
'oaid' => $data->hausnummer_oaid,
'cluster_id' => $data->netzgebiet_extref,
'zip' => $data->plz,
'city' => $data->gemeinde,
"municipality" => "",
'district' => $data->ortschaft,
'street' => $data->strasse,
'housenumber' => $housenumber,
'gps_lat' => ($data->gps_lat) ? (float)$data->gps_lat : null,
'gps_long' => ($data->gps_long) ? (float)$data->gps_long : null,
"homes" => []
];
if($this->district_is_city) {
$b[$data->hausnummer_id]['city'] = $data->ortschaft;
$b[$data->hausnummer_id]['municipality'] = $data->gemeinde;
} else {
unset($b[$data->hausnummer_id]['municipality']);
}
}
$b[$data->hausnummer_id]["homes"][] = [
'id' => $data->wohneinheit_id,
'oaid' => $data->wohneinheit_oaid,
'num' => (int)$data->num,
'block' => $data->block,
'stiege' => $data->stiege,
'stock' => $data->stock,
'tuer' => $data->tuer,
'zusatz' => $data->zusatz,
];
}
/*foreach($b as $tmp_b) {
$homes = array_values($tmp_b["homes"]);
return mfResponse::Ok(["Homes" => $homes]);
unset($tmp_b["homes"]);
$tmp_b["homes"] = array_values($homes);
$buildings[] = $tmp_b;
}*/
$buildings = array_values($b);
return mfResponse::Ok(["buildings" => $buildings]);
}
}

View File

@@ -156,7 +156,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
foreach(PreorderModel::searchActive($preorder_search) as $preorder) {
$return[] = $preorder->getApiArray();
}
$this->requestLog->debug(print_r($return, true));
return mfResponse::Ok(["preorders" => $return]);
}

View File

@@ -13,7 +13,20 @@ class Contractqueue extends mfBaseModel {
private $sla;
private $creator;
private $editor;
protected function afterSave() {
$this->crediting_partner = null;
$this->reseller = null;
$this->owner = null;
$this->billingaddress = null;
$this->product = null;
$this->orderproduct = null;
$this->termination = null;
$this->sla = null;
$this->creator = null;
$this->editor = null;
}
public function generateMatchcode() {
$owner_address = $this->getProperty("owner")->street.", ".$this->getProperty("owner")->zip." ".$this->getProperty("owner")->city;

View File

@@ -29,7 +29,7 @@ class ContractqueueController extends mfBaseController {
}
}
$this->layout->set("filter", $filter);
$this->layout->set("filter", array_map(fn($a) => htmlentities($a), $filter));
$filter = $this->getPreparedFilter($filter);
// pagination defaults
@@ -67,7 +67,7 @@ class ContractqueueController extends mfBaseController {
}
protected function getPreparedFilter($filter) {
return $filter;
}
@@ -108,7 +108,6 @@ class ContractqueueController extends mfBaseController {
var_dump($product_attribs);exit;
}*/
if(is_array($product_attribs) && array_key_exists("crediting_partner", $product_attribs) && $product_attribs["crediting_partner"] && is_object($product_attribs["crediting_partner"])) {
if($product_attribs["crediting_partner"]->value) {
$contract->crediting_partner_id = $product_attribs["crediting_partner"]->value;
}
@@ -124,6 +123,7 @@ class ContractqueueController extends mfBaseController {
if($contract->matchcode) {
$primary_matchcode = $contract->matchcode;
}
$contract->crediting_matchcode = $order->owner->getCompanyOrName().", ".$order->owner->street.", ".$order->owner->zip." ".$order->owner->city;
$contracts[] = $contract;
}
@@ -168,4 +168,140 @@ class ContractqueueController extends mfBaseController {
$this->layout()->setFlash("Alle Bestellungen importiert", "success");
$this->redirect("Contractqueue");
}
protected function apiAction() {
if(!$this->me->is(["Admin"])) {
$this->redirect("Dashboard");
}
$do = $this->request->do;
$data = [];
switch($do) {
case "saveContract":
$return = $this->saveContractApi();
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 saveContractApi() {
$r = $this->request;
$valid_fields = [
"product" => "product_id",
"matchcode" => "matchcode",
"price" => "price",
"price_setup" => "price_setup",
"billing_period" => "billing_period",
"billing_delay" => "billing_delay"
];
$data = [];
foreach($r->get() as $f => $v) {
if(array_key_exists($f, $valid_fields)) {
$data[$valid_fields[$f]] = $v;
}
}
if(!count($data)) {
return false;
}
$cq = new Contractqueue($r->id);
if(!$cq->id) {
return false;
}
if(array_key_exists("product_id", $data)) {
$product = new Product($data["product_id"]);
if(!$product->id) {
$this->log->error(__METHOD__.": neue product_id nicht gefunden");
return false;
}
$data["product_name"] = $product->name;
}
$cq->update($data);
if(!$cq->save()) {
return false;
}
//var_dump($cq->product, $cq->product->attributes);exit;
// find reseller / receiver of credit
// from product
$product_attribs = $cq->product->attributes;
/*if($op->id == "8666") {
var_dump($product_attribs);exit;
}*/
$cq->crediting_partner_id = null;
$cq->crediting_partner_rate = null;
if(is_array($product_attribs) && array_key_exists("crediting_partner", $product_attribs) && $product_attribs["crediting_partner"] && is_object($product_attribs["crediting_partner"])) {
if($product_attribs["crediting_partner"]->value && $product_attribs["crediting_partner"]->value != $cq->crediting_partner_id) {
$cq->crediting_partner_id = $product_attribs["crediting_partner"]->value;
}
if($product_attribs["crediting_rate"]->value) {
$crediting_rate_price = round($cq->price / 100 * $product_attribs["crediting_rate"]->value, 4);
if($crediting_rate_price != $cq->crediting_partner_rate) {
$cq->crediting_partner_rate = $crediting_rate_price;
}
}
}
// or from netowner if anschluss product
if(!$cq->crediting_partner_id && $cq->termination_id && $cq->product->price_nne > 0) {
$cq->crediting_partner_id = $cq->termination->building->network->owner_id;
}
if(!$cq->save()) {
return false;
}
$return = [];
$return["product"] = $cq->product_id;
$return["product_name"] = $cq->product->name;
$return["termination"] = ($cq->termination_id) ? $cq->termination->code." ".str_replace("\n", " - ", $cq->termination->getAddress()) : null;
$return["matchcode"] = $cq->matchcode;
$return["price"] = $cq->price;
$return["price_setup"] = $cq->price_setup;
$return["billing_period"] = $cq->billing_period;
$return["billing_delay"] = $cq->billing_delay;
$credit = [];
$credit["crediting_rate"] = null;
$credit["crediting_partner_id"] = $cq->crediting_partner_id;
$credit["crediting_partner_name"] = "";
$credit["crediting_rate"] = 0;
$credit["crediting_matchcode"] = "";
if($cq->crediting_partner_id) {
$credit["crediting_partner_name"] = $cq->crediting_partner->getCompanyOrName();
if($cq->crediting_partner_rate) {
$credit["crediting_rate"] = $cq->crediting_partner_rate;
$credit["crediting_partner_name"] = "".number_format($cq->crediting_partner_rate, 4, ",",".")." (Prozentrate)";
} else {
$credit["crediting_rate"] = $cq->price_nne;
$credit["crediting_partner_name"] = "".number_format($cq->crediting_partner_rate, 4, ",",".")." (NNE)";
}
$credit["crediting_matchcode"] = $cq->crediting_matchcode;
}
return ["contract" => $return, "credit" => $credit];
}
}

View File

@@ -14,6 +14,7 @@ class ContractqueueModel {
public $product_name;
public $product_info;
public $matchcode;
public $crediting_matchcode;
public $amount;
public $sla_id = null;
public $product_external;

View File

@@ -76,6 +76,7 @@ class NetworkController extends mfBaseController {
$data['name'] = $r->name;
$data['note'] = $r->note;
$data['adb_netzgebiet_id'] = ($r->adb_netzgebiet_id) ? $r->adb_netzgebiet_id : null;
$data['opsystem'] = ($r->opsystem === "snopp") ? "snopp" : null;
if($r->sytemowner_action_status) {
$data['sytemowner_action_status'] = $r->sytemowner_action_status;

View File

@@ -4,6 +4,7 @@ class NetworkModel {
public $name;
public $owner_id ;
public $adb_netzgebiet_id;
public $opsystem;
public $sytemowner_action_status;
public $note;
@@ -141,6 +142,13 @@ class NetworkModel {
$where .= " AND adb_netzgebiet_id IN (". implode(",", $adb_netzgebiet_id).")";
}
}
if(array_key_exists("opsystem", $filter)) {
$opsystem = FronkDB::singleton()->escape($filter['opsystem']);
if($opsystem) {
$where .= " AND Network.`opsystem` = '$opsystem'";
}
}

View File

@@ -10,9 +10,14 @@ final class CreateContractqueue extends AbstractMigration
if($this->getEnvironment() == "thetool") {
$table = $this->table("Contractqueue");
$table->addColumn("approved", "integer", ["null" => false, "default" => 0]);
$table->addColumn("approved_credit", "integer", ["null" => false, "default" => 0]);
$table->addColumn("contract_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("order_id", "integer", ["null" => false]);
$table->addColumn("orderproduct_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("crediting_partner_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("crediting_partner_rate", "decimal", ["null" => true, "default" => null, "precision" => 10, "scale" => 4]);
$table->addColumn("reseller_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("reseller_rate", "decimal", ["null" => true, "default" => null, "precision" => 10, "scale" => 4]);
$table->addColumn("owner_id", "integer", ["null" => false]);
$table->addColumn("billingaddress_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("termination_id", "integer", ["null" => true, "default" => null]);
@@ -20,6 +25,7 @@ final class CreateContractqueue extends AbstractMigration
$table->addColumn("product_name", "string", ["null" => false, "limit" => 255]);
$table->addColumn("product_info", "text", ["null" => true, "default" => null]);
$table->addColumn("matchcode", "string", ["null" => true, "default" => null, "limit" => 255]);
$table->addColumn("crediting_matchcode", "string", ["null" => true, "default" => null, "limit" => 255]);
$table->addColumn("amount", "decimal", ["null" => false, "precision" => 9, "scale" => 6]);
$table->addColumn("sla_id", "integer", ["null" => true, "default" => null]);
$table->addColumn("product_external", "integer", ["null" => false, "default" => 0, "limit" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY]);
@@ -30,6 +36,7 @@ final class CreateContractqueue extends AbstractMigration
$table->addColumn("price_nbe", "decimal", ["null" => false, "default" => 0, "precision" => 14, "scale" => 4]);
$table->addColumn("billing_delay", "integer", ["null" => false, "default" => 0]);
$table->addColumn("billing_period", "integer", ["null" => false, "default" => 1]);
$table->addColumn("contract_term", "integer", ["null" => false, "default" => 12]);
$table->addColumn("order_date", "integer", ["null" => true, "default" => null]);
$table->addColumn("finish_date", "integer", ["null" => true, "default" => null]);
$table->addColumn("finish_date_by", "integer", ["null" => true, "default" => null]);

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class NetworkAddOpsystem extends AbstractMigration
{
public function up(): void
{
if($this->getEnvironment() == "thetool") {
$table = $this->table("Network");
$table->addColumn("opsystem", "enum", ["null" => true, "default" => null, "values" => "snopp", "after" => "adb_netzgebiet_id"]);
$table->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
public function down(): void
{
if($this->getEnvironment() == "thetool") {
$this->table("Network")->removeColumn("opsystem")->update();
}
if($this->getEnvironment() == "addressdb") {
}
}
}

View File

@@ -103,7 +103,7 @@ class mfBaseApicontroller {
private function logRequest() {
$this->requestLog->debug("==================================================================");
$this->requestLog->debug("new API request for ".$_SERVER['REQUEST_URI']. " from ".$_SERVER['REMOTE_ADDR']);
$this->requestLog->debug("new API request: ".$_SERVER['REQUEST_METHOD']." ".$_SERVER['REQUEST_URI']. " from ".$_SERVER['REMOTE_ADDR']);
$this->requestLogstr = "";
foreach($_GET as $key => $value) {
$this->requestLogstr .= "; $key='$value'";
@@ -157,6 +157,7 @@ class mfBaseApicontroller {
foreach(apache_request_headers() as $header => $value) {
$this->headers[strtolower($header)] = $value;
}
// GET parameters
$get = $params;
unset($get['mod']);