Statistieken
This commit is contained in:
47
src/Application/Helper/Statistieken.php
Normal file
47
src/Application/Helper/Statistieken.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Inforbank\Application\Helper;
|
||||
|
||||
use Exception;
|
||||
use Inforbank\Application;
|
||||
|
||||
class Statistieken {
|
||||
public static $EIGENAAR = 1;
|
||||
|
||||
public static function getSaldoverloop($dagen, $rekeningNummer){
|
||||
if(!Rekeningen::isEigenRekeningnr($rekeningNummer)){
|
||||
throw new Exception("Dit is niet uw eigen rekening", Statistieken::$EIGENAAR);
|
||||
}
|
||||
$xas = array();
|
||||
for($i = $dagen; $i >= 0; $i--){
|
||||
$xas[] = date("d M", strtotime("-$i day"));
|
||||
}
|
||||
$container = Application::getContainer();
|
||||
$user = $container->auth->getUserID();
|
||||
$db = $container->db;
|
||||
$saldo = $db->rekeningen->where("rekeningnr", $rekeningNummer)[array("rekeningnr" => $rekeningNummer)]['saldo'];
|
||||
$eraf = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("van", $rekeningNummer)
|
||||
->group("datum")->order("datum ASC, id DESC");
|
||||
$erbij = $db->transacties->select("datum, SUM(bedrag) as bedr")->where("naar", $rekeningNummer)
|
||||
->group("datum")->order("datum ASC, id DESC");
|
||||
$huidigSaldo = (double)$saldo;
|
||||
$yas = array($huidigSaldo);
|
||||
for($i = 1; $i <= $dagen; $i++){
|
||||
$af = (double)$eraf[array("datum" => date("Y-m-d", strtotime("-" . $i . " day")))]['bedr'];
|
||||
$bij = (double)$erbij[array("datum" => date("Y-m-d", strtotime("-" . $i . " day")))]['bedr'];
|
||||
if(!isset($af)){
|
||||
$af = 0;
|
||||
}
|
||||
if(!isset($bij)){
|
||||
$bij = 0;
|
||||
}
|
||||
$huidigSaldo += $af;
|
||||
$huidigSaldo -= $bij;
|
||||
array_unshift($yas, $huidigSaldo);
|
||||
}
|
||||
return [
|
||||
"x-as" => $xas,
|
||||
"y-as" => $yas
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user