From febad2f409ea3e8cea9e00efd9d3e9bae5047067 Mon Sep 17 00:00:00 2001
From: cortylal <alexcortyl@gmail.com>
Date: Thu, 19 Jun 2014 02:13:57 +0200
Subject: [PATCH] stats

---
 class/stats.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-
 view/stats.php  | 25 +++++++++++++++---
 2 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/class/stats.php b/class/stats.php
index 8110111..4a5a8a2 100644
--- a/class/stats.php
+++ b/class/stats.php
@@ -15,6 +15,72 @@ class Stats
         return $ligne;
     }
 
+    public function nbClient()
+    {
+        $bdd = new Db();
+
+        $requete_prepare = $bdd->db->prepare("  SELECT COUNT(*) AS nb
+                                                FROM client" ); // on prépare notre requête
+        $requete_prepare->execute();
+
+        $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
+
+        return $ligne;
+    }
+
+    public function nbAnimaux()
+    {
+        $bdd = new Db();
+
+        $requete_prepare = $bdd->db->prepare("  SELECT COUNT(*) AS nb
+                                                FROM animaux" ); // on prépare notre requête
+        $requete_prepare->execute();
+
+        $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
+
+        return $ligne;
+    }
+
+    public function totalCA()
+    {
+        $bdd = new Db();
+
+        $requete_prepare = $bdd->db->prepare("  SELECT SUM(prix_total) AS ca
+                                                FROM facture" ); // on prépare notre requête
+        $requete_prepare->execute();
+
+        $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
+
+        return $ligne;
+    }
+
+    public function nbEmploye()
+    {
+        $bdd = new Db();
+
+        $requete_prepare = $bdd->db->prepare("  SELECT COUNT(*) AS nb
+                                                FROM employe" ); // on prépare notre requête
+        $requete_prepare->execute();
+
+        $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
+
+        return $ligne;
+    }
+
+    public function nbVeterinaire()
+    {
+        $bdd = new Db();
+
+        $requete_prepare = $bdd->db->prepare("  SELECT COUNT(*) AS nb
+                                                FROM employe e
+                                                WHERE e.is_veterinaire = '1'" ); // on prépare notre requête
+        $requete_prepare->execute();
+
+        $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
+
+        return $ligne;
+    }
+
     public function nbAnimalMoyClient()
     {
         $bdd = new Db();
@@ -36,7 +102,7 @@ class Stats
     {
         $bdd = new Db();
 
-        $requete_prepare = $bdd->db->prepare("  SELECT c.nom, c.prenom, COUNT(a.client)
+        $requete_prepare = $bdd->db->prepare("  SELECT c.nom, c.prenom, COUNT(a.client) as count
                                                 FROM animal a, client c 
                                                 WHERE a.client = c.id
                                                 GROUP BY c.nom, c.prenom, c.id" ); // on prépare notre requête
diff --git a/view/stats.php b/view/stats.php
index df2d3da..a021d48 100644
--- a/view/stats.php
+++ b/view/stats.php
@@ -7,14 +7,33 @@
         <h4>Statistiques générales : </h4>
       <table class="table">
         <thead>
-            
-                <th>Facture moyenne : </th>
-                <th><?php $tmp = $stats->factureMoy(); $nb_formated = number_format($tmp["value"], 2, ',', ' '); echo $nb_formated; ?></th>
+                <th>Nombre de client : </th>
+                <th><?php $tmp = $stats->nbClient(); $nb_formated = number_format($tmp["nb"], 2, ',', ' '); echo $nb_formated; ?></th>
+        </thead>
+        <thead>
+                <th>Nombre d'employé' : </th>
+                <th><?php $tmp = $stats->nbEmploye(); $nb_formated = number_format($tmp["nb"], 2, ',', ' '); echo $nb_formated; ?></th>
+        </thead>
+        <thead>
+                <th>Nombre de vétérinaire' : </th>
+                <th><?php $tmp = $stats->nbVeterinaire(); $nb_formated = number_format($tmp["nb"], 2, ',', ' '); echo $nb_formated; ?></th>
+        </thead>
+        <thead>
+                <th>Nombre d'animaux : </th>
+                <th><?php $tmp = $stats->nbAnimaux(); $nb_formated = number_format($tmp["nb"], 2, ',', ' '); echo $nb_formated; ?></th>
         </thead>
         <thead>
                 <th>Nombre moyen d'animal par client : </th>
                 <th><?php $tmp = $stats->nbAnimalMoyClient(); $nb_formated = number_format($tmp["value"], 2, ',', ' '); echo $nb_formated; ?></th>
         </thead>
+        <thead>
+                <th>Facture moyenne : </th>
+                <th><?php $tmp = $stats->factureMoy(); $nb_formated = number_format($tmp["value"], 2, ',', ' '); echo $nb_formated; ?></th>
+        </thead>
+        <thead>
+                <th>Total du chiffre d'affaire : </th>
+                <th><?php $tmp = $stats->totalCA(); $nb_formated = number_format($tmp["ca"], 2, ',', ' '); echo $nb_formated; ?></th>
+        </thead>
       </table>
 
       <br/>
-- 
GitLab