Files
thetool/Layout/default/Dashboard/Dashboard.php
2024-02-26 13:33:15 +01:00

463 lines
18 KiB
PHP

<?php
$thetime = microtime(true);
$additionalJS = ["plugins/chart.js/Chart.min.js"];
$chartColors = [
'#3366CC',
'#DC3912',
'#FF9900',
'#109618',
'#990099',
'#3B3EAC',
'#0099C6',
'#DD4477',
'#66AA00',
'#B82E2E',
'#316395',
'#994499',
'#22AA99',
'#AAAA11',
'#6633CC',
'#E67300',
'#8B0707',
'#329262',
'#5574A6',
'#3B3EAC'
]
?>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<div class="row justify-content-center mt-1">
<div class="col-12 col-xl-10">
<h3>Dashboard</h3>
</div>
</div>
<?php if(is_array($newss) && count($newss)): ?>
<?php foreach($newss as $news): ?>
<div class="row justify-content-center mt-1">
<div class="col-12 col-xl-10 mt-2">
<h4>Neuigkeiten</h4>
<div class="card no-shadow" style="border: 1px solid #ced4da">
<div class="card-header bg-info text-white pt-1 pb-1" style="font-size: 1rem; font-weight: 400;">
<span><?=date("d.m.Y", $news->create)?>:</span>
<?php if($news->subject): ?>
<?=$news->subject?>
<?php endif; ?>
</div>
<div class="card-body pb-0 pt-1">
<div class="row col-12">
<div><?=$news->text?></div>
</div>
</div>
<div class="card-footer pt-1 pb-1 bg-light text-secondary text-monospace font-italic">
<?=$news->editor->name?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="row justify-content-center mt-2">
<div class="col-12 col-xl-10">
<div class="card bg-light border-top-success">
<div class="card-header pb-0">
<h4 class="card-title">Akquise Statistiken</h4>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<h4>Filter</h4>
<?php if($me->is("Admin")): ?>
<h5 class="mt-3">Netzinhaber:</h5>
<div class="row mb-2">
<div class="col-3 pb-1">
<a href="<?=self::getUrl("Dashboard")?>" class="form-control btn btn-rounded <?=(!$netowner_id) ? "btn-primary" : "btn-outline-primary"?>">Alle</a>
</div>
<?php foreach(AddressModel::search(["addresstype" => ["netowner"]]) as $netowner): ?>
<div class="col-3 pb-1">
<?php if($netowner_id == $netowner->id): ?>
<a href="<?=self::getUrl("Dashboard")?>" class="form-control btn btn-rounded btn-primary"><?=$netowner->getCompanyOrName()?></a>
<?php else: ?>
<a href="<?=self::getUrl("Dashboard", "", ["netowner_id" => $netowner->id])?>" class="form-control btn btn-rounded btn-outline-primary"><?=$netowner->getCompanyOrName()?></a>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<label for="campaign_id">Kampagne:</label>
<select name="campaign_id" id="campaign_id" class="form-control mb-2">
<option value="0">Alle</option>
<?php foreach($campaigns as $c): ?>
<option value="<?=$c->id?>" <?=($c->id == $campaign_id) ? 'selected="selected"' : ""?>><?=$c->name?></option>
<?php endforeach; ?>
</select>
<label for="gemeinde_id" class="mt-2">Gemeinde:</label>
<select name="gemeinde_id" id="gemeinde_id" class="form-control">
<option value="0">Alle</option>
<?php foreach($gemeinden as $g): ?>
<option value="<?=$g->id?>" <?=($g->id == $gemeinde_id) ? 'selected="selected"' : ""?>><?=$g->name?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-danger">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="fad fa-shopping-cart text-white widget-icon font-24"></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>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline1"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-success">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="fas fa-check text-white widget-icon font-24"></i>
</div>
<h5 class="text-white font-weight-normal mt-0">Aktive Anschlüsse</h5>
<h3 class="mt-2 text-white"><?=$status_connected?> / <?=$count_orders?></h3>
</div>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline4"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-primary">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="fad fa-building text-white widget-icon font-24"></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>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline2"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
<div class="col-xl-3 col-lg-6">
<div class="card">
<div class="card-body p-0 bg-info">
<div style="height: 128px;" class="p-3">
<div class="float-right">
<i class="fad fa-buildings text-white widget-icon font-24"></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>
<canvas style="position: absolute; bottom:0;" height="60" id="sparkline3"></canvas>
</div> <!-- end card-body-->
</div> <!-- end card-->
</div> <!-- end col-->
</div>
<div class="row mt-2">
<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(count($partner_orders)): ?>
<div class="col-12 col-xl-6">
<canvas id="partner-chart" height="200"></canvas>
</div>
<div class="col-12 col-xl-6">
<table>
<?php $i=0; foreach($partner_orders as $partner => $count): ?>
<tr style="border-bottom: 1px solid <?=$chartColors[$i]?>;">
<td><span style="background-color: <?=$chartColors[$i]?>; color: <?=$chartColors[$i]?>">##</span></td>
<td class="pl-2 pr-2" style="white-space: nowrap;"><?=round(($count / $total_orders) * 100, 1)?>% (<?=($count)?>)</td>
<td title="<?=$partner?>" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><?=$this->strtrim($partner,22)?></td>
</tr>
<?php $i++; endforeach; ?>
</table>
</div>
<?php else: ?>
<i>Keine Bestellungen</i>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="col-12 col-xl-6">
<div class="card">
<div class="card-body">
<h4 class="card-title">Bestellstatus je Partner</h4>
<hr />
<div class="row">
<?php if(count($partner_orders_by_status)): ?>
<?php $i=0; foreach($partner_orders_by_status as $partner => $status): ?>
<div class="col-lg-12">
<div class="card">
<div class="card-header no-decoration">
<span class="card-title" title="<?=$partner?>"><?=$this->strtrim($partner, 200)?></span>
</div>
<div class="card-body">
<div class="row">
<div class="col-12 col-xl-6">
<canvas id="partner-status-<?=$i?>"></canvas>
</div>
<div class="col-12 col-xl-6">
<table>
<?php $j=0; foreach($status as $status_id => $count): ?>
<?php if($status_id == "total") continue; ?>
<tr style="border-bottom: 1px solid <?=$chartColors[$j]?>;">
<td class="align-top"><span style="background-color: <?=$chartColors[$j]?>; color: <?=$chartColors[$j]?>">##</span></td>
<td class="align-top pl-2 pr-2" style="white-space: nowrap;"><?=round(($count / $status['total']) * 100, 1)?>% (<?=($count)?>)</td>
<td title="<?=$stati[$status_id]["code"]?> - <?=$stati[$status_id]["name"]?>">
<?=$stati[$status_id]["code"]." - ".$stati[$status_id]["name"]?>
</td>
</tr>
<?php $j++; endforeach; ?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php if($i % 2 != 0): ?>
</div>
<div class="row">
<?php endif; ?>
<?php $i++; endforeach; ?>
<?php if($i % 2 == 0): ?>
</div>
<?php endif; ?>
<?php else: ?>
<i>Keine Bestellungen</i>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#campaign_id").select2();
$("#gemeinde_id").select2();
$("#campaign_id").change(function() {
var cid = parseInt($(this).val());
<?php if($campaign_id): ?>
if(cid == <?=$campaign_id?>) {
return;
}
<?php endif; ?>
if(cid > 0) {
location.href="<?=self::getUrl("Dashboard")?>?campaign_id=" + cid;
} else {
location.href="<?=self::getUrl("Dashboard")?>";
}
});
$("#gemeinde_id").change(function() {
var gid = parseInt($(this).val());
<?php if($gemeinde_id): ?>
if(gid == <?=$gemeinde_id?>) {
return;
}
<?php endif; ?>
if(gid > 0) {
location.href="<?=self::getUrl("Dashboard")?>?gemeinde_id=" + gid;
} else {
location.href="<?=self::getUrl("Dashboard")?>";
}
});
<?php if(count($partner_orders)): ?>
var providerChart = new Chart(document.getElementById('partner-chart').getContext('2d'), {
type: 'doughnut',
data: {
labels: [
<?php foreach($partner_orders as $partner => $c): ?>
"<?=$partner?> (<?=round(($c / $total_orders) * 100, 1)?>%)",
<?php endforeach; ?>
],
datasets: [{
data: [
<?php foreach($partner_orders as $c): ?>
<?=($c)?>,
<?php endforeach; ?>
],
backgroundColor: [
"<?=implode('","', $chartColors)?>"
],
borderWidth: 2
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
},
legend: false,
}
});
<?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; ?>
var productCharts = [];
<?php $i=0; foreach($partner_orders_by_status as $partner => $status): ?>
productCharts[<?=$i?>] = new Chart(document.getElementById('partner-status-<?=$i?>').getContext('2d'), {
type: 'doughnut',
data: {
labels: [
<?php foreach($status as $status_id => $count): ?>
<?php if($status_id == "total") continue; ?>
"<?=$stati[$status_id]['code']?> - <?=$stati[$status_id]['name']?> (<?=round($count / $status["total"] * 100, 1)?>%)",
<?php endforeach; ?>
],
datasets: [{
data: [
<?php foreach($status as $status_id => $count): ?>
<?php if($status_id == "total") continue; ?>
<?=$count?>,
<?php endforeach; ?>
],
backgroundColor: [
"<?=implode('","', $chartColors)?>"
],
/*borderColor: [
"#d54369",
"#4592e0"
],*/
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
},
legend: false
}
});
<?php $i++; endforeach; ?>
});
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
<?php
$thetime = microtime(true) - $thetime;
$this->log->debug("Rendering Dashboard page took $thetime microseconds");
?>