Updated Dashboard and made it live

This commit is contained in:
Luca Haid
2025-01-13 10:44:32 +01:00
parent 9f7338c77f
commit a6df4c6496
5 changed files with 185 additions and 168 deletions

View File

@@ -22,9 +22,8 @@ class DashboardController extends mfBaseController {
$this->layout()->set("newss", $newss);
if($this->me->can("Statistics") && $this->me->is(["Admin", "netowner", "salespartner"])) {
return $this->dashboardAction();
$this->redirect("DashboardNew");
}
}
protected function dashboardAction() {

View File

@@ -5,6 +5,7 @@ class DashboardNewController extends mfBaseController {
private User $me;
protected function init(): void {
$this->needlogin=true;
$me = new User();
$me->loadMe();
$this->layout()->set("me", $me);
@@ -12,19 +13,24 @@ class DashboardNewController extends mfBaseController {
}
protected function indexAction() {
if (!$this->me->can("Statistics") || !$this->me->is(["Admin", "netowner", "salespartner"])) {
$this->redirect("Dashboard");
}
$this->layout()->set('additionalJS', ["plugins/chart.js/chart.4.4.6.js", "plugins/chart.js/chartjs-adapter-moment.min.js"]);
Helper::renderVue($this, "DashboardNew", $this->mod, []);
Helper::renderVue($this, $this->mod, "Dashboard", ["IS_ADMIN" => $this->me->is("Admin") ? "true" : "false"]);
}
protected function getNetOwnerFilterOptionsAction() {
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
$allPreorderCampaigns = PreordercampaignModel::getAll();
$netowners = [];
foreach ($allPreorderCampaigns as $campaign) {
$network = new Network($campaign->network_id);
if (!$this->me->is("Admin") && $network->owner_id != $this->me->address_id) continue;
$networkOwner = new Address($network->owner_id);
$ownerName = $networkOwner->getCompanyOrName();
@@ -37,12 +43,11 @@ class DashboardNewController extends mfBaseController {
}
protected function getCampaignFilterOptionsAction() {
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
$post = json_decode(file_get_contents('php://input'), true);
$netowner_ids = isset($post['netOwners']) ? [$post['netOwners']] : [];
$campaigns = [];
$all_campaigns = PreordercampaignModel::getAll();
$all_campaigns = $this->me->is("Admin") ? PreordercampaignModel::getAll() : PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
if (!empty($netowner_ids)) {
foreach ($all_campaigns as $campaign) {
@@ -64,13 +69,12 @@ class DashboardNewController extends mfBaseController {
}
protected function getCampaignGemeindeFilterOptionsAction() {
if (!$this->me->is("Admin")) return; // TODO: enable for RML and Energie Steiermark
$post = json_decode(file_get_contents('php://input'), true);
$netowner_ids = isset($post['netOwners']) ? [$post['netOwners']] : [];
$campaign_ids = isset($post['campaigns']) ? [$post['campaigns']] : [];
$campaigns = [];
$all_campaigns = PreordercampaignModel::getAll();
$all_campaigns = $this->me->is("Admin") ? PreordercampaignModel::getAll() : PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
if (!empty($netowner_ids)) {
foreach ($all_campaigns as $campaign) {
@@ -94,6 +98,30 @@ class DashboardNewController extends mfBaseController {
self::returnJson($this->getGemeindenFromCampaigns($campaigns));
}
private function checkParameterAuthorization($campaign_ids = []) {
// $campaigns = PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
// $campaign_filter = ["preordercampaign_id" => $campaign_ids];
// if(!$campaign_ids) {
// foreach(PreordercampaignModel::search(["owner_id" => $this->me->address_id]) as $campaign) {
// $campaign_ids[] = $campaign->id;
// }
// }
// we need to use this if the user is not a admin to only show his campaigns
// we will pass the campaign_ids to the function and check if the user is allowed to see the data
// if the user is not allowed to see the data we will return an empty array
$campaigns = PreordercampaignModel::search(["owner_id" => $this->me->address_id]);
// loop through the campaigns and check if the user is allowed to see the data
foreach ($campaigns as $campaign) {
if (!in_array($campaign->id, $campaign_ids)) {
$key = array_search($campaign->id, $campaign_ids);
unset($campaign_ids[$key]);
}
}
return $campaign_ids;
}
private function getGemeindenFromCampaigns($campaignids = []) {
$gemeinden = [];
@@ -138,24 +166,11 @@ class DashboardNewController extends mfBaseController {
$mph_connection_types = ["apartment-building", "apartment", "multi-dwelling"];
$countFunction = function($params, $statusFlag = null) use ($campaign_ids, $gemeinde_ids) {
$baseParams = ["preordercampaign_id" => $campaign_ids];
if (!empty($gemeinde_ids)) {
// as the count only supports 1 gemeinde id as filter we need to use a foreach to get the count for multiple gemeinde ids
$count = 0;
foreach ($gemeinde_ids as $gemeinde_id) {
$baseParams["gemeinde_id"] = $gemeinde_id;
$count += $statusFlag ?
PreorderModel::countStatusFlagsActive($baseParams, $statusFlag) :
PreorderModel::countActive($baseParams);
}
return $count;
} else {
$params = array_merge($baseParams, $params);
return $statusFlag ?
PreorderModel::countStatusFlagsActive($params, $statusFlag) :
PreorderModel::countActive($params);
}
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
$params = array_merge($baseParams, $params);
return $statusFlag ?
PreorderModel::countStatusFlagsActive($params, $statusFlag) :
PreorderModel::countActive($params);
};
@@ -205,16 +220,8 @@ class DashboardNewController extends mfBaseController {
private function getTimeline($type, $campaign_ids, $gemeinde_ids) { //TODO: fix gemeinde
$timeline = [];
$baseParams = ["preordercampaign_id" => $campaign_ids];
if (!empty($gemeinde_ids)) {
foreach ($gemeinde_ids as $gemeinde_id) {
$baseParams["gemeinde_id"] = $gemeinde_id;
$timeline[] = $this->getTimelineData($type, $baseParams);
}
} else {
$timeline[] = $this->getTimelineData($type, $baseParams);
}
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
$timeline[] = $this->getTimelineData($type, $baseParams);
return $timeline;
}
@@ -240,7 +247,7 @@ class DashboardNewController extends mfBaseController {
}
// Load cached data if it exists
if (file_exists($cacheFile)) {
if (file_exists($cacheFile) && false) {
$cachedData = json_decode(file_get_contents($cacheFile), true);
$lastCachedDate = end($cachedData)['date'];
$lastCachedTimestamp = strtotime($lastCachedDate);

View File

@@ -748,9 +748,12 @@ class PreorderModel {
}
if(array_key_exists("gemeinde_id", $filter)) {
$gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']);
if($gemeinde_id) {
if(!is_array($filter['gemeinde_id'])) {
$gemeinde_id = FronkDB::singleton()->escape($filter['gemeinde_id']);
$where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id = $gemeinde_id";
} elseif(count($filter['gemeinde_id'])) {
$gemeinde_id = $filter['gemeinde_id'];
$where .= " AND `".ADDRESSDB_DBNAME."`.adb_hausnummer.gemeinde_id IN (".implode(",",$gemeinde_id).")";
}
}

View File

@@ -29,6 +29,10 @@
gap: 1rem;
}
.dashboard-data-selector--no-net-owner {
grid-template-columns: repeat(2, 1fr);
}
.dashboard-chart {
height: 400px;
margin-top: 20px;

View File

@@ -1,7 +1,7 @@
Vue.component('dashboard-location-selector', {
template: `
<div class="dashboard-data-selector">
<tt-select sm label="Netzbesitzer" :value="selectedNetworkOwner" :options="filterOptions.netOwners" @input="$emit('update:selectedNetworkOwner', $event)"/>
<div class="dashboard-data-selector" :class="{ 'dashboard-data-selector--no-net-owner': !showNetOwnerFilter }">
<tt-select sm label="Netzbesitzer" v-if="showNetOwnerFilter" :value="selectedNetworkOwner" :options="filterOptions.netOwners" @input="$emit('update:selectedNetworkOwner', $event)"/>
<tt-select sm label="Kampagne" :value="selectedCampaign" :options="filterOptions.campaigns" @input="$emit('update:selectedCampaign', $event)"/>
<tt-select sm label="Gemeinde" :value="selectedGemeinde" :options="filterOptions.gemeinden" @input="$emit('update:selectedGemeinde', $event)"/>
</div>
@@ -15,6 +15,7 @@ Vue.component('dashboard-location-selector', {
,
data() {
return {
showNetOwnerFilter: window.TT_CONFIG["IS_ADMIN"] === 'true',
filterOptions: {
netOwners: [],
campaigns: [],
@@ -189,137 +190,140 @@ Vue.component('tt-timeline-chart', {
Vue.component('dashboard-new', {
template: `
<tt-card>
<tt-loader v-if="isLoading" style="margin: -1.5rem"/>
<div class="dashboard-new">
<dashboard-location-selector
:selectedNetworkOwner="selectedNetworkOwner"
:selectedCampaign="selectedCampaign"
:selectedGemeinde="selectedGemeinde"
@update:selectedNetworkOwner="selectedNetworkOwner = $event"
@update:selectedCampaign="selectedCampaign = $event"
@update:selectedGemeinde="selectedGemeinde = $event"
/>
<hr>
<h4 class="mt-4">Bestellungen</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Bestellungen gesamt"
icon="fas fa-check"
:text="dashboardData.order_actual_order + ' / ' + dashboardData.order_max_home_addrdb + ' (' + Math.round((dashboardData.order_actual_order / dashboardData.order_max_home_addrdb) * 100) + '%)'"
:subHeaders="[
<tt-card>
<template v-slot:header>
<h3>Akquise Statistiken</h3>
</template>
<tt-loader v-if="isLoading" style="margin: -5rem -1.5rem -1.5rem;"/>
<div class="dashboard-new">
<dashboard-location-selector
:selectedNetworkOwner="selectedNetworkOwner"
:selectedCampaign="selectedCampaign"
:selectedGemeinde="selectedGemeinde"
@update:selectedNetworkOwner="selectedNetworkOwner = $event"
@update:selectedCampaign="selectedCampaign = $event"
@update:selectedGemeinde="selectedGemeinde = $event"
/>
<hr>
<h4 class="mt-4">Bestellungen</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Bestellungen gesamt"
icon="fas fa-check"
:text="dashboardData.order_actual_order + ' / ' + dashboardData.order_max_home_addrdb + ' (' + Math.round((dashboardData.order_actual_order / dashboardData.order_max_home_addrdb) * 100) + '%)'"
:subHeaders="[
// add percentage in () here
'Vollanschluss: ' + (parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss)) + ' (' + Math.round(((parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss)) / parseInt(dashboardData.order_actual_order) * 100)) + '%)',
'Vorsorgeanschluss: ' + (parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge)) + ' (' + Math.round(((parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge)) / parseInt(dashboardData.order_actual_order) * 100)) + '%)'
]"
color="#28a745"
/>
<tt-dashboard-display-card
header="Bestellungen gesamt EFH"
icon="fas fa-home"
:text="dashboardData.order_efh"
:subHeaders="[
color="#28a745"
/>
<tt-dashboard-display-card
header="Bestellungen gesamt EFH"
icon="fas fa-home"
:text="dashboardData.order_efh"
:subHeaders="[
'Vollanschluss: ' + dashboardData.order_efh_vollanschluss + ' (' + Math.round((dashboardData.order_efh_vollanschluss / dashboardData.order_efh) * 100) + '%)',
'Vorsorgeanschluss: ' + dashboardData.order_efh_vorsorge + ' (' + Math.round((dashboardData.order_efh_vorsorge / dashboardData.order_efh) * 100) + '%)'
]"
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Bestellungen gesamt MPH"
icon="fas fa-building"
:text="dashboardData.order_mph"
:subHeaders="[
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Bestellungen gesamt MPH"
icon="fas fa-building"
:text="dashboardData.order_mph"
:subHeaders="[
'Vollanschluss: ' + dashboardData.order_mph_vollanschluss + ' (' + Math.round((dashboardData.order_mph_vollanschluss / dashboardData.order_mph) * 100) + '%)',
'Vorsorgeanschluss: ' + dashboardData.order_mph_vorsorge + ' (' + Math.round((dashboardData.order_mph_vorsorge / dashboardData.order_mph) * 100) + '%)'
]"
color="#f5b902"
/>
</div>
<hr>
<h4 class="mt-4">Baufortschritt</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Leerrohr an der Grundstücksgrenze abgelegt"
icon="fas fa-road"
:text="dashboardData.baufortschritt_140 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.baufortschritt_140 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#28a745"
/>
<tt-dashboard-display-card
header="Installationspaket erhalten"
icon="fas fa-box-open"
:text="dashboardData.installationspaket_erhalten + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.installationspaket_erhalten / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Leerrohr im Haus"
icon="fas fa-house-user"
:text="dashboardData.lehrrohr_im_haus + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.lehrrohr_im_haus / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#f5b902"
/>
<tt-dashboard-display-card
header="Inhousekabel verlegt EFH"
icon="fas fa-plug"
:text="dashboardData.inhouse_kabel_verlegt_efh + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.inhouse_kabel_verlegt_efh / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#007bff"
/>
<tt-dashboard-display-card
header="Inhousekabel verlegt MPH"
icon="fas fa-building-user"
:text="dashboardData.inhouse_kabel_verlegt_mph + ' / ' + dashboardData.order_mph + ' (' + Math.round((dashboardData.inhouse_kabel_verlegt_mph / dashboardData.order_mph) * 100) + '%)'"
:subHeaders="[]"
color="#0bb36c"
/>
</div>
<hr>
<h4 class="mt-4">Installationsfortschritt</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Installation freigegeben"
icon="fas fa-tools"
:text="dashboardData.installationsfortschritt_245 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.installationsfortschritt_245 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#28a745"
/>
<tt-dashboard-display-card
header="ONT installiert"
icon="fas fa-wifi"
:text="dashboardData.ont_installiert_300 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.ont_installiert_300 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Vollanschluss dokumentiert"
icon="fas fa-file-alt"
:text="dashboardData.vollanschluss_dokumentiert_350 + ' / ' + (parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss)) + ' (' + Math.round((dashboardData.vollanschluss_dokumentiert_350 / (parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss))) * 100) + '%)'"
:subHeaders="[]"
color="#f5b902"
/>
<tt-dashboard-display-card
header="Vorsorgeanschluss dokumentiert"
icon="fas fa-file-alt"
:text="dashboardData.vorsorge_dokumentiert_351 + ' / ' + (parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge)) + ' (' + Math.round((dashboardData.vorsorge_dokumentiert_351 / (parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge))) * 100) + '%)'"
:subHeaders="['']"
color="#007bff"
/>
<tt-dashboard-display-card
header="Provider bestellt"
icon="fas fa-shopping-cart"
:text="dashboardData.provider_bestellt_500 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.provider_bestellt_500 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#0bb36c"
/>
</div>
color="#f5b902"
/>
</div>
<hr>
<h4 class="mt-4">Baufortschritt</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Leerrohr an der Grundstücksgrenze abgelegt"
icon="fas fa-road"
:text="dashboardData.baufortschritt_140 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.baufortschritt_140 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#28a745"
/>
<tt-dashboard-display-card
header="Installationspaket erhalten"
icon="fas fa-box-open"
:text="dashboardData.installationspaket_erhalten + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.installationspaket_erhalten / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Leerrohr im Haus"
icon="fas fa-house-user"
:text="dashboardData.lehrrohr_im_haus + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.lehrrohr_im_haus / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#f5b902"
/>
<tt-dashboard-display-card
header="Inhousekabel verlegt EFH"
icon="fas fa-plug"
:text="dashboardData.inhouse_kabel_verlegt_efh + ' / ' + dashboardData.order_efh + ' (' + Math.round((dashboardData.inhouse_kabel_verlegt_efh / dashboardData.order_efh) * 100) + '%)'"
:subHeaders="[]"
color="#007bff"
/>
<tt-dashboard-display-card
header="Inhousekabel verlegt MPH"
icon="fas fa-building-user"
:text="dashboardData.inhouse_kabel_verlegt_mph + ' / ' + dashboardData.order_mph + ' (' + Math.round((dashboardData.inhouse_kabel_verlegt_mph / dashboardData.order_mph) * 100) + '%)'"
:subHeaders="[]"
color="#0bb36c"
/>
</div>
<hr>
<h4 class="mt-4">Installationsfortschritt</h4>
<div class="dashboard-cards position-relative">
<tt-dashboard-display-card
header="Installation freigegeben"
icon="fas fa-tools"
:text="dashboardData.installationsfortschritt_245 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.installationsfortschritt_245 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#28a745"
/>
<tt-dashboard-display-card
header="ONT installiert"
icon="fas fa-wifi"
:text="dashboardData.ont_installiert_300 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.ont_installiert_300 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#17a2b8"
/>
<tt-dashboard-display-card
header="Vollanschluss dokumentiert"
icon="fas fa-file-alt"
:text="dashboardData.vollanschluss_dokumentiert_350 + ' / ' + (parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss)) + ' (' + Math.round((dashboardData.vollanschluss_dokumentiert_350 / (parseInt(dashboardData.order_efh_vollanschluss) + parseInt(dashboardData.order_mph_vollanschluss))) * 100) + '%)'"
:subHeaders="[]"
color="#f5b902"
/>
<tt-dashboard-display-card
header="Vorsorgeanschluss dokumentiert"
icon="fas fa-file-alt"
:text="dashboardData.vorsorge_dokumentiert_351 + ' / ' + (parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge)) + ' (' + Math.round((dashboardData.vorsorge_dokumentiert_351 / (parseInt(dashboardData.order_efh_vorsorge) + parseInt(dashboardData.order_mph_vorsorge))) * 100) + '%)'"
:subHeaders="['']"
color="#007bff"
/>
<tt-dashboard-display-card
header="Provider bestellt"
icon="fas fa-shopping-cart"
:text="dashboardData.provider_bestellt_500 + ' / ' + dashboardData.order_actual_order + ' (' + Math.round((dashboardData.provider_bestellt_500 / dashboardData.order_actual_order) * 100) + '%)'"
:subHeaders="[]"
color="#0bb36c"
/>
</div>
<hr>
<h4 class="mt-4">Bestellverlauf</h4>
<div class="dashboard-chart">
<tt-timeline-chart
v-if="dashboardData.timeline.length > 0"
:datasets="[
<hr>
<h4 class="mt-4">Bestellverlauf</h4>
<div class="dashboard-chart">
<tt-timeline-chart
v-if="dashboardData.timeline.length > 0"
:datasets="[
{
label: 'Bestellungen',
data: dashboardData.timeline[0],
@@ -345,13 +349,13 @@ Vue.component('dashboard-new', {
order: 1
}
]"
label="KW"
:showGrid="false"
/>
label="KW"
:showGrid="false"
/>
</div>
</div>
</tt-card>
</div>
</div>
</tt-card>
`,
data() {
return {