Qual: Uniformize code.

This commit is contained in:
Laurent Destailleur 2008-09-08 13:32:37 +00:00
parent 758a78ef85
commit e461753e43
7 changed files with 331 additions and 229 deletions

View File

@ -80,14 +80,10 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, count(*)"; $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"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 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"; $sql .= " WHERE date_format(p.datep,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if($user->societe_id)
{
$sql .= " AND p.fk_soc = ".$user->societe_id;
}
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
return $this->_getNbByMonth($year, $sql); return $this->_getNbByMonth($year, $sql);
@ -103,14 +99,9 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%Y') as dm, count(*)"; $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"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE p.fk_statut > 0"; $sql.= " WHERE ".$this->where;
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"; $sql.= " GROUP BY dm DESC";
return $this->_getNbByYear($sql); return $this->_getNbByYear($sql);
@ -125,14 +116,10 @@ class PropaleStats extends Stats
$sql = "SELECT date_format(p.datep,'%m') as dm, sum(p.total_ht)"; $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"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 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"; $sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if($user->societe_id)
{
$sql .= " AND p.fk_soc = ".$user->societe_id;
}
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";
return $this->_getAmountByMonth($year, $sql); return $this->_getAmountByMonth($year, $sql);
@ -146,15 +133,11 @@ class PropaleStats extends Stats
global $user; global $user;
$sql = "SELECT date_format(p.datep,'%m') as dm, avg(p.total_ht)"; $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"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(p.datep,'%Y') = $year AND p.fk_statut > 0"; $sql.= " WHERE date_format(p.datep,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if($user->societe_id)
{
$sql .= " AND p.fk_soc = ".$user->societe_id;
}
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";
return $this->_getAverageByMonth($year, $sql); return $this->_getAverageByMonth($year, $sql);
@ -170,9 +153,9 @@ class PropaleStats extends Stats
global $user; global $user;
$sql = "SELECT date_format(p.datep,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg"; $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"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE ".$this->where; $sql.= " WHERE ".$this->where;
$sql.= " GROUP BY year DESC"; $sql.= " GROUP BY year DESC";

View File

@ -15,34 +15,58 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/commande/stats/commandestats.class.php * \file htdocs/commande/stats/commandestats.class.php
\ingroup commandes * \ingroup commandes
\brief Fichier de la classe de gestion des stats des commandes * \brief Fichier de la classe de gestion des stats des commandes
\version $Revision$ * \version $Id$
*/ */
include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
include_once DOL_DOCUMENT_ROOT . "/commande/commande.class.php";
/** /**
\class CommandeStats * \class CommandeStats
\brief Classe permettant la gestion des stats des commandes * \brief Classe permettant la gestion des stats des commandes
*/ */
class CommandeStats extends Stats class CommandeStats extends Stats
{ {
var $db ; var $db ;
function CommandeStats($DB, $socid) var $socid;
var $where;
var $table_element;
var $field;
/**
* Constructor
*
* @param $DB Database handler
* @param $socid Id third party
* @return PropaleStats
*/
function CommandeStats($DB, $socid=0)
{ {
global $user;
$this->db = $DB; $this->db = $DB;
$object=new Commande($this->db);
$this->table_element=$object->table_element;
$this->field='total_ht';
$this->socid = $socid; $this->socid = $socid;
$this->where.= " c.fk_statut > 0";
if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if($this->socid)
{
$this->where .= " AND c.fk_soc = ".$this->socid;
}
} }
/** /**
@ -55,16 +79,11 @@ class CommandeStats extends Stats
global $user; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb"; $sql = "SELECT date_format(c.date_commande,'%m') as dm, count(*) nb";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0"; $sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if ($this->socid) $sql.= " GROUP BY dm DESC";
{
$sql .= " AND c.fk_soc = ".$this->socid;
}
$sql .= " GROUP BY dm";
$sql .= " ORDER BY dm DESC";
return $this->_getNbByMonth($year, $sql); return $this->_getNbByMonth($year, $sql);
} }
@ -78,15 +97,10 @@ class CommandeStats extends Stats
global $conf; global $conf;
global $user; global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.total_ht)"; $sql = "SELECT date_format(c.date_commande,'%Y') as dm, count(*), sum(c.".$this->field.")";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE c.fk_statut > 0"; $sql.= " WHERE ".$this->where;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($this->socid)
{
$sql .= " AND c.fk_soc = ".$this->socid;
}
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";
return $this->_getNbByYear($sql); return $this->_getNbByYear($sql);
@ -101,15 +115,11 @@ class CommandeStats extends Stats
global $conf; global $conf;
global $user; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.total_ht)"; $sql = "SELECT date_format(c.date_commande,'%m') as dm, sum(c.".$this->field.")";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0"; $sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if ($this->socid)
{
$sql .= " AND c.fk_soc = ".$this->socid;
}
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";
return $this->_getAmountByMonth($year, $sql); return $this->_getAmountByMonth($year, $sql);
@ -124,19 +134,34 @@ class CommandeStats extends Stats
global $conf; global $conf;
global $user; global $user;
$sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.total_ht)"; $sql = "SELECT date_format(c.date_commande,'%m') as dm, avg(c.".$this->field.")";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE date_format(c.date_commande,'%Y') = $year AND c.fk_statut > 0"; $sql.= " WHERE date_format(c.date_commande,'%Y') = ".$year;
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND ".$this->where;
if ($this->socid)
{
$sql .= " AND c.fk_soc = ".$this->socid;
}
$sql.= " GROUP BY dm DESC"; $sql.= " GROUP BY dm DESC";
return $this->_getAverageByMonth($year, $sql); return $this->_getAverageByMonth($year, $sql);
} }
/**
* \brief Return nb, total and average
* \return array Array of values
*/
function getAllByYear()
{
global $user;
$sql = "SELECT date_format(c.date_commande,'%Y') as year, count(*) as nb, sum(".$this->field.") as total, avg(".$this->field.") as avg";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", sc.fk_soc, sc.fk_user";
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c";
if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE ".$this->where;
$sql.= " GROUP BY year DESC";
return $this->_getAllByYear($sql);
}
} }
?> ?>

View File

@ -41,36 +41,39 @@ if ($user->societe_id > 0)
$socid = $user->societe_id; $socid = $user->societe_id;
} }
$year = strftime("%Y", time());
$startyear=$year-2;
$endyear=$year;
/*
* View
*/
llxHeader(); llxHeader();
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
$stats = new CommandeStats($db, $socid);
$year = strftime("%Y", time());
$startyear=$year-2;
$endyear=$year;
$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
// Création répertoire pour images générées
$dir=$conf->commande->dir_temp; $dir=$conf->commande->dir_temp;
if (! file_exists($dir))
{ create_exdir($dir);
if (create_exdir($dir) < 0)
{ $stats = new CommandeStats($db, $socid);
$mesg = $langs->trans("ErrorCanNotCreateDir",$dir);
} // Build graphic number of object
} $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
if (!$user->rights->societe->client->voir || $user->societe_id) if (!$user->rights->societe->client->voir || $user->societe_id)
{ {
$filename = $conf->commande->dir_temp.'/nbcommande2year-'.$user->id.'-'.$year.'.png'; $filenamenb = $dir.'/ordersnbinyear-'.$user->id.'-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=nbcommande2year-'.$user->id.'-'.$year.'.png'; $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$user->id.'-'.$year.'.png';
} }
else else
{ {
$filename = $conf->commande->dir_temp.'/nbcommande2year-'.$year.'.png'; $filenamenb = $dir.'/ordersnbinyear-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=nbcommande2year-'.$year.'.png'; $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png';
} }
$px = new DolGraph(); $px = new DolGraph();
@ -87,6 +90,7 @@ if (! $mesg)
} }
$px->SetLegend($legend); $px->SetLegend($legend);
$px->SetMaxValue($px->GetCeilMaxValue()); $px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue(min(0,$px->GetFloorMinValue()));
$px->SetWidth($WIDTH); $px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT); $px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("NbOfOrder")); $px->SetYLabel($langs->trans("NbOfOrder"));
@ -94,31 +98,109 @@ if (! $mesg)
$px->SetHorizTickIncrement(1); $px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0); $px->SetPrecisionY(0);
$px->mode='depth'; $px->mode='depth';
$px->draw($filename); $px->SetTitle($langs->trans("NumberOfOrdersByMonth"));
$px->draw($filenamenb);
} }
$rows = $stats->getNbByYear();
$num = sizeof($rows); // Build graphic amount of object
$data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear);
//var_dump($data);
// $data = array(array('Lib',val1,val2,val3),...)
if (!$user->rights->societe->client->voir || $user->societe_id)
{
$filenameamount = $dir.'/ordersamountinyear-'.$user->id.'-'.$year.'.png';
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$user->id.'-'.$year.'.png';
}
else
{
$filenameamount = $dir.'/ordersamountinyear-'.$year.'.png';
$fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$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("AmountOfOrders"));
$px->SetShading(3);
$px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0);
$px->mode='depth';
$px->SetTitle($langs->trans("AmountOfOrdersByMonthHT"));
$px->draw($filenameamount);
}
print '<table class="notopnoleftnopadd" width="100%"><tr>';
print '<td align="center" valign="top">';
// Show array
$data = $stats->getAllByYear();
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td align="center">'.$langs->trans("Year").'</td><td width="10%" align="center">'.$langs->trans("NbOfOrders").'</td><td align="center">'.$langs->trans("AmountTotal").'</td>'; print '<tr height="24">';
print '<td align="center" valign="top" rowspan="'.($num + 1).'">'; print '<td align="center">'.$langs->trans("Year").'</td>';
if ($px->isGraphKo()) { print '<font class="error">'.$px->isGraphKo().'</div>'; } print '<td align="center">'.$langs->trans("NbOfOrders").'</td>';
else { print '<img src="'.$fileurl.'" alt="Nombre de commande par mois">'; } print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
print '</td></tr>'; print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
$i = 0; print '</tr>';
while (list($key, $value) = each ($rows))
$oldyear=0;
foreach ($data as $val)
{ {
$year = $value[0]; $year = $val['year'];
$nbproduct = $value[1]; print $avg;
$price = $value[2]; while ($oldyear > $year+1)
print "<tr>"; { // If we have empty year
print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td><td align="center">'.$nbproduct.'</td><td align="center">'.price($price).'</td></tr>'; $oldyear--;
$i++; print '<tr height="24">';
print '<td align="center"><a href="month.php?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
print '<td align="right">0</td>';
print '<td align="right">0</td>';
print '<td align="right">0</td>';
print '</tr>';
}
print '<tr height="24">';
print '<td align="center"><a href="month.php?year='.$year.'">'.$year.'</a></td>';
print '<td align="right">'.$val['nb'].'</td>';
print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';
print '</tr>';
$oldyear=$year;
} }
print '</table>'; print '</table>';
print '</td>';
print '<td align="center" valign="top">';
// Show graphs
print '<table class="border" width="100%"><tr valign="top"><td align="center">';
if ($mesg) { print $mesg; }
else {
print '<img src="'.$fileurlnb.'" title="'.$langs->trans("NbOfOrders").'" alt="'.$langs->trans("NbOfProposals").'">';
print "<br>\n";
print '<img src="'.$fileurlamount.'" title="'.$langs->trans("AmountTotal").'" alt="'.$langs->trans("AmountTotal").'">';
}
print '</td></tr></table>';
print '</td></tr></table>';
$db->close(); $db->close();
llxFooter('$Date$ - $Revision$'); llxFooter('$Date$ - $Revision$');

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (c) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -18,57 +18,71 @@
*/ */
/** /**
\file htdocs/commande/stats/month.php * \file htdocs/commande/stats/month.php
\ingroup commande * \ingroup commande
\brief Page des stats commandes par mois * \brief Page des stats commandes par mois
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php"); require_once(DOL_DOCUMENT_ROOT."/commande/stats/commandestats.class.php");
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
// Sécurité accés client $GRAPHWIDTH=500;
$GRAPHHEIGHT=200;
// Check security access
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socid = $user->societe_id; $socid = $user->societe_id;
} }
llxHeader();
$year = isset($_GET["year"])?$_GET["year"]:date("Y",time()); $year = isset($_GET["year"])?$_GET["year"]:date("Y",time());
$mesg = '<a href="month.php?year='.($year - 1).'">'.img_previous().'</a> '; $mode='customer';
$mesg.= $langs->trans("Year")." $year"; if (isset($_GET["mode"])) $mode=$_GET["mode"];
$mesg.= ' <a href="month.php?year='.($year + 1).'">'.img_next().'</a>';
$WIDTH=500;
$HEIGHT=200;
/* /*
* * View
*
*/ */
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); llxHeader();
if ($mode == 'customer')
{
$title=$langs->trans("OrdersStatistics");
$dir=$conf->commande->dir_temp;
}
if ($mode == 'supplier')
{
$title=$langs->trans("OrdersStatisticsSuppliers");
$dir=$conf->fournisseur->commande->dir_temp;
}
$mesg = '<a href="month.php?year='.($year - 1).'&amp;mode='.$mode.'">'.img_previous().'</a> ';
$mesg.= $langs->trans("Year")." $year";
$mesg.= ' <a href="month.php?year='.($year + 1).'&amp;mode='.$mode.'">'.img_next().'</a>';
print_fiche_titre($title, $mesg);
create_exdir($dir);
$stats = new CommandeStats($db, $socid, $mode);
$stats = new CommandeStats($db, $socid);
$data = $stats->getNbByMonth($year); $data = $stats->getNbByMonth($year);
create_exdir($conf->commande->dir_temp);
if (!$user->rights->societe->client->voir || $user->societe_id) if (!$user->rights->societe->client->voir || $user->societe_id)
{ {
$filename = $conf->commande->dir_temp.'/commande-'.$user->id.'-'.$year.'.png'; $filename = $dir.'/ordersnb-'.$user->id.'-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commande-'.$user->id.'-'.$year.'.png'; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$user->id.'-'.$year.'.png';
} }
else else
{ {
$filename = $conf->commande->dir_temp.'/commande'.$year.'.png'; $filename = $dir.'/ordersnb-'.$year.'.png';
$fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commande'.$year.'.png'; $fileurl = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnb-'.$year.'.png';
} }
$px = new DolGraph(); $px = new DolGraph();
@ -77,8 +91,9 @@ if (! $mesg)
{ {
$px->SetData($data); $px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue()); $px->SetMaxValue($px->GetCeilMaxValue());
$px->SetWidth($WIDTH); $px->SetMinValue($px->GetFloorMinValue());
$px->SetHeight($HEIGHT); $px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetYLabel($langs->trans("NbOfOrders")); $px->SetYLabel($langs->trans("NbOfOrders"));
$px->SetShading(3); $px->SetShading(3);
$px->SetHorizTickIncrement(1); $px->SetHorizTickIncrement(1);
@ -86,24 +101,18 @@ if (! $mesg)
$px->draw($filename); $px->draw($filename);
} }
$res = $stats->getAmountByMonth($year);
$data = array(); $data = $stats->getAmountByMonth($year);
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]);
}
if (!$user->rights->societe->client->voir || $user->societe_id) if (!$user->rights->societe->client->voir || $user->societe_id)
{ {
$filename_amount = $conf->commande->dir_temp.'/commandeamount-'.$user->id.'-'.$year.'.png'; $filename_amount = $dir.'/ordersamount-'.$user->id.'-'.$year.'.png';
$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeamount-'.$user->id.'-'.$year.'.png'; $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$user->id.'-'.$year.'.png';
} }
else else
{ {
$filename_amount = $conf->commande->dir_temp.'/commandeamount'.$year.'.png'; $filename_amount = $dir.'/ordersamount-'.$year.'.png';
$fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeamount'.$year.'.png'; $fileurl_amount = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamount-'.$year.'.png';
} }
$px = new DolGraph(); $px = new DolGraph();
@ -111,11 +120,12 @@ $mesg = $px->isGraphKo();
if (! $mesg) if (! $mesg)
{ {
$px->SetData($data); $px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("AmountTotal")); $px->SetYLabel($langs->trans("AmountTotal"));
$px->SetShading(5); $px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1); $px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0); $px->SetPrecisionY(0);
$px->draw($filename_amount); $px->draw($filename_amount);
@ -131,13 +141,13 @@ for ($i = 1 ; $i < 13 ; $i++)
if (!$user->rights->societe->client->voir || $user->societe_id) if (!$user->rights->societe->client->voir || $user->societe_id)
{ {
$filename_avg = $conf->commande->dir_temp.'/commandeaverage-'.$user->id.'-'.$year.'.png'; $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png';
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeaverage-'.$user->id.'-'.$year.'.png'; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$user->id.'-'.$year.'.png';
} }
else else
{ {
$filename_avg = $conf->commande->dir_temp.'/commandeaverage'.$year.'.png'; $filename_avg = $dir.'/ordersaverage-'.$year.'.png';
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=commandeaverage'.$year.'.png'; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersaverage-'.$year.'.png';
} }
$px = new DolGraph(); $px = new DolGraph();
@ -145,11 +155,12 @@ $mesg = $px->isGraphKo();
if (! $mesg) if (! $mesg)
{ {
$px->SetData($data); $px->SetData($data);
$px->SetMaxValue($px->GetCeilMaxValue());
$px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetYLabel($langs->trans("AmountAverage")); $px->SetYLabel($langs->trans("AmountAverage"));
$px->SetShading(5); $px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue());
$px->SetWidth($GRAPHWIDTH);
$px->SetHeight($GRAPHHEIGHT);
$px->SetShading(3);
$px->SetHorizTickIncrement(1); $px->SetHorizTickIncrement(1);
$px->SetPrecisionY(0); $px->SetPrecisionY(0);
$px->draw($filename_avg); $px->draw($filename_avg);

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (c) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -136,7 +136,6 @@ $mesg = $px->isGraphKo();
if (! $mesg) if (! $mesg)
{ {
$px->SetData($data); $px->SetData($data);
$px->SetPrecisionY(0);
$px->SetYLabel($langs->trans("AmountAverage")); $px->SetYLabel($langs->trans("AmountAverage"));
$px->SetMaxValue($px->GetCeilMaxValue()); $px->SetMaxValue($px->GetCeilMaxValue());
$px->SetMinValue($px->GetFloorMinValue()); $px->SetMinValue($px->GetFloorMinValue());

View File

@ -69,6 +69,7 @@ AllOrders=All orders
NbOfOrders=Number of orders NbOfOrders=Number of orders
OrdersStatistics=Orders' statistics OrdersStatistics=Orders' statistics
NumberOfOrdersByMonth=Number of orders by month NumberOfOrdersByMonth=Number of orders by month
AmountOfOrdersByMonthHT=amount of orders by month (net of tax)
ListOfOrders=List of orders ListOfOrders=List of orders
CloseOrder=Close order CloseOrder=Close order
ConfirmCloseOrder=Are you sure you want to close this order ? Once an order is closed, it can only be billed. ConfirmCloseOrder=Are you sure you want to close this order ? Once an order is closed, it can only be billed.

View File

@ -69,6 +69,7 @@ AllOrders=Toutes les commandes
NbOfOrders=Nombre de commandes NbOfOrders=Nombre de commandes
OrdersStatistics=Statistiques des commandes OrdersStatistics=Statistiques des commandes
NumberOfOrdersByMonth=Nombre de commandes par mois NumberOfOrdersByMonth=Nombre de commandes par mois
AmountOfOrdersByMonthHT=Montant total de commandes par mois (HT)
ListOfOrders=Liste des commandes ListOfOrders=Liste des commandes
CloseOrder=Cloturer commande CloseOrder=Cloturer commande
ConfirmCloseOrder=Êtes-vous sur de vouloir cloturer cette commande ? Une fois une commande cloturée, elle doit être facturée. ConfirmCloseOrder=Êtes-vous sur de vouloir cloturer cette commande ? Une fois une commande cloturée, elle doit être facturée.