Added temporary script to create Contracts from Orders
This commit is contained in:
@@ -111,6 +111,22 @@ class Contract extends mfBaseModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function generateMatchcode() {
|
||||
$owner_address = $this->getProperty("owner")->street.", ".$this->getProperty("owner")->zip." ".$this->getProperty("owner")->city;
|
||||
|
||||
if($this->termination_id) {
|
||||
$termination = new Termination($this->termination_id);
|
||||
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
||||
return $termination_address;
|
||||
}
|
||||
|
||||
if(stripos($this->getProperty("product")->name, "dsl") != false) {
|
||||
return $owner_address;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -136,12 +152,6 @@ class Contract extends mfBaseModel {
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if($name == "product") {
|
||||
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
||||
if($this->product === null) {
|
||||
@@ -164,6 +174,14 @@ class Contract extends mfBaseModel {
|
||||
return $this->orderproduct;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*if($name == "contractConfigGroups") {
|
||||
$product = $this->getProperty("product");
|
||||
$this->contractConfigGroups = ContractconfigGroupModel::search(['producttech_id' => $product->producttech_id]);
|
||||
@@ -265,7 +283,6 @@ class Contract extends mfBaseModel {
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
|
||||
@@ -54,6 +54,58 @@ class ContractModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function createFromOrderproduct($op) {
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
if(!$op->id) {
|
||||
$log->warning(__METHOD__."(): Invalid OrderProduct object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = $op->order;
|
||||
$product = $op->product;
|
||||
|
||||
if(!$order->id || !$product->id) {
|
||||
$log->warning(__METHOD__."(): Invalid Order or Product");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$order->finish_date || $order->finish_date > date("U")) {
|
||||
$log->warning(__METHOD__."(): Order not finished yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["orderproduct_id"] = $op->id;
|
||||
$data["owner_id"] = $order->owner_id;
|
||||
$data["billingaddress_id"] = $order->billingaddress_id;
|
||||
$data["termination_id"] = ($op->termination_id) ? $op->termination_id : null;
|
||||
$data["product_id"] = $op->product_id;
|
||||
$data["product_name"] = $product->name;
|
||||
$data["product_info"] = $product->description;
|
||||
$data["amount"] = $op->amount;
|
||||
$data["sla_id"] = $product->sla_id;
|
||||
$data["produt_external"] = ($product->external) ? $product->external : 0;
|
||||
$data["product_external_id"] = ($product->external) ? $product->external_id : null;
|
||||
$data["price"] = $op->price;
|
||||
$data["price_setup"] = $op->price_setup;
|
||||
$data["price_nne"] = $op->price_nne;
|
||||
$data["price_nbe"] = $op->price_nbe;
|
||||
$data["billing_delay"] = $op->billing_delay;
|
||||
$data["billing_period"] = $op->billing_period;
|
||||
$data["order_date"] = $order->order_date;
|
||||
|
||||
$data["finish_date"] = $order->finish_date;
|
||||
$data["finish_date_by"] = 1;
|
||||
$data["note"] = $order->note;
|
||||
|
||||
$contract = ContractModel::create($data);
|
||||
$contract->matchcode = $contract->generateMatchcode();
|
||||
//var_dump($contract);exit;
|
||||
|
||||
return $contract;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user