diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php
index 0e2c76a0f62..41076245c28 100644
--- a/htdocs/commande/stats/index.php
+++ b/htdocs/commande/stats/index.php
@@ -21,8 +21,15 @@
*/
require("./pre.inc.php");
require("../commande.class.php");
-require("../../graph.class.php");
require("./commandestats.class.php");
+/*
+ * Sécurité accés client
+ */
+if ($user->societe_id > 0)
+{
+ $action = '';
+ $socidp = $user->societe_id;
+}
llxHeader();
/*
@@ -32,47 +39,41 @@ llxHeader();
print_fiche_titre('Statistiques commandes', $mesg);
-$stats = new CommandeStats($db);
+$stats = new CommandeStats($db, $socidp);
+
$year = strftime("%Y", time());
$data = $stats->getNbCommandeByMonthWithPrevYear($year);
$filev = "/document/images/nbcommande2year.png";
-$px = new Graph($data);
+$px = new BarGraph($data);
$px->SetMaxValue($px->GetMaxValue());
$px->SetWidth(450);
$px->SetHeight(280);
$px->SetYLabel("Nombre de commande");
$px->draw(DOL_DOCUMENT_ROOT.$filev, $data, $year);
-$sql = "SELECT count(*), date_format(date_commande,'%Y') as dm, sum(total_ht) FROM llx_commande WHERE fk_statut > 0 GROUP BY dm DESC ";
-if ($db->query($sql))
-{
- $num = $db->num_rows();
+$rows = $stats->getNbByYear();
+$num = sizeof($rows);
- print '
';
- print '| Année | Nb de commande | Somme des commandes | ';
- print '';
- print 'Nombre de commande par mois
';
- print ' |
';
- $i = 0;
- while ($i < $num)
- {
- $row = $db->fetch_row($i);
- $nbproduct = $row[0];
- $year = $row[1];
- print "";
- print '| '.$year.' | '.$nbproduct.' | '.price($row[2]).' |
';
- $i++;
- }
-
- print '
';
- $db->free();
-}
-else
+print '';
+print '| Année | Nb de commande | Somme des commandes | ';
+print '';
+print 'Nombre de commande par mois
';
+print ' |
';
+$i = 0;
+while (list($key, $value) = each ($rows))
{
- print "Erreur";
+ $nbproduct = $value[0];
+ $price = $value[1];
+ $year = $key;
+ print "";
+ print '| '.$year.' | '.$nbproduct.' | '.price($price).' |
';
+ $i++;
}
+print '
';
+$db->free();
+
$db->close();