WIP Contract linking / productchange

This commit is contained in:
Frank Schubert
2023-01-11 15:53:13 +01:00
parent b47bf6ca0f
commit 25236493ee
15 changed files with 672 additions and 127 deletions
+56 -14
View File
@@ -100,7 +100,7 @@ class Contract extends mfBaseModel {
}
$now = date('U');
if($this->cancel_date < $now) {
if($this->cancel_date <= $now) {
return true;
}
@@ -110,11 +110,18 @@ class Contract extends mfBaseModel {
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return 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") {
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);
@@ -125,18 +132,12 @@ class Contract extends mfBaseModel {
return $this->owner;
}
if($name == "billingaddress") {
$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(!$this->id) {
return null;
}
if($name == "product") {
$this->product = mfValuecache::singleton()->get("mfObjectmodel-Product-".$this->product_id);
if($this->product === null) {
@@ -264,4 +265,45 @@ class Contract extends mfBaseModel {
return $this->$name;
}
/*
* When object is cloned, new object will call this funtion to let us clean up the new Contract.
* Throws Exception if cloning fails.
*/
public function __clone() {
$me = new User;
$me->loadMe();
$old_id = $this->id;
$old_nummer = $this->nummer;
unset($this->id);
// cleanup Contract daten
$this->orderproduct_id = null;
$this->order_date = null;
$this->finish_date = null;
$this->finish_date_by = null;
$this->cancel_date = null;
$this->cancel_date_by = null;
$this->create_by = $me->id;
$this->edit_by = $me->id;
$this->create = null;
$this->edit = null;
$this->saved = 0;
$this->mode = "new";
$this->_old_data = new StdClass();
//$this->save();
if($old_id == $this->id) {
$this->log->error("save() of cloned Contract $old_nummer failed!");
throw new Exception("Saving clone failed.");
}
$this->log->debug("Cloned Contract $old_id");
}
}