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) {
|
||||
|
||||
|
||||
@@ -14,6 +14,88 @@ class TerminationController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$term = new Termination($id);
|
||||
if(!$term->id) {
|
||||
$this->layout()->setFlash("Anschluss nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$building = new Building($r->building_id);
|
||||
if(!$building->id) {
|
||||
$this->layout()->setFlash("Anschluss nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['building_id'] = $r->building_id;
|
||||
$data['name'] = $r->name;
|
||||
$data['contact'] = $r->contact;
|
||||
$data['phone'] = $r->phone;
|
||||
$data['email'] = $r->email;
|
||||
$data['lineworker_id'] = $building->lineworker_id;
|
||||
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
$data['create_by'] = $this->me->id;
|
||||
$term = TerminationModel::create($data);
|
||||
} else {
|
||||
$term->update($data);
|
||||
}
|
||||
|
||||
$new_id = $term->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
$this->redirect("Building", "Index", [], "building=".$term->building_id);
|
||||
}
|
||||
|
||||
if(!$term->code) {
|
||||
$term->code = $term->getNewObjectCode();
|
||||
$term->save();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Anschluss gespeichert.", "success");
|
||||
$this->redirect("Building", "Index", [], "building=".$term->building_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function delete() {
|
||||
if(!$this->me->is("Admin")) {
|
||||
$this->layout()->setFlash("Keine Berechtigung", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$id = $this->request->id;
|
||||
|
||||
if(!is_numeric($id) || !$id) {
|
||||
$this->layout()->setFlash("Objekt nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$term = new Termination($id);
|
||||
if(!$term->id) {
|
||||
$this->layout()->setFlash("Anschluss nicht gefunden", "error");
|
||||
$this->redirect("Building");
|
||||
}
|
||||
|
||||
$building_id = $term->building_id;
|
||||
|
||||
$term->delete();
|
||||
|
||||
$this->layout()->setFlash("Anschluss gelöscht", "success");
|
||||
$this->redirect("Building", "Index", [], "building=".$building_id);
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
$do = $this->request->do;
|
||||
|
||||
Reference in New Issue
Block a user