From d7c6937675b16073a06b054dc5912cd928d15711 Mon Sep 17 00:00:00 2001
From: Rodolphe Quiedeville <rodolphe@quiedeville.org>
Date: Sun, 31 Jul 2005 18:36:05 +0000
Subject: [PATCH] Bugfix

---
 scripts/banque/graph-solde.php | 153 +++++++++++++++++----------------
 1 file changed, 77 insertions(+), 76 deletions(-)

diff --git a/scripts/banque/graph-solde.php b/scripts/banque/graph-solde.php
index 31557cd1e6a..0013e9c9042 100644
--- a/scripts/banque/graph-solde.php
+++ b/scripts/banque/graph-solde.php
@@ -31,8 +31,7 @@ include_once (JPGRAPH_DIR."jpgraph_canvas.php");
 
 $error = 0;
 
-$labels = array();
-$datas = array();
+
 
 $datetime = time();
 $month = strftime("%m", $datetime);
@@ -64,7 +63,7 @@ $sql .= " WHERE date_format(datev,'%Y%m') = '".$year.$month."'";
 
 $resql = $db->query($sql);
 
-$amounts = array();
+$accounts = array();
 
 if ($resql)
 {
@@ -85,8 +84,10 @@ $account = 1;
 foreach ($accounts as $account)
 {
 
-
-
+  $labels = array();
+  $datas = array();
+  $amounts = array();
+  
 
   $sql = "SELECT sum(amount)";
   $sql .= " FROM ".MAIN_DB_PREFIX."bank";
@@ -105,82 +106,82 @@ foreach ($accounts as $account)
     }
 
 
-$sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)";
-$sql .= " FROM ".MAIN_DB_PREFIX."bank";
-$sql .= " WHERE fk_account = ".$account;
-$sql .= " AND date_format(datev,'%Y%m') = '".$year.$month."'";
-$sql .= " GROUP BY date_format(datev,'%Y%m%d');";
-
-$resql = $db->query($sql);
-
-$amounts = array();
+  $sql = "SELECT date_format(datev,'%Y%m%d'), sum(amount)";
+  $sql .= " FROM ".MAIN_DB_PREFIX."bank";
+  $sql .= " WHERE fk_account = ".$account;
+  $sql .= " AND date_format(datev,'%Y%m') = '".$year.$month."'";
+  $sql .= " GROUP BY date_format(datev,'%Y%m%d');";
 
-if ($resql)
-{
-  $num = $db->num_rows($resql);
+  $resql = $db->query($sql);
+  
+  $amounts = array();
+  
+  if ($resql)
+    {
+      $num = $db->num_rows($resql);
+      $i = 0;
+      
+      while ($i < $num)
+	{
+	  $row = $db->fetch_row($resql);
+	  $amounts[$row[0]] = $row[1];
+	  $i++;
+	}
+      
+    }
+  else
+    {
+      print $sql ;
+    }
+  
+  $subtotal = 0;
+  
+  
+  $day = mktime(1,1,1,$month,1,$year);
+  
+  $xmonth = substr("00".strftime("%m",$day), -2);
   $i = 0;
-
-  while ($i < $num)
+  while ($xmonth == $month)
     {
-      $row = $db->fetch_row($resql);
-      $amounts[$row[0]] = $row[1];
+      //print strftime ("%e %d %m %y",$day)."\n";
+      
+      $subtotal = $subtotal + $amounts[strftime("%Y%m%d",$day)];
+      
+      $datas[$i] = $solde + $subtotal;
+      $labels[$i] = strftime("%d",$day);
+      
+      $day += 86400;
+      $xmonth = substr("00".strftime("%m",$day), -2);
       $i++;
     }
-
-}
-else
-{
-  print $sql ;
-}
-
-$subtotal = 0;
-
-
-$day = mktime(1,1,1,$month,1,$year);
-
-$xmonth = substr("00".strftime("%m",$day), -2);
-$i = 0;
-while ($xmonth == $month)
-{
-  //print strftime ("%e %d %m %y",$day)."\n";
-
-  $subtotal = $subtotal + $amounts[strftime("%Y%m%d",$day)];
-
-  $datas[$i] = $solde + $subtotal;
-  $labels[$i] = strftime("%d",$day);
-
-  $day += 86400;
-  $xmonth = substr("00".strftime("%m",$day), -2);
-  $i++;
-}
-
-	      
-$width = 750;
-$height = 350;
-	      
-$graph = new Graph($width, $height,"auto");    
-$graph->SetScale("textlin");
-
-$graph->yaxis->scale->SetGrace(2);
-$graph->SetFrame(1);
-$graph->img->SetMargin(40,20,20,35);
-
-$b2plot = new BarPlot($datas);
-
-$b2plot->SetColor("blue");
-//$b2plot->SetWeight(2);
-
-$graph->title->Set("Solde");
-
-$graph->xaxis->SetTickLabels($labels);   
-//$graph->xaxis->title->Set(strftime("%d/%m/%y %H:%M:%S", time()));
-
-$graph->Add($b2plot);
-$graph->img->SetImgFormat("png");
-
-$file= DOL_DATA_ROOT."/graph/banque/solde.$account.png";
-
-$graph->Stroke($file);
+  
+  
+  $width = 750;
+  $height = 350;
+  
+  $graph = new Graph($width, $height,"auto");    
+  $graph->SetScale("textlin");
+  
+  $graph->yaxis->scale->SetGrace(2);
+  $graph->SetFrame(1);
+  $graph->img->SetMargin(40,20,20,35);
+  
+  $b2plot = new BarPlot($datas);
+  
+  $b2plot->SetColor("blue");
+  //$b2plot->SetWeight(2);
+  
+  $graph->title->Set("Solde");
+  
+  $graph->xaxis->SetTickLabels($labels);   
+  //$graph->xaxis->title->Set(strftime("%d/%m/%y %H:%M:%S", time()));
+  
+  $graph->Add($b2plot);
+  $graph->img->SetImgFormat("png");
+  
+  $file= DOL_DATA_ROOT."/graph/banque/solde.$account.png";
+  
+  $graph->Stroke($file);
 }
 
 ?>
-- 
GitLab