diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 475051da56c..509e8792c8f 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -659,7 +659,11 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST["save"] == $langs->trans("Save"))
{
$propal = new Propal($db);
- if (! $propal->fetch($_POST['propalid']) > 0) dolibarr_print_error($db);
+ if (! $propal->fetch($_POST['propalid']) > 0)
+ {
+ dolibarr_print_error($db,$propal->error);
+ exit;
+ }
// Define info_bits
$info_bits=0;
@@ -671,9 +675,12 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
// On vérifie que le prix minimum est respecté
$productid = $_POST['productid'] ;
- $pruduct = new Product($db) ;
- $pruduct->fetch($productid) ;
- if ($pruduct->price_min && ($_POST['productid']!='')&&( price2num($_POST['subprice'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min)))
+ if ($productid)
+ {
+ $pruduct = new Product($db) ;
+ $res=$pruduct->fetch($productid) ;
+ }
+ if ($productid && $pruduct->price_min && ( price2num($_POST['subprice'])*(1-price2num($_POST['remise_percent'])/100) < price2num($pruduct->price_min)))
{
$mesg = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($pruduct->price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).'
' ;
}
@@ -1913,18 +1920,24 @@ else
if ($result)
{
- $num = $db->num_rows($result);
$propalstatic=new Propal($db);
- print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&socid='.$socid.'&viewstatut='.$viewstatut,$sortfield,$sortorder,'',$num);
+
+ $num = $db->num_rows($result);
+
+ $param='&socid='.$socid.'&viewstatut='.$viewstatut;
+ if ($month) $param.='&month='.$month;
+ if ($year) $param.='&year='.$year;
+ print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php',$param,$sortfield,$sortorder,'',$num);
+
$i = 0;
print '';
print '';
- print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','','&socid='.$socid.'&viewstatut='.$viewstatut,'',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','','&socid='.$socid.'&viewstatut='.$viewstatut,'',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="center"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="center"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.total_ht','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','','&socid='.$socid.'&viewstatut='.$viewstatut,'align="right"',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Ref'),$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Company'),$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Date'),$_SERVER["PHP_SELF"],'p.datep','',$param, 'align="center"',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('DateEndPropalShort'),$_SERVER["PHP_SELF"],'dfv','',$param, 'align="center"',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Price'),$_SERVER["PHP_SELF"],'p.total_ht','',$param, 'align="right"',$sortfield,$sortorder);
+ print_liste_field_titre($langs->trans('Status'),$_SERVER["PHP_SELF"],'p.fk_statut','',$param,'align="right"',$sortfield,$sortorder);
print '| | ';
print "
\n";
// Lignes des champs de filtre
@@ -1938,12 +1951,11 @@ else
print '';
print '';
print '';
- print $langs->trans('Month').': ';
+ print $langs->trans('Month').': ';
print ' '.$langs->trans('Year').': ';
$max_year = date("Y");
$syear = $year;
- if($syear == '')
- $syear = date("Y");
+ //if($syear == '') $syear = date("Y");
$html->select_year($syear,'year',1, '', $max_year);
print ' | ';
print ' | ';
@@ -2015,7 +2027,7 @@ else
// Date fin validite
if ($objp->dfv)
{
- print ''.dolibarr_print_date($objp->dfv);
+ print ' | '.dolibarr_print_date($objp->dfv,'day');
print ' | ';
}
else
diff --git a/htdocs/comm/propal/stats/index.php b/htdocs/comm/propal/stats/index.php
index f9d9cc6da98..1af520b1779 100644
--- a/htdocs/comm/propal/stats/index.php
+++ b/htdocs/comm/propal/stats/index.php
@@ -31,28 +31,46 @@ require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
$WIDTH=500;
$HEIGHT=200;
+// Sécurité accés client
+if ($user->societe_id > 0)
+{
+ $action = '';
+ $socid = $user->societe_id;
+}
+$year = strftime("%Y", time());
+$startyear=$year-2;
+$endyear=$year;
+
+/*
+ * View
+ */
+
llxHeader();
print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg);
-$stats = new PropaleStats($db);
-$year = strftime("%Y", time());
-$startyear=$year-2;
-$endyear=$year;
-$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
+$dir=$conf->propal->dir_temp;
+
+create_exdir($dir);
+
+$stats = new PropaleStats($db, $socid);
+
+// Build graphic number of object
+$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
+//var_dump($data);
+// $data = array(array('Lib',val1,val2,val3),...)
-create_exdir($conf->propal->dir_temp);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename = $conf->propal->dir_temp.'/nbpropale2year-'.$user->id.'-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=nbpropale2year-'.$user->id.'-'.$year.'.png';
+ $filenamenb = $conf->propal->dir_temp.'/proposalsnbinyear-'.$user->id.'-'.$year.'.png';
+ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename = $conf->propal->dir_temp.'/nbpropale2year-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=nbpropale2year-'.$year.'.png';
+ $filenamenb = $conf->propal->dir_temp.'/proposalsnbinyear-'.$year.'.png';
+ $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnbinyear-'.$year.'.png';
}
$px = new DolGraph();
@@ -69,6 +87,7 @@ if (! $mesg)
}
$px->SetLegend($legend);
$px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue(min(0,$px->GetFloorMinValue()));
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("NbOfProposals"));
@@ -76,60 +95,109 @@ if (! $mesg)
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->mode='depth';
- $px->draw($filename);
+ $px->SetTitle($langs->trans("NbOfProposals"));
+
+ $px->draw($filenamenb);
}
-$sql = "SELECT count(*) as nb, date_format(p.datep,'%Y') as dm, sum(p.total) as total_ttc";
-if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
-$sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
-if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
-$sql.= " WHERE fk_statut > 0";
-if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
-if($user->societe_id)
-{
- $sql .= " AND p.fk_soc = ".$user->societe_id;
-}
-$sql.= " GROUP BY dm DESC ";
-$result=$db->query($sql);
-if ($result)
-{
- $num = $db->num_rows($result);
+// Build graphic amount of object
+$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
+//var_dump($data);
+// $data = array(array('Lib',val1,val2,val3),...)
- print '';
- print '| '.$langs->trans("Year").' | '.$langs->trans("NbOfProposals").' | '.$langs->trans("AmountTotal").' | ';
- print '';
-
- if ($mesg)
- {
- print "$mesg";
- }
- else
- {
- print ' ';
- }
-
- print ' |
';
- $i = 0;
- while ($i < $num)
- {
- $obj = $db->fetch_object($result);
- $nbproduct = $obj->nb;
- $year = $obj->dm;
- print "";
- print '| '.$year.' | ';
- print ''.$nbproduct.' | ';
- print ''.price($obj->total_ttc).' |
';
- $i++;
- }
-
- print '
';
- $db->free($result);
+if (!$user->rights->societe->client->voir || $user->societe_id)
+{
+ $filenameamount = $conf->propal->dir_temp.'/proposalsamountinyear-'.$user->id.'-'.$year.'.png';
+ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$user->id.'-'.$year.'.png';
}
else
{
- dolibarr_print_error($db);
+ $filenameamount = $conf->propal->dir_temp.'/proposalsamountinyear-'.$year.'.png';
+ $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamountinyear-'.$year.'.png';
}
+$px = new DolGraph();
+$mesg = $px->isGraphKo();
+if (! $mesg)
+{
+ $px->SetData($data);
+ $px->SetPrecisionY(0);
+ $i=$startyear;
+ while ($i <= $endyear)
+ {
+ $legend[]=$i;
+ $i++;
+ }
+ $px->SetLegend($legend);
+ $px->SetMaxValue($px->GetCeilMaxValue());
+ $px->SetMinValue(min(0,$px->GetFloorMinValue()));
+ $px->SetWidth($WIDTH);
+ $px->SetHeight($HEIGHT);
+ $px->SetYLabel($langs->trans("AmountOfProposals"));
+ $px->SetShading(3);
+ $px->SetHorizTickIncrement(1);
+ $px->SetPrecisionY(0);
+ $px->mode='depth';
+ $px->SetTitle($langs->trans("AmountOfProposalsByMonthHT"));
+
+ $px->draw($filenameamount);
+}
+
+print '';
+print '';
+
+// Show array
+$data = $stats->getAllByYear();
+
+print '';
+print '';
+print '| '.$langs->trans("Year").' | ';
+print ''.$langs->trans("NbOfProposals").' | ';
+print ''.$langs->trans("AmountTotal").' | ';
+print ''.$langs->trans("AmountAverage").' | ';
+print ' ';
+
+$oldyear=0;
+foreach ($data as $val)
+{
+ $year = $val['year'];
+ print $avg;
+ while ($oldyear > $year+1)
+ { // If we have empty year
+ $oldyear--;
+ print '';
+ print '| '.$oldyear.' | ';
+ print '0 | ';
+ print '0 | ';
+ print '0 | ';
+ print ' ';
+ }
+ print '';
+ print '| '.$year.' | ';
+ print ''.$val['nb'].' | ';
+ print ''.price(price2num($val['total'],'MT'),1).' | ';
+ print ''.price(price2num($val['avg'],'MT'),1).' | ';
+ print ' ';
+ $oldyear=$year;
+}
+
+print ' ';
+
+
+print ' | ';
+print '';
+
+// Show graphs
+print '';
+if ($mesg) { print $mesg; }
+else {
+ print ' ';
+ print " \n";
+ print ' ';
+}
+print ' | ';
+
+print ' |
';
$db->close();
diff --git a/htdocs/comm/propal/stats/month.php b/htdocs/comm/propal/stats/month.php
index e497330533e..bc4f1211479 100644
--- a/htdocs/comm/propal/stats/month.php
+++ b/htdocs/comm/propal/stats/month.php
@@ -28,39 +28,48 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/comm/propal/stats/propalestats.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
+$GRAPHWIDTH=500;
+$GRAPHHEIGHT=200;
-llxHeader();
+// Check security access
+if ($user->societe_id > 0)
+{
+ $action = '';
+ $socid = $user->societe_id;
+}
$year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
+
+/*
+ * View
+ */
+
+llxHeader();
+
+$dir=$conf->propal->dir_temp;
+
$mesg = ''.img_previous().' ';
$mesg.= $langs->trans("Year")." $year";
$mesg.= ' '.img_next().'';
-
-$WIDTH=500;
-$HEIGHT=200;
-
-/*
- *
- *
- */
-
print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg);
-$stats = new PropaleStats($db);
-$data = $stats->getNbByMonth($year);
+create_exdir($dir);
-create_exdir($conf->propal->dir_temp);
+$stats = new PropaleStats($db, $socid);
+
+
+$data = $stats->getNbByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename = $conf->propal->dir_temp.'/propale-'.$user->id.'-'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale-'.$user->id.'-'.$year.'.png';
+ $filename = $dir.'/proposalsnb-'.$user->id.'-'.$year.'.png';
+ $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnb-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename = $conf->propal->dir_temp.'/propale'.$year.'.png';
- $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propale'.$year.'.png';
+ $filename = $dir.'/proposalsnb-'.$year.'.png';
+ $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsnb-'.$year.'.png';
}
$px = new DolGraph();
@@ -68,34 +77,29 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetPrecisionY(0);
$px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename);
}
-$res = $stats->getAmountByMonth($year);
-$data = array();
-for ($i = 1 ; $i < 13 ; $i++)
-{
- $data[$i-1] = array(ucfirst(substr(strftime("%b",dolibarr_mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
-}
+$data = $stats->getAmountByMonth($year);
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename_amount = $conf->propal->dir_temp.'/propaleamount-'.$user->id.'-'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount-'.$user->id.'-'.$year.'.png';
+ $filename_amount = $dir.'/proposalsamount-'.$user->id.'-'.$year.'.png';
+ $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamount-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename_amount = $conf->propal->dir_temp.'/propaleamount'.$year.'.png';
- $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleamount'.$year.'.png';
+ $filename_amount = $dir.'/proposalsamount-'.$year.'.png';
+ $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsamount-'.$year.'.png';
}
$px = new DolGraph();
@@ -103,16 +107,18 @@ $mesg = $px->isGraphKo();
if (! $mesg)
{
$px->SetData($data);
- $px->SetPrecisionY(0);
$px->SetYLabel($langs->trans("AmountTotal"));
$px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
- $px->draw($filename_amount, $data, $year);
+ $px->draw($filename_amount);
}
+
+
$res = $stats->getAverageByMonth($year);
$data = array();
@@ -124,13 +130,13 @@ for ($i = 1 ; $i < 13 ; $i++)
if (!$user->rights->societe->client->voir || $user->societe_id)
{
- $filename_avg = $conf->propal->dir_temp.'/propaleaverage-'.$user->id.'-'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage-'.$user->id.'-'.$year.'.png';
+ $filename_avg = $dir.'/proposalsaverage-'.$user->id.'-'.$year.'.png';
+ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsaverage-'.$user->id.'-'.$year.'.png';
}
else
{
- $filename_avg = $conf->propal->dir_temp.'/propaleaverage'.$year.'.png';
- $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png';
+ $filename_avg = $dir.'/proposalsaverage-'.$year.'.png';
+ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=proposalsaverage-'.$year.'.png';
}
$px = new DolGraph();
@@ -141,8 +147,9 @@ if (! $mesg)
$px->SetPrecisionY(0);
$px->SetYLabel($langs->trans("AmountAverage"));
$px->SetMaxValue($px->GetCeilMaxValue());
- $px->SetWidth($WIDTH);
- $px->SetHeight($HEIGHT);
+ $px->SetMinValue($px->GetFloorMinValue());
+ $px->SetWidth($GRAPHWIDTH);
+ $px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
diff --git a/htdocs/comm/propal/stats/propalestats.class.php b/htdocs/comm/propal/stats/propalestats.class.php
index cd7ccc2e32c..717e8d5c3a6 100644
--- a/htdocs/comm/propal/stats/propalestats.class.php
+++ b/htdocs/comm/propal/stats/propalestats.class.php
@@ -15,124 +15,169 @@
* 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$
*/
/**
- \file htdocs/comm/propal/stats/propalestats.class.php
- \ingroup propales
- \brief Fichier de la classe de gestion des stats des propales
- \version $Revision$
-*/
+ * \file htdocs/comm/propal/stats/propalestats.class.php
+ * \ingroup propales
+ * \brief Fichier de la classe de gestion des stats des propales
+ * \version $Id$
+ */
include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
+include_once DOL_DOCUMENT_ROOT . "/propal.class.php";
/**
- \class PropaleStats
- \brief Classe permettant la gestion des stats des propales
-*/
-
+ * \class PropaleStats
+ * \brief Classe permettant la gestion des stats des propales
+ */
class PropaleStats extends Stats
{
- var $db ;
+ var $db ;
- function PropaleStats($DB)
- {
- $this->db = $DB;
- }
+ var $socid;
+ var $where;
+
+ var $table_element;
+ var $field;
- /**
- * Renvoie le nombre de proposition par mois pour une année donnée
- *
- */
- function getNbByMonth($year)
- {
- global $user;
-
- $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
-
- return $this->_getNbByMonth($year, $sql);
- }
+ /**
+ * Constructor
+ *
+ * @param $DB Database handler
+ * @param $socid Id third party
+ * @return PropaleStats
+ */
+ function PropaleStats($DB, $socid=0)
+ {
+ global $user;
+
+ $this->db = $DB;
- /**
- * Renvoie le nombre de propale par année
- *
- */
- function getNbByYear()
- {
- global $user;
-
- $sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
+ $object=new Propal($this->db);
+ $this->table_element=$object->table_element;
+ $this->field='total';
+
+ $this->socid = $socid;
+ $this->where.= " fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($this->socid)
+ {
+ $this->where .= " AND p.fk_soc = ".$this->socid;
+ }
+ }
- return $this->_getNbByYear($sql);
- }
- /**
- * Renvoie le nombre de propale par mois pour une année donnée
- *
- */
- function getAmountByMonth($year)
- {
- global $user;
-
- $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
- return $this->_getAmountByMonth($year, $sql);
- }
- /**
- *
- *
- */
- function getAverageByMonth($year)
- {
- global $user;
-
- $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
- $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
- $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
- if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
- if($user->societe_id)
- {
- $sql .= " AND p.fk_soc = ".$user->societe_id;
- }
- $sql .= " GROUP BY dm DESC";
+ /**
+ * Renvoie le nombre de proposition par mois pour une année donnée
+ *
+ */
+ function getNbByMonth($year)
+ {
+ global $user;
+
+ $sql = "SELECT date_format(p.datep,'%m') as dm, count(*)";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($user->societe_id)
+ {
+ $sql .= " AND p.fk_soc = ".$user->societe_id;
+ }
+ $sql .= " GROUP BY dm DESC";
+
+ return $this->_getNbByMonth($year, $sql);
+ }
+
+ /**
+ * Renvoie le nombre de propale par année
+ *
+ */
+ function getNbByYear()
+ {
+ global $user;
+
+ $sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql .= " WHERE p.fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($user->societe_id)
+ {
+ $sql .= " AND p.fk_soc = ".$user->societe_id;
+ }
+ $sql .= " GROUP BY dm DESC";
+
+ return $this->_getNbByYear($sql);
+ }
+ /**
+ * Renvoie le nombre de propale par mois pour une année donnée
+ *
+ */
+ function getAmountByMonth($year)
+ {
+ global $user;
+
+ $sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($user->societe_id)
+ {
+ $sql .= " AND p.fk_soc = ".$user->societe_id;
+ }
+ $sql .= " GROUP BY dm DESC";
+
+ return $this->_getAmountByMonth($year, $sql);
+ }
+ /**
+ *
+ *
+ */
+ function getAverageByMonth($year)
+ {
+ global $user;
+
+ $sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
+ if($user->societe_id)
+ {
+ $sql .= " AND p.fk_soc = ".$user->societe_id;
+ }
+ $sql .= " GROUP BY dm DESC";
+
+ return $this->_getAverageByMonth($year, $sql);
+ }
+
+
+ /**
+ * \brief Return nb, total and average
+ * \return array Array of values
+ */
+ function getAllByYear()
+ {
+ global $user;
+
+ $sql = "SELECT date_format(p.datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
+ $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
+ if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
+ $sql.= " WHERE ".$this->where;
+ $sql.= " GROUP BY year DESC";
+
+ return $this->_getAllByYear($sql);
+ }
- return $this->_getAverageByMonth($year, $sql);
- }
}
-
?>
diff --git a/htdocs/compta/facture/stats/facturestats.class.php b/htdocs/compta/facture/stats/facturestats.class.php
index 9360e74d1dd..b0c56f0697a 100644
--- a/htdocs/compta/facture/stats/facturestats.class.php
+++ b/htdocs/compta/facture/stats/facturestats.class.php
@@ -41,6 +41,14 @@ class FactureStats extends Stats
var $table_element;
var $field;
+ /**
+ * Constructor
+ *
+ * @param $DB Database handler
+ * @param $socid Id third party
+ * @param $mode Option
+ * @return FactureStats
+ */
function FactureStats($DB, $socid=0, $mode)
{
$this->db = $DB;
diff --git a/htdocs/compta/facture/stats/index.php b/htdocs/compta/facture/stats/index.php
index dcc7381dd35..15c8d09c6c0 100644
--- a/htdocs/compta/facture/stats/index.php
+++ b/htdocs/compta/facture/stats/index.php
@@ -69,14 +69,14 @@ create_exdir($dir);
$stats = new FactureStats($db, $socid, $mode);
-// Build graphic number of invoices
+// Build graphic number of object
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
-$filenamenbinvoices = $dir."/invoicesnbinyear-".$year.".png";
-if ($mode == 'customer') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png';
-if ($mode == 'supplier') $fileurlnbinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png';
+$filenamenb = $dir."/invoicesnbinyear-".$year.".png";
+if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png';
+if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -101,17 +101,17 @@ if (! $mesg)
$px->mode='depth';
$px->SetTitle($langs->trans("NumberOfBillsByMonth"));
- $px->draw($filenamenbinvoices);
+ $px->draw($filenamenb);
}
-// Build graphic amount of invoices
+// Build graphic amount of object
$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
-$filenameamountinvoices = $dir."/invoicesamountinyear-".$year.".png";
-if ($mode == 'customer') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png';
-if ($mode == 'supplier') $fileurlamountinvoices = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png';
+$filenameamount = $dir."/invoicesamountinyear-".$year.".png";
+if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png';
+if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -137,7 +137,7 @@ if (! $mesg)
$px->mode='depth';
$px->SetTitle($langs->trans("AmountOfBillsByMonthHT"));
- $px->draw($filenameamountinvoices);
+ $px->draw($filenameamount);
}
@@ -192,9 +192,9 @@ print '';
print '';
if ($mesg) { print $mesg; }
else {
- print ' ';
+ print ' ';
print " \n";
- print ' ';
+ print ' ';
}
print ' | ';
diff --git a/htdocs/compta/facture/stats/month.php b/htdocs/compta/facture/stats/month.php
index 07256ab7969..dae0963bde0 100644
--- a/htdocs/compta/facture/stats/month.php
+++ b/htdocs/compta/facture/stats/month.php
@@ -73,9 +73,9 @@ $stats = new FactureStats($db, $socid, $mode);
$data = $stats->getNbByMonth($year);
-$filename = $dir."/invoices-".$year.".png";
-if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoices-'.$year.'.png';
-if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoices-'.$year.'.png';
+$filename = $dir."/invoicesnb-".$year.".png";
+if ($mode == 'customer') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnb-'.$year.'.png';
+if ($mode == 'supplier') $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnb-'.$year.'.png';
$px = new DolGraph();
$mesg = $px->isGraphKo();
@@ -84,7 +84,6 @@ if (! $mesg)
$px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
- $px->SetPrecisionY(0);
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
@@ -109,7 +108,6 @@ if (! $mesg)
$px->SetYLabel($langs->trans("AmountTotal"));
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
- $px->SetPrecisionY(0);
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
@@ -144,7 +142,7 @@ if (! $mesg)
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
- $px->SetShading(5);
+ $px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->draw($filename_avg);
diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php
index 0ba06e78b96..7f19b740210 100644
--- a/htdocs/propal.class.php
+++ b/htdocs/propal.class.php
@@ -37,10 +37,9 @@ require_once(DOL_DOCUMENT_ROOT ."/contact.class.php");
/**
- \class Propal
- \brief Classe permettant la gestion des propales
+ * \class Propal
+ * \brief Classe permettant la gestion des propales
*/
-
class Propal extends CommonObject
{
var $db;
@@ -95,9 +94,9 @@ class Propal extends CommonObject
/**
* \brief Constructeur
- * \param DB Handler d'acc�s base
- * \param socid Id de la soci�t�
- * \param propalid Id de la propal
+ * \param DB Database handler
+ * \param socid Id third party
+ * \param propalid Id proposal
*/
function Propal($DB, $socid="", $propalid=0)
{
diff --git a/htdocs/stats.class.php b/htdocs/stats.class.php
index 2baa45cd6e3..529d9ae51f8 100644
--- a/htdocs/stats.class.php
+++ b/htdocs/stats.class.php
@@ -111,6 +111,7 @@ class Stats
{
$result = array();
+ dolibarr_syslog("Stats::_getNbByYear sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -139,6 +140,7 @@ class Stats
{
$result = array();
+ dolibarr_syslog("Stats::_getAllByYear sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
@@ -169,8 +171,8 @@ class Stats
{
$result = array();
- $resql=$this->db->query($sql);
dolibarr_syslog("Stats::_getNbByMonth sql=".$sql);
+ $resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
@@ -248,7 +250,7 @@ class Stats
{
$result = array();
- dolibarr_syslog("Stats::_getAmountByMonth sql=".$sql);
+ dolibarr_syslog("Stats::_getAverageByMonth sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
|