diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php
index 4a1eae6b1d765afa45a5305dd2794eca3cb8916f..eef574ad600dbc841462ef905882bc68b227244f 100644
--- a/htdocs/compta/bank/graph.php
+++ b/htdocs/compta/bank/graph.php
@@ -210,6 +210,7 @@ if ($_GET["account"] || $_GET["ref"])
 		    $px->SetHeight($height);
 			$px->SetType('lines');
 			$px->setBgColor('onglet');
+			$px->setBgColorGrid(array(255,255,255));
 			$px->SetHorizTickIncrement(1);
 			$px->SetPrecisionY(0);
 		    $px->draw($file);
@@ -283,12 +284,12 @@ if ($_GET["account"] || $_GET["ref"])
 			$xday = substr($textdate,6,2);
 		
 			$i = 0;
-			while ($xyear == $year)
+			while ($xyear == $year && $day <= $datetime)
 			{
 				$subtotal = $subtotal + (isset($amounts[$textdate]) ? $amounts[$textdate] : 0);
 				if ($day > $now)
 				{
-					$datas[$i] = ''; // Valeur sp�ciale permettant de ne pas tracer le graph
+					$datas[$i] = ''; // Valeur speciale permettant de ne pas tracer le graph
 				}
 				else
 				{
@@ -327,6 +328,8 @@ if ($_GET["account"] || $_GET["ref"])
 		    $px->SetHeight($height);
 			$px->SetType('lines');
 			$px->setBgColor('onglet');
+			$px->setBgColorGrid(array(255,255,255));
+			$px->SetHideXGrid(true);
 			//$px->SetHorizTickIncrement(30.41);	// 30.41 jours/mois en moyenne
 			$px->SetPrecisionY(0);
 		    $px->draw($file);
@@ -426,6 +429,7 @@ if ($_GET["account"] || $_GET["ref"])
 		    $px->SetHeight($height);
 			$px->SetType('lines');
 			$px->setBgColor('onglet');
+			$px->setBgColorGrid(array(255,255,255));
 			$px->SetPrecisionY(0);
 		    $px->draw($file);
 		
@@ -525,6 +529,7 @@ if ($_GET["account"] || $_GET["ref"])
 			$px->SetType('bars');
 			$px->SetShading(3);
 			$px->setBgColor('onglet');
+			$px->setBgColorGrid(array(255,255,255));
 			$px->SetHorizTickIncrement(1);
 			$px->SetPrecisionY(0);
 		    $px->draw($file);
@@ -620,6 +625,7 @@ if ($_GET["account"] || $_GET["ref"])
 			$px->SetType('bars');
 			$px->SetShading(3);
 			$px->setBgColor('onglet');
+			$px->setBgColorGrid(array(255,255,255));
 			$px->SetHorizTickIncrement(1);
 			$px->SetPrecisionY(0);
 		    $px->draw($file);
diff --git a/htdocs/core/dolgraph.class.php b/htdocs/core/dolgraph.class.php
index 861a0a3ad459103aea960ab981e89faa5815dae7..1e309c0fb29dfc2f49a67c35920e2366764809e9 100644
--- a/htdocs/core/dolgraph.class.php
+++ b/htdocs/core/dolgraph.class.php
@@ -18,28 +18,28 @@
  */
 
 /**
-	\file       htdocs/dolgraph.class.php
-	\brief      Fichier de la classe mere de gestion des graph
-	\version    $Id$
-	\remarks    Usage:
-				$graph_data = array(array('labelA',yA),array('labelB',yB));
-				array(array('labelA',yA1,...,yAn),array('labelB',yB1,...yBn));
-				$px = new DolGraph();
-				$px->SetData($graph_data);
-				$px->SetMaxValue($px->GetCeilMaxValue());
-				$px->SetMinValue($px->GetFloorMinValue());
-				$px->SetTitle("title");
-				$px->SetLegend(array("Val1","Val2"));
-				$px->SetWidth(width);
-				$px->SetHeight(height);
-				$px->draw("file.png");
-*/
+ \file       htdocs/dolgraph.class.php
+ \brief      Fichier de la classe mere de gestion des graph
+ \version    $Id$
+ \remarks    Usage:
+ $graph_data = array(array('labelA',yA),array('labelB',yB));
+ array(array('labelA',yA1,...,yAn),array('labelB',yB1,...yBn));
+ $px = new DolGraph();
+ $px->SetData($graph_data);
+ $px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetTitle("title");
+ $px->SetLegend(array("Val1","Val2"));
+ $px->SetWidth(width);
+ $px->SetHeight(height);
+ $px->draw("file.png");
+ */
 
 
 /**
-	\class      Graph
-	\brief      Classe mere permettant la gestion des graph
-*/
+ \class      Graph
+ \brief      Classe mere permettant la gestion des graph
+ */
 
 class DolGraph
 {
@@ -54,9 +54,16 @@ class DolGraph
 	var $MaxValue=0;
 	var $MinValue=0;
 	var $SetShading=0;
+
 	var $PrecisionY=-1;
-	var $SetHorizTickIncrement=-1;
+	
+	var $horizTickIncrement=-1;
 	var $SetNumXTicks=-1;
+	var $labelInterval=-1;
+	
+	var $hideXGrid=false;
+	var $hideYGrid=false;
+	
 	var $Legend=array();
 	var $LegendWidthMin=0;
 
@@ -67,6 +74,7 @@ class DolGraph
 
 	var $bordercolor;		// array(R,G,B)
 	var $bgcolor;			// array(R,G,B)
+	var $bgcolorgrid;		// array(R,G,B)
 	var $datacolor;			// array(array(R,G,B),...)
 
 
@@ -113,204 +121,59 @@ class DolGraph
 	}
 
 
-	function isGraphKo()
+	/**
+	 */
+	function SetPrecisionY($which_prec)
 	{
-		return $this->error;
+		$this->PrecisionY = $which_prec;
+		return true;
 	}
 
 	/**
-	 *    \brief      Genere le fichier graphique sur le disque
-	 *    \param      file    Nom du fichier image
+	 *		\remarks	Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
 	 */
-	function draw($file)
+	function SetHorizTickIncrement($xi)
 	{
-		if (! is_array($this->data) || sizeof($this->data) < 1)
-		{
-			$this->error="Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
-			dolibarr_syslog("DolGraph::draw ".$this->error, LOG_ERR);
-			return -1;			
-		}
-		$call = "draw_".$this->library;
-		$this->$call($file);
+		$this->horizTickIncrement = $xi;
+		return true;
 	}
 
-
 	/**
-	 * 	\brief		Generation graph a partir de la lib Artichow
-	 *	\param		file		Nom fichier a generer
+	 *		\remarks	Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
 	 */
-	function draw_artichow($file)
+	function SetNumXTicks($xt)
 	{
-		dolibarr_syslog("DolGraph.class::draw_artichow this->type=".$this->type);
-
-		if (! defined('SHADOW_RIGHT_TOP'))  define('SHADOW_RIGHT_TOP',3);
-		if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2);
-		if (! defined('LEGEND_LINE'))       define('LEGEND_LINE',1);
-		
-		// Create graph
-		$class='';
-		if ($this->type == 'bars')  $class='BarPlot';
-		if ($this->type == 'lines') $class='LinePlot';
-		include_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/".$class.".class.php";
-
-		// Definition de couleurs
-		$bgcolor=new Color($this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]);
-		$colortrans=new Color(0,0,0,100);
-		$colorsemitrans=new Color(255,255,255,60);
-		$colorgradient= new LinearGradient(new Color(235, 235, 235),new Color(255, 255, 255),0);
-
-		// Graph
-		$graph = new Graph($this->width, $this->height);
-		$graph->border->hide();
-		$graph->setAntiAliasing(true);
-		if (isset($this->title))
-		{
-			$graph->title->set($this->title);
-			$graph->title->setFont(new Tuffy(10));
-		}
-		//		$graph->setBackgroundColor($bgcolor);
-		$graph->setBackgroundGradient($colorgradient);
-
-		$group = new PlotGroup;
-		//$group->setSpace(5, 5, 0, 0);
-
-		$paddleft=50;
-		$paddright=10;
-		$strl=strlen(max(abs($this->MaxValue),abs($this->MinValue)));
-		if ($strl > 6) $paddleft += ($strln * 4);
-		$group->setPadding($paddleft, $paddright);		// Width on left and right for Y axis values		
-		$group->legend->setSpace(0);
-		$group->legend->setPadding(2,2,2,2);
-		$group->legend->setPosition(NULL,0.1);
-		$group->legend->setBackgroundColor($colorsemitrans);
-		$group->grid->setBackgroundColor($colortrans);
-
-
-		// On boucle sur chaque lot de donnees
-		$legends=array();
-		$i=0;
-		$nblot=sizeof($this->data[0])-1;
-
-		while ($i < $nblot)
-		{
-			$j=0;
-			$values=array();
-			foreach($this->data as $key => $valarray)
-			{
-				$legends[$j] = $valarray[0];
-				$values[$j]  = $valarray[$i+1];
-				$j++;
-			}
-
-			// Artichow ne gere pas les valeurs inconnues
-			// Donc si inconnu, on la fixe a null
-			$newvalues=array();
-			foreach($values as $val)
-			{
-				$newvalues[]=(is_numeric($val) ? $val : null);
-			}
-
-
-			if ($this->type == 'bars')
-			{
-				//print "Lot de donnees $i<br>";
-				//print_r($values);
-				//print '<br>';
-				
-				$colorgrey=new Color(100,100,100);
-				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
-				$colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]);
-
-				if ($this->mode == 'side')  $plot = new BarPlot($newvalues, $i+1, $nblot);
-				if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5);
-
-				$plot->barBorder->setColor($colorgrey);
-				$plot->setBarColor($color);
-
-				if ($this->mode == 'side')  $plot->setBarPadding(0.1, 0.1);
-				if ($this->mode == 'depth') $plot->setBarPadding(0.1, 0.4);
-				if ($this->mode == 'side')  $plot->setBarSpace(5);
-				if ($this->mode == 'depth') $plot->setBarSpace(2);
-
-				$plot->barShadow->setSize($this->SetShading);
-				$plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
-				$plot->barShadow->setColor(new Color(160, 160, 160, 50));
-				$plot->barShadow->smooth(TRUE);
-				//$plot->setSize(1, 0.96);
-				//$plot->setCenter(0.5, 0.52);
-
-				// Le mode automatique est plus efficace
-				$plot->SetYMax($this->MaxValue);
-				$plot->SetYMin($this->MinValue);
-			}
-
-			if ($this->type == 'lines')
-			{
-				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
-
-				$plot = new LinePlot($newvalues);
-				//$plot->setSize(1, 0.96);
-				//$plot->setCenter(0.5, 0.52);
-
-				$plot->setColor($color);
-				$plot->setThickness(2);
-
-				// Le mode automatique est plus efficace
-				$plot->SetYMax($this->MaxValue);
-				$plot->SetYMin($this->MinValue);
-				//$plot->setYAxis(0);
-				//$plot->hideLine(true);
-			}
-
-			//$plot->reduce(80);		// Evite temps d'affichage trop long et nombre de ticks absisce satures
-
-			if (sizeof($this->Legend))
-			{
-				if ($this->type == 'bars')  $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
-				if ($this->type == 'lines') $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
-			}
-			$group->add($plot);
-
-			$i++;
-		}
-
-		$group->axis->bottom->setLabelText($legends);
-		$group->axis->bottom->label->setFont(new Tuffy(7));
-
-		$graph->add($group);
-
-		// Generate file
-		$graph->draw($file);
+		$this->SetNumXTicks = $xt;
+		return true;
 	}
 
