Qual: Uniformisation du code des pages de stats graphiques.

This commit is contained in:
Laurent Destailleur 2005-07-16 14:56:25 +00:00
parent b63e0e84c1
commit 0812a19c5c
10 changed files with 85 additions and 137 deletions

View File

@ -31,6 +31,10 @@
require("./pre.inc.php"); require("./pre.inc.php");
require("./propalestats.class.php"); require("./propalestats.class.php");
$WIDTH=500;
$HEIGHT=250;
llxHeader(); llxHeader();
print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg); print_fiche_titre($langs->trans("ProposalsStatistics"), $mesg);
@ -50,8 +54,8 @@ if (! $mesg) {
$px->SetData($data); $px->SetData($data);
$px->SetLegend(array($year - 1, $year)); $px->SetLegend(array($year - 1, $year));
$px->SetMaxValue($px->GetMaxValue()); $px->SetMaxValue($px->GetMaxValue());
$px->SetWidth(450); $px->SetWidth($WIDTH);
$px->SetHeight(280); $px->SetHeight($HEIGHT);
$px->draw($filename); $px->draw($filename);
} }
@ -82,11 +86,11 @@ if ($db->query($sql))
} }
else else
{ {
print "Erreur : $sql"; dolibarr_print_error($db);
} }
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -73,7 +73,7 @@ $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_amount = $conf->propal->dir_images."/propaleamount".$year.".png"; $filename_amount = $conf->propal->dir_images."/propaleamount".$year.".png";
@ -95,7 +95,7 @@ $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_avg = $conf->propal->dir_images."/propaleaverage".$year.".png"; $filename_avg = $conf->propal->dir_images."/propaleaverage".$year.".png";
$fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png'; $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=propalstats&file=propaleaverage'.$year.'.png';
@ -130,5 +130,5 @@ print '</td></tr></table>';
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2005 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
@ -20,8 +21,21 @@
* *
*/ */
/**
\file htdocs/propal/stats/propalestats.class.php
\ingroup propales
\brief Fichier de la classe de gestion des stats des propales
\version $Revision$
*/
include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
/**
\class PropaleStats
\brief Classe permettant la gestion des stats des propales
*/
class PropaleStats extends Stats class PropaleStats extends Stats
{ {
var $db ; var $db ;

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2005 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
@ -17,21 +18,24 @@
* *
* $Id$ * $Id$
* $Source$ * $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 $Revision$
*/ */
include_once DOL_DOCUMENT_ROOT . "/stats.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 class CommandeStats extends Stats
{ {
var $db ; var $db ;
@ -41,29 +45,12 @@ class CommandeStats
$this->socidp = $socidp; $this->socidp = $socidp;
} }
function getNbCommandeByMonthWithPrevYear($year)
{
$data1 = $this->getNbCommandeByMonth($year - 1);
$data2 = $this->getNbCommandeByMonth($year);
$data = array();
for ($i = 0 ; $i < 12 ; $i++)
{
$data[$i] = array($data1[$i][0],
$data1[$i][1],
$data2[$i][1]);
}
return $data;
}
/** /**
* \brief Renvoie le nombre de commande par mois pour une année donnée * \brief Renvoie le nombre de commande par mois pour une année donnée
* *
*/ */
function getNbCommandeByMonth($year) function getNbByMonth($year)
{ {
$tabresult = array();
$sql = "SELECT date_format(date_commande,'%m') as dm, count(*) nb FROM ".MAIN_DB_PREFIX."commande"; $sql = "SELECT date_format(date_commande,'%m') as dm, count(*) nb FROM ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0";
if ($this->socidp) if ($this->socidp)
@ -72,29 +59,8 @@ class CommandeStats
} }
$sql .= " GROUP BY dm"; $sql .= " GROUP BY dm";
$sql .= " ORDER BY dm DESC"; $sql .= " ORDER BY dm DESC";
$result=$this->db->query($sql);
if ($result) return $this->_getNbByMonth($year, $sql);
{
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_object($result);
$j = $row->dm;
$tabresult[$j+0] = $row->nb;
$i++;
}
$this->db->free($result);
}
$data = array();
for ($i = 1 ; $i < 13 ; $i++)
{
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $tabresult[$i] );
}
return $data;
} }
/** /**
@ -103,35 +69,22 @@ class CommandeStats
*/ */
function getNbByYear() function getNbByYear()
{ {
$result = array();
$sql = "SELECT date_format(date_commande,'%Y') as dm, count(*), sum(total_ht) FROM ".MAIN_DB_PREFIX."commande WHERE fk_statut > 0"; $sql = "SELECT date_format(date_commande,'%Y') as dm, count(*), sum(total_ht) FROM ".MAIN_DB_PREFIX."commande WHERE fk_statut > 0";
if ($this->socidp) if ($this->socidp)
{ {
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
if ($this->db->query($sql))
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$result[$row[0]] = array($row[1], $row[2]);
$i++; return $this->_getNbByYear($sql);
}
$this->db->free();
}
return $result;
} }
/** /**
* Renvoie le nombre de commande par mois pour une année donnée * Renvoie le nombre de commande par mois pour une année donnée
* *
*/ */
function getCommandeAmountByMonth($year) function getAmountByMonth($year)
{ {
$result = array();
$sql = "SELECT date_format(date_commande,'%m') as dm, sum(total_ht) FROM ".MAIN_DB_PREFIX."commande"; $sql = "SELECT date_format(date_commande,'%m') as dm, sum(total_ht) FROM ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0";
if ($this->socidp) if ($this->socidp)
@ -140,34 +93,15 @@ class CommandeStats
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
if ($this->db->query($sql)) return $this->_getAmountByMonth($year, $sql);
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$j = $row[0] * 1;
$result[$j] = $row[1];
$i++;
}
$this->db->free();
}
for ($i = 1 ; $i < 13 ; $i++)
{
$res[$i] = $result[$i] + 0;
}
return $res;
} }
/** /**
* Renvoie le nombre de commande par mois pour une année donnée * Renvoie le nombre de commande par mois pour une année donnée
* *
*/ */
function getCommandeAverageByMonth($year) function getAverageByMonth($year)
{ {
$result = array();
$sql = "SELECT date_format(date_commande,'%m') as dm, avg(total_ht) FROM ".MAIN_DB_PREFIX."commande"; $sql = "SELECT date_format(date_commande,'%m') as dm, avg(total_ht) FROM ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0"; $sql .= " WHERE date_format(date_commande,'%Y') = $year AND fk_statut > 0";
if ($this->socidp) if ($this->socidp)
@ -176,26 +110,7 @@ class CommandeStats
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
if ($this->db->query($sql)) return $this->_getAverageByMonth($year, $sql);
{
$num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($i);
$j = $row[0] * 1;
$result[$j] = $row[1];
$i++;
}
$this->db->free();
}
for ($i = 1 ; $i < 13 ; $i++)
{
$res[$i] = $result[$i] + 0;
}
return $res;
} }
} }

