From 28546cf4d0b0fbd7a549190e725382e478603fd9 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 10 Jun 2025 09:45:57 +0200 Subject: [PATCH] changed logic of unit count calculation based on internal tool type --- Layout/default/Preordercampaign/Index-new.php | 215 ------------ Layout/default/Preordercampaign/Index.php | 318 ------------------ .../ADBNetzgebiet/ADBNetzgebietModel.php | 15 +- application/Dashboard/DashboardController.php | 43 +-- .../DashboardNew/DashboardNewController.php | 53 +-- application/Preorder/PreorderModel.php | 129 ++++--- .../Preordercampaign/Preordercampaign.php | 38 --- .../PreordercampaignController.php | 2 +- 8 files changed, 135 insertions(+), 678 deletions(-) delete mode 100644 Layout/default/Preordercampaign/Index-new.php delete mode 100644 Layout/default/Preordercampaign/Index.php diff --git a/Layout/default/Preordercampaign/Index-new.php b/Layout/default/Preordercampaign/Index-new.php deleted file mode 100644 index f218bfffb..000000000 --- a/Layout/default/Preordercampaign/Index-new.php +++ /dev/null @@ -1,215 +0,0 @@ -getUrl($Mod,"Index"); - $pagination_baseurl_params = ["filter" => $filter]; - $pagination_entity_name = "Vorbestellkampagnen"; -?> - - - -
-
-
-
- -
-

Vorbestellkampagnen

-
-
-
- - -
-
- -
-
-

Filter

- -
"> -
- -
- - -
- - is("Admin")): ?> -
- - -
- - -
- - " /> -
- -
- - " /> -
- -
-
-
- - ">Filter zurücksetzen -
-
-
- -
-
- - - address_id == 1 || $me->address_id == 4807): // xinon, rml ?> - - - -
-
-
-

Liste aller Vorbestellkampagnen

-
-
- is("Admin")): ?> - "> Neue Vorbestellkampagne anlegen - -
- -
-
- - -
-
- - - - - - - - - - - - - - - = $camp->from && date('U') <= $camp->to) ? "class='active'" : ""?>> - - - - - - - - - - - -
NetzgebieteNameVorbestellungenWorkordersStartEnde
- = $camp->from && date('U') <= $camp->to): ?> - - - - - - - $camp->id])?>"> - network->name?>name?> - -
- -
- - - total_homes_sd): // automatic value from AdressDB ?> - - - - - - - - total_homes_md): // automatic value from AdressdB ?> - - - - - - - - - - - - -
EFH:active_preorder_count_sd?> /total_homes_sd?>(active_preorder_count_sd / $camp->total_homes_sd) * 100, 2))?> %)
MPH:active_preorder_count_md?> /total_homes_md?>(active_preorder_count_md / $camp->total_homes_md) * 100, 2))?> %)
Gesamt:active_preorder_count?> / - homes_total): // manual value ?> - homes_total?> - total_homes): // automatic value from AdressDB ?> - total_homes?> - - - homes_total): // manual value ?> - (active_preorder_count / $camp->homes_total) * 100, 2))?> %) - total_homes): // automatic value from AdressDB ?> - (active_preorder_count / $camp->total_homes) * 100, 2))?> %) - -
-
- -
- - - -
- workorder_count): ?> - workorder_count?> - - 0 - - / active_preorder_count?> - from)?>to)?> - $camp->id])?>" title="Bestellte Zusatzdienste exportieren"> - ["preordercampaign_id" => $camp->id]])?>" title="Email Aussendungen"> - is("Admin")): ?> - $camp->id])?>"> - $camp->id])?>"> - $camp->id])?>" class="text-danger" onclick="if(!confirm('Vorbestellkampagne wirklich löschen?')) return false;" title="Vorbestellkampagne Löschen"> - -
- - - - -
-
- -
-
- - diff --git a/Layout/default/Preordercampaign/Index.php b/Layout/default/Preordercampaign/Index.php deleted file mode 100644 index b917d4dea..000000000 --- a/Layout/default/Preordercampaign/Index.php +++ /dev/null @@ -1,318 +0,0 @@ -getUrl($Mod,"Index"); - $pagination_baseurl_params = ["filter" => $filter]; - $pagination_entity_name = "Vorbestellkampagnen"; -?> - - - - - - - - - -
-
-
-
- -
-

