Files
thetool/application/Invoiceposition/Invoiceposition.php
2024-07-12 18:57:46 +02:00

118 lines
3.3 KiB
PHP

<?php
class Invoiceposition extends mfBaseModel {
private $invoice;
private $contract;
public function setOption($name, $value) {
$options = $this->getOptions;
if($options) {
$options = json_decode($this->options);
if(json_last_error() !== JSON_ERROR_NONE) {
$options = new stdClass();
}
} else {
$options = new stdClass();
}
$options->$name = $value;
$this->options = json_encode($options);
}
public function getOption($name) {
if(!$this->options) return null;
$this->log->debug("getOptions ($name): ".print_r($this->options, true));
$options = json_decode($this->options);
if(json_last_error() !== JSON_ERROR_NONE) {
$this->log->debug("getOptions ($name) decoding failed");
return null;
}
if(property_exists($options, $name)) {
return $options->$name;
}
return null;
}
public function __clone() {
$me = new User;
$me->loadMe();
$old_id = $this->id;
$this->id = null;
// cleanup data
$this->invoice_id = 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_id failed!");
throw new Exception("Saving clone failed.");
}*/
//$this->log->debug("Cloned Invoiceposition $old_id");
}
public function getProperty($name) {
if($this->$name == null) {
if(!$this->id) {
return null;
}
if($name == "creator") {
$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->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;
}
}