diff --git a/htdocs/product/stats/commandestats.class.php b/htdocs/product/stats/commandestats.class.php new file mode 100644 index 00000000000..543b6f60cd9 --- /dev/null +++ b/htdocs/product/stats/commandestats.class.php @@ -0,0 +1,152 @@ + + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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$ + * + */ + +class CommandeStats +{ + var $db ; + + Function CommandeStats($DB) + { + $this->db = $DB; + } + /** + * Renvoie le nombre de commande par année + * + */ + Function getNbCommandeByYear() + { + $result = array(); + $sql = "SELECT date_format(date_commande,'%Y') as dm, count(*) FROM llx_commande 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[$i] = $row; + + $i++; + } + $this->db->free(); + } + return $result; + } + /** + * Renvoie le nombre de commande par mois pour une année donnée + * + */ + Function getNbCommandeByMonth($year) + { + $result = array(); + $sql = "SELECT date_format(date_commande,'%m') as dm, count(*) FROM llx_commande"; + $sql .= " WHERE date_format(date_commande,'%Y') = $year"; + $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); + $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 + * + */ + Function getCommandeAmountByMonth($year) + { + $result = array(); + $sql = "SELECT date_format(date_commande,'%m') as dm, sum(total_ht) FROM llx_commande"; + $sql .= " WHERE date_format(date_commande,'%Y') = $year"; + $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); + $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 + * + */ + Function getCommandeAverageByMonth($year) + { + $result = array(); + $sql = "SELECT date_format(date_commande,'%m') as dm, avg(total_ht) FROM llx_commande"; + $sql .= " WHERE date_format(date_commande,'%Y') = $year"; + $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); + $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; + } +} + +?> diff --git a/htdocs/product/stats/index.php b/htdocs/product/stats/index.php index 5507dd3c804..ae1c3af3a8e 100644 --- a/htdocs/product/stats/index.php +++ b/htdocs/product/stats/index.php @@ -19,65 +19,37 @@ * $Source$ * */ - require("./pre.inc.php"); -require("../../propal.class.php"); +require("../commande.class.php"); require("../../graph.class.php"); llxHeader(); - -$mesg = ''; - /* * * */ -$sql = "SELECT count(*) FROM llx_product WHERE fk_product_type = 0"; -if ($db->query($sql)) -{ - $row = $db->fetch_row(0); - $nbproduct = $row[0]; -} -$db->free(); -$sql = "SELECT count(*) FROM llx_product WHERE envente = 0 AND fk_product_type = 0"; -if ($db->query($sql)) -{ - $row = $db->fetch_row(0); - $nbhv = $row[0]; -} -$db->free(); -print_fiche_titre('Statistiques produits et services', $mesg); +print_fiche_titre('Statistiques commandes', $mesg); -print ''; -print ""; -print ''; -print ''; -print ""; -print ''; -print ''; +print '
Nb de produit dans le catalogue'.$nbproduct.'
Nb de produit dans le catalogue qui ne sont pas en vente'.$nbhv.'
'; +print ''; -$sql = "SELECT count(*) FROM llx_product WHERE fk_product_type = 1"; +$sql = "SELECT count(*), date_format(date_commande,'%Y') as dm FROM llx_commande GROUP BY dm DESC"; if ($db->query($sql)) { - $row = $db->fetch_row(0); - $nbproduct = $row[0]; + $num = $db->num_rows(); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($i); + $nbproduct = $row[0]; + $year = $row[1]; + print ""; + print ''; + $i++; + } } $db->free(); -$sql = "SELECT count(*) FROM llx_product WHERE envente = 0 AND fk_product_type = 1"; -if ($db->query($sql)) -{ - $row = $db->fetch_row(0); - $nbhv = $row[0]; -} -$db->free(); - -print ""; -print ''; -print ''; -print ""; -print ''; -print ''; print '
Nb de commandeAnnée
'.$nbproduct.''.$year.'
Nb de service dans le catalogue'.$nbproduct.'
Nb de service dans le catalogue qui ne sont pas en vente'.$nbhv.'
';