Finished Building -> termination
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user