-
 	/**
+	 *		\brief		Set label interval to reduce number of labels
 	 */
-	function SetPrecisionY($which_prec)
+	function SetLabelInterval($x)
 	{
-		$this->PrecisionY = $which_prec;
+		$this->labelInterval = $x;
 		return true;
 	}
-
+	
 	/**
-	 \remarks	Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
+	 * 		\brief		Hide X grid
 	 */
-	function SetHorizTickIncrement($xi)
+	function SetHideXGrid($bool)
 	{
-		$this->SetHorizTickIncrement = $xi;
+		$this->hideXGrid = $bool;
 		return true;
 	}
 
 	/**
-	 \remarks	Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
+	 * 		\brief		Hide Y grid
 	 */
-	function SetNumXTicks($xt)
+	function SetHideYGrid($bool)
 	{
-		$this->SetNumXTicks = $xt;
+		$this->hideYGrid = $bool;
 		return true;
 	}
-
-
+	
 	function SetYLabel($label)
 	{
 		$this->YLabel = $label;
@@ -378,8 +241,19 @@ class DolGraph
 		unset($this->bgcolor);
 	}
 
+	function ResetBgColorGrid()
+	{
+		unset($this->bgcolorgrid);
+	}
+
+	function isGraphKo()
+	{
+		return $this->error;
+	}
+
+	
 	/**
-	 *	\brief		Definie la couleur de fond du graphique
+	 *	\brief		Definie la couleur de fond de l'image complete
 	 *	\param		bg_color		array(R,G,B) ou 'onglet' ou 'default'
 	 */
 	function SetBgColor($bg_color = array(255,255,255))
@@ -388,14 +262,14 @@ class DolGraph
 		if (! is_array($bg_color))
 		{
 			if ($bg_color == 'onglet')
-	  {
-	  	//print 'ee'.join(',',$theme_bgcoloronglet);
-	  	$this->bgcolor = $theme_bgcoloronglet;
-	  }
-	  else
-	  {
-	  	$this->bgcolor = $theme_bgcolor;
-	  }
+		  	{
+		  		//print 'ee'.join(',',$theme_bgcoloronglet);
+		  		$this->bgcolor = $theme_bgcoloronglet;
+		  	}
+		  	else
+		  	{
+		  		$this->bgcolor = $theme_bgcolor;
+			}
 		}
 		else
 		{
@@ -403,6 +277,31 @@ class DolGraph
 		}
 	}
 
