ConstructionConsent live
This commit is contained in:
@@ -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"];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user