rapport_liberations.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. define("LIBERATIONSWEB", 20091223);
  3. session_start();
  4. //Librairie de fonctions
  5. require_once(__DIR__ . '/vendor/autoload.php');
  6. require_once("lib/libconfig.inc.php");
  7. require_once("lib/libsession.inc.php");
  8. require_once("lib/libfonctions.inc.php");
  9. require_once("lib/libmysql.inc.php");
  10. require_once("lib/libencode.inc.php");
  11. require_once("lib/libcourriel.inc.php");
  12. require_once("lib/libliberations.inc.php");
  13. require_once("lib/libcentrale.inc.php");
  14. require_once("fpdf/fpdf.php");
  15. class PDF extends FPDF {
  16. var $NomEmploye;
  17. var $NumEmploye;
  18. var $PremierDeNomEmployeur;
  19. var $DateLiberation;
  20. var $Commentaire;
  21. var $CalculDuree;
  22. var $Nombre;
  23. var $TOperation;
  24. var $NoArticle;
  25. var $Texte24;
  26. var $Texte27;
  27. var $Texte19;
  28. var $Texte20;
  29. var $syndicatAcr;
  30. var $syndicatNom;
  31. var $configCentrale;
  32. function WordWrap(&$text, $maxwidth) {
  33. $text = trim($text);
  34. if ($text === '')
  35. return 0;
  36. $space = $this->GetStringWidth(' ');
  37. $lines = explode("\n", $text);
  38. $text = '';
  39. $count = 0;
  40. foreach ($lines as $line) {
  41. $words = preg_split('/ +/', $line);
  42. $width = 0;
  43. foreach ($words as $word) {
  44. $wordwidth = $this->GetStringWidth($word);
  45. if ($wordwidth > $maxwidth) {
  46. // Word is too long, we cut it
  47. for ($i = 0;
  48. $i < strlen($word);
  49. $i++) {
  50. $wordwidth = $this->GetStringWidth(substr($word, $i, 1));
  51. if ($width + $wordwidth <= $maxwidth) {
  52. $width += $wordwidth;
  53. $text .= substr($word, $i, 1);
  54. } else {
  55. $width = $wordwidth;
  56. $text = rtrim($text) . "\n" . substr($word, $i, 1);
  57. $count++;
  58. }
  59. }
  60. } elseif ($width + $wordwidth <= $maxwidth) {
  61. $width += $wordwidth + $space;
  62. $text .= $word . ' ';
  63. } else {
  64. $width = $wordwidth + $space;
  65. $text = rtrim($text) . "\n" . $word . ' ';
  66. $count++;
  67. }
  68. }
  69. $text = rtrim($text) . "\n";
  70. $count++;
  71. }
  72. $text = rtrim($text);
  73. return $count;
  74. }
  75. // ****************************************************
  76. // Entête de page
  77. // ****************************************************
  78. function Header() {
  79. $Image41 = 'logo/' . $_SESSION["syndicatnom"] . "." . $_SESSION['logo'];
  80. $this->Image($Image41, 139, 25, 47, 22);
  81. $etiquette18 = mb_convert_encoding("Liste des libérations", 'ISO-8859-1', 'UTF-8');
  82. $this->SetXY(26, 26);
  83. $this->SetFont('Times', 'BI', 20);
  84. $this->Cell(114, 8, $etiquette18, 0, 0, 'L');
  85. $this->SetLineWidth(1);
  86. $this->Line(25, 50, 189, 50);
  87. $this->SetY(52);
  88. }
  89. // ****************************************************
  90. // Pied de page
  91. // ****************************************************
  92. function Footer() {
  93. //Numéro de page
  94. //Positionnement à 1,5 cm du bas
  95. //Police Arial italique 8
  96. $this->SetY(-12);
  97. $this->SetFont('Arial', 'I', 8);
  98. $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C');
  99. $etiquette43 = $this->configCentrale["syndicat_nom"];
  100. $etiquette45 = $this->configCentrale["adresse"] . ", " . $this->configCentrale["ville"] .
  101. " (" . $this->configCentrale["province"] . ") " . $this->configCentrale["codepostal"] .
  102. " Téléphone : " . str_replace(array("(", ")"), "", $this->configCentrale["telephone"]) .
  103. " Télécopieur : " . str_replace(array("(", ")"), "", $this->configCentrale["telecopieur"]);
  104. $this->SetLineWidth(0);
  105. $this->Line(25, 264, 184, 264);
  106. $this->SetXY(25, 259);
  107. $this->SetFont('Times', 'B', 9);
  108. $this->Cell(160, 4, mb_convert_encoding($etiquette43, 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
  109. $this->SetXY(25, 264);
  110. $this->SetFont('Times', 'B', 9);
  111. $this->Cell(160, 4, mb_convert_encoding($etiquette45, 'ISO-8859-1', 'UTF-8'), 0, 0, 'C');
  112. }
  113. }
  114. // ****************************************************
  115. // Ajout le total des libérations pour chaque employé
  116. // ****************************************************
  117. function ajoutTotalSommaireEmploye($pdf, $nombredeligne, $calculduree) {
  118. $pdf->SetX(29);
  119. $pdf->SetFont('Times', 'B', 9);
  120. $pdf->Cell(1, 4, mb_convert_encoding("Nombre de libérations :", 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  121. $pdf->SetX(121);
  122. $pdf->SetFont('Times', 'B', 9);
  123. $pdf->Cell(1, 4, mb_convert_encoding("Durée totale :", 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  124. $pdf->SetX(70);
  125. $pdf->SetFont('Times', 'B', 9);
  126. $pdf->Cell(1, 4, $nombredeligne, 0, 0, 'L');
  127. $pdf->SetX(154);
  128. $pdf->SetFont('Times', 'B', 9);
  129. $pdf->Cell(9, 4, sprintf("%02.2f / %dhrs", $calculduree, $calculduree * 8), 0, 0, 'R'); //1 journée correspond à 8 heures
  130. $pdf->ln();
  131. }
  132. // ****************************************************
  133. // Ajout le total des libérations pour chaque employeur
  134. // ****************************************************
  135. function ajoutTotalSommaireEmployeur($pdf, $nombredeligne2, $calculduree2) {
  136. $pdf->SetX(29);
  137. $pdf->SetFont('Times', 'BU', 11);
  138. $pdf->Cell(1, 4, mb_convert_encoding("Nombre de libérations :", 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  139. $pdf->SetX(121);
  140. $pdf->SetFont('Times', 'BU', 11);
  141. $pdf->Cell(1, 4, mb_convert_encoding("Durée totale :", 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  142. $pdf->SetX(70);
  143. $pdf->SetFont('Times', 'BU', 11);
  144. $pdf->Cell(1, 4, $nombredeligne2, 0, 0, 'L');
  145. $pdf->SetX(154);
  146. $pdf->SetFont('Times', 'BU', 11);
  147. $pdf->Cell(9, 4, sprintf("%02.2f / %dhrs", $calculduree2, $calculduree2 * 8), 0, 0, 'R'); //1 journée correspond à 8 heures
  148. $pdf->ln();
  149. $pdf->ln();
  150. }
  151. // ****************************************************
  152. // Requête SQL principale
  153. // ****************************************************
  154. $i = 0;
  155. unset($sqlparam);
  156. $sqlparam["table"][] = "employes";
  157. $sqlparam["table"][] = "employeurs";
  158. $sqlparam["table"][] = "liberations";
  159. $sqlparam["table"][] = "ligneliberations";
  160. $sqlparam["table"][] = "articles";
  161. $sqlparam["table"][] = "duree";
  162. $sqlparam["join"][] = "employes.refemployeur=employeurs.refemployeur";
  163. $sqlparam["join"][] = "employes.refemploye = liberations.refemploye";
  164. $sqlparam["join"][] = "liberations.refliberation = ligneliberations.refliberation";
  165. $sqlparam["join"][] = "ligneliberations.refarticle = articles.refarticle";
  166. $sqlparam["join"][] = "duree.refduree=ligneliberations.duree";
  167. $sqlparam["champs"][] = "CONCAT(employes.nomfamille,', ',employes.prenom) as nomemploye";
  168. $sqlparam["champs"][] = "employes.numemploye";
  169. $sqlparam["champs"][] = "employeurs.nomemployeur";
  170. $sqlparam["champs"][] = "unix_timestamp(liberations.datedemande) as nombre";
  171. $sqlparam["champs"][] = "If(liberations.typeoperation=2,'Annulation','Demande') AS toperation";
  172. $sqlparam["champs"][] = "articles.noarticle";
  173. $sqlparam["champs"][] = "unix_timestamp(ligneliberations.dateliberation) as dateliberation";
  174. $sqlparam["champs"][] = "If(liberations.typeoperation=1,duree.dureeNombre,0-dureeNombre) AS calculduree";
  175. $sqlparam["champs"][] = "employes.refemploye";
  176. $sqlparam["champs"][] = "ligneliberations.commentaire";
  177. $sqlparam["ordre"][] = "employeurs.nomemployeur";
  178. $sqlparam["ordre"][] = "CONCAT(employes.nomfamille, ', ', employes.prenom)";
  179. $sqlparam["ordre"][] = "ligneliberations.dateliberation";
  180. require_once("lib/librapports.inc.php");
  181. $result = executerRequeteSql($sqlparam);
  182. // ****************************************************
  183. // Vérification de la présence de détails dans la liste
  184. // ****************************************************
  185. if (!($result && is_array($result) && sizeof($result) > 0)) {
  186. print"<center>Aucune libérations trouvée!";
  187. print "<br>";
  188. print "<input type='button' onclick='javascript:window.close();' value='Fermer'></center>";
  189. die();
  190. }
  191. // ********************
  192. // Traitement principal
  193. // ********************
  194. //Instanciation de la classe dérivée
  195. $pdf = new PDF('P', 'mm', 'Letter');
  196. $pdf->SetMargins(25, 25);
  197. $pdf->AliasNbPages();
  198. $pdf->AddPage();
  199. $pdf->syndicatAcr = $_SESSION["syndicatnom"];
  200. $pdf->configCentrale = buildConfigCentrale();
  201. $nomemploye = "";
  202. $nomemployeur = "";
  203. $debutemploye = 0;
  204. $debutemployeur = 0;
  205. $calculduree = 0;
  206. $nombredeligne = 0;
  207. $calculduree2 = 0;
  208. $nombredeligne2 = 0;
  209. // *******************
  210. // Lecture des données
  211. // *******************
  212. foreach ($result as $clef => $champs) {
  213. if ($nomemploye != $champs["nomemploye"]) {
  214. if ($debutemploye > 0) {
  215. ajoutTotalSommaireEmploye($pdf, $nombredeligne, $calculduree);
  216. $calculduree = 0;
  217. $nombredeligne = 0;
  218. }
  219. if ($nomemployeur != $champs["nomemployeur"] && $debutemployeur > 0) {
  220. ajoutTotalSommaireEmployeur($pdf, $nombredeligne2, $calculduree2);
  221. $nomemployeur = $champs["nomemployeur"];
  222. $calculduree2 = 0;
  223. $nombredeligne2 = 0;
  224. }
  225. //Ajout du nom de l'employé avec son employeur
  226. $NomEmploye = mb_convert_encoding($champs["nomemploye"], 'ISO-8859-1', 'UTF-8');
  227. $NumEmploye = $champs["numemploye"];
  228. $NomEmployeur = $champs["nomemployeur"];
  229. $pdf->SetX(25);
  230. $pdf->SetFillColor(199, 199, 199);
  231. $pdf->SetFont('Times', '', 8);
  232. $pdf->Cell(163, 12, " ", 0, 0, 'L', true);
  233. $pdf->SetFillColor(255, 255, 255);
  234. $pdf->SetX(25);
  235. $pdf->SetFont('Times', '', 8);
  236. $pdf->Cell(48, 4, $NomEmploye . " (" . $NumEmploye . ")", 0, 0, 'L');
  237. if (!isset($bHavEmployeur)) {
  238. $pdf->SetX(74);
  239. $pdf->SetFont('Times', '', 8);
  240. $pdf->Cell(72, 4, mb_convert_encoding($NomEmployeur, 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  241. } elseif (isset($bHavEmployeur) && $bHavEmployeur && $debutemploye == 0) {
  242. $pdf->SetXY(25, 45);
  243. $pdf->SetFont('Times', 'BI', 15);
  244. $pdf->Cell(72, 4, mb_convert_encoding($NomEmployeur, 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  245. $pdf->SetY(52);
  246. }
  247. $pdf->ln();
  248. $pdf->ln();
  249. //Détail par libérations
  250. $pdf->SetX(29);
  251. $pdf->SetFont('Times', '', 8);
  252. $pdf->Cell(18, 4, "Date", 0, 0, 'L');
  253. $pdf->SetX(52);
  254. $pdf->SetFont('Times', '', 8);
  255. $pdf->Cell(17, 4, "Type", 0, 0, 'L');
  256. $pdf->SetX(70);
  257. $pdf->SetFont('Times', '', 8);
  258. $pdf->Cell(12, 4, "Article", 0, 0, 'L');
  259. $pdf->SetX(86);
  260. $pdf->SetFont('Times', '', 8);
  261. $pdf->Cell(67, 4, "Commentaire", 0, 0, 'L');
  262. $pdf->SetX(154);
  263. $pdf->SetFont('Times', '', 8);
  264. $pdf->Cell(1, 4, mb_convert_encoding("Durée", 'ISO-8859-1', 'UTF-8'), 0, 0, 'L');
  265. $pdf->ln();
  266. $nomemploye = $champs["nomemploye"]; //0
  267. }
  268. $nomemployeur = $champs["nomemployeur"];
  269. $debutemployeur++;
  270. $TOperation = mb_convert_encoding($champs["toperation"], 'ISO-8859-1', 'UTF-8'); //4
  271. $NoArticle = mb_convert_encoding($champs["noarticle"], 'ISO-8859-1', 'UTF-8'); //5
  272. $DateLiberation = mb_convert_encoding(date("Y-m-d", $champs["dateliberation"]), 'ISO-8859-1', 'UTF-8'); //6
  273. $CDuree = mb_convert_encoding($champs["calculduree"], 'ISO-8859-1', 'UTF-8'); //7
  274. $Commentaire = mb_convert_encoding($champs["commentaire"], 'ISO-8859-1', 'UTF-8'); //9
  275. $pdf->SetX(29);
  276. $pdf->SetFont('Times', '', 8);
  277. $pdf->Cell(18, 4, $DateLiberation, 0, 0, 'L');
  278. $pdf->SetX(52);
  279. if ($TOperation == "Annulation") {
  280. $pdf->SetTextColor(255, 0, 0);
  281. }
  282. $pdf->SetFont('Times', '', 8);
  283. $pdf->Cell(17, 4, $TOperation, 0, 0, 'L');
  284. if ($TOperation == "Annulation") {
  285. $pdf->SetTextColor(0, 0, 0);
  286. }
  287. $pdf->SetX(70);
  288. $pdf->SetFont('Times', '', 8);
  289. $pdf->Cell(12, 4, $NoArticle, 0, 0, 'L');
  290. $pdf->SetX(154);
  291. if ($TOperation == "Annulation") {
  292. $pdf->SetTextColor(255, 0, 0);
  293. }
  294. $pdf->SetFont('Times', '', 8);
  295. $pdf->Cell(9, 4, sprintf("%02.2f / %dhrs", $CDuree, $CDuree * 8), 0, 0, 'R'); //1 journée correspond à 8 heures
  296. if ($TOperation == "Annulation") {
  297. $pdf->SetTextColor(0, 0, 0);
  298. }
  299. $pdf->SetX(86);
  300. $pdf->WordWrap($Commentaire, 67);
  301. $pdf->MultiCell(67, 4, $Commentaire);
  302. //Calcul par employé
  303. $calculduree = $calculduree + $CDuree;
  304. $nombredeligne++;
  305. //Calcul par employeur
  306. $calculduree2 = $calculduree2 + $CDuree;
  307. $nombredeligne2++;
  308. //Nombre de ligne totale
  309. $debutemploye++;
  310. }
  311. ajoutTotalSommaireEmploye($pdf, $nombredeligne, $calculduree);
  312. ajoutTotalSommaireEmployeur($pdf, $nombredeligne2, $calculduree2);
  313. $pdf->Output();