Possibilité de générer les graph de n'importe quel mois
This commit is contained in:
parent
d7c6937675
commit
e46629b147
@ -31,10 +31,18 @@ include_once (JPGRAPH_DIR."jpgraph_canvas.php");
|
|||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
|
|
||||||
|
$opt = getopt("m:y:");
|
||||||
|
|
||||||
$datetime = time();
|
$datetime = time();
|
||||||
$month = strftime("%m", $datetime);
|
|
||||||
|
if ($opt['m'] > 0)
|
||||||
|
{
|
||||||
|
$month = $opt['m'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$month = strftime("%m", $datetime);
|
||||||
|
}
|
||||||
$year = strftime("%Y", $datetime);
|
$year = strftime("%Y", $datetime);
|
||||||
|
|
||||||
if ($month == 1)
|
if ($month == 1)
|
||||||
@ -45,6 +53,7 @@ if ($month == 1)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$monthprev = substr("00".($month - 1), -2) ;
|
$monthprev = substr("00".($month - 1), -2) ;
|
||||||
|
$yearprev = $year ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($month == 12)
|
if ($month == 12)
|
||||||
@ -59,7 +68,7 @@ else
|
|||||||
|
|
||||||
$sql = "SELECT distinct(fk_account)";
|
$sql = "SELECT distinct(fk_account)";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."bank";
|
$sql .= " FROM ".MAIN_DB_PREFIX."bank";
|
||||||
$sql .= " WHERE date_format(datev,'%Y%m') = '".$year.$month."'";
|
//$sql .= " WHERE date_format(datev,'%Y%m') = '".$year.$month."'";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
|
|
||||||
@ -83,12 +92,10 @@ $account = 1;
|
|||||||
|
|
||||||
foreach ($accounts as $account)
|
foreach ($accounts as $account)
|
||||||
{
|
{
|
||||||
|
|
||||||
$labels = array();
|
$labels = array();
|
||||||
$datas = array();
|
$datas = array();
|
||||||
$amounts = array();
|
$amounts = array();
|
||||||
|
|
||||||
|
|
||||||
$sql = "SELECT sum(amount)";
|
$sql = "SELECT sum(amount)";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."bank";
|
$sql .= " FROM ".MAIN_DB_PREFIX."bank";
|
||||||
$sql .= " WHERE fk_account = ".$account;
|
$sql .= " WHERE fk_account = ".$account;
|
||||||
@ -96,10 +103,10 @@ foreach ($accounts as $account)
|
|||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$row = $db->fetch_row($resql);
|
$row = $db->fetch_row($resql);
|
||||||
$solde = $row[0];
|
$solde = $row[0];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $sql ;
|
print $sql ;
|
||||||
@ -126,8 +133,7 @@ foreach ($accounts as $account)
|
|||||||
$row = $db->fetch_row($resql);
|
$row = $db->fetch_row($resql);
|
||||||
$amounts[$row[0]] = $row[1];
|
$amounts[$row[0]] = $row[1];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -136,7 +142,6 @@ foreach ($accounts as $account)
|
|||||||
|
|
||||||
$subtotal = 0;
|
$subtotal = 0;
|
||||||
|
|
||||||
|
|
||||||
$day = mktime(1,1,1,$month,1,$year);
|
$day = mktime(1,1,1,$month,1,$year);
|
||||||
|
|
||||||
$xmonth = substr("00".strftime("%m",$day), -2);
|
$xmonth = substr("00".strftime("%m",$day), -2);
|
||||||
@ -146,16 +151,23 @@ foreach ($accounts as $account)
|
|||||||
//print strftime ("%e %d %m %y",$day)."\n";
|
//print strftime ("%e %d %m %y",$day)."\n";
|
||||||
|
|
||||||
$subtotal = $subtotal + $amounts[strftime("%Y%m%d",$day)];
|
$subtotal = $subtotal + $amounts[strftime("%Y%m%d",$day)];
|
||||||
|
|
||||||
$datas[$i] = $solde + $subtotal;
|
if ($day > time())
|
||||||
|
{
|
||||||
|
$datas[$i] = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$datas[$i] = $solde + $subtotal;
|
||||||
|
}
|
||||||
|
|
||||||
$labels[$i] = strftime("%d",$day);
|
$labels[$i] = strftime("%d",$day);
|
||||||
|
|
||||||
$day += 86400;
|
$day += 86400;
|
||||||
$xmonth = substr("00".strftime("%m",$day), -2);
|
$xmonth = substr("00".strftime("%m",$day), -2);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$width = 750;
|
$width = 750;
|
||||||
$height = 350;
|
$height = 350;
|
||||||
|
|
||||||
@ -171,7 +183,7 @@ foreach ($accounts as $account)
|
|||||||
$b2plot->SetColor("blue");
|
$b2plot->SetColor("blue");
|
||||||
//$b2plot->SetWeight(2);
|
//$b2plot->SetWeight(2);
|
||||||
|
|
||||||
$graph->title->Set("Solde");
|
$graph->title->Set("Solde $month $year");
|
||||||
|
|
||||||
$graph->xaxis->SetTickLabels($labels);
|
$graph->xaxis->SetTickLabels($labels);
|
||||||
//$graph->xaxis->title->Set(strftime("%d/%m/%y %H:%M:%S", time()));
|
//$graph->xaxis->title->Set(strftime("%d/%m/%y %H:%M:%S", time()));
|
||||||
@ -179,7 +191,7 @@ foreach ($accounts as $account)
|
|||||||
$graph->Add($b2plot);
|
$graph->Add($b2plot);
|
||||||
$graph->img->SetImgFormat("png");
|
$graph->img->SetImgFormat("png");
|
||||||
|
|
||||||
$file= DOL_DATA_ROOT."/graph/banque/solde.$account.png";
|
$file= DOL_DATA_ROOT."/graph/banque/solde.$account.$year.$month.png";
|
||||||
|
|
||||||
$graph->Stroke($file);
|
$graph->Stroke($file);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user