+	/**
+	 *	\brief		Definie la couleur de fond de la grille
+	 *	\param		bg_colorgrid		array(R,G,B) ou 'onglet' ou 'default'
+	 */
+	function SetBgColorGrid($bg_colorgrid = array(255,255,255))
+	{
+		global $theme_bgcolor,$theme_bgcoloronglet;
+		if (! is_array($bg_colorgrid))
+		{
+			if ($bg_colorgrid == 'onglet')
+		  	{
+		  		//print 'ee'.join(',',$theme_bgcoloronglet);
+		  		$this->bgcolorgrid = $theme_bgcoloronglet;
+		  	}
+		  	else
+		  	{
+		  		$this->bgcolorgrid = $theme_bgcolor;
+			}
+		}
+		else
+		{
+			$this->bgcolorgrid = $bg_colorgrid;
+		}
+	}
+
 	function ResetDataColor()
 	{
 		unset($this->datacolor);
@@ -480,15 +379,203 @@ class DolGraph
 		return $res;
 	}
 
-	
-	
-	
+	/**
+	 *    \brief      Genere le fichier graphique sur le disque
+	 *    \param      file    Nom du fichier image
+	 */
+	function draw($file)
+	{
+		if (! is_array($this->data) || sizeof($this->data) < 1)
+		{
+			$this->error="Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
+			dolibarr_syslog("DolGraph::draw ".$this->error, LOG_ERR);
+			return -1;
+		}
+		$call = "draw_".$this->library;
+		$this->$call($file);
+	}
+
+
+	/**
+	 * 	\brief		Generation graph a partir de la lib Artichow
+	 *	\param		file		Nom fichier a generer
+	 */
+	function draw_artichow($file)
+	{
+		dolibarr_syslog("DolGraph.class::draw_artichow this->type=".$this->type);
+
+		if (! defined('SHADOW_RIGHT_TOP'))  define('SHADOW_RIGHT_TOP',3);
+		if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2);
+		if (! defined('LEGEND_LINE'))       define('LEGEND_LINE',1);
+
+		// Create graph
+		$class='';
+		if ($this->type == 'bars')  $class='BarPlot';
+		if ($this->type == 'lines') $class='LinePlot';
+		include_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/".$class.".class.php";
+
+		// Definition de couleurs
+		$bgcolor=new Color($this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]);
+		$bgcolorgrid=new Color($this->bgcolorgrid[0],$this->bgcolorgrid[1],$this->bgcolorgrid[2]);
+		$colortrans=new Color(0,0,0,100);
+		$colorsemitrans=new Color(255,255,255,60);
+		$colorgradient= new LinearGradient(new Color(235, 235, 235),new Color(255, 255, 255),0);
+		$colorwhite=new Color(255,255,255);
+		
+		// Graph
+		$graph = new Graph($this->width, $this->height);
+		$graph->border->hide();
+		$graph->setAntiAliasing(true);
+		if (isset($this->title))
+		{
+			$graph->title->set($this->title);
+			$graph->title->setFont(new Tuffy(10));
+		}
+
+		if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor);
+		else $graph->setBackgroundGradient($colorgradient);
+
+		$group = new PlotGroup;
+		//$group->setSpace(5, 5, 0, 0);
+
+		$paddleft=50;
+		$paddright=10;
+		$strl=strlen(max(abs($this->MaxValue),abs($this->MinValue)));
+		if ($strl > 6) $paddleft += ($strln * 4);
+		$group->setPadding($paddleft, $paddright);		// Width on left and right for Y axis values
+		$group->legend->setSpace(0);
+		$group->legend->setPadding(2,2,2,2);
+		$group->legend->setPosition(NULL,0.1);
+		$group->legend->setBackgroundColor($colorsemitrans);
+
+		if (is_array($this->bgcolorgrid)) $group->grid->setBackgroundColor($bgcolorgrid);
+		else $group->grid->setBackgroundColor($colortrans);
+
+		if ($this->hideXGrid)	$group->grid->hideVertical(true);
+		if ($this->hideYGrid)	$group->grid->hideHorizontal(true);
+		
+		// On boucle sur chaque lot de donnees
+		$legends=array();
+		$i=0;
+		$nblot=sizeof($this->data[0])-1;
+
+		while ($i < $nblot)
+		{
+			$j=0;
+			$values=array();
+			foreach($this->data as $key => $valarray)
+			{
+				$legends[$j] = $valarray[0];
+				$values[$j]  = $valarray[$i+1];
+				$j++;
+			}
+
+			// Artichow ne gere pas les valeurs inconnues
+			// Donc si inconnu, on la fixe a null
+			$newvalues=array();
+			foreach($values as $val)
+			{
+				$newvalues[]=(is_numeric($val) ? $val : null);
+			}
+
+
+			if ($this->type == 'bars')
+			{
+				//print "Lot de donnees $i<br>";
+				//print_r($values);
+				//print '<br>';
+
+				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
+				$colorbis=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),50);
+				
+				$colorgrey=new Color(100,100,100);
+				$colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]);
+
+				if ($this->mode == 'side')  $plot = new BarPlot($newvalues, $i+1, $nblot);
+				if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5);
+
+				$plot->barBorder->setColor($colorgrey);
+				//$plot->setBarColor($color);
+				$plot->setBarGradient( new LinearGradient($colorbis, $color, 90) );
+				
+				if ($this->mode == 'side')  $plot->setBarPadding(0.1, 0.1);
+				if ($this->mode == 'depth') $plot->setBarPadding(0.1, 0.4);
+				if ($this->mode == 'side')  $plot->setBarSpace(5);
+				if ($this->mode == 'depth') $plot->setBarSpace(2);
+
+				$plot->barShadow->setSize($this->SetShading);
+				$plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
+				$plot->barShadow->setColor(new Color(160, 160, 160, 50));
+				$plot->barShadow->smooth(TRUE);
+				//$plot->setSize(1, 0.96);
+				//$plot->setCenter(0.5, 0.52);
+
+				// Le mode automatique est plus efficace
+				$plot->SetYMax($this->MaxValue);
+				$plot->SetYMin($this->MinValue);
+			}
+
+			if ($this->type == 'lines')
+			{
+				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
+				$colorbis=new Color(min($this->datacolor[$i][0]+20,255),min($this->datacolor[$i][1]+20,255),min($this->datacolor[$i][2]+20,255),60);
+				$colorter=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),90);
+				
+				$plot = new LinePlot($newvalues);
+				//$plot->setSize(1, 0.96);
+				//$plot->setCenter(0.5, 0.52);
+				
+				$plot->setColor($color);
+				$plot->setThickness(1);
+
+				// Set line background gradient
+				$plot->setFillGradient( new LinearGradient($colorter, $colorbis, 90) );
+
+				$plot->xAxis->setLabelText($legends);
+				
+				// Le mode automatique est plus efficace
+				$plot->SetYMax($this->MaxValue);
+				$plot->SetYMin($this->MinValue);
+				//$plot->setYAxis(0);
+				//$plot->hideLine(true);
+			}
+		
+			//$plot->reduce(80);		// Evite temps d'affichage trop long et nombre de ticks absisce satures
+
+			if (sizeof($this->Legend))
+			{
+				if ($this->type == 'bars')  $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
+				if ($this->type == 'lines') $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
+			}
+			$group->add($plot);
+
+			$i++;
+		}
+
+		$group->axis->bottom->setLabelText($legends);
+		$group->axis->bottom->label->setFont(new Tuffy(7));
+
+		//print $group->axis->bottom->getLabelNumber();
+		if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval);
+		
+		$graph->add($group);
+
+		// Generate file
+		$graph->draw($file);
+	}
+
+
+
+	/*
+	 * Special function
+	 * \TODO Replace by standard code
+	 */
 	function BarLineAnnualArtichow($file='', $barvalues, $linevalues, $legends='')
 	{
 		require_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/BarPlot.class.php";
 		require_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/LinePlot.class.php";
 
-		$graph = new Graph(240, 220);
+		$graph = new Graph(240, 200);
 
 		$graph->title->set($this->title);
 		$graph->title->setFont(new Tuffy(10));
@@ -565,6 +652,10 @@ class DolGraph
 		$graph->draw($file);
 	}
 
