Merge branch 'fronkdev' into 'master'

WIP ConstructionConsent

See merge request fronk/thetool!887
This commit is contained in:
Frank Schubert
2025-01-13 15:30:07 +00:00
13 changed files with 924 additions and 23 deletions
@@ -1,14 +1,64 @@
<?php
class ConstructionConsent extends mfBaseModel {
protected $forcestr = ["name", "ez", "kg", "gst", "gstnr", "usage_length"];
private $project;
private $termnination;
private $adb_hausnummer;
private $adb_strasse;
private $owners;
private $creator;
private $editor;
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";
private $footer_size = "8";
public function createConsentFormPdf(ConstructionConsentOwner $owner = null) : ?string {
if($owner) {
$owners = [$owner];
} else {
if(!is_array($this->getProperty("owners")) || !count($this->getProperty("owners"))) {
return null;
}
$owners = $this->owners;
}
$pdf_vars = [
"consent" => $this,
"owners" => $owners
];
$footer_text = $this->footer_text;
$footer_font = $this->footer_font;
$footer_size = $this->footer_size;
$pdf = new PdfForm("ConstructionConsent/Consentform.pdf", $pdf_vars);
$wkOpts = "--footer-center '$footer_text' --footer-font-name '$footer_font' --footer-font-size '$footer_size'";
$filename = $pdf->render($wkOpts);
if(!file_exists($filename) || !is_file($filename)) {
return null;
}
return $filename;
}
public function getProperty($name) {
if($this->$name == null) {
if($name == "project") {
$project = new ConstructionConsentProject($this->id);
if($project->id) {
$this->project = $project;
}
return $this->project;
}
if($name == "adb_hausnummer") {
if(!$this->adb_hausnummer_id) return null;
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
@@ -27,6 +77,38 @@ class ConstructionConsent extends mfBaseModel {
return $this->adb_strasse;
}
if($name == "owners") {
if(!$this->id) return null;
$owners = ConstructionConsentOwner::search(["constructionconsent_id" => $this->id]);
if(count($owners)) {
$this->owners = $owners;
}
return $this->owners;
}
if($name == "creator") {
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($this->creator === null) {
$this->creator = new User($this->create_by);
if($this->creator->id) {
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
}
}
return $this->creator;
}
if($name == "editor") {
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
if($this->editor === null) {
$this->editor = new User($this->edit_by);
if($this->editor->id) {
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
}
}
return $this->editor;
}
$classname = ucfirst($name);
$idfield = $name."_id";
@@ -55,8 +137,9 @@ class ConstructionConsent extends mfBaseModel {
$model = new ConstructionConsent();
$table_fields = [
"termination_id","adb_wohneinheit_id","object_type","ez","owner_name","owner_street","owner_zip","owner_city",
"owner_country","status","result","create_by","edit_by","create","edit"
"constructionconsentproject_id", "termination_id","adb_hausnummer_id", "adb_strasse_id", "object_type", "name", "ez", "kg", "gst", "gstnr",
"usage_length", "usage_pipe_on_plot", "usage_pipe_in_building", "usage_manhole", "usage_owner",
"status", "result", "result_text", "note", "create_by","edit_by","create","edit"
];
foreach($data as $field => $value) {
@@ -90,6 +90,25 @@ class ConstructionConsentController extends mfBaseController {
return $new_filter;
}
protected function viewAction() : void {
$this->layout()->setTemplate("ConstructionConsent/View");
$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");
}
$this->layout()->set("item", $item);
}
protected function addAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Form");
}
@@ -111,6 +130,49 @@ class ConstructionConsentController extends mfBaseController {
$this->addAction();
}
protected function download() {
//var_dump($r->get());exit;
$owner_id = $this->request->owner_id;
if (!is_numeric($owner_id) || $owner_id < 1) {
$this->layout()->setFlash("Besitzer nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$owner = new ConstructionConsentOwner($owner_id);
if (!$owner->id) {
$this->layout()->setFlash("Besitzer nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
$cc = $owner->consent;
if(!$cc) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden.", "error");
$this->redirect("ConstructionConsent");
}
$this->layout()->setTemplate("ConstructionConsent/Consentform.pdf");
$this->layout()->set("ressourcePathPrefix", MFFANCYBASEURL);
$this->layout()->set("owners", [$owner]);
$this->layout()->set("consent", $cc);
//return true;
$filename = $cc->createConsentFormPdf();
if(!$filename) {
$this->layout()->setFlash("Beim Erstellen des PDFs ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
$this->redirect("ConstructionConsent", "View", ["id" => $cc->id]);
}
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="Zustimmungserklärung-'.$cc->id.'-'.$owner_id.'.pdf"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: ' . mime_content_type($filename));
header("Content-Length: " . filesize($filename));
readfile($filename);
exit;
}
protected function saveAction() {
$r = $this->request;
//var_dump($r->get());exit;
@@ -131,16 +193,16 @@ class ConstructionConsentController extends mfBaseController {
$data["constructionconsentproject_id"] = $r->constructionconsentproject_id;
$data["object_type"] = $r->object_type;
$data["name"] = $r->name;
$data["adb_street_id"] = $r->adb_street_id;
$data["adb_strasse_id"] = $r->adb_strasse_id;
$data["ez"] = $r->ez;
$data["kg"] = $r->kg;
$data["gst"] = $r->gst;
$data["gstnr"] = $r->gstnr;
$data["usage_length"] = $r->usage_length;
$data["usage_pipe_on_plot"] = $r->usage_pipe_on_plot;
$data["usage_pipe_in_building"] = $r->usage_pipe_in_building;
$data["usage_manhole"] = $r->usage_manhole;
$data["usage_owner"] = $r->usage_owner;
$data["usage_length"] = $r->usage_length ?: null;
$data["usage_pipe_on_plot"] = $r->usage_pipe_on_plot ? 1 : 0;
$data["usage_pipe_in_building"] = $r->usage_pipe_in_building ? 1 : 0;
$data["usage_manhole"] = $r->usage_manhole ? 1 : 0;
$data["usage_owner"] = $r->usage_owner ? 1 : 0;
if($mode == "add") {
$item = ConstructionConsent::create($data);
@@ -258,7 +320,6 @@ class ConstructionConsentController extends mfBaseController {
$adb = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$res = $adb->query($sql);
$this->log->debug("done");
if(!$adb->num_rows($res)) {
header("Content-Type: application/json");
@@ -1,10 +1,18 @@
<?php
class ConstructionConsentOwner extends mfBaseModel {
private $consent;
public function getProperty($name) {
if($this->$name == null) {
if($name == "consent") {
$consent = new ConstructionConsent($this->constructionconsent_id);
if($consent->id) {
$this->consent = $consent;
}
return $consent;
}
$classname = ucfirst($name);
$idfield = $name."_id";
@@ -33,8 +41,8 @@ class ConstructionConsentOwner extends mfBaseModel {
$model = new ConstructionConsentOwner();
$table_fields = [
"constructionconsent_id", "owner_name", "owner_street", "owner_zip", "owner_city", "owner_country", "owner_phone",
"owner_fax", "owner_email", "status", "result", "create_by","edit_by","create","edit"
"constructionconsent_id", "name", "street", "zip", "city", "country", "phone",
"fax", "email", "status", "result", "create_by","edit_by","create","edit"
];
foreach($data as $field => $value) {
@@ -61,7 +69,7 @@ class ConstructionConsentOwner extends mfBaseModel {
$db = FronkDB::singleton();
$res = $db->select("ConstructionConsentOwner", "*", "1 = 1 ORDER BY owner_name");
$res = $db->select("ConstructionConsentOwner", "*", "1 = 1 ORDER BY name");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ConstructionConsentOwner($data);
@@ -77,7 +85,7 @@ class ConstructionConsentOwner extends mfBaseModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM ConstructionConsentOwner
WHERE $where
ORDER BY adb_hausnummer_id LIMIT 1";
ORDER BY name LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
@@ -114,7 +122,7 @@ class ConstructionConsentOwner extends mfBaseModel {
$items = [];
if(!$order) {
$order = "owner_name ASC";
$order = "name ASC";
}
$db = FronkDB::singleton();
@@ -0,0 +1,70 @@
<?php
class ConstructionConsentOwnerController extends mfBaseController
{
protected function init(): void
{
$this->needlogin = true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me", $me);
if (!$me->is(["Admin"])) {
$this->redirect("Dashboard");
}
}
protected function saveAction()
{
$r = $this->request;
//var_dump($r->get());exit;
$id = $r->id;
if (is_numeric($id) && $id > 0) {
$mode = "edit";
$item = new ConstructionConsentOwner($id);
if (!$item->id) {
$this->layout()->setFlash("Zustimmungserklärung nicht gefunden", "error");
$this->redirect("ConstructionConsent");
}
} else {
$id = false;
$mode = "add";
}
$cc_id = $r->constructionconsent_id;
$cc = new ConstructionConsent($cc_id);
if(!$cc_id || !$cc->id) {
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
$this->redirect("ConstructionConsent");
}
$data = [];
$data["constructionconsent_id"] = $cc_id;
$data["name"] = $r->name;
$data["street"] = $r->street;
$data["zip"] = $r->zip;
$data["city"] = $r->city;
$data["country"] = $r->country;
$data["phone"] = $r->phone;
$data["fax"] = $r->fax;
$data["email"] = $r->email;
if($mode == "add") {
$data["status"] = "new";
$item = ConstructionConsentOwner::create($data);
} else {
$item->update($data);
}
if(!$item->save()) {
$this->layout()->setFlash("Beim Speichern ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.", "error");
} else {
$this->layout()->setFlash("Besitzer wurde erfolgreich gespeichert.", "success");
}
$this->redirect("ConstructionConsent", "View", ["id" => $cc_id]);
}
}