218 lines
7.2 KiB
PHP
218 lines
7.2 KiB
PHP
<?php
|
|
|
|
class Contractqueue extends mfBaseModel {
|
|
protected $forcestr = ["product_name","product_info","matchcode"];
|
|
|
|
private $crediting_partner;
|
|
private $reseller;
|
|
private $owner;
|
|
private $billingaddress;
|
|
private $product;
|
|
private $orderproduct;
|
|
private $termination;
|
|
private $voicenumbers;
|
|
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;
|
|
|
|
// phone
|
|
if($this->getProperty("product")->productgroup->mathcodeorigin == "voicenumber") {
|
|
|
|
}
|
|
// domain
|
|
if($this->getProperty("product")->productgroup->mathcodeorigin == "domain") {
|
|
|
|
}
|
|
|
|
if($this->termination_id) {
|
|
$termination = new Termination($this->termination_id);
|
|
$termination_address = $termination->building->street.", ".$termination->building->zip." ".$termination->building->city;
|
|
return $termination_address;
|
|
} else {
|
|
|
|
|
|
|
|
// everything else
|
|
|
|
return $owner_address;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function getCredit() {
|
|
$crediting = [];
|
|
|
|
if(!$this->crediting_partner_id) {
|
|
return false;
|
|
}
|
|
|
|
$crediting["partner"] = $this->getProperty("crediting_partner");
|
|
|
|
if($this->crediting_partner_rate) {
|
|
// use rate
|
|
$crediting["rate_source"] = "rate";
|
|
$crediting["rate"] = round($this->price / 100 * $this->crediting_partner_rate, 4);
|
|
} else {
|
|
$crediting["rate_source"] = "nne";
|
|
}
|
|
|
|
return $crediting;
|
|
}
|
|
|
|
public function getProperty($name) {
|
|
if($this->$name == null) {
|
|
|
|
if($name == "billingaddress" && $this->billingaddress_id) {
|
|
$this->billingaddress = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->billingaddress_id);
|
|
if($this->billingaddress === null) {
|
|
$this->billingaddress = new Address($this->billingaddress_id);
|
|
if($this->billingaddress->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->billingaddress_id, $this->billingaddress);
|
|
}
|
|
}
|
|
return $this->billingaddress;
|
|
}
|
|
|
|
if($name == "owner" && $this->owner_id) {
|
|
$this->owner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->owner_id);
|
|
if($this->owner === null) {
|
|
$this->owner = new Address($this->owner_id);
|
|
if($this->owner->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->owner_id, $this->owner);
|
|
}
|
|
}
|
|
return $this->owner;
|
|
}
|
|
|
|
if($name == "crediting_partner" && $this->crediting_partner_id) {
|
|
$this->crediting_partner = mfValuecache::singleton()->get("mfObjectmodel-Address-".$this->crediting_partner_id);
|
|
if($this->crediting_partner === null) {
|
|
$this->crediting_partner = new Address($this->crediting_partner_id);
|
|
if($this->crediting_partner->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Address-".$this->crediting_partner_id, $this->crediting_partner);
|
|
}
|
|
}
|
|
return $this->crediting_partner;
|
|
}
|
|
|
|
if($name == "product") {
|
|
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
|
|
if($this->product === null) {
|
|
$this->product = new Product($this->product_id);
|
|
if($this->product->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-Product-".$this->product_id, $this->product);
|
|
}
|
|
}
|
|
return $this->product;
|
|
}
|
|
|
|
if($name == "orderproduct") {
|
|
$this->orderproduct = mfValuecache::singleton()->get("mfObjectmodel-OrderProduct-".$this->orderproduct_id);
|
|
if($this->orderproduct === null) {
|
|
$this->orderproduct = new OrderProduct($this->orderproduct_id);
|
|
if($this->orderproduct->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-OrderProduct-".$this->orderproduct_id, $this->orderproduct);
|
|
}
|
|
}
|
|
return $this->orderproduct;
|
|
}
|
|
|
|
if($name == "voicenumbers") {
|
|
$this->voicenumbers = [];
|
|
if(!$this->voicenumber) return [];
|
|
|
|
$json = json_decode($this->voicenumber);
|
|
//var_dump($json);exit;
|
|
|
|
if(!is_array($json)) return [];
|
|
|
|
$voicenumbers = [];
|
|
foreach($json as $number) {
|
|
$number = str_replace("+","",$number);
|
|
if(!$number) continue;
|
|
$voicenumber = VoicenumberModel::getFirst(["number" => $number]);
|
|
if($voicenumber) {
|
|
$voicenumbers[] = $voicenumber;
|
|
} else {
|
|
// find block
|
|
$block_id = null;
|
|
|
|
$block = Voicenumberblock::findBlock($number);
|
|
if($block) {
|
|
$block_id = $block->id;
|
|
}
|
|
$voicenumber = VoicenumberModel::create([
|
|
'voicenumberblock_id' => $block_id,
|
|
"contract_id" => null,
|
|
'active' => 1,
|
|
'activated_date' => date('U'),
|
|
'routing' => "kolmisoft",
|
|
'number' => $number,
|
|
'disabled' => 0
|
|
]);
|
|
$voicenumbers[] = $voicenumber;
|
|
}
|
|
}
|
|
$this->voicenumbers = $voicenumbers;
|
|
return $this->voicenumbers;
|
|
}
|
|
|
|
|
|
if($name == "creator" && $this->id) {
|
|
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
|
if($this->creator === null) {
|
|
$this->creator = new User($this->create_by);
|
|
if($this->creator->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
|
}
|
|
}
|
|
return $this->creator;
|
|
}
|
|
|
|
if($name == "editor" && $this->id) {
|
|
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
|
if($this->editor === null) {
|
|
$this->editor = new User($this->edit_by);
|
|
if($this->editor->id) {
|
|
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
|
}
|
|
}
|
|
return $this->editor;
|
|
}
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
|
if(!$this->$name) {
|
|
$this->$name = new $classname($this->$idfield);
|
|
}
|
|
|
|
if($this->$name->id) {
|
|
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
} |