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; } // 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; 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; } }