+	/*
+	 * Special function
+	 * \TODO Replace by standard code
+	 */
 	function BarLineOneYearArtichow($file='', $barvalues, $linevalues, $legends='')
 	{
 		$ok = 0;
@@ -583,7 +674,7 @@ class DolGraph
 			require_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/BarPlot.class.php";
 			require_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/LinePlot.class.php";
 
-			$graph = new Graph(540, 220);
+			$graph = new Graph(540, 200);
 
 			$graph->title->set($this->title);
 			$graph->title->setFont(new Tuffy(10));
@@ -661,6 +752,10 @@ class DolGraph
 		}
 	}
 
+	/*
+	 * Special function
+	 * \TODO Replace by standard code
+	 */
 	function BarAnnualArtichow($file='', $values='', $legends='')
 	{
 		require_once DOL_DOCUMENT_ROOT."/../external-libs/Artichow/BarPlot.class.php";
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index 1a4ebf7723529d46c2646f4b5ca4032888203123..2b7d5fb8d5623a7d8d94f3da5819a509d1d9fdbf 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -29,4 +29,5 @@ ErrorGenbarCodeNotfound=File not found (Bad path, wrong permissions or access de
 ErrorFunctionNotAvailableInPHP=Function <b>%s</b> is required for this feature but is not available in this version/setup of PHP.
 ErrorDirAlreadyExists=A directory with this name already exists.
 WarningAllowUrlFopenMustBeOn=Parameter <b>allow_url_fopen</b> must be set to <b>on</b> in filer <b>php.ini</b> for having this module working completely. You must modify this file manually.
-ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.
\ No newline at end of file
+ErrorFieldCanNotContainSpecialCharacters=Field <b>%s</b> must not contains special characters.
+WarningBuildScriptNotRunned=Script <b>%s</b> was not yet ran to build graphics.
\ No newline at end of file
diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang
index 256e9230b44c637b6040061a6e85a601f4cd1d78..c0fd11d99ebf301026d9d455a944854f4af51f58 100644
--- a/htdocs/langs/fr_FR/errors.lang
+++ b/htdocs/langs/fr_FR/errors.lang
@@ -30,3 +30,4 @@ ErrorFunctionNotAvailableInPHP=La fonction <b>%s</b> est requise pour cette fonc
 ErrorDirAlreadyExists=Un r�pertoire portant ce nom existe d�j�.
 WarningAllowUrlFopenMustBeOn=Attention, le param�tre <b>allow_url_fopen</b> doit etre positionn� � <b>on</b> dans le fichier <b>php.ini</b> pour que ce module soit pleinement op�rationnel. Vous devez modifier ce fichier manuellement.
 ErrorFieldCanNotContainSpecialCharacters=Le champ <b>%s</b> ne peut contenir de caract�res sp�ciaux.
+WarningBuildScriptNotRunned=Le script <b>%s</b> n'a pas encore �t� lanc� pour g�n�rer les graphiques.
\ No newline at end of file
diff --git a/htdocs/product/stats/fiche.php b/htdocs/product/stats/fiche.php
index 875da6b192792e31ab6dbe33ca1c143fabc58ee3..a77cbda2610f3f0e0ab535a267005dfaf12448af 100644
--- a/htdocs/product/stats/fiche.php
+++ b/htdocs/product/stats/fiche.php
@@ -51,7 +51,7 @@ $mesg = '';
 
 
 /*
- *
+ *	View
  */
 $html = new Form($db);
 
@@ -103,10 +103,11 @@ if ($_GET["id"] || $_GET["ref"])
 		print $product->getLibStatut(2);
 		print '</td></tr>';
 
-		// Graphs additionels generes pas les cron
+		
+		// Graphs additionels generes pas le script product-graph.php
 		$year = strftime('%Y',time());
 		$file = get_exdir($product->id, 3) . "ventes-".$year."-".$product->id.".png";	
-		if (file_exists (DOL_DATA_ROOT.'/graph/product/'.$file) )
+		if (file_exists (DOL_DATA_ROOT.'/product/temp/'.$file) )
 		{
 			print '<tr><td>Ventes</td><td>';
 			
@@ -118,9 +119,9 @@ if ($_GET["id"] || $_GET["ref"])
 			print '</td></tr>';
 		}
 
+		
 		print '</table>';
 		print '</div>';
-
 		
 		
 		print '<table width="100%">';
diff --git a/htdocs/product/stock/fiche-valo.php b/htdocs/product/stock/fiche-valo.php
index 1d8be40d8f2b909f422cdb9a73a97ad350f45055..3fa84aa4828dc1ebcf5906b0bc0114daf3635d2a 100644
--- a/htdocs/product/stock/fiche-valo.php
+++ b/htdocs/product/stock/fiche-valo.php
@@ -18,11 +18,11 @@
  */
 
 /**
-   \file       htdocs/product/stock/fiche.php
-    \ingroup    stock
-     \brief      Page fiche de valorisation du stock dans l'entrepot
-      \version    $Id$
-*/
+ *	\file       htdocs/product/stock/fiche.php
+ *	\ingroup    stock
+ *	\brief      Page fiche de valorisation du stock dans l'entrepot
+ *	\version    $Id$
+ */
 
 require("./pre.inc.php");
 
@@ -31,105 +31,117 @@ $langs->load("stocks");
 $langs->load("companies");
 $mesg = '';
 
+
+
+/*
+ * View
+ */
+
 llxHeader("","",$langs->trans("WarehouseCard"));
 
 if ($_GET["id"])
 {
-  if ($mesg) print $mesg;
-  
-  $entrepot = new Entrepot($db);
-  $result = $entrepot->fetch($_GET["id"]);
-  if ($result < 0)
-    {
-      dolibarr_print_error($db);
-    }
-  
-  /*
-   * Affichage fiche
-   */
-
-      /*
-       * Affichage onglets
-       */
-      $h = 0;
-      
-      $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id;
-      $head[$h][1] = $langs->trans("WarehouseCard");
-      $h++;
-      
-      $head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id;
-      $head[$h][1] = $langs->trans("StockMovements");
-      $h++;
-      
-      $head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id;
-      $head[$h][1] = $langs->trans("EnhancedValue");
-      $hselected=$h;
-      $h++;
-      
-          if ($conf->global->STOCK_USE_WAREHOUSE_BY_USER)
-          {
-          // Add the constant STOCK_USE_WAREHOUSE_BY_USER in cont table to use this feature.
-          // Should not be enabled by defaut because does not work yet correctly because
-          // there is no way to add values in the table llx_user_entrepot
-            $head[$h][0] = DOL_URL_ROOT.'/product/stock/user.php?id='.$entrepot->id;
-		    $head[$h][1] = $langs->trans("Users");
-      		$h++;
-          }
-      $head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id;
-      $head[$h][1] = $langs->trans("Info");
-      $h++;
-      
-      dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle);
-      
-      print '<table class="border" width="100%">';
-      
-      // Ref
-      print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'.$entrepot->libelle.'</td>';
-      
-      print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
-      
-      // Description
-      print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($entrepot->description).'</td></tr>';
-      
-      print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
-      print $entrepot->address;
-      print '</td></tr>';
-      
-      print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->cp.'</td>';
-      print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->ville.'</td></tr>';
-      
-      print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
-      print $entrepot->pays;
-      print '</td></tr>';
-      
-      // Statut
-      print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
-      
-      print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
-      print $entrepot->nb_products();
-      print "</td></tr>";           
-      print "</table>";      
-      print '</div>';
-      
-      
-      /* ************************************************************************** */
-      /*                                                                            */
-      /* Graph                                                                      */
-      /*                                                                            */
-      /* ************************************************************************** */
-            
-      print "<div class=\"graph\">\n";
-      $year = strftime("%Y",time());
-      $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file=entrepot-'.$entrepot->id.'-'.$year.'.png';
-      print '<img src="'.$url.'" alt="Valorisation du stock ann�e '.($year).'">';
-      
-      if (file_exists(DOL_DATA_ROOT.'/graph/entrepot/entrepot-'.$entrepot->id.'-'.($year-1).'.png'))
+	if ($mesg) print $mesg;
+
+	$entrepot = new Entrepot($db);
+	$result = $entrepot->fetch($_GET["id"]);
+	if ($result < 0)
+	{
+		dolibarr_print_error($db);
+	}
+
+	/*
+	 * Affichage onglets
+	 */
+	$h = 0;
+
+	$head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche.php?id='.$entrepot->id;
+	$head[$h][1] = $langs->trans("WarehouseCard");
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/product/stock/mouvement.php?id='.$entrepot->id;
+	$head[$h][1] = $langs->trans("StockMovements");
+	$h++;
+
+	$head[$h][0] = DOL_URL_ROOT.'/product/stock/fiche-valo.php?id='.$entrepot->id;
+	$head[$h][1] = $langs->trans("EnhancedValue");
+	$hselected=$h;
+	$h++;
+
+	if ($conf->global->STOCK_USE_WAREHOUSE_BY_USER)
+	{
+		// Add the constant STOCK_USE_WAREHOUSE_BY_USER in cont table to use this feature.
+		// Should not be enabled by defaut because does not work yet correctly because
+		// there is no way to add values in the table llx_user_entrepot
+		$head[$h][0] = DOL_URL_ROOT.'/product/stock/user.php?id='.$entrepot->id;
+		$head[$h][1] = $langs->trans("Users");
+		$h++;
+	}
+
+	$head[$h][0] = DOL_URL_ROOT.'/product/stock/info.php?id='.$entrepot->id;
+	$head[$h][1] = $langs->trans("Info");
+	$h++;
+
+	dolibarr_fiche_head($head, $hselected, $langs->trans("Warehouse").': '.$entrepot->libelle);
+
+	print '<table class="border" width="100%">';
+
+	// Ref
+	print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">'.$entrepot->libelle.'</td>';
+
+	print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
+
+	// Description
+	print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="3">'.nl2br($entrepot->description).'</td></tr>';
+
+	print '<tr><td>'.$langs->trans('Address').'</td><td colspan="3">';
+	print $entrepot->address;
+	print '</td></tr>';
+
+	print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$entrepot->cp.'</td>';
+	print '<td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$entrepot->ville.'</td></tr>';
+
+	print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
+	print $entrepot->pays;
+	print '</td></tr>';
+
+	// Statut
+	print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
+
+	print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
+	print $entrepot->nb_products();
+	print "</td></tr>";
+	print "</table>";
+	print '</div>';
+
+
+	/* ************************************************************************** */
+	/*                                                                            */
+	/* Graph                                                                      */
+	/*                                                                            */
+	/* ************************************************************************** */
+
+	print "<div class=\"graph\">\n";
+	$year = strftime("%Y",time());
+
+	if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year).'.png'))
+	{
+		$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file=entrepot-'.$entrepot->id.'-'.$year.'.png';
+		print '<img src="'.$url.'" alt="Valorisation du stock ann�e '.($year).'">';
+	
+		if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year-1).'.png'))
+		{
+			$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file=entrepot-'.$entrepot->id.'-'.($year-1).'.png';
+			print '<br /><img src="'.$url.'" alt="Valorisation du stock ann�e '.($year-1).'">';
+		}
+	}
+	else
 	{
-	  $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file=entrepot-'.$entrepot->id.'-'.($year-1).'.png';
-	  print '<br /><img src="'.$url.'" alt="Valorisation du stock ann�e '.($year-1).'">';
+		$langs->load("errors");
+		if ($user->admin) print info_admin($langs->trans("WarningBuildScriptNotRunned",'stock-graph.php'));
 	}
 
