WIP Contractqueue & snopp api
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user