Browse Source

Maj Stat & Maj add Page (variable)

stany.ferer 3 months ago
parent
commit
6d24170134

+ 42 - 12
core/class/chart.class.php

@@ -35,22 +35,52 @@ class chart
         $opacity = 0.5;
         $nbData = count($_data);
 
+        
         $data["backgroundColor"] = array(
-            "rgba(255, 99, 132, " . $opacity . ")", // Red
-            "rgba(54, 162, 235, " . $opacity . ")", // Blue
-            "rgba(255, 206, 86, " . $opacity . ")", // Yellow
-            "rgba(75, 192, 192, " . $opacity . ")", // Green,
-            "rgba(153, 102, 255, " . $opacity . ")", // Purple
-            "rgba(255, 159, 64, " . $opacity . ")" // Orange
+            "rgba(242, 84, 84, 0.6)",
+            "rgba(242, 132, 84, 0.6)",
+            "rgba(242, 179, 84, 0.6)",
+            "rgba(242, 226, 84, 0.6)",
+            "rgba(210, 242, 84, 0.6)",
+            "rgba(163, 242, 84, 0.6)",
+            "rgba(116, 242, 84, 0.6)",
+            "rgba(84, 242, 100, 0.6)",
+            "rgba(84, 242, 147, 0.6)",
+            "rgba(84, 242, 195, 0.6)",
+            "rgba(84, 242, 242, 0.6)",
+            "rgba(84, 195, 242, 0.6)",
+            "rgba(84, 147, 242, 0.6)",
+            "rgba(84, 100, 242, 0.6)",
+            "rgba(116, 84, 242, 0.6)",
+            "rgba(163, 84, 242, 0.6)",
+            "rgba(210, 84, 242, 0.6)",
+            "rgba(242, 84, 226, 0.6)",
+            "rgba(242, 84, 179, 0.6)",
+            "rgba(242, 84, 132, 0.6)"
         );
 
+
         $data["borderColor"] = array(
-            "rgba(255,99,132,1)", // Red
-            "rgba(54, 162, 235, 1)", // Blue
-            "rgba(255, 206, 86, 1)", // Yellow
-            "rgba(75, 192, 192, 1)", // Green
-            "rgba(153, 102, 255, 1)", // Purple
-            "rgba(255, 159, 64, 1)" // Orange
+            "rgba(242, 84, 84, 1.0)",
+            "rgba(242, 132, 84, 1.0)",
+            "rgba(242, 179, 84, 1.0)",
+            "rgba(242, 226, 84, 1.0)",
+            "rgba(210, 242, 84, 1.0)",
+            "rgba(163, 242, 84, 1.0)",
+            "rgba(116, 242, 84, 1.0)",
+            "rgba(84, 242, 100, 1.0)",
+            "rgba(84, 242, 147, 1.0)",
+            "rgba(84, 242, 195, 1.0)",
+            "rgba(84, 242, 242, 1.0)",
+            "rgba(84, 195, 242, 1.0)",
+            "rgba(84, 147, 242, 1.0)",
+            "rgba(84, 100, 242, 1.0)",
+            "rgba(116, 84, 242, 1.0)",
+            "rgba(163, 84, 242, 1.0)",
+            "rgba(210, 84, 242, 1.0)",
+            "rgba(242, 84, 226, 1.0)",
+            "rgba(242, 84, 179, 1.0)",
+            "rgba(242, 84, 132, 1.0)"
         );
 
         for ($i = 0; $i < $nbData; $i++) {

+ 12 - 5
core/class/get.class.php

@@ -21,7 +21,7 @@ class get
         return (core::ifGet("p") == FALSE AND in_array(self::getDefautPage(), $_menu)) ? TRUE : FALSE;
     }
 
