Grafiek fix en sneller statistiek algorithme
This commit is contained in:
parent
8552933a52
commit
4a20995bc3
7
assets/moment.min.js
vendored
Normal file
7
assets/moment.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -14,30 +14,39 @@ class Statistieken {
|
|||||||
}
|
}
|
||||||
$xas = array();
|
$xas = array();
|
||||||
for($i = $dagen; $i >= 0; $i--){
|
for($i = $dagen; $i >= 0; $i--){
|
||||||
$xas[] = date("d M", strtotime("-$i day"));
|
$xas[] = date("Y-m-d", strtotime("now") - $i * 86400);
|
||||||
}
|
}
|
||||||
$container = Application::getContainer();
|
$container = Application::getContainer();
|
||||||
$user = $container->auth->getUserID();
|
|
||||||
$db = $container->db;
|
$db = $container->db;
|
||||||
$saldo = $db->rekeningen->where("rekeningnr", $rekeningNummer)[array("rekeningnr" => $rekeningNummer)]['saldo'];
|
$saldo = $db->rekeningen->where("rekeningnr", $rekeningNummer)[array("rekeningnr" => $rekeningNummer)]['saldo'];
|
||||||
$eraf = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("van", $rekeningNummer)
|
$eraf = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("van", $rekeningNummer)
|
||||||
->group("datum");
|
->and("`datum` >= '" . date("Y-m-d", strtotime("now") - $dagen * 86400) . "'")->group("datum")->order("datum DESC");
|
||||||
$erbij = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("naar", $rekeningNummer)
|
$erbij = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("naar", $rekeningNummer)
|
||||||
->group("datum");
|
->group("datum")->order("datum DESC");
|
||||||
$huidigSaldo = (double)$saldo;
|
$huidigSaldo = (double)$saldo;
|
||||||
$yas = array($huidigSaldo);
|
$vandaag = strtotime("now");
|
||||||
for($i = 1; $i <= $dagen; $i++){
|
$yas = array_fill(0, $dagen + 1, 0);
|
||||||
$af = (double)$eraf[array("datum" => date("Y-m-d", strtotime("-" . $i + 1 . " day")))]['bedr'];
|
foreach($eraf as $af){
|
||||||
$bij = (double)$erbij[array("datum" => date("Y-m-d", strtotime("-" . $i + 1 . " day")))]['bedr'];
|
$dag = strtotime($af['datum']);
|
||||||
if(!isset($af)){
|
$diff = floor(($vandaag - $dag)/86400);
|
||||||
$af = 0;
|
if($diff <= $dagen){
|
||||||
|
$yas[$dagen - $diff] = (double)$af['bedr'];
|
||||||
}
|
}
|
||||||
if(!isset($bij)){
|
|
||||||
$bij = 0;
|
|
||||||
}
|
}
|
||||||
$huidigSaldo += $af;
|
foreach($erbij as $bij){
|
||||||
$huidigSaldo -= $bij;
|
$dag = strtotime($bij['datum']);
|
||||||
array_unshift($yas, $huidigSaldo);
|
$diff = floor(($vandaag - $dag)/86400);
|
||||||
|
if($diff <= $dagen){
|
||||||
|
$yas[$dagen - $diff + 1] -= (double)$bij['bedr'];
|
||||||
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$verandering = 0;
|
||||||
|
for($i = $dagen; $i >= 0; $i--){
|
||||||
|
$huidigSaldo += $verandering;
|
||||||
|
$verandering = $yas[$i];
|
||||||
|
$yas[$i] = $huidigSaldo;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
"x-as" => $xas,
|
"x-as" => $xas,
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<title>Inforbank</title>
|
<title>Inforbank</title>
|
||||||
<link rel="stylesheet" href="<?= $header['base'] ?>assets/css/main.css">
|
<link rel="stylesheet" href="<?= $header['base'] ?>assets/css/main.css">
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||||
|
<script src="<?= $header['base']?>assets/moment.min.js"></script>
|
||||||
<script src="<?= $header['base']?>assets/chart.min.js"></script>
|
<script src="<?= $header['base']?>assets/chart.min.js"></script>
|
||||||
<base href="<?= $header['base'] ?>">
|
<base href="<?= $header['base'] ?>">
|
||||||
</head>
|
</head>
|
||||||
|
@ -1,27 +1,42 @@
|
|||||||
<?php include '__header.phtml'; ?>
|
<?php include '__header.phtml'; ?>
|
||||||
<a class="btn btn-default pull-left" href="rekeningen/<?= $rekeningnr ?>" role="button">Terug</a>
|
<a class="btn btn-default pull-left" href="rekeningen/<?= $rekeningnr ?>" role="button">Terug</a>
|
||||||
<canvas id="myChart" height="100"></canvas>
|
<canvas id="grafiek" height="100"></canvas>
|
||||||
<script>
|
<script>
|
||||||
function newDate(days) {
|
|
||||||
return moment().add(days, 'd');
|
|
||||||
}
|
|
||||||
Chart.defaults.global.legend.display = false;//Geen legenda
|
Chart.defaults.global.legend.display = false;//Geen legenda
|
||||||
var ctx = document.getElementById("myChart");
|
var grafiek = document.getElementById("grafiek");
|
||||||
var myChart = new Chart(ctx, {
|
var myChart = new Chart(grafiek, {
|
||||||
type: "line",
|
type: "line",
|
||||||
options: {
|
options: {
|
||||||
title: {
|
title: {
|
||||||
display: true,
|
display: true,
|
||||||
text: "Saldo van de afgelopen maand"
|
text: "Saldo van de afgelopen maand"
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
type: "time",
|
||||||
|
unit: "day",
|
||||||
|
time: {
|
||||||
|
displayFormats: {
|
||||||
|
"day": "D MMM"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero:true
|
||||||
|
}
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
|
//Laad de dagen in
|
||||||
labels: <?php echo json_encode($statistieken['x-as']); ?>,
|
labels: <?php echo json_encode($statistieken['x-as']); ?>,
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: "Saldo",
|
label: "Saldo",
|
||||||
|
//Laad de saldo's in
|
||||||
data: <?php echo json_encode($statistieken['y-as']); ?>,
|
data: <?php echo json_encode($statistieken['y-as']); ?>,
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
lineTension: 0,
|
lineTension: 0, //Rechte lijnen
|
||||||
fill: false,
|
fill: false,
|
||||||
borderColor: "black",
|
borderColor: "black",
|
||||||
pointRadius: 5,
|
pointRadius: 5,
|
||||||
|
Reference in New Issue
Block a user