From 7a9363cd609635e56c17d757efe594b26d0dad7c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Dec 2007 03:52:43 +0000 Subject: [PATCH] Fix: Total sur stats propal New: Les graph en bar ont 2 modes: bar cote a cote ou l'une derriere l'autre. New: Affichage de 3 ans au lieu de 2 sur graph stat propal --- htdocs/comm/propal/stats/index.php | 33 ++++++++++++------- .../comm/propal/stats/propalestats.class.php | 2 -- htdocs/dolgraph.class.php | 28 +++++++++++----- htdocs/stats.class.php | 30 ++++++++++------- htdocs/theme/eldy/graph-color.php | 5 ++- 5 files changed, 61 insertions(+), 37 deletions(-) diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php index 3c6b3d974c6..cb6fd0fd521 100644 --- a/htdocs/comm/propal/stats/index.php +++ b/htdocs/comm/propal/stats/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2007 Laurent Destailleur * * 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 @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -41,7 +40,9 @@ print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); $stats = new PropaleStats($db); $year = strftime("%Y", time()); -$data = $stats->getNbByMonthWithPrevYear($year); +$startyear=$year-2; +$endyear=$year; +$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); create_exdir($conf->propal->dir_temp); @@ -62,17 +63,24 @@ if (! $mesg) { $px->SetData($data); $px->SetPrecisionY(0); - $px->SetLegend(array($year - 1, $year)); + $i=$startyear; + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px->SetLegend($legend); $px->SetMaxValue($px->GetCeilMaxValue()); $px->SetWidth($WIDTH); $px->SetHeight($HEIGHT); $px->SetShading(3); $px->SetHorizTickIncrement(1); $px->SetPrecisionY(0); + $px->mode='depth'; $px->draw($filename); } -$sql = "SELECT count(*), date_format(p.datep,'%Y') as dm, sum(p.price)"; +$sql = "SELECT count(*) as nb, date_format(p.datep,'%Y') as dm, sum(p.total) as total_ttc"; if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->commercial->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -83,9 +91,10 @@ if($user->societe_id) $sql .= " AND p.fk_soc = ".$user->societe_id; } $sql.= " GROUP BY dm DESC "; -if ($db->query($sql)) +$result=$db->query($sql); +if ($result) { - $num = $db->num_rows(); + $num = $db->num_rows($result); print ''; print ''; @@ -104,18 +113,18 @@ if ($db->query($sql)) $i = 0; while ($i < $num) { - $row = $db->fetch_row($i); - $nbproduct = $row[0]; - $year = $row[1]; + $obj = $db->fetch_object($result); + $nbproduct = $obj->nb; + $year = $obj->dm; print ""; print ''; print ''; - print ''; + print ''; $i++; } print '
'.$langs->trans("Year").''.$langs->trans("NbOfProposals").''.$langs->trans("AmountTotal").'
'.$year.''.$nbproduct.''.price($row[2]).'
'.price($obj->total_ttc).'
'; - $db->free(); + $db->free($result); } else { diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php index bae25f80862..63c90f0f004 100644 --- a/htdocs/comm/propal/stats/propalestats.class.php +++ b/htdocs/comm/propal/stats/propalestats.class.php @@ -17,8 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ - * */ /** diff --git a/htdocs/dolgraph.class.php b/htdocs/dolgraph.class.php index 338a7249168..eefc49d4ca2 100644 --- a/htdocs/dolgraph.class.php +++ b/htdocs/dolgraph.class.php @@ -47,6 +47,8 @@ class DolGraph { //! Type du graphique var $type='bars'; // bars, lines, ... + var $mode='side'; // Mode bars graph: side, depth + //! Tableau de donnees var $data; // array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...) var $width=380; @@ -146,7 +148,7 @@ class DolGraph // 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,50); + $colorsemitrans=new Color(255,255,255,60); $colorgradient= new LinearGradient(new Color(235, 235, 235),new Color(255, 255, 255),0); // Graph @@ -163,7 +165,12 @@ class DolGraph $group = new PlotGroup; //$group->setSpace(5, 5, 0, 0); - $group->setPadding(strlen(max(abs($this->MaxValue),abs($this->MinValue)))*8+20, 10); // Width on left and right for Y axis values + + $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); @@ -175,7 +182,7 @@ class DolGraph $legends=array(); $i=0; $nblot=sizeof($this->data[0])-1; - if (! $nblot) $end=1; + while ($i < $nblot) { $j=0; @@ -201,18 +208,21 @@ class DolGraph //print "Lot de donnees $i
"; //print_r($values); //print '
'; - + + $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]); - //$plot = new BarPlot($newvalues,1,1,0); - $plot = new BarPlot($newvalues, $i+1, $nblot); + 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($colorborder); + $plot->barBorder->setColor($colorgrey); $plot->setBarColor($color); - $plot->setBarPadding(0.1, 0.1); - $plot->setBarSpace(5); + 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); diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php index e3e964a2389..3019f32cf80 100644 --- a/htdocs/stats.class.php +++ b/htdocs/stats.class.php @@ -16,8 +16,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ - * */ class Stats @@ -29,24 +27,34 @@ class Stats $this->db = $DB; } - function getNbByMonthWithPrevYear($year) + function getNbByMonthWithPrevYear($endyear,$startyear) { - $data1 = $this->getNbByMonth($year - 1); - $data2 = $this->getNbByMonth($year); + $datay=array(); + + $year=$startyear; + while($year <= $endyear) + { + $datay[$year] = $this->getNbByMonth($year); + $year++; + } $data = array(); for ($i = 0 ; $i < 12 ; $i++) { - $data[$i] = array($data1[$i][0], - $data1[$i][1], - $data2[$i][1]); + $data[$i][]=$datay[$endyear][$i][0]; + $year=$startyear; + while($year <= $endyear) + { + $data[$i][]=$datay[$year][$i][1]; + $year++; + } } return $data; } /** - * \brief Renvoie le nombre de proposition par mois pour une année donnée + * \brief Renvoie le nombre de proposition par mois pour une annee donnee * */ function _getNbByMonth($year, $sql) @@ -85,7 +93,7 @@ class Stats /** - * \brief Renvoie le nombre d'element par année + * \brief Renvoie le nombre d'element par ann�e * */ function _getNbByYear($sql) @@ -111,7 +119,7 @@ class Stats } /** - * \brief Renvoie le nombre d'element par mois pour une année donnée + * \brief Renvoie le nombre d'element par mois pour une ann�e donn�e * */ diff --git a/htdocs/theme/eldy/graph-color.php b/htdocs/theme/eldy/graph-color.php index dc087c8f29b..e8a80f43400 100755 --- a/htdocs/theme/eldy/graph-color.php +++ b/htdocs/theme/eldy/graph-color.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2007 Laurent Destailleur * * 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 @@ -17,7 +17,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ - * $Source$ */ /** @@ -29,7 +28,7 @@ global $theme_bordercolor, $theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet; $theme_bordercolor = array(235,235,224); -$theme_datacolor = array(array(120,130,150), array(160,160,180), array(190,190,220)); +$theme_datacolor = array(array(120,130,150), array(200,160,180), array(190,190,220)); $theme_bgcolor = array(hexdec('F4'),hexdec('F4'),hexdec('F4')); $theme_bgcoloronglet = array(hexdec('DE'),hexdec('E7'),hexdec('EC'));