From c56ed3076f2b3d68264bdd1808f8471328e3529e Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Wed, 12 Oct 2022 14:07:37 +0200 Subject: [PATCH] Added percentage of preorders to total homes --- Layout/default/Preordercampaign/Index.php | 10 +++++++++- .../ADBHausnummer/ADBHausnummerModel.php | 11 ++++++++-- .../ADBWohneinheit/ADBWohneinheitModel.php | 20 +++++++++++++++++-- application/Preorder/PreorderModel.php | 4 ++-- .../Preordercampaign/Preordercampaign.php | 12 +++++++++++ 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Layout/default/Preordercampaign/Index.php b/Layout/default/Preordercampaign/Index.php index f16b5eaa1..6c7f8fd4c 100644 --- a/Layout/default/Preordercampaign/Index.php +++ b/Layout/default/Preordercampaign/Index.php @@ -98,7 +98,15 @@ network->name?> name?> area?> - ["preordercampaign_id" => $camp->id]])?>">active_preorders)?> + + $camp->id])?>"> + ["preordercampaign_id" => $camp->id]])?>"> + active_preorders)?> + total_homes): ?> + / total_homes?> (active_preorders) / $camp->total_homes) * 100, 2))?> %) + + + from)?> to)?> diff --git a/application/ADBHausnummer/ADBHausnummerModel.php b/application/ADBHausnummer/ADBHausnummerModel.php index 00783b2d3..846543cad 100644 --- a/application/ADBHausnummer/ADBHausnummerModel.php +++ b/application/ADBHausnummer/ADBHausnummerModel.php @@ -129,6 +129,15 @@ class ADBHausnummerModel { } } + if(array_key_exists("netzgebiet_id", $filter)) { + $netzgebiet_id = $filter['netzgebiet_id']; + if(is_numeric($netzgebiet_id)) { + $where .= " AND Hausnummer.netzgebiet_id=$netzgebiet_id"; + } elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) { + $where .= " AND Hausnummer.netzgebiet_id IN (". implode(",", $netzgebiet_id).")"; + } + } + if(array_key_exists("plz_id", $filter)) { $plz_id = $filter['plz_id']; if(is_numeric($plz_id)) { @@ -147,8 +156,6 @@ class ADBHausnummerModel { } } - - if(array_key_exists("hausnummer", $filter)) { $hausnummer = FronkDB::singleton()->escape($filter['hausnummer']); if($hausnummer) { diff --git a/application/ADBWohneinheit/ADBWohneinheitModel.php b/application/ADBWohneinheit/ADBWohneinheitModel.php index 36d47e10c..38ba34615 100644 --- a/application/ADBWohneinheit/ADBWohneinheitModel.php +++ b/application/ADBWohneinheit/ADBWohneinheitModel.php @@ -79,10 +79,15 @@ class ADBWohneinheitModel { $db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); $where = self::getSqlFilter($filter); - $sql = "SELECT COUNT(*) as cnt FROM Wohneinheit - WHERE $where + $sql = "SELECT COUNT(*) as cnt FROM + (SELECT Wohneinheit.* FROM Wohneinheit + LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) + WHERE $where + GROUP BY Wohneinheit.id + ) as tbl "; + mfLoghandler::singleton()->debug($sql); $res = $db->query($sql); if($db->num_rows($res)) { $data = $db->fetch_object($res); @@ -97,7 +102,9 @@ class ADBWohneinheitModel { $where = self::getSqlFilter($filter); $sql = "SELECT Wohneinheit.* FROM Wohneinheit + LEFT JOIN Hausnummer ON (Hausnummer.id = Wohneinheit.hausnummer_id) WHERE $where + GROUP BY Wohneinheit.id ORDER BY hausnummer_id,block,stiege,LENGTH(stock),stock,LENGTH(tuer),tuer"; mfLoghandler::singleton()->debug($sql); @@ -128,6 +135,15 @@ class ADBWohneinheitModel { } } + if(array_key_exists("netzgebiet_id", $filter)) { + $netzgebiet_id = $filter['netzgebiet_id']; + if(is_numeric($netzgebiet_id)) { + $where .= " AND Hausnummer.netzgebiet_id=$netzgebiet_id"; + } elseif(is_array($netzgebiet_id) && count($netzgebiet_id)) { + $where .= " AND Hausnummer.netzgebiet_id IN (". implode(",", $netzgebiet_id).")"; + } + } + if(array_key_exists("hausnummer_id", $filter)) { $hausnummer_id = $filter['hausnummer_id']; if(is_numeric($hausnummer_id)) { diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index 350acd774..364736a01 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -131,9 +131,9 @@ class PreorderModel { if(is_numeric($deleted)) { $where .= " AND deleted=$deleted"; } - if($deleted === null) { + /*if($deleted === null) { $where .= " AND deleted IS NULL"; - } + }*/ } if(array_key_exists("preordercampaign_id", $filter)) { diff --git a/application/Preordercampaign/Preordercampaign.php b/application/Preordercampaign/Preordercampaign.php index 485f23d46..fd41dc1d7 100644 --- a/application/Preordercampaign/Preordercampaign.php +++ b/application/Preordercampaign/Preordercampaign.php @@ -9,6 +9,7 @@ class Preordercampaign extends mfBaseModel { private $salesclusters; private $apiusers; private $corsorigins; + private $total_homes; public function addTypes(Array $types) { @@ -70,6 +71,17 @@ class Preordercampaign extends mfBaseModel { public function getProperty($name) { if($this->$name == null) { + if($name == "total_homes") { + $total = 0; + foreach($this->getProperty("salesclusters") as $scluster) { + $netzgebiet_id = $scluster->salescluster_id; + $total += ADBWohneinheitModel::count(['netzgebiet_id' => $netzgebiet_id]); + } + $this->total_homes = $total; + return $total; + } + + if($name == "preorders") { $this->preorders = PreorderModel::search(['preordercampaign_id' => $this->id]); return $this->preorders;