1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

48 lines
1.7 KiB
PHP

<?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 + 1 . " day")))]['bedr'];
$bij = (double)$erbij[array("datum" => date("Y-m-d", strtotime("-" . $i + 1 . " 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
];
}
}