Merge branch 'fronkdev2' into 'master'

Preorder AHA Report Download

See merge request fronk/thetool!703
This commit is contained in:
Frank Schubert
2024-11-08 15:57:25 +00:00
35 changed files with 172586 additions and 31 deletions
@@ -248,10 +248,10 @@ class ADBWohneinheit extends mfBaseModel {
}
if($name == "rimo_workorders") {
$this->rimo_workorders = RimoWorkorderModel::search(["adb_wohneinheit_id" => $this->id]);
/*if(count($workorders)) {
$this->rimo_workorders = $workorders;
}*/
$rimo_workorders = RimoWorkorderModel::search(["adb_wohneinheit_id" => $this->id]);
if(count($rimo_workorders)) {
$this->rimo_workorders = $rimo_workorders;
}
return $this->rimo_workorders;
}
@@ -251,7 +251,6 @@ class PreorderApicontroller extends mfBaseApicontroller {
"deleted" => 0
];
$preorder_search = [];
if($this->me->is("preorderaddressreporting")) {
$user_networks_json = $this->me->getFlag("preorder_networks");
$user_networks = json_decode($user_networks_json);
+5 -1
View File
@@ -164,7 +164,9 @@ class BillingModel {
$sql = "SELECT * FROM Billing
WHERE $where
ORDER BY billingaddress_id LIMIT 1";
//var_dump($sql);exit;
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -186,6 +188,8 @@ class BillingModel {
WHERE $where
ORDER BY `create` DESC LIMIT 1";
//var_dump($sql);exit;
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
@@ -0,0 +1,259 @@
<?php
class ConstructionConsent extends mfBaseModel {
private $termnination;
private $adb_hausnummer;
private $adb_strasse;
public function getProperty($name) {
if($this->$name == null) {
if($name == "adb_hausnummer") {
if(!$this->adb_hausnummer_id) return null;
$hausnummer = new ADBHausnummer($this->adb_hausnummer_id);
if($hausnummer->id) {
$this->adb_hausnummer = $hausnummer;
}
return $this->adb_hausnummer;
}
if($name == "adb_strasse") {
if(!$this->adb_strasse_id) return null;
$strasse = new ADBStrasse($this->adb_strasse_id);
if($strasse->id) {
$this->adb_strasse = $strasse;
}
return $this->adb_strasse;
}
$classname = ucfirst($name);
$idfield = $name."_id";
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
if(!$this->$name) {
$this->$name = new $classname($this->$idfield);
}
if($this->$name->id) {
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
return $this->$name;
} else {
return null;
}
}
return $this->$name;
}
/********************************
* Begin static Model functions
*/
public static function create(Array $data) {
$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"
];
foreach($data as $field => $value) {
if(in_array($field, $table_fields)) {
$model->$field = $value;
}
}
$me = new User();
$me->loadMe();
if($model->create_by === null) {
$model->create_by = $me->id;
}
if($model->edit_by === null) {
$model->edit_by = $me->id;
}
return $model;
}
public static function getAll() {
$items = [];
$db = FronkDB::singleton();
$res = $db->select("ConstructionConsent", "*", "1 = 1 ORDER BY adb_hausnummer_id");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ConstructionConsent($data);
}
}
return $items;
}
public static function getFirst($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM ConstructionConsent
WHERE $where
ORDER BY adb_hausnummer_id LIMIT 1";
//var_dump($sql);exit;
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ConstructionConsent($data);
if($item->id) {
return $item;
} else {
return null;
}
}
return null;
}
public static function count($filter) {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM ConstructionConsent
WHERE $where";
//mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->cnt;
}
return 0;
}
public static function search($filter, $limit = false, $order = false) {
//var_dump($filter);exit;
$items = [];
if(!$order) {
$order = "adb_hausnummer_id ASC";
}
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM ConstructionConsent
WHERE $where
ORDER BY $order";
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
mfLoghandler::singleton()->debug($sql);
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[$data->id] = new ConstructionConsent($data);
}
}
return $items;
}
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("adb_wohneinheit_id", $filter)) {
$adb_wohneinheit_id = $filter['adb_wohneinheit_id'];
if(is_numeric($adb_wohneinheit_id)) {
$where .= " AND ConstructionConsent.adb_wohneinheit_id=$adb_wohneinheit_id";
}
}
if(array_key_exists("termination_id", $filter)) {
$termination_id = $filter['termination_id'];
if(is_numeric($termination_id)) {
$where .= " AND ConstructionConsent.termination_id=$termination_id";
}
}
if(array_key_exists("object_type", $filter)) {
$object_type = FronkDB::singleton()->escape($filter["object_type"]);
if($object_type) {
$where .= " AND object_type='$object_type'";
}
}
if(array_key_exists("ez", $filter)) {
$ez = FronkDB::singleton()->escape($filter["ez"]);
if($ez) {
$where .= " AND ez='$ez'";
}
}
if(array_key_exists("status", $filter)) {
$status = FronkDB::singleton()->escape($filter["status"]);
if($status) {
$where .= " AND status='$status'";
}
}
if(array_key_exists("result", $filter)) {
$result = FronkDB::singleton()->escape($filter["result"]);
if($result) {
$where .= " AND result='$result'";
}
}
if(array_key_exists("owner_name", $filter)) {
$owner_name = FronkDB::singleton()->escape($filter["owner_name"]);
if($owner_name) {
$where .= " AND owner_name like '%$owner_name%'";
}
}
if(array_key_exists("owner_street", $filter)) {
$owner_street = FronkDB::singleton()->escape($filter["owner_street"]);
if($owner_street) {
$where .= " AND owner_street like '%$owner_street%'";
}
}
if(array_key_exists("owner_zip", $filter)) {
$owner_zip = FronkDB::singleton()->escape($filter["owner_zip"]);
if($owner_zip) {
$where .= " AND owner_zip like '%$owner_zip%'";
}
}
if(array_key_exists("owner_city", $filter)) {
$owner_city = FronkDB::singleton()->escape($filter["owner_city"]);
if($owner_city) {
$where .= " AND owner_city like '%$owner_city%'";
}
}
if(array_key_exists("owner_country", $filter)) {
$owner_country = FronkDB::singleton()->escape($filter["owner_country"]);
if($owner_country) {
$where .= " AND owner_country like '%$owner_country%'";
}
}
if(array_key_exists("add-where", $filter)) {
$where .= " ".$filter['add-where'];
}
//var_dump($filter, $where);exit;
return $where;
}
}
@@ -0,0 +1,91 @@
<?php
class ConstructionConsentController 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 indexAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Index");
if ($this->request->resetFilter) {
unset($_SESSION[MFAPPNAME . '-ConstructionConsent-filter']);
$this->redirect("ConstructionConsent");
}
$filter = [];
if (is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[MFAPPNAME . '-ConstructionConsent-filter'] = $filter;
} else {
if (array_key_exists(MFAPPNAME . '-ConstructionConsent-filter', $_SESSION) && count($_SESSION[MFAPPNAME . '-ConstructionConsent-filter'])) {
$filter = $_SESSION[MFAPPNAME . '-ConstructionConsent-filter'];
}
}
$this->layout->set("filter", $filter);
$filter = $this->getPreparedFilter($filter);
// pagination defaults
$pagination = [];
$pagination['start'] = 0;
$pagination['count'] = 20;
$pagination['maxItems'] = 0;
if (is_numeric($this->request->s)) {
$pagination['start'] = intval($this->request->s);
}
//var_dump($filter);exit;
$pagination['maxItems'] = ConstructionConsent::count($filter);
$this->layout()->set("pagination", $pagination);
$items = ConstructionConsent::search($filter);
$this->layout->set("items", $items);
}
private function getPreparedFilter($filter) : array
{
$new_filter = [];
if (is_array($filter) && count($filter)) {
foreach ($filter as $name => $value) {
$new_filter[$name] = $value;
}
}
return $new_filter;
}
protected function addAction() : void {
$this->layout()->setTemplate("ConstructionConsent/Form");
}
protected function editAction() : void {
$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);
$this->addAction();
}
}
+9 -9
View File
@@ -48,7 +48,7 @@ class OpenAccessId extends mfBaseModel {
public function exportToRimoAndAssignFtu() {
$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
//$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
// XXX for now only support ADB Addresses
if(!$this->adb_wohneinheit_id) {
@@ -91,7 +91,7 @@ class OpenAccessId extends mfBaseModel {
}
if($fetch_ftu) {
$resp_data = $rimo->getFtuData($wohneinheit->extref);
$resp_data = Rimoapi::getFtuData($this->oaid, $wohneinheit->extref);
if(!is_array($resp_data->ftus->item) || !count($resp_data->ftus->item)) {
$this->log->warning(__METHOD__.": Homes ftus object has no items ".$this->oaid);
@@ -120,7 +120,7 @@ class OpenAccessId extends mfBaseModel {
$existing_rimo_export_data = $this->getExportData("rimo");
//if(!is_object($existing_rimo_export_data) || (!isset($existing_rimo_export_data->oaid_id) || !$existing_rimo_export_data->oaid_id) || (!isset($existing_rimo_export_data->name) || !$existing_rimo_export_data->name)) {
$oaid_data = $rimo->getOaid();
$oaid_data = Rimoapi::getOaid($this->oaid);
// try to create, if it fails, it already exists
if(!$oaid_data) {
$this->createInRimo();
@@ -135,12 +135,12 @@ class OpenAccessId extends mfBaseModel {
$ftu_data = $wohneinheit->ftu_data;
if($ftu_data['id'] && $ftu_data['name']) {
$resp_data = $rimo->getOaid();
$resp_data = Rimoapi::getOaid($this->oaid);
if(!$resp_data) {
// oaid was not found in rimo, try creating it
$this->createInRimo();
$resp_data = $rimo->getOaid();
$resp_data = Rimoapi::getOaid($this->oaid);
}
$assign_oaid = false;
@@ -150,7 +150,7 @@ class OpenAccessId extends mfBaseModel {
$old_ftu_id = $resp_data->terminiationUnit->id;
// unassign oaid from FTU
$resp_data = $rimo->unassignOaid($old_ftu_id);
$resp_data = Rimoapi::unassignOaid($this->oaid, $old_ftu_id);
$assign_oaid = true;
}
@@ -160,7 +160,7 @@ class OpenAccessId extends mfBaseModel {
if ($assign_oaid) {
// assign oaid to Wohneinheit FTU
$resp_data = $rimo->assignOaid($ftu_data['id']);
$resp_data = Rimoapi::assignOaid($this->oaid, $ftu_data['id']);
// update OAID export data
$exp_data_update = json_decode($this->export_data);
@@ -212,9 +212,9 @@ class OpenAccessId extends mfBaseModel {
}
public function createInRimo() {
$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
//$rimo = new OpenAccessId_Helper_Rimo($this->oaid);
$resp_data = $rimo->createOaid();
$resp_data = Rimoapi::createOaid($this->oaid);
if(!$resp_data) {
return false;
}
@@ -126,7 +126,7 @@ class OpenAccessIdController extends mfBaseController {
$old_preorder->save();
}
$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
//$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
// unassign oaid from rimo ftu
//$rimo->unassignOaid($oaid)
@@ -24,6 +24,16 @@ class RimoWorkorder extends mfBaseModel {
AddressDB::handleRimoStatusUpdate($wohneinheit->id);
}
}
public function getAha() {
if(!$this->id) return false;
$ah = Rimoapi::getWorkorderAhaReport($this->rimo_id);
return $ah;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -0,0 +1,43 @@
<?php
class RimoWorkorderController extends mfBaseController {
protected function init() {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->me = $me;
$this->layout()->set("me",$me);
}
protected function downloadAhaAction() {
$workorder_id = $this->request->id;
if(!$workorder_id || $workorder_id < 1) {
header("HTTP/1.1 400 Bad Request");
echo "Invalid workorder id.";
exit;
}
$workorder = new RimoWorkorder($workorder_id);
if(!$workorder->id) {
header("HTTP/1.1 404 Not Found");
echo "Workorder nicht gefunden.";
exit;
}
$return = $workorder->getAha();
if($return === false) {
header("HTTP/1.1 500 Not Found");
echo "Fehler beim Herunterladen des AHA-Reports aus Rimo.";
exit;
}
header("Content-type: text/pdf");
header('Content-disposition: attachment; filename="'.$workorder->rimo_name.'_AHA.pdf"');
echo $return;
exit;
}
}
@@ -119,14 +119,14 @@ class RimoWorkorderModel {
if(is_array($limit) && count($limit)) {
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
} elseif(is_numeric($count)) {
} elseif(is_numeric($limit['count'])) {
$sql .= " LIMIT ".$limit['count'];
}
}
$res = $db->query($sql);
//mfLoghandler::singleton()->debug($sql);
mfLoghandler::singleton()->debug($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {