Merge branch 'fronkdev' into 'master'
Added preorder import Stiftingtal See merge request fronk/thetool!312
This commit is contained in:
@@ -481,6 +481,7 @@ class AddressController extends mfBaseController {
|
||||
}
|
||||
|
||||
$a = $address->toArray();
|
||||
$a['name'] = $address->getCompanyOrName();
|
||||
|
||||
return ['address' => $a];
|
||||
}
|
||||
|
||||
265
application/Api/v1/OperationaldataApicontroller.php
Normal file
265
application/Api/v1/OperationaldataApicontroller.php
Normal 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]);
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -60,13 +60,17 @@ class Preorder extends mfBaseModel {
|
||||
|
||||
public function runStatusTrigger() {
|
||||
if(!$this->id) return true;
|
||||
if($this->status_id == $this->_old_data->status_id) return true;
|
||||
if(property_exists($this->_old_data, "status_id") && $this->status_id == $this->_old_data->status_id) return true;
|
||||
|
||||
$this->log->debug(__METHOD__." running");
|
||||
|
||||
$new_status = $this->getProperty("status");
|
||||
if(!property_exists($this->_old_data, "status_id")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$old_status = new Preorderstatus($this->_old_data->status_id);
|
||||
|
||||
|
||||
if(!$new_status->id || !$old_status->id) return true;
|
||||
$this->log->debug(__METHOD__." status changed from '".($old_status ? $old_status->code : "")."' to '".$new_status->code."'");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user