View File

@ -28,31 +28,29 @@
\version $Revision$ \version $Revision$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require("../commande.class.php"); require("../commande.class.php");
require("./commandestats.class.php"); require("./commandestats.class.php");
/*
* Sécurité accés client $WIDTH=500;
*/ $HEIGHT=250;
// Sécurité accés client
if ($user->societe_id > 0) if ($user->societe_id > 0)
{ {
$action = ''; $action = '';
$socidp = $user->societe_id; $socidp = $user->societe_id;
} }
llxHeader(); llxHeader();
/*
*
*
*/
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
$stats = new CommandeStats($db, $socidp); $stats = new CommandeStats($db, $socidp);
$year = strftime("%Y", time()); $year = strftime("%Y", time());
$data = $stats->getNbCommandeByMonthWithPrevYear($year); $data = $stats->getNbByMonthWithPrevYear($year);
if (! is_dir($conf->commande->dir_images)) if (! is_dir($conf->commande->dir_images))
{ {
@ -68,8 +66,9 @@ $mesg = $px->isGraphKo();
if (! $mesg) { if (! $mesg) {
$px->SetData($data); $px->SetData($data);
$px->SetMaxValue($px->GetMaxValue()); $px->SetMaxValue($px->GetMaxValue());
$px->SetWidth(450); $px->SetLegend(array($year - 1, $year));
$px->SetHeight(280); $px->SetWidth($WIDTH);
$px->SetHeight($HEIGHT);
$px->SetYLabel("Nombre de commande"); $px->SetYLabel("Nombre de commande");
$px->draw($filename); $px->draw($filename);
} }
@ -85,9 +84,9 @@ print '</td></tr>';
$i = 0; $i = 0;
while (list($key, $value) = each ($rows)) while (list($key, $value) = each ($rows))
{ {
$nbproduct = $value[0]; $year = $value[0];
$price = $value[1]; $nbproduct = $value[1];
$year = $key; $price = $value[2];
print "<tr>"; print "<tr>";
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>'; 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>';
$i++; $i++;

View File

@ -60,7 +60,7 @@ $HEIGHT=250;
print_fiche_titre($langs->trans("OrdersStatistics"), $mesg); print_fiche_titre($langs->trans("OrdersStatistics"), $mesg);
$stats = new CommandeStats($db, $socidp); $stats = new CommandeStats($db, $socidp);
$data = $stats->getNbCommandeByMonth($year); $data = $stats->getNbByMonth($year);
if (! is_dir($conf->commande->dir_images)) { mkdir($conf->commande->dir_images); } if (! is_dir($conf->commande->dir_images)) { mkdir($conf->commande->dir_images); }
@ -78,13 +78,13 @@ if (! $mesg) {
$px->draw($filename); $px->draw($filename);
} }
$res = $stats->getCommandeAmountByMonth($year); $res = $stats->getAmountByMonth($year);
$data = array(); $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_amount = $conf->commande->dir_images."/commandeamount".$year.".png"; $filename_amount = $conf->commande->dir_images."/commandeamount".$year.".png";
@ -100,13 +100,13 @@ if (! $mesg) {
$px->SetYLabel($langs->trans("AmountTotal")); $px->SetYLabel($langs->trans("AmountTotal"));
$px->draw($filename_amount); $px->draw($filename_amount);
} }
$res = $stats->getCommandeAverageByMonth($year); $res = $stats->getAverageByMonth($year);
$data = array(); $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_avg = $conf->commande->dir_images."/commandeaverage".$year.".png"; $filename_avg = $conf->commande->dir_images."/commandeaverage".$year.".png";
@ -142,5 +142,5 @@ print '</td></tr></table>';
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2005 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
@ -20,8 +21,21 @@
* *
*/ */
/**
\file htdocs/facture/stats/facturestats.class.php
\ingroup factures
\brief Fichier de la classe de gestion des stats des factures
\version $Revision$
*/
include_once DOL_DOCUMENT_ROOT . "/stats.class.php"; include_once DOL_DOCUMENT_ROOT . "/stats.class.php";
/**
\class FactureStats
\brief Classe permettant la gestion des stats des factures
*/
class FactureStats extends Stats class FactureStats extends Stats
{ {
var $db ; var $db ;
@ -61,6 +75,7 @@ class FactureStats extends Stats
return $this->_getNbByYear($sql); return $this->_getNbByYear($sql);
} }
/** /**
* Renvoie le nombre de facture par mois pour une année donnée * Renvoie le nombre de facture par mois pour une année donnée
* *
@ -90,8 +105,8 @@ class FactureStats extends Stats
$sql .= " AND fk_soc = ".$this->socidp; $sql .= " AND fk_soc = ".$this->socidp;
} }
$sql .= " GROUP BY dm DESC"; $sql .= " GROUP BY dm DESC";
return $this->_getAverageByMonth($year, $sql);
return $this->_getAverageByMonth($year, $sql);
} }
} }

View File

@ -105,5 +105,5 @@ else
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -76,7 +76,7 @@ $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_amount = $conf->facture->dir_images."/factureamount".$year.".png"; $filename_amount = $conf->facture->dir_images."/factureamount".$year.".png";
@ -98,7 +98,7 @@ $data = array();
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$data[$i-1] = array(strftime("%b",mktime(12,12,12,$i,1,$year)), $res[$i]); $data[$i-1] = array(ucfirst(substr(strftime("%b",mktime(12,12,12,$i,1,$year)),0,3)), $res[$i]);
} }
$filename_avg = $conf->facture->dir_images."/factureaverage".$year.".png"; $filename_avg = $conf->facture->dir_images."/factureaverage".$year.".png";
@ -107,6 +107,7 @@ $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=factureave
$px = new BarGraph(); $px = new BarGraph();
$mesg = $px->isGraphKo(); $mesg = $px->isGraphKo();
if (! $mesg) { if (! $mesg) {
$px->SetData($data);
$px->SetYLabel($langs->trans("AmountAverage")); $px->SetYLabel($langs->trans("AmountAverage"));
$px->SetMaxValue($px->GetAmountMaxValue()); $px->SetMaxValue($px->GetAmountMaxValue());
$px->SetWidth($GRAPHWIDTH); $px->SetWidth($GRAPHWIDTH);
@ -133,5 +134,5 @@ print '</td></tr></table>';
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -135,14 +135,14 @@ class Graph
// Défini position du graphe (et legende) au sein de l'image // Défini position du graphe (et legende) au sein de l'image
if (isset($this->Legend)) if (isset($this->Legend))
{ {
$this->graph->SetMarginsPixels(60,100,10,30); $this->graph->SetMarginsPixels(100,100,10,30);
$this->graph->SetLegend($this->Legend); $this->graph->SetLegend($this->Legend);
$this->graph->SetLegendWorld(13,$this->MaxValue); $this->graph->SetLegendWorld(13,$this->MaxValue);
} }
else else
{ {
$this->graph->SetMarginsPixels(60,10,10,30); $this->graph->SetMarginsPixels(100,10,10,30);
} }
if (substr($this->MaxValue,0,1) == 1) if (substr($this->MaxValue,0,1) == 1)