rapport_liberations_paiement.php 14 KB

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