ConstructionConsent live

This commit is contained in:
Frank Schubert
2025-01-27 02:12:55 +01:00
parent 39cf386638
commit 9657fc56fb
10 changed files with 532 additions and 29 deletions
@@ -14,6 +14,8 @@ class ConstructionConsent extends mfBaseModel {
private $preorder_count;
private $journal;
private $history;
private $inspection_protocol_planner;
private $inspection_protocol_electrician;
private $footer_text = "Energie Steiermark Breitband GmbH, A-8010 Graz, Leonhardgürtel 10, Telefon +43 (0)316 9000-0\nSitz Graz, FN 576705x, Landesgericht für ZRS Graz, ATU 77949678, breitband@e-steiermark.com, www.e-steiermark.com";
private $footer_font = "ITC Officina Sans Std";
@@ -184,6 +186,23 @@ class ConstructionConsent extends mfBaseModel {
return $this->file;
}
if($name == "inspection_protocol_planner") {
if(!$this->id) return [];
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id, "filename" => "inspection_protocol_planner"]);
if($file) {
$this->inspection_protocol_planner = $file;
}
return $this->inspection_protocol_planner;
}
if($name == "inspection_protocol_electrician") {
if(!$this->id) return [];
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $this->id, "filename" => "inspection_protocol_electrician"]);
if($file) {
$this->inspection_protocol_electrician = $file;
}
return $this->inspection_protocol_electrician;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
@@ -314,6 +314,133 @@ class ConstructionConsentController extends mfBaseController {
}
protected function saveDate() {
$r = $this->request;
$id = $r->consent_id;
if(is_numeric($id) && $id > 0) {
$mode = "edit";
$item = new ConstructionConsent($id);
if(!$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
} else {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$data = [];
if($r->inspection_date_planner) {
$data["inspection_date_planner"] = Layout::dateToInt($r->inspection_date_planner);
}
if($r->inspection_date_electrician) {
$data["inspection_date_electrician"] = Layout::dateToInt($r->inspection_date_electrician);
}
if(count($data)) {
$item->update($data);
if(!$item->save()) {
$this->layout()->setFlash("Fehler beim Speichern", "error");
return $this->addAction();
}
}
$this->layout()->setFlash("Zustimmungserklärung erfolgreich gespeichert", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $item->id]);
}
protected function uploadFileAction() {
$id = $this->request->consent_id;
if(!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$item = new ConstructionConsent($id);
if(!$item || !$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$upload_type = $this->request->upload_type;
if($upload_type != "planner" && $upload_type != "electrician") {
$this->layout()->setFlash("Falscher Dateityp", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $item->id]);
}
if(is_array($_FILES) && array_key_exists("inspection_protocol_file", $_FILES) && !$_FILES['inspection_protocol_file']['error']) {
try {
// returns File object or throws Exception on error
$file = mfUpload::handleFormUpload("inspection_protocol_file", false, TT_CONSTRUCTIONCONSENT_FILE_UPLOAD_SUBFOLDER);
} catch (Exception $ex) {
$this->layout()->setFlash("Fehler beim Hochladen: " . $ex->getMessage(), "warning");
$this->redirect("ConstructionConsent", "View", ["id" => $item->id]);
}
$history = ConstructionConsentHistory::create([
"constructionconsent_id" => $item->id,
"key" => "inspection_protocol_$upload_type",
"old_value" => ($item->{"inspection_protocol_$upload_type"}) ? $item->{"inspection_protocol_$upload_type"}->file->id : null,
"new_value" => $file->id
]);
$ccf = ConstructionConsentFile::create([
'constructionconsent_id' => $item->id,
'file_id' => $file->id,
'filename' => "inspection_protocol_$upload_type",
]);
// delete previous image
if($item->{"inspection_protocol_$upload_type"}) {
$item->{"inspection_protocol_$upload_type"}->file->delete();
$item->{"inspection_protocol_$upload_type"}->delete();
}
if (!$ccf->save()) {
$this->layout()->setFlash("Fehler beim Speichern des Begehungsprotokolls", "warning");
}
$history->save();
$this->layout()->setFlash("Begehungsprotokoll erfolgreich hochgeladen", "success");
}
$this->redirect("ConstructionConsent", "View", ["id" => $item->id]);
}
protected function deleteFileAction()
{
$id = $this->request->id;
if (!is_numeric($id) || $id < 1) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$item = new ConstructionConsent($id);
if (!$item || !$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$file_id = $this->request->file_id;
$file = ConstructionConsentFile::getFirst(["constructionconsent_id" => $id, "file_id" => $file_id]);
if(!$file) {
$this->layout()->setFlash("Datei nicht gefunden", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
}
$file->file->delete();
$file->delete();
$this->layout()->setFlash("Datei gelöscht", "success");
$this->redirect("ConstructionConsent", "View", ["id" => $id]);
}
protected function apiAction() {
if(!$this->me->is(["Admin","netowner"]) && !$this->me->can("Preorder")) {
$this->redirect("Dashboard");
@@ -334,6 +461,9 @@ class ConstructionConsentController extends mfBaseController {
case "saveRimoPlanPreview":
$return = $this->saveRimoPlanPreviewApi();
break;
case "saveCheckbox":
$return = $this->saveCheckboxApi();
break;
default:
$this->log->warn(__METHOD__ . ": Called API function '$do' does not exist");
$return = false;
@@ -732,22 +862,42 @@ class ConstructionConsentController extends mfBaseController {
return ["image_mimetype" => $file->mimetype, "image_base64" => base64_encode($image_content), "file_id" => $file->id];
/*$pf = PreorderFile::create([
"preorder_id" => $this->id,
"file_id" => $file->id,
"filename" => $filename
]);
if(!$pf->save()) {
$this->log->error(__METHOD__.": Error saving PreorderFile Object");
return false;
}*/
//return $pf;
}
private function saveRimoPlanPreviewApi() {
$adb_hausnummer_id = $this->request->building_id;
$consent_id = $this->request->constructionconsent_id;
}
private function saveCheckboxApi() {
$r = $this->request;
$consent_id = $r->id;
$consent = new ConstructionConsent($consent_id);
if(!$consent->id) return false;
$data = [];
if($r->isset("inspection_planner")) {
$data["inspection_planner"] = ($r->inspection_planner > 0) ? date("U") : 0;
}
if($r->isset("inspection_electrician")) {
$data["inspection_electrician"] = ($r->inspection_electrician > 0) ? date("U") : 0;
}
if($r->isset("conduit_installed_building")) {
$data["conduit_installed_building"] = ($r->conduit_installed_building > 0) ? date("U") : 0;
}
if($r->isset("conduit_installed_ftu")) {
$data["conduit_installed_ftu"] = ($r->conduit_installed_ftu > 0) ? date("U") : 0;
}
if($r->isset("inhouse_cabling")) {
$data["inhouse_cabling"] = ($r->inhouse_cabling > 0) ? date("U") : 0;
}
if(count($data)) {
$consent->update($data);
$consent->save();
}
return ["message" => "ConstructionConsent saved successfully"];
}
}
@@ -174,6 +174,13 @@ class ConstructionConsentFile extends mfBaseModel {
}
}
if(array_key_exists("filename", $filter)) {
$filename = $db->escape($filter['filename']);
if($filename) {
$where .= " AND ConstructionConsentFile.`filename` = '$filename'";
}
}
//var_dump($filter, $where);exit;
return $where;
}
@@ -77,6 +77,17 @@ class ConstructionConsentHistory extends mfBaseModel {
return "Plan/Skizze Upload";
case "constructionconsentproject_id":
return "Projekt";
case "inspection_planner":
return "Status Begehung mit Planer";
case "inspection_electrician";
return "Status Begehung mit Elektriker";
case "conduit_installed_building":
return "Status Leerohr in FTTx Location";
case "conduit_installed_ftu":
return "Status Leerohr bis HAK";
case "inhouse_cabling":
return "Status Inhouseverkabelung";
}
return $key;
}
@@ -96,6 +107,14 @@ class ConstructionConsentHistory extends mfBaseModel {
}
}
if($this->key == "inspection_date_planner" || $this->key == "inspection_date_electrician" && $value) {
$value = date("d.m.Y", $value);
}
if(in_array($this->key, ["inspection_planner","inspection_electrician","conduit_installed_building","conduit_installed_ftu","inhouse_cabling"])) {
$value = ($value > 0) ? 1 : 0;
}
if(!is_object($value)) {
return $value;
}