proweb.class.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. class proweb
  3. {
  4. public static function getBase()
  5. {
  6. db::query("SELECT *,
  7. IF(contrat = 1, 'Actif', 'Désactivé') AS texteContrat,
  8. IF(actif = 1, 'Actif', 'Désactivé') AS texteActif,
  9. IF(RHBase = 1, 'Présent', 'Absent') AS texteRHBase,
  10. IF(error = 1, 'Erreur', 'Valide') AS texteError
  11. FROM " . DB_T_SALARIES_PROWEB);
  12. return db::resultset();
  13. }
  14. public static function getExcelById(int $_id)
  15. {
  16. db::query("SELECT * FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
  17. db::bind(':id', $_id);
  18. return db::single();
  19. }
  20. public static function deleteExcel(int $_id)
  21. {
  22. $tmp = self::getExcelById($_id);
  23. file::delete($tmp["md5"]);
  24. db::query("DELETE FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
  25. db::bind(':id', $_id);
  26. try {
  27. db::execute();
  28. return TRUE;
  29. } catch (Exception $ex) {
  30. return FALSE;
  31. }
  32. }
  33. public static function getExcel()
  34. {
  35. db::query("SELECT * FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1");
  36. return db::single();
  37. }
  38. public static function convertDateMoisAn(string $datetime)
  39. {
  40. $pieces = explode(" ", $datetime);
  41. $pieces2 = explode("-", $pieces[0]);
  42. return $pieces2[0] . $pieces2[1];
  43. }
  44. public static function convertDateMoisAnJour(string $datetime)
  45. {
  46. $pieces = explode(" ", $datetime);
  47. return $pieces[0];
  48. }
  49. public static function archiveExcelValues(array $_array)
  50. {
  51. $_return["error"] = 0;
  52. $_return["errorJson"] = array();
  53. // ----
  54. $_return["idProweb"] = $_array[0];
  55. $_return["nom"] = self::archiveExcelValuesNom($_array[1]);
  56. $_return["prenom"] = self::archiveExcelValuesPrenom($_array[2]);
  57. $_return["sexe"] = self::archiveExcelValuesSexe($_array[3]);
  58. $_return["jourEntree"] = self::archiveExcelValuesDate($_array[4]);
  59. $_return["jourSortie"] = self::archiveExcelValuesDate($_array[5]);
  60. $_return["actif"] = self::archiveExcelValuesActif($_array[6]);
  61. $_return["lieu"] = self::archiveExcelValuesLieu($_array[7]);
  62. $_return["loginId"] = self::archiveExcelValuesloginId($_array[8]);
  63. $verifRH = self::checksalarieByLoginId($_return["loginId"], $_return["nom"], $_return["prenom"]);
  64. if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
  65. $dateDataRH = intval(self::convertDateMoisAn(self::getExcel()["dateData"]));
  66. $dateDataProWeb = intval(self::convertDateMoisAn($_return["jourEntree"]));
  67. } else {
  68. $dateDataRH = $dateDataProWeb = 0;
  69. }
  70. if (empty($verifRH["id"]) and $_return["jourSortie"] == "N/A" and $dateDataRH > $dateDataProWeb) {
  71. $_return["contrat"] = $_return["actif"] = $_return["RHBase"] = $_return["loginIdRH"] = $_return["jourEntreeRH"] = "N/A";
  72. array_push($_return["errorJson"], "absent");
  73. } else {
  74. $_return["loginIdRH"] = (empty($verifRH["loginId"]) or $verifRH["loginId"] == $_return["loginId"]) ? NULL : $verifRH["loginId"];
  75. $_return["jourEntreeRH"] = (empty($verifRH["jourEntree"]) or self::convertDateMoisAnJour($verifRH["jourEntree"]) == $_return["jourEntree"]) ? NULL : self::convertDateMoisAnJour($verifRH["jourEntree"]);
  76. $_return["jourSortie"] = (isset($verifRH["jourSortie"])) ? $verifRH["jourSortie"] : $_return["jourSortie"];
  77. $_return["RHBase"] = (isset($verifRH["jourSortie"]) or empty($verifRH["id"])) ? 0 : 1;
  78. $_return["actif"] = (isset($verifRH["jourSortie"]) or empty($verifRH["id"])) ? 0 : 1;
  79. $_return["contrat"] = (isset($verifRH["contrat"])) ? $verifRH["contrat"] : 0;
  80. // ----
  81. if (!self::checkValuesNom($_return["nom"])) {
  82. $_return["error"] = 1;
  83. array_push($_return["errorJson"], "nom");
  84. }
  85. if (!self::checkValuesPrenom($_return["prenom"])) {
  86. $_return["error"] = 1;
  87. array_push($_return["errorJson"], "prenom");
  88. }
  89. if (!self::checkValuesloginId($_return["loginId"], $_return["loginIdRH"])) {
  90. $_return["error"] = 1;
  91. array_push($_return["errorJson"], "loginId");
  92. }
  93. if (!self::checkValuesJourEntree($_return["jourEntree"])) {
  94. $_return["error"] = 1;
  95. array_push($_return["errorJson"], "jourEntree");
  96. }
  97. if ($_return["jourEntreeRH"] != NULL and $_return["jourEntree"] != "N/A") {
  98. $_return["error"] = 1;
  99. array_push($_return["errorJson"], "jourEntree");
  100. }
  101. if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
  102. if ($dateDataRH > $dateDataProWeb) {
  103. if (!self::checkValuesRHBase($_return["RHBase"], $_return["actif"], $_return["jourSortie"])) {
  104. $_return["error"] = 1;
  105. array_push($_return["errorJson"], "RHBase");
  106. }
  107. }
  108. }
  109. // if ($_return["contrat"] == 0 AND $_return["jourSortie"] == "N/A") {
  110. // $_return["error"] = 1;
  111. // array_push($_return["errorJson"], "contrat");
  112. // }
  113. }
  114. $_return["errorJson"] = (!empty($_return["errorJson"][0])) ? json_encode($_return["errorJson"]) : NULL;
  115. return $_return;
  116. }
  117. // Les initialisations
  118. private static function archiveExcelValuesDate(string $_string)
  119. {
  120. if(!isset($_string) or $_string == "00-00-0000"){
  121. return "N/A";
  122. } else {
  123. return str_replace(" 00:00:00", "", $_string);
  124. }
  125. }
  126. private static function archiveExcelValuesSexe(string $_string)
  127. {
  128. return (empty($_string)) ? "N/A" : $_string;
  129. }
  130. private static function archiveExcelValuesloginId(string $_string)
  131. {
  132. return core::cleanAccent($_string);
  133. }
  134. private static function archiveExcelValuesNom(string $_string)
  135. {
  136. return core::cleanAccent($_string);
  137. }
  138. private static function archiveExcelValuesPrenom(string $_string)
  139. {
  140. return core::cleanAccent($_string);
  141. }
  142. private static function archiveExcelValuesActif(string $_string)
  143. {
  144. if ($_string == "Actif") {
  145. return 1;
  146. } elseif ($_string == "Inactif") {
  147. return 0;
  148. } else {
  149. return "N/A";
  150. }
  151. }
  152. private static function archiveExcelValuesLieu(string $_string)
  153. {
  154. return (empty($_string)) ? "N/A" : $_string;
  155. }
  156. // Les checks
  157. public static function checkSalarieByLoginId(string $_loginId, string $_nom = NULL, string $_prenom = NULL)
  158. {
  159. // Récupération des données de l'excel au format Json
  160. if ($_nom == NULL) {
  161. db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId");
  162. } else {
  163. db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId OR (nom = :nom AND prenom = :prenom)");
  164. db::bind(':nom', $_nom);
  165. db::bind(':prenom', $_prenom);
  166. }
  167. db::bind(':loginId', $_loginId);
  168. return db::single();
  169. }
  170. private static function checkValuesActif(string $_string)
  171. {
  172. return ($_string == "N/A") ? FALSE : TRUE;
  173. }
  174. private static function checkValuesloginId(string $_idLogin, string $_idLoginRH = NULL)
  175. {
  176. if ($_idLoginRH != NULL) {
  177. if (empty(self::checkSalarieByLoginId($_idLogin)["id"])) {
  178. return FALSE;
  179. } elseif (core::checkStringOnly($_idLogin)) {
  180. return FALSE;
  181. } elseif (strlen($_idLogin) > 10) {
  182. return FALSE;
  183. } elseif (empty($_idLogin)) {
  184. return FALSE;
  185. } else {
  186. return TRUE;
  187. }
  188. } else {
  189. return TRUE;
  190. }
  191. }
  192. private static function checkValuesRHBase(string $_string, int $_actif, string $_sortie)
  193. {
  194. return ($_string == 0 and $_actif == 1 and $_sortie == "N/A") ? FALSE : TRUE;
  195. }
  196. private static function checkValuesJourEntree(string $_string)
  197. {
  198. return ($_string == "N/A") ? FALSE : TRUE;
  199. }
  200. private static function checkValuesJourSortie(string $_string, int $_actif)
  201. {
  202. return ($_string != "N/A" and $_actif == 1) ? FALSE : TRUE;
  203. }
  204. private static function checkValuesNom(string $_string)
  205. {
  206. return (empty($_string)) ? FALSE : TRUE;
  207. }
  208. private static function checkValuesPrenom(string $_string)
  209. {
  210. return (empty($_string)) ? FALSE : TRUE;
  211. }
  212. private static function checkValuesSexe(string $_string)
  213. {
  214. return ($_string == NULL or ($_string != "M." and $_string != "Mme")) ? FALSE : TRUE;
  215. }
  216. private static function checkValuesLieu(string $_string)
  217. {
  218. return (empty($_string)) ? FALSE : TRUE;
  219. }
  220. public static function downloadExcel(int $_id, string $_file)
  221. {
  222. $data = base64_decode(self::getExcelById($_id)["file"]);
  223. $fileTemp = fopen(DIR_TEMP . $_file, "w");
  224. file_put_contents(DIR_TEMP . $_file, $data);
  225. fclose($fileTemp);
  226. return DIR_TEMP . $_file;
  227. }
  228. }