-    public static function page(?string $_page = NULL)
+    public static function page(?string $_page = NULL, array $vars = [])
     {
         if (isset($_page)) {
             $page = $_page;
@@ -30,14 +30,21 @@ class get
         } else {
             $page = self::getDefautPage();
         }
-        if (access::check($page, "page") OR in_array($page, WHITE_ACCESS)) { 
-            (file_exists(DIR_PHP_VIEWS_PAGE . self::environnement() . $page . '.php')) ?
-                require_once DIR_PHP_VIEWS_PAGE . self::environnement() . $page . '.php' : alert::recError("Page introuvable : " . $page);
-        } else { 
+
+        if (access::check($page, "page") || in_array($page, WHITE_ACCESS)) {
+            $file = DIR_PHP_VIEWS_PAGE . self::environnement() . $page . '.php';
+            if (file_exists($file)) {
+                extract($vars); // rend les variables disponibles dans la page
+                include $file;
+            } else {
+                alert::recError("Page introuvable : " . $page);
+            }
+        } else {
             alert::recError("La page que vous tentez de charger ne vous est pas disponible.");
         }
     }
 
+
     public static function submit()
     {
 

+ 67 - 75
core/class/stats.class.php

@@ -1,87 +1,79 @@
 <?php
 
 class stats {
-    
+
     public static function countStatistiquesGenerale(int $_actifOnly = 1){
         $actif = ($_actifOnly == 1) ? " AND actif = 1" : "";
-        db::query("SELECT "
-                . "SUM(IF(sexe = 'F'" . $actif . ", 1, 0)) AS Femme, "
-                . "SUM(IF(sexe = 'M'" . $actif . ", 1, 0)) AS Homme, "
-                . "SUM(IF(contrat = 1" . $actif . ", 1, 0)) AS ContratOn, "
-                . "SUM(IF(contrat = 0" . $actif . ", 1, 0)) AS ContratOff, "
-                . "SUM(IF(actif = 1, 1, 0)) AS ActifOn, "
-                . "SUM(IF(actif = 0, 1, 0)) AS ActifOff, "
-                . "SUM(IF(lieu = 'ISSY - 147', 1, 0)" . $actif . ") AS lieuParis147, "
-                . "SUM(IF(lieu = 'LYON (IVOIRE)', 1, 0)" . $actif . ") AS lieuLyonIvoire, "
-                . "SUM(IF(lieu = 'PEROLS', 1, 0)" . $actif . ") AS lieuPerols, "
-                . "SUM(IF(lieu = 'PARIS CAMBACERE', 1, 0)" . $actif . ") AS lieuParisCambaceres, "
-                . "SUM(IF(lieu = 'BLAGNAC CENT. 3', 1, 0)" . $actif . ") AS lieuToulouseBalgnac, "
-                . "SUM(IF(lieu = 'PARIS-BOUCHARDO', 1, 0)" . $actif . ") AS lieuParisBouchardo "
-                . "FROM " . DB_T_SALARIES);
-        return db::single();
-    }
-    
-    private static function byLieu(string $_lieu){
-        switch ($_lieu) {
-            case "147":
-            return "ISSY - 147";
-                break;
-            case "LYON":
-            return "LYON (IVOIRE)";   
-                break;
-            case "PEROLS":
-            return "PEROLS";
-                break;
-            case "CAMBACERE":
-            return "PARIS CAMBACERE";
-                break;
-            case "BLAGNAC":
-            return "BLAGNAC CENT. 3";
-                break;
-            case "BOUCHARDO":
-            return "PARIS-BOUCHARDO";
-                break;
-            default:
-            return NULL;  
-        }
-    }
 
-    public static function countStatistiquesGenraleEntrees(string $_lieu = NULL, int $_actifOnly = 1){
-        $return = [];
-        $actif = ($_actifOnly == 1) ? " WHERE contrat = 1" : "";
-        $lieu = ($_lieu == NULL) ? "" : " AND lieu = '" . self::byLieu($_lieu) . "'";
-        
-        db::query("SELECT SUBSTR(jourEntree, 1 , 4) AS anEntree FROM " . DB_T_SALARIES . $actif . $lieu);
-        foreach (db::resultset() as $value) {
-            $return[$value["anEntree"]] = (empty($return[$value["anEntree"]])) ? 1 : $return[$value["anEntree"]]+1;
-        }
-        if(!empty($return)){
-            ksort($return);
-        } else {
-            $return = array(date("Y") => 0);
-        }
-        
-        return $return;
-    }
-    
-    public static function countStatistiquesByLieu(string $_lieu){
-        $lieu = self::byLieu($_lieu);
-        
-        if($lieu == NULL){
-            return FALSE;
+        // Récupération des lieux distincts
+        $lieuxQuery = db::query("SELECT DISTINCT lieu FROM " . DB_T_SALARIES);
+        $lieuxList = db::resultset($lieuxQuery);
+
+        $lieuxStats = [];
+        $globalEntrees = [];
+
+        foreach ($lieuxList as $row) {
+            $lieu = addslashes($row['lieu']);
+
+            // Statistiques par lieu
+            $sql = "SELECT "
+                . "SUM(IF(sexe = 'F'{$actif} AND lieu = '{$lieu}', 1, 0)) AS Femme, "
+                . "SUM(IF(sexe = 'M'{$actif} AND lieu = '{$lieu}', 1, 0)) AS Homme, "
+                . "SUM(IF(contrat = 1{$actif} AND lieu = '{$lieu}', 1, 0)) AS ContratOn, "
+                . "SUM(IF(contrat = 0{$actif} AND lieu = '{$lieu}', 1, 0)) AS ContratOff, "
+                . "SUM(IF(actif = 1 AND lieu = '{$lieu}', 1, 0)) AS ActifOn, "
+                . "SUM(IF(actif = 0 AND lieu = '{$lieu}', 1, 0)) AS ActifOff "
+                . "FROM " . DB_T_SALARIES;
+
+            db::query($sql);
+            $stats = db::single();
+
+            $totalLieu = $stats['Femme'] + $stats['Homme'];
+            $stats['PourcentageFemme'] = $totalLieu > 0 ? round(($stats['Femme'] / $totalLieu) * 100, 2) : 0;
+            $stats['PourcentageHomme'] = $totalLieu > 0 ? round(($stats['Homme'] / $totalLieu) * 100, 2) : 0;
+
+            // Entrées par année pour ce lieu
+            $entrees = [];
+            $entreeQuery = db::query("SELECT SUBSTR(jourEntree, 1, 4) AS anEntree FROM " . DB_T_SALARIES . " WHERE lieu = '{$lieu}'" . ($_actifOnly == 1 ? " AND actif = 1" : ""));
+            foreach (db::resultset() as $value) {
+                $an = $value["anEntree"];
+                $entrees[$an] = isset($entrees[$an]) ? $entrees[$an] + 1 : 1;
+
+                // Comptage global
+                $globalEntrees[$an] = isset($globalEntrees[$an]) ? $globalEntrees[$an] + 1 : 1;
+            }
+            if (empty($entrees)) {
+                $entrees[date("Y")] = 0;
+            } else {
+                ksort($entrees);
+            }
+
+            $stats['EntreesParAnnee'] = $entrees;
+            $lieuxStats[$row['lieu']] = $stats;
         }
 
-        db::query("SELECT "
-                . "SUM(IF(sexe = 'F' AND actif = 1, 1, 0)) AS Femme, "
-                . "SUM(IF(sexe = 'M' AND actif = 1, 1, 0)) AS Homme, "
-                . "SUM(IF(contrat = 1 AND actif = 1, 1, 0)) AS ContratOn, "
-                . "SUM(IF(contrat = 0 AND actif = 1, 1, 0)) AS ContratOff, "
+        // Statistiques globales
+        $sqlGlobal = "SELECT "
+                . "SUM(IF(sexe = 'F'{$actif}, 1, 0)) AS Femme, "
+                . "SUM(IF(sexe = 'M'{$actif}, 1, 0)) AS Homme, "
+                . "SUM(IF(contrat = 1{$actif}, 1, 0)) AS ContratOn, "
+                . "SUM(IF(contrat = 0{$actif}, 1, 0)) AS ContratOff, "
                 . "SUM(IF(actif = 1, 1, 0)) AS ActifOn, "
                 . "SUM(IF(actif = 0, 1, 0)) AS ActifOff "
-                . "FROM " . DB_T_SALARIES . " "
-                . "WHERE lieu = :lieu");
-        db::bind(':lieu', $lieu);
-        return db::single();
+                . "FROM " . DB_T_SALARIES;
+
+        db::query($sqlGlobal);
+        $globalStats = db::single();
+
+        $totalGlobal = $globalStats['Femme'] + $globalStats['Homme'];
+        $globalStats['PourcentageFemme'] = $totalGlobal > 0 ? round(($globalStats['Femme'] / $totalGlobal) * 100, 2) : 0;
+        $globalStats['PourcentageHomme'] = $totalGlobal > 0 ? round(($globalStats['Homme'] / $totalGlobal) * 100, 2) : 0;
+
+        ksort($globalEntrees);
+        $globalStats['EntreesParAnnee'] = $globalEntrees;
+        $globalStats['Lieux'] = $lieuxStats;
+
+        return $globalStats;
     }
-    
+
 }

+ 19 - 22
core/json/cms.stats-general.php

@@ -1,33 +1,30 @@
 <?php 
 
-function create(string $_lieu){
-    $return = array();
-    $return = stats::countStatistiquesByLieu($_lieu);
-    $return["Lieu"] = $_lieu;
-    $return["PourcentageFemme"] = core::caculPourcentage($return["Femme"], $return["ActifOn"]);
-    $return["PourcentageHomme"] = core::caculPourcentage($return["Homme"], $return["ActifOn"]);
-    return $return;
-}
-
 $statGeneral = stats::countStatistiquesGenerale();
 
-$return[] = array(
+$return = [[
     "Lieu" => "TOUT INVENT",
+    "ActifOn" => $statGeneral["ActifOn"],
     "Femme" => $statGeneral["Femme"],
     "Homme" => $statGeneral["Homme"],
+    "PourcentageFemme" => $statGeneral["PourcentageFemme"],
+    "PourcentageHomme" => $statGeneral["PourcentageHomme"],
     "ContratOn" => $statGeneral["ContratOn"],
-    "ContratOff" => $statGeneral["ContratOff"],
-    "ActifOn" => $statGeneral["ActifOn"],
-    "ActifOff" => $statGeneral["ActifOff"],
-    "PourcentageFemme" => core::caculPourcentage($statGeneral["Femme"], $statGeneral["ActifOn"]),
-    "PourcentageHomme" => core::caculPourcentage($statGeneral["Homme"], $statGeneral["ActifOn"]),
-);
+    "ContratOff" => $statGeneral["ContratOff"]
+]];
+
 
-$return[] = create("147");
-$return[] = create("LYON");
-$return[] = create("PEROLS");
-$return[] = create("CAMBACERE");
-$return[] = create("BLAGNAC");
-$return[] = create("BOUCHARDO");
+foreach ($statGeneral["Lieux"] as $keyLieu => $valueLieu) {
+    array_push($return, [
+        "Lieu" => $keyLieu,
+        "ActifOn" => $valueLieu["ActifOn"],
+        "Femme" => $valueLieu["Femme"],
+        "Homme" => $valueLieu["Homme"],
+        "PourcentageFemme" => $valueLieu["PourcentageFemme"],
+        "PourcentageHomme" => $valueLieu["PourcentageHomme"],
+        "ContratOn" => $valueLieu["ContratOn"],
+        "ContratOff" => $valueLieu["ContratOff"]
+    ]);
+}
 
 echo json_encode($return);

+ 11 - 79
core/views/pages/cms.stats-an-entree.php

@@ -1,12 +1,3 @@
-<?php
-    $statGeneral = stats::countStatistiquesGenraleEntrees();
-    $stat147 = stats::countStatistiquesGenraleEntrees("147");
-    $statLyon = stats::countStatistiquesGenraleEntrees("LYON");
-    $statPerol = stats::countStatistiquesGenraleEntrees("PEROLS");
-    $statCambacere = stats::countStatistiquesGenraleEntrees("CAMBACERE");
-    $statBlagnac = stats::countStatistiquesGenraleEntrees("BLAGNAC");
-    $statBouchardo = stats::countStatistiquesGenraleEntrees("BOUCHARDO");
-?>
 <div class="row" style="margin-top: 20x;">
     
     <div class="col-md-10" style="margin-top: 30px;">
@@ -16,91 +7,32 @@
             "id" => "statGeneralAnEntree",
             "charts" => "line",
             "label" => "Général",
-            "data" => array($statGeneral)
-        );
-
-        chart::printCanvas($config);
-        ?>
-    </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - 147</h6>
-        <?php
-        $config = array(
-            "id" => "stat147Entree",
-            "charts" => "line",
-            "label" => "Paris - 147",
-            "data" => array($stat147)
-        );
-
-        chart::printCanvas($config);
-        ?>
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Lyon</h6>
-        <?php
-        $config = array(
-            "id" => "statLyonEntree",
-            "charts" => "line",
-            "label" => "Lyon",
-            "data" => array($statLyon)
+            "data" => array($statGeneral["EntreesParAnnee"])
         );
 
         chart::printCanvas($config);
         ?>
     </div>
     
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Montpellier - Pérols</h6>
-        <?php
-        $config = array(
-            "id" => "statPerolsEntree",
-            "charts" => "line",
-            "label" => "Montpellier - Pérols",
-            "data" => array($statPerol)
-        );
+<?php
+    foreach ($statGeneral["Lieux"] as $keyLieu => $valueLieu) {
+?>
 
-        chart::printCanvas($config);
-        ?>
-    </div>
     <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - Cambacérès</h6>
+        <h6 class="bg-light p-2"><?= $keyLieu ?></h6>
         <?php
         $config = array(
-            "id" => "statCambacereEntree",
+            "id" => "EntreesParAnnee-".md5($keyLieu),
             "charts" => "line",
-            "label" => "Paris - Cambacérès",
-            "data" => array($statCambacere)
+            "label" => "<?= $keyLieu ?>",
+            "data" => array($valueLieu["EntreesParAnnee"])
         );
 
         chart::printCanvas($config);
         ?>
     </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Toulouse - Blagnac</h6>
-        <?php
-        $config = array(
-            "id" => "statBlagnacEntree",
-            "charts" => "line",
-            "label" => "Toulouse - Blagnac",
-            "data" => array($statBlagnac)
-        );
 
-        chart::printCanvas($config);
-        ?>
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - Bouchardo</h6>
-        <?php
-        $config = array(
-            "id" => "statBouchardoEntree",
-            "charts" => "line",
-            "label" => "Paris - Bouchardo",
-            "data" => array($statBouchardo)
-        );
-
-        chart::printCanvas($config);
-        ?>
-    </div>
+<?php
+    }
+?>
 </div>

+ 11 - 88
core/views/pages/cms.stats-contrats.php

@@ -1,12 +1,3 @@
-<?php
-    $statGeneral = stats::countStatistiquesGenerale();
-    $stat147 = stats::countStatistiquesByLieu("147");
-    $statLyon = stats::countStatistiquesByLieu("LYON");
-    $statPerol = stats::countStatistiquesByLieu("PEROLS");
-    $statCambacere = stats::countStatistiquesByLieu("CAMBACERE");
-    $statBlagnac = stats::countStatistiquesByLieu("BLAGNAC");
-    $statBouchardo = stats::countStatistiquesByLieu("BOUCHARDO"); 
-?>
 <div class="row" style="margin-top: 20x;">
     
     <div class="col-md-10" style="margin-top: 30px;">
@@ -24,98 +15,30 @@
         chart::printCanvas($config);
         ?>  
     </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - 147</h6>
-        <?php
-        $config = array(
-            "id" => "stat147ContratActif",
-            "charts" => "doughnut",
-            "label" => "Paris - 147",
-            "data" => array(
-                array("label" => "Contrats actifs", "nb" => $stat147["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $stat147["ContratOff"]))
-        );
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Lyon</h6>
-        <?php
-        $config = array(
-            "id" => "statLyonContratActif",
-            "charts" => "doughnut",
-            "label" => "Lyon",
-            "data" => array(
-                array("label" => "Contrats actifs", "nb" => $statLyon["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $statLyon["ContratOff"]))
-        );
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Montpellier - Pérols</h6>
-        <?php
-        $config = array(
-            "id" => "statPerolContratActif",
-            "charts" => "doughnut",
-            "label" => "Montpellier - Pérols",
-            "data" => array(
-                array("label" => "Contrats actifs", "nb" => $statPerol["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $statPerol["ContratOff"]))
-        );
+<?php
+    foreach ($statGeneral["Lieux"] as $keyLieu => $valueLieu) {
+?>
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
     <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - Cambacérès</h6>
+        <h6 class="bg-light p-2"><?= $keyLieu ?></h6>
         <?php
         $config = array(
-            "id" => "statCambacereContratActif",
+            "id" => "Contrat-".md5($keyLieu),
             "charts" => "doughnut",
-            "label" => "Paris - Cambacérès",
+            "label" => "<?= $keyLieu ?>",
             "data" => array(
-                array("label" => "Contrats actifs", "nb" => $statCambacere["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $statCambacere["ContratOff"]))
+                array("label" => "Contrats actifs", "nb" => $valueLieu["ContratOn"]),
+                array("label" => "Contrats en arrêt", "nb" => $valueLieu["ContratOff"]))
         );
 
         chart::printCanvas($config);
         ?>  
     </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Toulouse - Blagnac</h6>
-        <?php
-        $config = array(
-            "id" => "statBlagnacContratActif",
-            "charts" => "doughnut",
-            "label" => "Toulouse - Blagnac",
-            "data" => array(
-                array("label" => "Contrats actifs", "nb" => $statBlagnac["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $statBlagnac["ContratOff"]))
-        );
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    <div class="col-md-5" style="margin-top: 40px;">
-        <h6 class="bg-light p-2">Paris - Bouchardo</h6>
-        <?php
-        $config = array(
-            "id" => "statBouchardoContratActif",
-            "charts" => "doughnut",
-            "label" => "Paris - Bouchardo",
-            "data" => array(
-                array("label" => "Contrats actifs", "nb" => $statBouchardo["ContratOn"]),
-                array("label" => "Contrats en arrêt", "nb" => $statBouchardo["ContratOff"]))
-        );
+<?php
+    }
+?>
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    
 </div>

+ 12 - 95
core/views/pages/cms.stats-femmes-hommes.php

@@ -1,12 +1,3 @@
-<?php
-    $statGeneral = stats::countStatistiquesGenerale();
-    $stat147 = stats::countStatistiquesByLieu("147");
-    $statLyon = stats::countStatistiquesByLieu("LYON");
-    $statPerol = stats::countStatistiquesByLieu("PEROLS");
-    $statCambacere = stats::countStatistiquesByLieu("CAMBACERE");
-    $statBlagnac = stats::countStatistiquesByLieu("BLAGNAC");
-    $statBouchardo = stats::countStatistiquesByLieu("BOUCHARDO"); 
-?>
 <div class="row" style="margin-top: 20x;">
     
     <div class="col-md-10" style="margin-top: 30px;">
@@ -25,104 +16,30 @@
         chart::printCanvas($config);
         ?>  
     </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - 147</h6>
-        <?php
-        $config = array(
-            "id" => "stat147HommeFemme",
-            "charts" => "doughnut",
-            "label" => "Paris - 147",
-            "data" => array(
-                array("label" => "Femme", "nb" => $stat147["Femme"]),
-                array("label" => "Homme", "nb" => $stat147["Homme"])
-            )
-        );
-
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Lyon</h6>
-        <?php
-        $config = array(
-            "id" => "statLyonHommeFemme",
-            "charts" => "doughnut",
-            "label" => "Lyon",
-            "data" => array(
-                array("label" => "Femme", "nb" => $statLyon["Femme"]),
-                array("label" => "Homme", "nb" => $statLyon["Homme"])
-            )
-        );
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Montpellier - Pérols</h6>
-        <?php
-        $config = array(
-            "id" => "statPerolHommeFemme",
-            "charts" => "doughnut",
-            "label" => "Montpellier - Pérols",
-            "data" => array(
-                array("label" => "Femme", "nb" => $statPerol["Femme"]),
-                array("label" => "Homme", "nb" => $statPerol["Homme"])
-            )
-        );
+    <?php
+    foreach ($statGeneral["Lieux"] as $keyLieu => $valueLieu) {
+?>
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - Cambacérès</h6>
+        <div class="col-md-5" style="margin-top: 30px;">
+        <h6 class="bg-light p-2"><?= $keyLieu ?></h6>
         <?php
         $config = array(
-            "id" => "statCambacereHommeFemme",
+            "id" => "FemmeHomme-".md5($keyLieu),
             "charts" => "doughnut",
-            "label" => "Paris - Cambacérès",
+            "label" => "<?= $keyLieu ?>",
             "data" => array(
-                array("label" => "Femme", "nb" => $statCambacere["Femme"]),
-                array("label" => "Homme", "nb" => $statCambacere["Homme"])
+                array("label" => "Femme", "nb" => $valueLieu["Femme"]),
+                array("label" => "Homme", "nb" => $valueLieu["Homme"])
             )
         );
 
         chart::printCanvas($config);
         ?>  
     </div>
-    
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Toulouse - Blagnac</h6>
-        <?php
-        $config = array(
-            "id" => "statBlagnacHommeFemme",
-            "charts" => "doughnut",
-            "label" => "Toulouse - Blagnac",
-            "data" => array(
-                array("label" => "Femme", "nb" => $statBlagnac["Femme"]),
-                array("label" => "Homme", "nb" => $statBlagnac["Homme"])
-            )
-        );
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    <div class="col-md-5" style="margin-top: 30px;">
-        <h6 class="bg-light p-2">Paris - Bouchardo</h6>
-        <?php
-        $config = array(
-            "id" => "statBouchardoHommeFemme",
-            "charts" => "doughnut",
-            "label" => "Paris - Bouchardo",
-            "data" => array(
-                array("label" => "Femme", "nb" => $statBouchardo["Femme"]),
-                array("label" => "Homme", "nb" => $statBouchardo["Homme"])
-            )
-        );
+<?php
+    }
+?>
 
-        chart::printCanvas($config);
-        ?>  
-    </div>
-    
 </div>

+ 12 - 14
core/views/pages/cms.stats-tous-sites.php

@@ -1,24 +1,22 @@
-<?php
-$statGeneral = stats::countStatistiquesGenerale();
-$statGeneralEntree = stats::countStatistiquesGenraleEntrees();
-?>
 <div class="row" style="margin-top: 20px;">
 
     <div class="col-md-10" style="margin-top: 10px;">
         <h6 class="bg-light p-2">Nb. salariés par site</h6>
         <?php
-        $config = array(
+
+        $data = [];
+        foreach ($statGeneral["Lieux"] as $keyLieu => $valueLieu) {
+            array_push($data, [
+                "label" => $keyLieu,
+                "nb" => $valueLieu["Homme"]+$valueLieu["Femme"]
+            ]);
+        }
+
+        $config = array(    
             "id" => "statGeneralLieu",
             "charts" => "bar",
             "label" => "Sites (général)",
-            "data" => array(
-                array("label" => "Paris - 147", "nb" => $statGeneral["lieuParis147"]),
-                array("label" => "Paris - Cambacérès", "nb" => $statGeneral["lieuParisCambaceres"]),
-                array("label" => "Paris - Bouchardo", "nb" => $statGeneral["lieuParisBouchardo"]),
-                array("label" => "Lyon - Tour d'ivoire", "nb" => $statGeneral["lieuLyonIvoire"]),
-                array("label" => "Montpellier - Pérols", "nb" => $statGeneral["lieuPerols"]),
-                array("label" => "Toulouse - BLanchar", "nb" => $statGeneral["lieuToulouseBalgnac"])
-            )
+            "data" => $data
         );
 
         chart::printCanvas($config);
@@ -32,7 +30,7 @@ $statGeneralEntree = stats::countStatistiquesGenraleEntrees();
             "id" => "statGeneralEntree",
             "charts" => "line",
             "label" => "Année d'entrée (général)",
-            "data" => array($statGeneralEntree)
+            "data" => array($statGeneral["EntreesParAnnee"])
         );
 
         chart::printCanvas($config);

+ 25 - 67
core/views/pages/cms.stats.php

@@ -1,3 +1,6 @@
+<?php 
+    $statGeneral = stats::countStatistiquesGenerale();
+?>
 <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
 <h2 class="bd-title" id="content">
     <span>RH : Stats salariés</span>
@@ -11,80 +14,35 @@
                 "Stats salariés" => "/stats.html")
         )); 
 ?>
-<ul class="nav nav-tabs" id="stats" role="tablist" style="margin-top: 40px;">
-    <li class="nav-item">
-        <a class="nav-link active" data-toggle="tab" id="stats-general-tab" role="tab" aria-selected="true">Général</a>
-    </li>
-    <li class="nav-item">
-        <a class="nav-link" data-toggle="tab" id="stats-tous-sites-tab" role="tab">Tous sites confondus</a>
-    </li>
-    <li class="nav-item">
-        <a class="nav-link" data-toggle="tab" id="stats-an-entree-tab" role="tab">Par année d'entrée</a>
-    </li>
-    <li class="nav-item">
-        <a class="nav-link" data-toggle="tab" id="stats-femmes-hommes-tab" role="tab">Femmes / Hommes</a>
-    </li>
-    <li class="nav-item">
-        <a class="nav-link" data-toggle="tab" id="stats-contrats-tab" role="tab">Contrats actifs</a>
-    </li>
+
+<ul class="nav nav-tabs" id="stats" style="margin-top: 40px;">
+    <li class="nav-item"><a class="nav-link active" data-tab="general">Général</a></li>
+    <li class="nav-item"><a class="nav-link" data-tab="tous-sites">Tous sites confondus</a></li>
+    <li class="nav-item"><a class="nav-link" data-tab="an-entree">Par année d'entrée</a></li>
+    <li class="nav-item"><a class="nav-link" data-tab="femmes-hommes">Femmes / Hommes</a></li>
+    <li class="nav-item"><a class="nav-link" data-tab="contrats">Contrats actifs</a></li>
 </ul>
 
 <div class="tab-content" style="margin-bottom:40px;">
-    <div id="tab-stats-general"> 
-        <?php get::page("stats-general") ?>
-    </div>
-    <div id="tab-stats-tous-sites" style="display: none;"> 
-        <?php get::page("stats-tous-sites") ?>
-    </div>
-    <div id="tab-stats-an-entree" style="display: none;"> 
-        <?php get::page("stats-an-entree") ?>
-    </div>
-    <div id="tab-stats-femmes-hommes" style="display: none;">
-        <?php get::page("stats-femmes-hommes") ?>
-    </div>
-    <div id="tab-stats-contrats" style="display: none;"> 
-        <?php get::page("stats-contrats") ?>
-    </div>
+    <div id="tab-general"><?php get::page("stats-general") ?></div>
+    <div id="tab-tous-sites" style="display:none;"><?php get::page("stats-tous-sites", ["statGeneral" => $statGeneral]) ?></div>
+    <div id="tab-an-entree" style="display:none;"><?php get::page("stats-an-entree", ["statGeneral" => $statGeneral]) ?></div>
+    <div id="tab-femmes-hommes" style="display:none;"><?php get::page("stats-femmes-hommes", ["statGeneral" => $statGeneral]) ?></div>
+    <div id="tab-contrats" style="display:none;"><?php get::page("stats-contrats", ["statGeneral" => $statGeneral]) ?></div>
 </div>
 
+
 <script>
-    $(document).ready(function(){
-        $("#stats-general-tab").click(function() {
-            $("#tab-stats-general").show();
-            $("#tab-stats-tous-sites").hide();
-            $("#tab-stats-an-entree").hide();
-            $("#tab-stats-femmes-hommes").hide();
-            $("#tab-stats-contrats").hide();
-        });
-        $("#stats-tous-sites-tab").click(function() {
-            $("#tab-stats-general").hide();
-            $("#tab-stats-tous-sites").show();
-            $("#tab-stats-an-entree").hide();
-            $("#tab-stats-femmes-hommes").hide();
-            $("#tab-stats-contrats").hide();
-        });
-        $("#stats-an-entree-tab").click(function() {
-            $("#tab-stats-general").hide();
-            $("#tab-stats-tous-sites").hide();
-            $("#tab-stats-an-entree").show();
-            $("#tab-stats-femmes-hommes").hide();
-            $("#tab-stats-contrats").hide();
-        });
-        $("#stats-femmes-hommes-tab").click(function() {
-            $("#tab-stats-general").hide();
-            $("#tab-stats-tous-sites").hide();
-            $("#tab-stats-an-entree").hide();
-            $("#tab-stats-femmes-hommes").show();
-            $("#tab-stats-contrats").hide();
-        });
-        $("#stats-contrats-tab").click(function() {
-            $("#tab-stats-general").hide();
-            $("#tab-stats-tous-sites").hide();
-            $("#tab-stats-an-entree").hide();
-            $("#tab-stats-femmes-hommes").hide();
-            $("#tab-stats-contrats").show();
+    $(document).ready(function() {
+        $(".nav-link").click(function() {
+            $(".nav-link").removeClass("active");
+            $(this).addClass("active");
+
+            const tabId = $(this).data("tab");
+            $(".tab-content > div").hide();
+            $("#tab-" + tabId).show();
         });
-    })
+    });
 </script>