compilation_soldes.inc.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?PHP
  2. CONST PX170 = "170px";
  3. // ------------------------------
  4. // Caractéristiques du module
  5. // ------------------------------
  6. unset($module);
  7. $module = array(
  8. "titre" => "Compilation des soldes",
  9. "urldest" => $SCRIPT_NAME . "?page=compilation_soldes",
  10. "autre" => 1,
  11. "tailleentete" => "1220",
  12. "tailleliste" => "800px",
  13. "boutonfermeraction" => "fermerfenetre",
  14. "colonneaction" => false,
  15. "lientri" => false,
  16. "jeton" => $jeton,
  17. "entete" => array(
  18. 1 => array("Article" => "refarticle", "largeur" => "85px"),
  19. 2 => array("Convention" => "expression", "largeur" => PX170),
  20. 3 => array("Utilisation" => "expression", "largeur" => PX170),
  21. 4 => array("Solde" => "expression", "largeur" => PX170),
  22. ),
  23. "colonneaction" => false,
  24. );
  25. if ($_SESSION['gestion_site'] == 'Non') {
  26. die();
  27. }
  28. // ****************************************************
  29. // Requête SQL principale
  30. // ****************************************************
  31. // Minimum requis : L'employeur
  32. $employeur = filter_input(INPUT_GET, "ListeEmployeurs");
  33. if (!isset($employeur)) {
  34. print"<center>Veuillez sélectionné l'employeur!";
  35. print "<br>";
  36. print "<input type='button' onclick='javascript:window.close();' value='Fermer'></center>";
  37. die();
  38. }
  39. $connex = setConnectionSql();
  40. // Lecture des paramètres du générateur de rapports.
  41. // Employeur
  42. $noEmployeur = antiInjection(substr(filter_input(INPUT_GET, "ListeEmployeurs"), 0,
  43. strlen(filter_input(INPUT_GET, "ListeEmployeurs")) - 1));
  44. // Article, si nécessaire
  45. $sqlWhereArticle = "";
  46. $article = filter_input(INPUT_GET, "ListeArticles");
  47. if (isset($article)) {
  48. $listeArticles = antiInjection(substr(filter_input(INPUT_GET, "ListeArticles"), 0,
  49. strlen(filter_input(INPUT_GET, "ListeArticles"))) - 1);
  50. $sqlWhereArticle = " AND articles.refarticle IN (" . $listeArticles . ")";
  51. }
  52. // Période pour les libérations
  53. // ****************************************************
  54. // Sélection de date
  55. // Toujours déterminer la date de début et de fin de la période courante.
  56. // ****************************************************
  57. $sqlab = "SELECT unix_timestamp(compteurautre.renouvellement) as dateAutre FROM compteurautre";
  58. $result = mysqli_query($connex, "$sqlab") or die(mysqli_error());
  59. $champs = mysqli_fetch_row($result);
  60. $datedebut = date("Y-m-d", mktime(0, 0, 0, date("m", $champs[0]), date("d", $champs[0]), date("Y", $champs[0]) - 1));
  61. $datefin = date("Y-m-d", mktime(0, 0, 0, date("m", $champs[0]), date("d", $champs[0]) - 1, date("Y", $champs[0])));
  62. mysqli_free_result($result);
  63. $sqla = "SELECT articles.refarticle, articles.noarticle, empl.nomemployeur, ifnull(lib.total_duree,0) as "
  64. . "total_duree, conv.nombre, ";
  65. $sqlb = "(conv.nombre-ifnull(lib.total_duree,0)) as total FROM (articles left join (select articles.noarticle, "
  66. . "articles.refarticle,";
  67. $sqlc = "sum(if(liberations.typeoperation=1,duree.dureeNombre,0-duree.dureeNombre)) as total_duree, ";
  68. $sqld = sprintf("employeurs.nomemployeur from employeurs, employes, liberations, ligneliberations, articles, duree "
  69. . "where employeurs.refemployeur=%d and ", $noEmployeur);
  70. $sqle = sprintf("(ligneliberations.dateliberation between \"%s\" And \"%s\") AND articles.refarticle=ligneliberations."
  71. . "refarticle AND ", $datedebut, $datefin);
  72. $sqlf = "ligneliberations.refliberation = liberations.refliberation AND liberations.refemploye=employes.refemploye "
  73. . "and employes.refemployeur=employeurs.refemployeur ";
  74. $sqlf1 = "and duree.refduree =ligneliberations.duree group by articles.refarticle) as lib on ";
  75. $sqlg = "lib.refarticle=articles.refarticle) left join ";
  76. $sqlh = "(SELECT convention.refarticle, convention.nombre, employeurs.nomemployeur ";
  77. $sqli = "FROM compteurautre, periodes, employeurs, nombreemployes ";
  78. $sqlj = "left JOIN convention ON (convention.condition1 <= nombreemployes.nombreemployes ";
  79. $sqlk = "AND convention.condition2 >= nombreemployes.nombreemployes) ";
  80. $sqll = "WHERE periodes.periode = compteurautre.renouvellement ";
  81. $sqlm = "AND nombreemployes.refperiode = periodes.refperiode ";
  82. $sqln = "and nombreemployes.refemployeur = employeurs.refemployeur ";
  83. $sqlo = sprintf("AND employeurs.refemployeur =%d) as conv on conv.refarticle=articles.refarticle, (select nomemployeur "
  84. . "from employeurs where refemployeur= %d) as empl ", $noEmployeur, $noEmployeur);
  85. $sqlp = "where articles.refarticle<>2 $sqlWhereArticle ";
  86. $sqlq = "group by articles.noarticle ";
  87. $sqlr = "order by LENGTH (articles.noarticle), articles.noarticle";
  88. $sqlprinc = "$sqla$sqlb$sqlc$sqld$sqle$sqlf$sqlf1$sqlg$sqlh$sqli$sqlj$sqlk$sqll$sqlm$sqln$sqlo$sqlp$sqlq$sqlr";
  89. $result2 = mysqli_query($connex, "$sqlprinc") or die("La requête (3) a échouée.");
  90. // ****************************************************
  91. // Vérification de la présence de détails dans la liste
  92. // ****************************************************
  93. if (mysqli_num_rows($result2) == 0) {
  94. print"<center>Aucune libération trouvée!";
  95. print "<br>";
  96. print "<input type='button' onclick='javascript:window.close();' value='Fermer'></center>";
  97. die();
  98. }
  99. $_SESSION['requêteSQL'] = $sqlprinc;
  100. $module["compte"] = 0;
  101. print preparerModule($module);
  102. $i = 1;
  103. unset($style);
  104. $style = "border:1px solid #cfcfcf; font-family:arial, helvetica, sans-serif; font-size:9pt; "
  105. . "margin-left:5px; margin-right:5px;";
  106. while ($champs = mysqli_fetch_row($result2)) {
  107. if ($i == 1) {
  108. print "<tr style='background-color:#f2f6f7;'>\n";
  109. print "<td style='border:1px solid #cfcfcf; font-family:arial, helvetica, sans-serif; "
  110. . "font-size:12pt;' colspan='5'>";
  111. print htmlentities($champs[2], ENT_SUBSTITUTE, "UTF-8") . "</td>";
  112. print "</tr>\n";
  113. }
  114. if ($champs[4] != 0) {
  115. $valeur1 = sprintf("%10.1f", $champs[4]);
  116. $valeur3 = sprintf("%10.1f", $champs[5]);
  117. } else {
  118. //Todo vérifier pour les valeurs vides des colonnes Convention et Solde
  119. $valeur1 = "&nbsp;";
  120. $valeur3 = "&nbsp;";
  121. }
  122. $valeur2 = sprintf("%10.1f", $champs[3]);
  123. $couleur = ($champs[5] >= 0) ? "positif" : "negatif";
  124. print "<tr style='background-color:#f2f6f7;'>\n";
  125. print "<td style='$style'>$i</td>\n";
  126. print "<td style='$style'>$champs[1]</td>\n";
  127. print "<td style='$style' align='center'>$valeur1</td>\n";
  128. print "<td style='$style' align='center'>$valeur2</td>";
  129. print "<td style='$style' align='center' "
  130. . "class='$couleur'>$valeur3</td>";
  131. print "</tr>\n";
  132. $i++;
  133. }
  134. print "</table>";
  135. mysqli_free_result($result2);
  136. print "<div style='width:" . $module["tailleliste"] . "; margin:auto;auto;'>\n";
  137. print "<a href=\"rapport_soldes.php\" class=\"rapport\"><span class=\"pdf\">Afficher le rapport des soldes</span></a>";
  138. print "</div>\n";