proweb.class.php 9.1 KB

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