WIP ConstructionConsent 2025-01-13

This commit is contained in:
Frank Schubert
2025-01-13 16:28:56 +01:00
parent 5f752da41f
commit 15bfe7c734
11 changed files with 541 additions and 22 deletions
@@ -1,6 +1,7 @@
<?php
class ConstructionConsent extends mfBaseModel {
protected $forcestr = ["name", "ez", "kg", "gst", "gstnr", "usage_length"];
private $project;
private $termnination;
private $adb_hausnummer;
@@ -9,6 +10,44 @@ class ConstructionConsent extends mfBaseModel {
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) {
@@ -130,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;
@@ -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";
@@ -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]);
}
}