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
+1 -1
View File
@@ -26,7 +26,7 @@ class Building extends mfBaseModel {
$code = "$cc-$zip-";
foreach($rnd as $r) {
$code .= dechex($r);
$code .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
}
if(BuildingModel::search(['code' => $code])) {
+2 -2
View File
@@ -188,11 +188,11 @@ class BuildingController extends mfBaseController {
$this->layout()->setFlash("Objekt nicht gefunden", "error");
$this->redirect("Building");
}
/*
if(TerminationModel::search(["building_id" => $id])) {
$this->layout()->setFlash("Das Objekt kann nicht gelöscht werden, da noch Anschlüsse zugeordnet sind.", "error");
$this->redirect("Building");
}*/
}
$building->delete();
+4 -11
View File
@@ -15,17 +15,10 @@ class DashboardController extends mfBaseController {
}
/*
protected function testAction() {
$search = [
'street' => "Kastellfeldgasse 20",
'zip' => "8010",
'city' => "Graz",
'country' => "AT"
];
$b = new Building(7);
var_dump($b->getNewObjectCode());exit;
$coords = Gmaps_Geocoding::getCoords($search);
var_dump($coords);
exit;
}*/
}
}
+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) {
@@ -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;