Finished Building -> termination

This commit is contained in:
Frank Schubert
2021-07-29 17:07:35 +02:00
parent 4ff09b319b
commit 112df1a958
7 changed files with 162 additions and 687 deletions
+42
View File
@@ -9,6 +9,48 @@ class Termination extends mfBaseModel {
private $creator;
private $editor;
public function getNewObjectCode() {
if(!$this->building_id) {
return false;
}
$bcode = $this->getProperty("building")->code;
if(!$bcode) {
return false;
}
$codes = [];
// get existing codes
$res = $this->db->select("Termination", "code", "code like '$bcode.%'");
if($this->db->num_rows($res)) {
while($data = $this->db->fetch_object($res)) {
$codes[] = $data->code;
}
}
if(count($codes)) {
sort($codes);
}
$last_code = end($codes);
$m = [];
if(preg_match('/\.(\d+)$/', $last_code, $m)) {
if($m[1]) {
$last_num = $m[1];
}
} else {
return false;
}
$new_num = ++$last_num;
$code = $bcode.".".sprintf("%03d", $new_num);
return $code;
}
public function getProperty($name) {
if($this->$name == null) {