added sparkline to order count on dashboard

This commit is contained in:
Frank Schubert
2024-01-11 22:47:26 +01:00
parent ea8fd727f6
commit bb93587135
2 changed files with 111 additions and 16 deletions

View File

@@ -61,12 +61,14 @@ $chartColors = [
<?php endif; ?>
<div class="row justify-content-center mt-4">
<div class="row justify-content-center mt-2">
<div class="col-12 col-xl-10">
<h4>Akquise Statistiken <small>Momentan nur für Admins sichtbar <i class="far fa-smile text-success"></i></small></h4>
<div class="card bg-light border-top-success">
<div class="card-header pb-0">
<h4 class="card-title">Akquise Statistiken <small>Momentan nur für Admins sichtbar <i class="far fa-smile text-success"></i></small></h4>
</div>
<div class="card-body">
<div class="row mb-2">
<div class="col">
<label for="campaign_id">Kampagne:</label>
@@ -83,14 +85,15 @@ $chartColors = [
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-danger">
<div class="p-3 pb-0">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="mdi mdi-cart text-white widget-icon"></i>
</div>
<h5 class="text-white font-weight-normal mt-0">Bestellungen</h5>
<h3 class="mt-2 text-white"><?=$count_orders?> / <?=$max_connections?></h3>
</div>
<div id="sparkline1"></div>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline1"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
@@ -98,14 +101,14 @@ $chartColors = [
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-primary">
<div class="p-3 pb-0">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="mdi mdi-cart text-white widget-icon"></i>
</div>
<h5 class="text-white font-weight-normal mt-0">Status BEP Installed (244, SD)</h5>
<h3 class="mt-2 text-white"><?=$status_connected_single?> / <?=$count_orders?></h3>
</div>
<div id="sparkline1"></div>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline2"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
@@ -113,14 +116,14 @@ $chartColors = [
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-info">
<div class="p-3 pb-0">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="mdi mdi-cart text-white widget-icon"></i>
</div>
<h5 class="text-white font-weight-normal mt-0">Status OTO Installed (245, MD)</h5>
<h3 class="mt-2 text-white"><?=$status_connected_multi?> / <?=$count_orders?></h3>
</div>
<div id="sparkline1"></div>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline3"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
@@ -128,14 +131,14 @@ $chartColors = [
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-warning">
<div class="p-3 pb-0">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="mdi mdi-cart text-dark widget-icon"></i>
</div>
<h5 class="text-dark font-weight-normal mt-0">Aktive Anschlüsse</h5>
<h3 class="mt-2 text-dark"><?=$status_connected?> / <?=$count_orders?></h3>
</div>
<div id="sparkline1"></div>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline4"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
@@ -143,18 +146,18 @@ $chartColors = [
</div>
<div class="row mt-2">
<div class="col-6">
<div class="col-12 col-xl-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">Kunden je Partner</h4>
<hr />
<div class="row">
<?php if(1): ?>
<div class="col-lg-7">
<?php if(count($partner_orders)): ?>
<div class="col-12 col-xl-7">
<canvas id="partner-chart" height="200"></canvas>
</div>
<div class="col-lg-5">
<div class="col-12 col-xl-5">
<table>
<?php $i=0; foreach($partner_orders as $provider => $count): ?>
<tr style="border-bottom: 1px solid <?=$chartColors[$i]?>;">
@@ -234,7 +237,70 @@ $chartColors = [
}
});
<?php endif; ?>
<?php if(count($weekly_orders)): ?>
const chart = new Chart(document.getElementById('sparkline1').getContext('2d'), {
type: 'line',
data: {
labels: [
<?php $wo = [] ?>
<?php foreach($weekly_orders as $time => $o): $wo[] = "KW".date("W Y", $time); endforeach; ?>
"<?=implode('","', $wo)?>"
],
datasets: [
{
label: "",
fill: true,
data: [
<?=implode(",", $weekly_orders)?>
]
}
]
},
options: {
responsive: true,
legend: {
display: false
},
elements: {
line: {
borderColor: '#800',
borderWidth: 1
},
point: {
radius: 0
}
},
tooltips: {
mode: 'index',
intersect: false
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
yAxes: [
{
display: false
}
],
xAxes: [
{
display: false
}
]
},
interaction: {
intersect: false,
mode: 'index',
},
}
});
<?php endif; ?>
});
</script>

View File

@@ -53,6 +53,7 @@ class DashboardController extends mfBaseController {
$max_connections = $this->getTotalHomes($campaign_ids);
$count_orders = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0]);
$weekly_orders = $this->getWeeklyOrders($campaign_ids);
$status_connected_single = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0, "status_code" => 244]);
$status_connected_multi = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0, "status_code" => 245]);
@@ -71,7 +72,8 @@ class DashboardController extends mfBaseController {
$max_connections = $this->getTotalHomes($campaign_ids);
$count_orders = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0]);
$weekly_orders = $this->getWeeklyOrders($campaign_ids);
$status_connected_single = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0, "status_code" => 244]);
$status_connected_multi = PreorderModel::count(["preordercampaign_id" => $campaign_ids, "deleted" => 0, "status_code" => 245]);
@@ -86,6 +88,8 @@ class DashboardController extends mfBaseController {
$this->layout()->set("max_connections", $max_connections);
$this->layout()->set("count_orders", $count_orders);
$this->layout()->set("weekly_orders", $weekly_orders);
$this->layout()->set("status_connected_single", $status_connected_single);
$this->layout()->set("status_connected_multi", $status_connected_multi);
$this->layout()->set("status_connected", $status_connected);
@@ -132,6 +136,31 @@ class DashboardController extends mfBaseController {
return $orders;
}
private function getWeeklyOrders($preordercampaign_id = []) {
$orders = [];
$week = new DateTime("now - 52 weeks");
$start = $week->getTimestamp();
for($w = 1; $w <= 52; $w++) {
$week->modify("+1 week");
$end = $week->getTimestamp();
/*$week = $now->modify("-$w weeks");
$week_before = $week->modify("-1 weeks");
$this->log->debug("now: ".$now->getTimestamp()." | week ".$week->getTimestamp()." | before: ".$week_before->getTimestamp());*/
$where = "AND (tt_preorder.`create` > $start AND tt_preorder.`create` <= $end)";
$count = PreorderModel::count(["preordercampaign_id" => $preordercampaign_id, "deleted" => 0, "add-where" => $where]);
$orders[$week->getTimestamp()] = $count;
$start = $end;
}
return $orders;
//var_dump($orders);exit;
}
protected function pdfAction() {
$order = new Order(7);
$owner = new Address(1);