71 lines
1.3 KiB
PHP
71 lines
1.3 KiB
PHP
<?php
|
|
|
|
class Termination extends mfBaseModel {
|
|
protected $forcestr = ['phone','email','note'];
|
|
|
|
private $building;
|
|
private $status;
|
|
private $lineworker;
|
|
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) {
|
|
|
|
$classname = ucfirst($name);
|
|
$idfield = $name."_id";
|
|
$this->$name = new $classname($this->$idfield);
|
|
|
|
if($this->$name->id) {
|
|
return $this->$name;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $this->$name;
|
|
}
|
|
|
|
} |