added new estmk export
This commit is contained in:
@@ -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", "<status_code" => "899"]);
|
||||
$ont_installiert_300 = $countFunction([">status_code" => "299", "<status_code" => "899"]);
|
||||
$provider_bestellt_500 = $countFunction([">status_code" => "499", "<status_code" => "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", "<status_code" => "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
|
||||
//
|
||||
|
||||
|
||||
@@ -594,7 +594,13 @@ Vue.component('dashboard-new', {
|
||||
template: `
|
||||
<tt-card>
|
||||
<template v-slot:header>
|
||||
<h3>Akquise Statistiken</h3>
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr">
|
||||
<h3>Akquise Statistiken</h3>
|
||||
|
||||
<tt-button
|
||||
v-if="window.TT_CONFIG['IS_ADMIN'] === 'true' || window.TT_CONFIG.ME_ADDRESS_ID === '209'"
|
||||
text="Gesamt CSV Download" additional-class="btn-success" @click="csvExport" icon="fa fa-download"/>
|
||||
</div>
|
||||
</template>
|
||||
<tt-loader v-if="isLoading" style="margin: -5rem -1.5rem -1.5rem;"/>
|
||||
<div class="dashboard-new">
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user