-      print "</div>";
+	print "</div>";
 }
 
 $db->close();
diff --git a/htdocs/product/stock/valo.php b/htdocs/product/stock/valo.php
index 4c90f755d9b53f6691972fbdc5f4e22b16696f12..399345e3e28d7e07c28a635419aaddd9d06deeaa 100644
--- a/htdocs/product/stock/valo.php
+++ b/htdocs/product/stock/valo.php
@@ -118,14 +118,14 @@ if ($result)
   print '<br />';
 
 	$file='entrepot-'.$year.'.png';
-	if (file_exists(DOL_DATA_ROOT.'/graph/entrepot/'.$file))
+	if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
 	{
 		$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
 		print '<img src="'.$url.'" alt="Valorisation du stock ann�e '.($year).'">';
 	}
 
 	$file='entrepot-'.($year-1).'.png';
-	if (file_exists(DOL_DATA_ROOT.'/graph/entrepot/'.$file))
+	if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
     {
       $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
       print '<br /><img src="'.$url.'" alt="Valorisation du stock ann�e '.($year-1).'">';
diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php
index 0b730874e98fd811bfb6ff550e2d6372bcd54e92..463e315a89499e15d7c2752d2901230833a75bbf 100644
--- a/htdocs/viewimage.php
+++ b/htdocs/viewimage.php
@@ -253,21 +253,21 @@ if ($modulepart)
     elseif ($modulepart == 'graph_stock')
     {
       $accessallowed=1;
-      $original_file=DOL_DATA_ROOT.'/graph/entrepot/'.$original_file;
+      $original_file=DOL_DATA_ROOT.'/entrepot/temp/'.$original_file;
     }
 
     // Wrapping pour les graph fournisseurs
     elseif ($modulepart == 'graph_fourn')
     {
       $accessallowed=1;
-      $original_file=DOL_DATA_ROOT.'/graph/fournisseur/'.$original_file;
+      $original_file=DOL_DATA_ROOT.'/fournisseur/temp/'.$original_file;
     }
 
     // Wrapping pour les graph des produits
     elseif ($modulepart == 'graph_product')
     {
       $accessallowed=1;
-      $original_file=DOL_DATA_ROOT.'/graph/product/'.$original_file;
+      $original_file=DOL_DATA_ROOT.'/product/temp/'.$original_file;
     }
 
     // Wrapping pour les code barre
diff --git a/scripts/banque/graph-solde.php b/scripts/banque/graph-solde.php
index 0210e87d5a4858c72e48cb2e5a44f9479206a9ce..81f687b3d4d211a2cf48065b445e178d304c1852 100644
--- a/scripts/banque/graph-solde.php
+++ b/scripts/banque/graph-solde.php
@@ -1,7 +1,7 @@
 #!/usr/bin/php
 <?PHP
-/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2006 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2006-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,15 +16,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- * $Source$
  */
 
 /**
-		\file       scripts/banque/graph-solde.php
-		\ingroup    banque
-		\brief      Script de g�n�ration des images des soldes des comptes
+		\file       	scripts/banque/graph-solde.php
+		\ingroup    	banque
+		\brief      	Script de g�n�ration des images des soldes des comptes
+		\deprecated		Ce script n'est pas utilise.
+		\version		$Id$
 */
 
 
@@ -39,7 +38,7 @@ if (substr($sapi_type, 0, 3) == 'cgi') {
 $path=eregi_replace('graph-solde.php','',$_SERVER["PHP_SELF"]);
 
 require_once($path."../../htdocs/master.inc.php");
-require_once($path."../../htdocs/core/dolgraph.class.php");
+require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
 
 
 $error = 0;
diff --git a/scripts/cron/facture-paye-stats.php b/scripts/cron/facture-paye-stats.php
index 220d98ee5e9d67d0bbd7fdd3b6f93c4091ef5057..b22c06d493c45aeae46d9a691d225d1595d90708 100644
--- a/scripts/cron/facture-paye-stats.php
+++ b/scripts/cron/facture-paye-stats.php
@@ -1,6 +1,6 @@
 <?PHP
-/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2007-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,15 +15,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- * $Source$
  */
 
 /**
-        \file       scripts/cron/facture-paye-stats.php
-        \ingroup    invoice
-        \brief      Statistiques sur le statut paye des factures
+        \file       	scripts/cron/facture-paye-stats.php
+        \ingroup    	invoice
+        \brief      	Script de mise a jour de la table facture_stats de statistiques
+		\deprecated		Ce script et ces tables ne sont pas utilisees.
+		\version		$Id$
 */
 
 // Test si mode CLI
diff --git a/scripts/cron/fournisseur-calcul-ca_genere.php b/scripts/cron/fournisseur-calcul-ca_genere.php
index 25b27623fe32ff36812678cca1a976a8307d1daa..c038921e5cd557ae776cff323478d84179af761e 100644
--- a/scripts/cron/fournisseur-calcul-ca_genere.php
+++ b/scripts/cron/fournisseur-calcul-ca_genere.php
@@ -1,6 +1,6 @@
 <?PHP
-/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2007-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -15,15 +15,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Id$
- * $Source$
  */
 
 /**
-        \file       scripts/cron/fournisseur-calcul-ca_genere.php
-        \ingroup    fournisseur
-        \brief      Calcul le CA g�n�r� par chaque fournisseur et genere graph
+        \file       	scripts/cron/fournisseur-calcul-ca_genere.php
+        \ingroup    	fournisseur
+        \brief      	Calcul le CA g�n�r� par chaque fournisseur et met a jour les tables fournisseur_ca et produit_ca 
+		\deprecated		Ce script et ces tables ne sont pas utilisees.
+		\version		$Id$
 */
 
 // Test si mode CLI
diff --git a/scripts/cron/fournisseur-graph.php b/scripts/cron/fournisseur-graph.php
index 793461598f546f6f27ec2f0bb604ad82ca848f98..9061616bcf68ee2a871f6182192efafe7063a8ef 100644
--- a/scripts/cron/fournisseur-graph.php
+++ b/scripts/cron/fournisseur-graph.php
@@ -18,10 +18,11 @@
  */
 
 /**
-        \file       scripts/cron/fournisseur-graph.php
-        \ingroup    fournisseur
-        \brief      Script de g�n�ration graph fournisseur
-		\version	$Id$
+        \file       	scripts/cron/fournisseur-graph.php
+        \ingroup    	fournisseur
+        \brief      	Script de g�n�ration graph ca fournisseur depuis tables fournisseur_ca
+		\deprecated		Ces graph ne sont pas utilises.
+		\version		$Id$
 */
 
 // Test si mode CLI
@@ -39,7 +40,7 @@ $version='$Revision$';
 $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
 
 require_once($path."../../htdocs/master.inc.php");
-require_once (DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
+require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
 
 
 $error=0;
@@ -63,7 +64,7 @@ for ($i = 1 ; $i < sizeof($argv) ; $i++)
 /*
  *
  */
-$dir = DOL_DATA_ROOT."/graph/fournisseur";
+$dir = DOL_DATA_ROOT."/fournisseur/temp";
 if (!is_dir($dir) )
 {
   if (! create_exdir($dir,0755))
diff --git a/scripts/cron/product-graph.php b/scripts/cron/product-graph.php
index 9ae93a2d3dfda49edd6a2753c6218ac7784fffd2..d7326a2edc050abf3c13cc41e8d6625bff8c214e 100644
--- a/scripts/cron/product-graph.php
+++ b/scripts/cron/product-graph.php
@@ -1,6 +1,6 @@
 <?PHP
-/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2007 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
+ * Copyright (C) 2007-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,28 +18,28 @@
  */
 
 /**
-        \file       scripts/cron/product-graph.php
-        \ingroup    product
-        \brief      Cr�e les graphiques pour les produits
-		\version	$Id$
-*/
- 
+ \file       scripts/cron/product-graph.php
+ \ingroup    product
+ \brief      Cr�e les graphiques pour les produits
+ \version	$Id$
+ */
+
 // Test si mode CLI
 $sapi_type = php_sapi_name();
-$script_file=__FILE__; 
+$script_file=__FILE__;
 if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
 
 if (substr($sapi_type, 0, 3) == 'cgi') {
-    echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
-    exit;
+	echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
+	exit;
 }
- 
+
 // Recupere env dolibarr
 $version='$Revision$';
 $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
 
 require_once($path."../../htdocs/master.inc.php");
-require_once (DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
+require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
 
 
 $error=0;
@@ -47,18 +47,18 @@ $verbose = 0;
 
 for ($i = 1 ; $i < sizeof($argv) ; $i++)
 {
-  if ($argv[$i] == "-v")
-    {
-      $verbose = 1;
-    }
-  if ($argv[$i] == "-vv")
-    {
-      $verbose = 2;
-    }
-  if ($argv[$i] == "-vvv")
-    {
-      $verbose = 3;
-    }
+	if ($argv[$i] == "-v")
+	{
+		$verbose = 1;
+	}
+	if ($argv[$i] == "-vv")
+	{
+		$verbose = 2;
+	}
+	if ($argv[$i] == "-vvv")
+	{
+		$verbose = 3;
+	}
 }
 
 $now = time();
@@ -67,13 +67,13 @@ $year = strftime('%Y',$now);
 /*
  *
  */
-$dir = DOL_DATA_ROOT."/graph/product";
+$dir = DOL_DATA_ROOT."/product/temp";
 if (!is_dir($dir) )
 {
-  if (! create_exdir($dir,0755))
-    {
-      die ("Can't create $dir\n");
-    }
+	if (! create_exdir($dir,0755))
+	{
+		die ("Can't create $dir\n");
+	}
 }
 /*
  *
@@ -85,77 +85,76 @@ $resql = $db->query($sql) ;
 $products = array();
 if ($resql)
 {
-  while ($row = $db->fetch_row($resql))
-    {
-      $fdir = $dir.'/'.get_exdir($row[0],3);
+	while ($row = $db->fetch_row($resql))
+	{
+		$fdir = $dir.'/'.get_exdir($row[0],3);
 
-      if ($verbose)
-	print $fdir."\n";
-      create_exdir($fdir);
+		if ($verbose) print $fdir."\n";
+		create_exdir($fdir);
 
-      $products[$row[0]] = $fdir;
-    }
-  $db->free($resql);
+		$products[$row[0]] = $fdir;
+	}
+	$db->free($resql);
 }
 else
 {
-  print $sql;
+	print $sql;
 }
 /*
  *
  */
 foreach ( $products as $id => $fdir)
 {
-  $num = array();
-  $ca = array();
-  $legends = array(); 
-
-  for ($i = 0 ; $i < 12 ; $i++)
-    {
-      $legends[$i] = strftime('%b',mktime(1,1,1,($i+1),1, $year) );
-      $num[$i]  = 0;
-      $ca[$i]  = 0;
-    }
-  
-  $sql  = "SELECT date_format(f.datef,'%b'), sum(fd.qty), sum(fd.total_ht), date_format(f.datef,'%m')";
-  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as fd";
-  $sql .= " WHERE f.rowid = fd.fk_facture AND date_format(f.datef,'%Y')='".$year."'";
-  $sql .= " AND fd.fk_product ='".$id."'";
-  $sql .= " GROUP BY date_format(f.datef,'%b')";
-  $sql .= " ORDER BY date_format(f.datef,'%m') ASC ;";
-
-  $resql = $db->query($sql) ;
-  
-  if ($resql)
-    {
-      $i = 0;
-      while ($row = $db->fetch_row($resql))
+	$num = array();
+	$ca = array();
+	$legends = array();
+
+	for ($i = 0 ; $i < 12 ; $i++)
 	{
+		$legends[$i] = strftime('%b',mktime(1,1,1,($i+1),1, $year) );
+		$num[$i]  = 0;
+		$ca[$i]  = 0;
+	}
+
+	$sql  = "SELECT date_format(f.datef,'%b'), sum(fd.qty), sum(fd.total_ht), date_format(f.datef,'%m')";
+	$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as fd";
+	$sql .= " WHERE f.rowid = fd.fk_facture AND date_format(f.datef,'%Y')='".$year."'";
+	$sql .= " AND fd.fk_product ='".$id."'";
+	$sql .= " GROUP BY date_format(f.datef,'%b')";
+	$sql .= " ORDER BY date_format(f.datef,'%m') ASC ;";
+
+	$resql = $db->query($sql) ;
+
+	if ($resql)
+	{
+		$i = 0;
+		while ($row = $db->fetch_row($resql))
+		{
 	  $legends[($row[3] - 1)] = $row[0];
 	  $num[($row[3] - 1)]  = $row[1];
-	  $ca[($row[3] - 1)]  = $row[2];	  
+	  $ca[($row[3] - 1)]  = $row[2];
 	  $i++;
+		}
+		$db->free($resql);
+	}
+	else
+	{
+		print $sql;
+	}
+
+	if ($i > 0)
+	{
+		$graph = new DolGraph();
+
+		$file = $fdir ."ventes-".$year."-".$id.".png";
+		$title = "Ventes";
+
+		$graph->SetTitle($title);
+		$graph->BarLineOneYearArtichow($file, $ca, $num, $legends);
+
+		if ($verbose)
+		print "$file\n";
 	}
-      $db->free($resql);
-    }
-  else
-    {
-      print $sql;
-    }
-
-  if ($i > 0)
-    {
-      $graph = new DolGraph();
-    
-      $file = $fdir ."ventes-".$year."-".$id.".png";
-      $title = "Ventes";
-      
-      $graph->SetTitle($title);
-      $graph->BarLineOneYearArtichow($file, $ca, $num, $legends);
-
-      if ($verbose)
-	print "$file\n";
-    }
 }
 /*
  * Ventes annuelles
@@ -163,49 +162,49 @@ foreach ( $products as $id => $fdir)
  */
 foreach ( $products as $id => $fdir)
 {
-  $num = array();
-  $ca = array();
-  $legends = array(); 
-  $sql  = "SELECT date_format(f.datef,'%Y'), sum(fd.qty), sum(fd.total_ht)";
-  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as fd";
-  $sql .= " WHERE f.rowid = fd.fk_facture";
-  $sql .= " AND fd.fk_product ='".$id."'";
-  $sql .= " GROUP BY date_format(f.datef,'%Y')";
-  $sql .= " ORDER BY date_format(f.datef,'%Y') ASC ;";
-
-  $resql = $db->query($sql) ;
-  
-  if ($resql)
-    {
-      $i = 0;
-      while ($row = $db->fetch_row($resql))
+	$num = array();
+	$ca = array();
+	$legends = array();
+	$sql  = "SELECT date_format(f.datef,'%Y'), sum(fd.qty), sum(fd.total_ht)";
+	$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as fd";
+	$sql .= " WHERE f.rowid = fd.fk_facture";
+	$sql .= " AND fd.fk_product ='".$id."'";
+	$sql .= " GROUP BY date_format(f.datef,'%Y')";
+	$sql .= " ORDER BY date_format(f.datef,'%Y') ASC ;";
+
+	$resql = $db->query($sql) ;
+
+	if ($resql)
 	{
+		$i = 0;
+		while ($row = $db->fetch_row($resql))
+		{
 	  $legends[$i] = $row[0];
 	  $num[$i]  = $row[1];
 	  $ca[$i]  = $row[2];
-	  
+	   
 	  $i++;
+		}
+		$db->free($resql);
+	}
+	else
+	{
+		print $sql;
+	}
+
+	if ($i > 0)
+	{
+		$graph = new DolGraph();
+
+		$file = $fdir ."ventes-".$id.".png";
+		$title = "Ventes";
+
+		$graph->SetTitle($title);
+		$graph->BarLineAnnualArtichow($file, $ca, $num, $legends);
+
+		if ($verbose)
+		print "$file\n";
 	}
-      $db->free($resql);
-    }
-  else
-    {
-      print $sql;
-    }
-
-  if ($i > 0)
-    {
-      $graph = new DolGraph();
-  
-      $file = $fdir ."ventes-".$id.".png";
-      $title = "Ventes";
-      
-      $graph->SetTitle($title);
-      $graph->BarLineAnnualArtichow($file, $ca, $num, $legends);
-      
-      if ($verbose)
-	print "$file\n";
-    }
 }
 
 
diff --git a/scripts/cron/stock-graph.php b/scripts/cron/stock-graph.php
index 693dd968854ff5445305f82ec1b9a0b85f6f1803..b309138852a38e1d01061463542b3e9eca34d38f 100644
--- a/scripts/cron/stock-graph.php
+++ b/scripts/cron/stock-graph.php
@@ -39,10 +39,16 @@ $version='$Revision$';
 $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
 
 require_once($path."../../htdocs/master.inc.php");
+require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
+
+
+/*
+ * Main
+ */
 
 $error=0;
-$verbose = 0;
 
+$verbose = 0;
 for ($i = 1 ; $i < sizeof($argv) ; $i++)
 {
   if ($argv[$i] == "-v")
@@ -60,7 +66,7 @@ for ($i = 1 ; $i < sizeof($argv) ; $i++)
 }
 
 
-$dir = DOL_DATA_ROOT."/graph/entrepot";
+$dir = DOL_DATA_ROOT."/entrepot/temp";
 $result=create_exdir($dir);
 
 
@@ -83,9 +89,6 @@ else
   dolibarr_print_error($db,$sql);
 }
 
-/*
- *
- */
 $now = time();
 $year = strftime('%Y',$now);
 $day = strftime('%j', $now);
@@ -100,7 +103,7 @@ for ($i = 0 ; $i < strftime('%j',$now) ; $i++)
 }
 
 /*
- *
+ * Read values
  */
 $sql  = "SELECT date_format(date_calcul,'%j'), valo_pmp, fk_entrepot";
 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot_valorisation as e";
@@ -153,9 +156,11 @@ for ($i = $max_day + 1 ; $i < ($day + 1) ; $i++)
 }
 
 
+// PMP = (quantit�s en stock x pmp ancien + nouvelles quantit�s x prix d'acquisition)/ (anciennes quantit�s + nouvelles quantit�s)
 
-require_once(DOL_DOCUMENT_ROOT."/../external-libs/Artichow/LinePlot.class.php");
-
+/*
+ * For each warehouse
+ */
 foreach ($entrepots as $key => $ent)
 {
   $file = $dir ."/entrepot-".$key."-".$year.".png";
@@ -167,12 +172,12 @@ foreach ($entrepots as $key => $ent)
   if ($verbose)
     print "$file\n";
 }
+
 /*
- * Graph cumulatif
- *
+ * For all warehouses
  */
-$file = DOL_DATA_ROOT."/graph/entrepot/entrepot-".$year.".png";
-$title = "Valorisation PMP du stock global (euros HT) sur l'ann�e ".$year;
+$file = $dir."/entrepot-".$year.".png";
+$title = "Valorisation PMP (Prix Moyen Pond�r�) du stock global (euros HT) sur l'ann�e ".$year;
 
 if ($total[$key] > 0)
   graph_datas($file, $title, $values[0], $legends);
@@ -180,7 +185,8 @@ if ($total[$key] > 0)
 if ($verbose)
   print "$file\n";
 
-  
+
+
 /**	\brief	Build graph
 *	\param	file		File
 *	\param	title		Title
@@ -189,44 +195,28 @@ if ($verbose)
 */
 function graph_datas($file, $title, $values, $legends)
 {
-
-  $graph = new Graph(800, 250);
-  $graph->title->set($title);
-  $graph->title->setFont(new Tuffy(10));
-
-  $graph->border->hide();
-    
-  $color = new Color(244,244,244);
-
-  $graph->setAntiAliasing(TRUE);
-  $graph->setBackgroundColor( $color );
-
-  //$plot->yAxis->title->set("euros");
-
-  $plot = new LinePlot($values);
-  $plot->setSize(1, 0.96);
-  $plot->setCenter(0.5, 0.52);
-
-  // Change line color
-  $plot->setColor(new Color(0, 0, 150, 20));
-
-  // Set line background gradient
-  $plot->setFillGradient(
-			 new LinearGradient(
-					    new Color(150, 150, 210),
-					    new Color(230, 230, 255),
-					    90
-					    )
-			 );
-  
-  $plot->xAxis->setLabelText($legends);
-  $plot->xAxis->label->setFont(new Tuffy(7));
-  
-  $plot->grid->hideVertical(TRUE);
-  $plot->xAxis->setLabelInterval(31);
-
-  $graph->add($plot);
-
-  $graph->draw($file);
+	$width=800;
+	$height=230;
+	
+	$newvalues=array();
+	foreach ($values as $abs=>$ord)
+	{
+		$newvalues[]=array($legends[$abs],$ord);
+	}
+	
+	$px = new DolGraph();
+	$px->SetData($newvalues);
+	//$px->SetLegend('');
+    $px->SetMaxValue($px->GetCeilMaxValue());
+    $px->SetMinValue($px->GetFloorMinValue());
+    $px->SetTitle($title);
+    $px->SetWidth($width);
+    $px->SetHeight($height);
+	$px->SetType('lines');
+	$px->setBgColor('default');
+  	$px->setBgColorGrid(array(255,255,255));
+	$px->SetHideXGrid(true);
+	$px->SetLabelInterval(31);
+	$px->draw($file);
 }
 ?>