From e2e19f86fd9c1a69ce1653b9b50df590b6d38b49 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 5 Jun 2025 15:24:45 +0200 Subject: [PATCH] added new estmk export --- .../DashboardNew/DashboardNewController.php | 85 ++++++++++++++++++- public/js/pages/DashboardNew/DashboardNew.js | 27 +++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/application/DashboardNew/DashboardNewController.php b/application/DashboardNew/DashboardNewController.php index ccaf37151..73a3a80e9 100644 --- a/application/DashboardNew/DashboardNewController.php +++ b/application/DashboardNew/DashboardNewController.php @@ -19,7 +19,10 @@ class DashboardNewController extends mfBaseController { } $this->layout()->set('additionalJS', ["plugins/chart.js/chart.4.4.6.js", "plugins/chart.js/chartjs-adapter-moment.min.js"]); - Helper::renderVue($this, $this->mod, "Dashboard", ["IS_ADMIN" => $this->me->is("Admin") ? "true" : "false"]); + Helper::renderVue($this, $this->mod, "Dashboard", [ + "IS_ADMIN" => $this->me->is("Admin") ? "true" : "false", + "ME_ADDRESS_ID" => $this->me->address_id, + ]); } protected function adbAction() { @@ -333,6 +336,86 @@ class DashboardNewController extends mfBaseController { ]); } + protected function exportAction() { + // Filter campaigns where network owner is 209 + $netowner_id = 209; + + // Get all campaigns for this network owner + $all_campaigns = $this->me->is("Admin") ? PreordercampaignModel::getAll() : PreordercampaignModel::search(["owner_id" => $this->me->address_id]); + + if (empty($all_campaigns) || $all_campaigns[0] === NULL) { + http_response_code(500); + self::returnJson(["status" => 500, "message" => "Keine Kampagnen gefunden"]); + return; + } + + // Filter campaigns by network owner + $filtered_campaigns = array_filter($all_campaigns, function($campaign) use ($netowner_id) { + $campaign_obj = new Preordercampaign($campaign->id); + return $campaign_obj->network->owner_id == $netowner_id; + }); + + if (empty($filtered_campaigns)) { + http_response_code(404); + self::returnJson(["status" => 404, "message" => "Keine Kampagnen für Netowner 209 gefunden"]); + return; + } + + $export_data = []; + + foreach ($filtered_campaigns as $campaign) { + $campaign_ids = [$campaign->id]; + $gemeinde_ids = []; // Empty array as in original + + $order_max_homes = $this->getTotalHomes($campaign_ids, $gemeinde_ids); + + $efh_connection_types = ["single-dwelling", "business"]; + $mph_connection_types = ["apartment-building", "apartment", "multi-dwelling"]; + + $countFunction = function($params, $statusFlag = null) use ($campaign_ids, $gemeinde_ids) { + $baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids]; + $params = array_merge($baseParams, $params); + return $statusFlag ? + PreorderModel::countStatusFlagsActive($params, $statusFlag) : + PreorderModel::countActive($params); + }; + + $baufortschritt_140 = $countFunction([">status_code" => "139", " "899"]); + $ont_installiert_300 = $countFunction([">status_code" => "299", " "899"]); + $provider_bestellt_500 = $countFunction([">status_code" => "499", " "899"]); + + $campaign_data = [ + 'campaign_id' => $campaign->id, + 'campaign_name' => $campaign->name ?? 'Unnamed Campaign', + '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"]), + '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), + 'installationsfortschritt_245' => $countFunction([">status_code" => "244", " "899"]), + 'ont_installiert_300' => $ont_installiert_300, + 'vollanschluss_dokumentiert_350' => $countFunction(["status_code" => ["350","500"], "type" => "order"]), + 'vorsorge_dokumentiert_351' => $countFunction(["status_code" => ["351","500"], "type" => "provision"]), + 'provider_bestellt_500' => $provider_bestellt_500 + ]; + + $export_data[] = $campaign_data; + } + + self::returnJson($export_data); + } + + + //Installationsfortschritt Provider // diff --git a/public/js/pages/DashboardNew/DashboardNew.js b/public/js/pages/DashboardNew/DashboardNew.js index c182186d4..e7fabb123 100644 --- a/public/js/pages/DashboardNew/DashboardNew.js +++ b/public/js/pages/DashboardNew/DashboardNew.js @@ -594,7 +594,13 @@ Vue.component('dashboard-new', { template: `
@@ -617,6 +623,7 @@ Vue.component('dashboard-new', { `, data() { return { + window, dashboardData: { type: 'unloaded', order_max_home_addrdb: 0, @@ -665,6 +672,24 @@ Vue.component('dashboard-new', { } finally { this.isLoading = false; } + }, + async csvExport() { + this.isLoading = true; + try { + const response = await axios.get(`${window.TT_CONFIG['BASE_URL']}/export`); + + const csvData = response.data; + const csvContent = "data:text/csv;charset=utf-8," + [Object.keys(csvData[0]), ...csvData.map(obj => Object.keys(csvData[0]).map(header => obj[header]))].map(e => e.join(";")).join("\n"); const encodedUri = encodeURI(csvContent); + const link = document.createElement("a"); + link.setAttribute("href", encodedUri); + link.setAttribute("download", `Statistik_${new Date().toISOString()}.csv`); + document.body.appendChild(link); // Required for FF + link.click(); + } catch (error) { + console.error('Error exporting CSV:', error); + } finally { + this.isLoading = false; + } } }, watch: {