Vorbestellkampagnen

-
-
-
- - -
-
- -
-
-

Filter

- -
"> -
- -
- - -
- - is("Admin")): ?> -
- - -
- - -
- - " /> -
- -
- - " /> -
- -
-
-
- - ">Filter zurücksetzen -
-
-
- -
-
- - - address_id == 1 || $me->address_id == 4807): // xinon, rml ?> - - - -
-
-
-

Liste aller Vorbestellkampagnen

- is("Admin")): ?> - "> Neue - Vorbestellkampagne anlegen - -
- -
-
- - -
-
-
- - - - - - - - - - - - - - - = $camp->from && date('U') <= $camp->to) ? "class='active'" : ""?>> - - - - - - - - - - - -
NetzgebieteNameVorbestellungenWorkordersStartEnde
- = $camp->from && date('U') <= $camp->to): ?> - - - - - - - $camp->id])?>"> - network->name?>name?> -
- -
- - - total_homes_sd): // automatic value from AdressDB ?> - - - - - - - - total_homes_md): // automatic value from AdressdB ?> - - - - - - - - - - - - -
EFH:active_preorder_count_sd?> /total_homes_sd?>(active_preorder_count_sd / $camp->total_homes_sd) * 100, 2))?> %)
MPH:active_preorder_count_md?> /total_homes_md?>(active_preorder_count_md / $camp->total_homes_md) * 100, 2))?> %)
Gesamt:active_preorder_count?> / - homes_total): // manual value ?> - homes_total?> - total_homes): // automatic value from AdressDB ?> - total_homes?> - - - homes_total): // manual value ?> - (active_preorder_count / $camp->homes_total) * 100, 2))?> %) - total_homes): // automatic value from AdressDB ?> - (active_preorder_count / $camp->total_homes) * 100, 2))?> %) - -
-
- -
-
- workorder_count): ?> - workorder_count?> - - 0 - - / active_preorder_count?> - from)?>to)?> - -
-
- - - - -
-
- -
-
- - - diff --git a/application/ADBNetzgebiet/ADBNetzgebietModel.php b/application/ADBNetzgebiet/ADBNetzgebietModel.php index 26185e839..2bc3c731a 100644 --- a/application/ADBNetzgebiet/ADBNetzgebietModel.php +++ b/application/ADBNetzgebiet/ADBNetzgebietModel.php @@ -7,10 +7,7 @@ class ADBNetzgebietModel { public $source_id; public $rimo_id; public $freigabe; - public $unit_count; - public $unit_count_sd; - public $unit_count_md; - + public $create = null; public $edit = null; @@ -175,13 +172,3 @@ class ADBNetzgebietModel { } } - -/* - * Update unit_count in Netzgebiet: - -UPDATE `Netzgebiet` -LEFT JOIN (SELECT netzgebiet_id, COUNT(*) as uc FROM Wohneinheit LEFT JOIN Hausnummer ON (Wohneinheit.hausnummer_id = Hausnummer.id) GROUP BY netzgebiet_id) AS uc_table ON (uc_table.netzgebiet_id = Netzgebiet.id) -SET unit_count = uc_table.uc -WHERE uc_table.uc IS NOT NULL; - - */ \ No newline at end of file diff --git a/application/Dashboard/DashboardController.php b/application/Dashboard/DashboardController.php index d15bb2428..c1e4a26f1 100644 --- a/application/Dashboard/DashboardController.php +++ b/application/Dashboard/DashboardController.php @@ -148,28 +148,29 @@ class DashboardController extends mfBaseController { } private function getTotalHomes($preordercampaign_id = [], $gemeinde_id = false) { - $total_homes = 0; + return 0; +// $i_total_calculated_homes = 0; - if($gemeinde_id) { - $sql = "SELECT COUNT(adb_wohneinheit.id) as cnt FROM `".ADDRESSDB_DBNAME."`.Wohneinheit adb_wohneinheit - LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer adb_hausnummer ON (adb_wohneinheit.hausnummer_id = adb_hausnummer.id) - LEFT JOIN `".ADDRESSDB_DBNAME."`.Strasse adb_strasse ON (adb_hausnummer.strasse_id = adb_strasse.id) - WHERE adb_strasse.gemeinde_id = $gemeinde_id - "; - $res = $this->db()->query($sql); - if($this->db()->num_rows($res)) { - $data = $this->db()->fetch_object($res); - return $data->cnt; - } - } else { - foreach($preordercampaign_id as $campaign_id) { - $campaign = new Preordercampaign($campaign_id); - if($campaign->id) { - $total_homes += ($campaign->homes_total) ? $campaign->homes_total : $campaign->total_homes; - } - } - } - return $total_homes; +// if($gemeinde_id) { +// $sql = "SELECT COUNT(adb_wohneinheit.id) as cnt FROM `".ADDRESSDB_DBNAME."`.Wohneinheit adb_wohneinheit +// LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer adb_hausnummer ON (adb_wohneinheit.hausnummer_id = adb_hausnummer.id) +// LEFT JOIN `".ADDRESSDB_DBNAME."`.Strasse adb_strasse ON (adb_hausnummer.strasse_id = adb_strasse.id) +// WHERE adb_strasse.gemeinde_id = $gemeinde_id +// "; +// $res = $this->db()->query($sql); +// if($this->db()->num_rows($res)) { +// $data = $this->db()->fetch_object($res); +// return $data->cnt; +// } +// } else { +// foreach($preordercampaign_id as $campaign_id) { +// $campaign = new Preordercampaign($campaign_id); +// if($campaign->id) { +// $i_total_calculated_homes += ($campaign->homes_DEPRECATED_total) ? $campaign->homes_DEPRECATED_total : $campaign->homes_DEPRECATED_total; +// } +// } +// } +// return $i_total_calculated_homes; } private function getPartnerOrderCount($preordercampaign_id = [], $gemeinde_id = false) { diff --git a/application/DashboardNew/DashboardNewController.php b/application/DashboardNew/DashboardNewController.php index 73a3a80e9..bc5a0f2a2 100644 --- a/application/DashboardNew/DashboardNewController.php +++ b/application/DashboardNew/DashboardNewController.php @@ -200,6 +200,9 @@ class DashboardNewController extends mfBaseController { $efh_connection_types = ["single-dwelling", "business"]; $mph_connection_types = ["apartment-building", "apartment", "multi-dwelling"]; + + $efh_connection_types = [0,1]; + $mph_connection_types = [2]; $countFunction = function($params, $statusFlag = null) use ($campaign_ids, $gemeinde_ids) { $baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids]; @@ -254,15 +257,15 @@ class DashboardNewController extends mfBaseController { 'baufortschritt_140' => $countFunction([">status_code" => "139", " "899"]), // MAYBE OVERWORK - 'order_efh' => $countFunction(["connection_type" => $efh_connection_types]), - 'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145), - 'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200), + 'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]), + 'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145), + 'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200), //END MAYBE OVERWORK 'inhouse_kabel_verlegt_efh' => $inhouse_kabel_verlegt_efh, 'inhouse_kabel_verlegt_efh_magenta' => $countFunction([">status_code" => "243", " "899", "partner_id" => 4803]), 'inhouse_kabel_verlegt_efh_salzburg' => $countFunction([">status_code" => "243", " "899", "partner_id" => 5668]), - 'order_mph' => $countFunction(["connection_type" => $mph_connection_types]), - 'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242), + 'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]), + 'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242), 'timeline' => $this->getTimeline('weekly-orders', $campaign_ids, $gemeinde_ids), 'timeline_inhouse_kabel_verlegt_efh' => $timeline_inhouse_kabel_verlegt_efh, @@ -311,17 +314,17 @@ class DashboardNewController extends mfBaseController { 'type' => 'default', 'order_max_home_addrdb' => $order_max_homes, 'order_actual_order' => $countFunction([]), - 'order_efh' => $countFunction(["connection_type" => $efh_connection_types]), - 'order_efh_vorsorge' => $countFunction(["connection_type" => $efh_connection_types, "type" => "provision"]), - 'order_efh_vollanschluss' => $countFunction(["connection_type" => $efh_connection_types, "type" => "order"]), - 'order_mph' => $countFunction(["connection_type" => $mph_connection_types]), - 'order_mph_vorsorge' => $countFunction(["connection_type" => $mph_connection_types, "type" => "provision"]), - 'order_mph_vollanschluss' => $countFunction(["connection_type" => $mph_connection_types, "type" => "order"]), + 'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]), + 'order_efh_vorsorge' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "provision"]), + 'order_efh_vollanschluss' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "order"]), + 'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]), + 'order_mph_vorsorge' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "provision"]), + 'order_mph_vollanschluss' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "order"]), 'baufortschritt_140' => $baufortschritt_140, - 'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145), - 'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200), - 'inhouse_kabel_verlegt_efh' => $countFunction(["connection_type" => $efh_connection_types], 242), - 'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242), + 'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145), + 'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200), + 'inhouse_kabel_verlegt_efh' => $countFunction(["tool_building_type" => $efh_connection_types], 242), + 'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242), 'installationsfortschritt_245' => $countFunction([">status_code" => "244", " "899"]), 'ont_installiert_300' => $ont_installiert_300, 'vollanschluss_dokumentiert_350' => $countFunction(["status_code" => ["350","500"], "type" => "order"]), @@ -390,17 +393,17 @@ class DashboardNewController extends mfBaseController { 'type' => 'default', 'order_max_home_addrdb' => $order_max_homes, 'order_actual_order' => $countFunction([]), - 'order_efh' => $countFunction(["connection_type" => $efh_connection_types]), - 'order_efh_vorsorge' => $countFunction(["connection_type" => $efh_connection_types, "type" => "provision"]), - 'order_efh_vollanschluss' => $countFunction(["connection_type" => $efh_connection_types, "type" => "order"]), - 'order_mph' => $countFunction(["connection_type" => $mph_connection_types]), - 'order_mph_vorsorge' => $countFunction(["connection_type" => $mph_connection_types, "type" => "provision"]), - 'order_mph_vollanschluss' => $countFunction(["connection_type" => $mph_connection_types, "type" => "order"]), + 'order_efh' => $countFunction(["tool_building_type" => $efh_connection_types]), + 'order_efh_vorsorge' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "provision"]), + 'order_efh_vollanschluss' => $countFunction(["tool_building_type" => $efh_connection_types, "type" => "order"]), + 'order_mph' => $countFunction(["tool_building_type" => $mph_connection_types]), + 'order_mph_vorsorge' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "provision"]), + 'order_mph_vollanschluss' => $countFunction(["tool_building_type" => $mph_connection_types, "type" => "order"]), 'baufortschritt_140' => $baufortschritt_140, - 'installationspaket_erhalten' => $countFunction(["connection_type" => $efh_connection_types], 145), - 'lehrrohr_im_haus' => $countFunction(["connection_type" => $efh_connection_types], 200), - 'inhouse_kabel_verlegt_efh' => $countFunction(["connection_type" => $efh_connection_types], 242), - 'inhouse_kabel_verlegt_mph' => $countFunction(["connection_type" => $mph_connection_types], 242), + 'installationspaket_erhalten' => $countFunction(["tool_building_type" => $efh_connection_types], 145), + 'lehrrohr_im_haus' => $countFunction(["tool_building_type" => $efh_connection_types], 200), + 'inhouse_kabel_verlegt_efh' => $countFunction(["tool_building_type" => $efh_connection_types], 242), + 'inhouse_kabel_verlegt_mph' => $countFunction(["tool_building_type" => $mph_connection_types], 242), 'installationsfortschritt_245' => $countFunction([">status_code" => "244", " "899"]), 'ont_installiert_300' => $ont_installiert_300, 'vollanschluss_dokumentiert_350' => $countFunction(["status_code" => ["350","500"], "type" => "order"]), diff --git a/application/Preorder/PreorderModel.php b/application/Preorder/PreorderModel.php index fea59bc67..5e5fefd96 100644 --- a/application/Preorder/PreorderModel.php +++ b/application/Preorder/PreorderModel.php @@ -495,7 +495,7 @@ class PreorderModel $where = self::getSqlFilter($filter); $sql = "SELECT COUNT(*) as cnt FROM `" . FRONKDB_DBNAME . "`.Preorder tt_preorder LEFT JOIN `" . FRONKDB_DBNAME . "`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id) - LEFT JOIN `" . ADDRESSDB_DBNAME . "`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.id) LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id) LEFT OUTER JOIN (SELECT adb_wohneinheit_id, count(*) cnt, MAX(rimo_status) as rimo_status, MAX(rimo_name) as rimo_name, MAX(rimo_team_name) as rimo_team_name, MAX(rimo_team_id) as rimo_team_id FROM `" . FRONKDB_DBNAME . "`.RimoWorkorder WHERE rimo_status NOT IN ('deleted', 'cancelled') GROUP BY adb_wohneinheit_id) workorder ON adb_wohneinheit.id = workorder.adb_wohneinheit_id WHERE $where @@ -795,6 +795,18 @@ class PreorderModel } } + if (array_key_exists("tool_building_type", $filter)) { + $tool_building_type = $filter['tool_building_type']; + if (is_array($tool_building_type) && count($tool_building_type)) { + $where .= " AND adb_hausnummer.tool_building_type IN ('" . implode("','", $tool_building_type) . "')"; + } else { + $tool_building_type = FronkDB::singleton()->escape($filter['connection_type']); + if ($tool_building_type) { + $where .= " AND adb_hausnummer.tool_building_type like '%$tool_building_type%'"; + } + } + } + if (array_key_exists("connection_count", $filter)) { $connection_count = $filter['connection_count']; if (intval($connection_count) === 1) { @@ -1095,7 +1107,7 @@ class PreorderModel $sql = "SELECT COUNT(*) as cnt FROM `" . FRONKDB_DBNAME . "`.Preorder tt_preorder LEFT JOIN `" . FRONKDB_DBNAME . "`.Preorderstatus tt_preorderstatus ON tt_preorder.status_id = tt_preorderstatus.id - LEFT JOIN `" . ADDRESSDB_DBNAME . "`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id) + LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.id) INNER JOIN `" . FRONKDB_DBNAME . "`.PreorderStatusflagValue psfv ON tt_preorder.id = psfv.preorder_id INNER JOIN `" . FRONKDB_DBNAME . "`.PreorderStatusflag psf ON psfv.flag_id = psf.id WHERE $where AND psf.code = " . $statusFlag . " AND psfv.value = 1"; @@ -1112,67 +1124,92 @@ class PreorderModel } public static function countActivePreorder($preorderCampaignId = null) { - $db = FronkDB::singleton(); + $db = FronkDB::singleton(); - $where = ""; - if ($preorderCampaignId) { - $where .= " AND p.preordercampaign_id = $preorderCampaignId"; - } + $where = ""; + if ($preorderCampaignId) { + $where .= " AND p.preordercampaign_id = $preorderCampaignId"; + } - $sql = "SELECT - COALESCE(SUM(CASE - WHEN LOWER(vh.gdaeigenschaft) IN ('multi dwelling', 'mehrparteienhaus', 'gebaeude mit 2 oder mehr wohnungen', 'gebäude mit 2 oder mehr wohnungen', 'wohngebaeude fuer gemeinschaften', 'wohngebäude für gemeinschaften', 'hotels und aehnliche gebaeude', 'hotels und ähnliche gebäude', 'wohngebäude mit 2 und mehr wohnungen') - OR LOWER(vh.rimo_type) IN ('multi dwelling', 'mehrparteienhaus', 'gebaeude mit 2 oder mehr wohnungen', 'gebäude mit 2 oder mehr wohnungen', 'wohngebaeude fuer gemeinschaften', 'wohngebäude für gemeinschaften', 'hotels und aehnliche gebaeude', 'hotels und ähnliche gebäude', 'wohngebäude mit 2 und mehr wohnungen') - THEN COALESCE(p.connection_count, 1) - ELSE 0 - END), 0) AS md_count, - COALESCE(SUM(COALESCE(p.connection_count, 1)), 0) AS total_count + $sql = "SELECT + COALESCE(SUM(CASE + WHEN h.tool_building_type = 2 THEN COALESCE(p.connection_count, 1) + ELSE 0 + END), 0) AS md_count, + COALESCE(SUM(COALESCE(p.connection_count, 1)), 0) AS total_count + FROM + `".FRONKDB_DBNAME."`.Preorder p + LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer h ON p.adb_hausnummer_id = h.id + LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON p.status_id = tt_preorderstatus.id + WHERE p.deleted = 0 AND tt_preorderstatus.code < 899"; -FROM - `".FRONKDB_DBNAME."`.Preorder p -LEFT JOIN `".ADDRESSDB_DBNAME."`.view_hausnummer vh ON p.adb_hausnummer_id = vh.hausnummer_id -LEFT JOIN `".FRONKDB_DBNAME."`.Preorderstatus tt_preorderstatus ON p.status_id = tt_preorderstatus.id -WHERE p.deleted = 0 AND tt_preorderstatus.code < 899"; + $queryStart = microtime(true); + $res = $db->query($sql . $where); + mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql); - $queryStart = microtime(true); - $res = $db->query($sql . $where); - mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql); - if ($db->num_rows($res)) { + if ($db->num_rows($res)) { $data = $db->fetch_object($res); - return ['md_count' => $data->md_count, 'sd_count' => $data->total_count - $data->md_count, 'total_count' => $data->total_count]; - } - return ['md_count' => 0, 'sd_count' => 0, 'total_count' => 0]; + return [ + 'md_count' => (int)$data->md_count, + 'sd_count' => (int)($data->total_count - $data->md_count), + 'total_count' => (int)$data->total_count + ]; + } + + return [ + 'md_count' => 0, + 'sd_count' => 0, + 'total_count' => 0 + ]; } public static function countTotalUnits($preorderCampaignId = null) { - $db = FronkDB::singleton(); + $db = FronkDB::singleton(); - $where = "1=1"; - if ($preorderCampaignId) { - $where .= " AND pc.id = $preorderCampaignId"; - } + $where = "1=1"; + if ($preorderCampaignId) { + $where .= " AND pc.id = $preorderCampaignId"; + } - $sql = "SELECT - pc.id AS campaign_id, - COALESCE(SUM(n.unit_count), 0) AS total_unit_count, - COALESCE(SUM(n.unit_count_sd), 0) AS total_unit_count_sd, - COALESCE(SUM(n.unit_count_md), 0) AS total_unit_count_md -FROM Preordercampaign pc -LEFT JOIN `".FRONKDB_DBNAME."`.PreordercampaignSalescluster pcs ON pc.id = pcs.preordercampaign_id -LEFT JOIN `".ADDRESSDB_DBNAME."`.Netzgebiet n ON pcs.salescluster_id = n.id -WHERE $where -GROUP BY pc.id"; + $sql = "SELECT + pc.id AS campaign_id, + COUNT(w.id) AS total_unit_count, + SUM(CASE + WHEN h.tool_building_type IN (0, 1) THEN 1 + ELSE 0 + END) AS total_unit_count_sd, + SUM(CASE + WHEN h.tool_building_type = 2 THEN 1 + ELSE 0 + END) AS total_unit_count_md + FROM Preordercampaign pc + LEFT JOIN `".FRONKDB_DBNAME."`.PreordercampaignSalescluster pcs ON pc.id = pcs.preordercampaign_id + LEFT JOIN `".ADDRESSDB_DBNAME."`.Netzgebiet n ON pcs.salescluster_id = n.id + LEFT JOIN `".ADDRESSDB_DBNAME."`.Hausnummer h ON n.id = h.netzgebiet_id + LEFT JOIN `".ADDRESSDB_DBNAME."`.Wohneinheit w ON h.id = w.hausnummer_id + WHERE $where + GROUP BY pc.id"; $queryStart = microtime(true); $res = $db->query($sql); mfLoghandler::singleton()->debug("[Query took: ".(microtime(true) - $queryStart)." seconds] " . $sql); + if ($db->num_rows($res)) { - $data = $db->fetch_object($res); - return ['total_unit_count' => $data->total_unit_count, 'total_unit_count_sd' => $data->total_unit_count_sd, 'total_unit_count_md' => $data->total_unit_count_md]; - } - return ['total_unit_count' => 0, 'total_unit_count_sd' => 0, 'total_unit_count_md' => 0]; + $data = $db->fetch_object($res); + return [ + 'total_unit_count' => (int)$data->total_unit_count, + 'total_unit_count_sd' => (int)$data->total_unit_count_sd, + 'total_unit_count_md' => (int)$data->total_unit_count_md + ]; } + return [ + 'total_unit_count' => 0, + 'total_unit_count_sd' => 0, + 'total_unit_count_md' => 0 + ]; + } + public static function countHistoryStatus($filter = [], $status_code = null) { if ($status_code === null) { die("Please select a status code"); diff --git a/application/Preordercampaign/Preordercampaign.php b/application/Preordercampaign/Preordercampaign.php index 5c71227cf..59f39398d 100644 --- a/application/Preordercampaign/Preordercampaign.php +++ b/application/Preordercampaign/Preordercampaign.php @@ -13,9 +13,6 @@ class Preordercampaign extends mfBaseModel { private $salesclusters; private $apiusers; private $corsorigins; - private $total_homes; - private $total_homes_sd; - private $total_homes_md; private $workorder_count; private $required_fields = []; private $banned_fcps; @@ -132,41 +129,6 @@ class Preordercampaign extends mfBaseModel { return $wo_count; } - if($name == "total_homes_sd") { - $this->getProperty("total_homes"); - return $this->total_homes_sd; - } - - if($name == "total_homes_md") { - $this->getProperty("total_homes"); - return $this->total_homes_md; - } - - if($name == "total_homes") { - $total = 0; - $total_sd = 0; - $total_md = 0; - - $netzgebiet_ids = null; - if ($this->getProperty("salesclusters")) { - foreach($this->getProperty("salesclusters") as $scluster) { - if($scluster->id) $netzgebiet_ids[] = $scluster->id; - } - } - if(is_array($netzgebiet_ids) && count($netzgebiet_ids)) { - foreach(ADBNetzgebietModel::search(["netzgebiet_id" => $netzgebiet_ids]) as $netzgebiet) { - $total += $netzgebiet->unit_count; - $total_sd += $netzgebiet->unit_count_sd; - $total_md += $netzgebiet->unit_count_md; - } - } - - $this->total_homes = $total; - $this->total_homes_sd = $total_sd; - $this->total_homes_md = $total_md; - return $total; - } - if($name == "required_fields") { if(!$this->required_preorder_fields) return []; $this->required_fields = json_decode($this->required_preorder_fields); diff --git a/application/Preordercampaign/PreordercampaignController.php b/application/Preordercampaign/PreordercampaignController.php index 20d50b281..70a3bdbc1 100644 --- a/application/Preordercampaign/PreordercampaignController.php +++ b/application/Preordercampaign/PreordercampaignController.php @@ -53,7 +53,7 @@ class PreordercampaignController extends mfBaseController { 'id' => $c->id, 'network_id' => $c->network_id, 'network_name' => $c->network->name, - 'network_owner_name' => $c->network->owner->getCompanyOrName(), + 'network_owner_name' => $c->network->owner ? $c->network->owner->getCompanyOrName() : '', 'name' => $c->name, 'area' => $c->area, 'from' => $c->from,