salaries.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <?php
  2. class salaries
  3. {
  4. public static function clean_tmp()
  5. {
  6. // Nettoyage de la table temporaire des salairés
  7. db::query("TRUNCATE " . DB_T_TEMP_SALARIES);
  8. db::execute();
  9. }
  10. public static function clean_accent(string $_data)
  11. {
  12. $search = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
  13. $replace = array('A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 'a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y');
  14. $return = str_replace($search, $replace, $_data);
  15. return strtoupper($return);
  16. }
  17. public static function get_salarieByidLocal(int $_idLocal)
  18. {
  19. // Récupération des données de l'excel au format Json
  20. db::query("SELECT * FROM " . DB_T_SALARIES . " WHERE idLocal = :idLocal");
  21. db::bind(':idLocal', $_idLocal);
  22. return db::single();
  23. }
  24. public static function get_salarieByLoginId(string $_loginId)
  25. {
  26. // Récupération des données de l'excel au format Json
  27. db::query("SELECT * FROM " . DB_T_SALARIES . " WHERE loginId = :loginId");
  28. db::bind(':loginId', $_loginId);
  29. return db::single();
  30. }
  31. public static function get_salarieById(int $_id)
  32. {
  33. // Récupération des données de l'excel au format Json
  34. db::query("SELECT * FROM " . DB_T_SALARIES . " WHERE id = :id");
  35. db::bind(':id', $_id);
  36. return db::single();
  37. }
  38. public static function get_salaries()
  39. {
  40. db::query("SELECT "
  41. . "idLocal, "
  42. . "loginId, "
  43. . "nom, "
  44. . "prenom, "
  45. . "sexe, "
  46. . "contrat, "
  47. . "DATE_FORMAT(jourEntree, '%Y-%m-%d') AS jourEntree, "
  48. . "DATE_FORMAT(repriseContrat, '%Y-%m-%d') AS repriseContrat, "
  49. . "DATE_FORMAT(jourSortie, '%Y-%m-%d') AS jourSortie, "
  50. . "sel, "
  51. . "lieu, "
  52. . "cree, "
  53. . "maj, "
  54. . "actif "
  55. . "FROM " . DB_T_SALARIES);
  56. return db::resultset();
  57. }
  58. public static function lastExcel()
  59. {
  60. db::query("SELECT MAX(id) AS id FROM " . DB_T_EXCEL);
  61. return db::single()["id"];
  62. }
  63. public static function lastExcel_forSFTP()
  64. {
  65. db::query("SELECT MAX(id) AS id FROM " . DB_T_EXCEL . " WHERE forSFTP IS NOT NULL");
  66. return db::single()["id"];
  67. }
  68. public static function get_excel_Md5(int $_id)
  69. {
  70. // Récupération des données de l'excel au format Json
  71. db::query("SELECT md5 FROM " . DB_T_EXCEL . " WHERE id = :id");
  72. db::bind(':id', $_id);
  73. return db::single()["md5"];
  74. }
  75. public static function get_excel_Json_forSFTP(int $_id)
  76. {
  77. // Récupération des données de l'excel au format Json
  78. db::query("SELECT forSFTP, md5forSFTP, createForSFTP, contratForSFTP FROM " . DB_T_EXCEL . " WHERE id = :id");
  79. db::bind(':id', $_id);
  80. return db::single();
  81. }
  82. public static function get_excel_Json_transfer_forSFTP(string $_md5)
  83. {
  84. // Récupération des données de l'excel au format Json
  85. db::query("SELECT transfertForSFTP FROM " . DB_T_EXCEL . " WHERE md5forSFTP = :md5forSFTP");
  86. db::bind(':md5forSFTP', $_md5);
  87. return db::single()["transfertForSFTP"];
  88. }
  89. public static function get_excel_json(int $_id)
  90. {
  91. // Récupération des données de l'excel au format Json
  92. db::query("SELECT json FROM " . DB_T_EXCEL . " WHERE id = :id");
  93. db::bind(':id', $_id);
  94. return base64_decode(db::single()["json"]);
  95. }
  96. public static function get_excel_name(int $_id)
  97. {
  98. // Récupération des données de l'excel au format Json
  99. db::query("SELECT
  100. " .DB_T_EXCEL. ".md5,
  101. " .DB_T_FILES. ".name
  102. FROM " . DB_T_EXCEL . "
  103. INNER JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL . ".md5 = " . DB_T_FILES . ".id
  104. WHERE " . DB_T_EXCEL . ".id = :id");
  105. db::bind(':id', $_id);
  106. return db::single()["name"];
  107. }
  108. public static function excel_update_in_progress(int $_id, int $_action = 1)
  109. {
  110. db::query("UPDATE
  111. " . DB_T_EXCEL . "
  112. SET inProgress = :inProgress
  113. WHERE id = :id");
  114. db::bind(':inProgress', $_action);
  115. db::bind(':id', $_id);
  116. try {
  117. db::execute();
  118. return TRUE;
  119. } catch (Exception $e) {
  120. return FALSE;
  121. }
  122. }
  123. public static function delete_excel(int $_id)
  124. {
  125. db::query("DELETE FROM " . DB_T_EXCEL . " WHERE id = :id");
  126. db::bind(':id', $_id);
  127. try {
  128. db::execute();
  129. return TRUE;
  130. } catch (Exception $e) {
  131. return FALSE;
  132. }
  133. }
  134. public static function excel_get_in_progress()
  135. {
  136. db::query("SELECT
  137. " .DB_T_EXCEL. ".id,
  138. " .DB_T_EXCEL. ".md5,
  139. " .DB_T_FILES. ".name
  140. FROM " . DB_T_EXCEL . "
  141. INNER JOIN " . DB_T_FILES . " ON " . DB_T_EXCEL . ".md5 = " . DB_T_FILES . ".id
  142. WHERE " . DB_T_EXCEL . ".inProgress = 1");
  143. return db::single();
  144. }
  145. public static function get_excel_array(int $_id)
  146. {
  147. return json_decode(self::get_excel_json($_id));
  148. }
  149. public static function excel_to_mysql(array $_value)
  150. {
  151. if ($_value[4] == "Actif") {
  152. $_value[4] = 1;
  153. } else {
  154. $_value[4] = 0;
  155. }
  156. return array(
  157. "idLocal" => $_value[0],
  158. "loginId" => $_value[7],
  159. "nom" => self::clean_accent($_value[1]),
  160. "prenom" => self::clean_accent($_value[2]),
  161. "sexe" => $_value[3],
  162. "contrat" => $_value[4],
  163. "jourEntree" => $_value[5],
  164. "lieu" => self::clean_accent($_value[6]),
  165. "actif" => 1
  166. );
  167. }
  168. public static function create_tmp(string $_excel)
  169. {
  170. db::query("SELECT idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif FROM " . DB_T_SALARIES);
  171. $row = db::resultset();
  172. if (!empty($row)) {
  173. foreach ($row as $salaries) {
  174. db::query("INSERT INTO " . DB_T_TEMP_SALARIES . " (idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif, new, excel) "
  175. . "VALUES (:idLocal, :loginId, :nom, :prenom, :sexe, :contrat, :jourEntree, :lieu, :actif, :new, :excel)");
  176. db::bind(':idLocal', $salaries["idLocal"]);
  177. db::bind(':loginId', $salaries["loginId"]);
  178. db::bind(':nom', $salaries["nom"]);
  179. db::bind(':prenom', $salaries["prenom"]);
  180. db::bind(':sexe', $salaries["sexe"]);
  181. db::bind(':contrat', $salaries["contrat"]);
  182. db::bind(':jourEntree', $salaries["jourEntree"]);
  183. db::bind(':lieu', $salaries["lieu"]);
  184. db::bind(':actif', 0);
  185. db::bind(':new', 0);
  186. db::bind(':excel', $_excel);
  187. db::execute();
  188. }
  189. }
  190. }
  191. public static function update_inactive_temp_salarie()
  192. {
  193. db::query("UPDATE " . DB_T_TEMP_SALARIES . " SET "
  194. . "log = :log "
  195. . "WHERE actif = :actif");
  196. db::bind(':log', "DISABLE");
  197. db::bind(':actif', 0);
  198. try {
  199. db::execute();
  200. return TRUE;
  201. } catch (Exception $e) {
  202. return FALSE;
  203. }
  204. }
  205. public static function update_json_excel(array $_json)
  206. {
  207. db::query("UPDATE " . DB_T_EXCEL . " SET "
  208. . "goMysql = current_timestamp(), "
  209. . "log = :log "
  210. . "WHERE id = :id");
  211. db::bind(':log', $_json["json"]);
  212. db::bind(':id', $_json["excel"]);
  213. try {
  214. db::execute();
  215. return TRUE;
  216. } catch (Exception $e) {
  217. return FALSE;
  218. }
  219. }
  220. public static function update_temp_salaries(array $_new_salaries, string $_excel)
  221. {
  222. $cp["INSERT"]["SUCCESS"] = 0;
  223. $cp["INSERT"]["ERROR"] = 0;
  224. $cp["UPDATE"]["SUCCESS"] = 0;
  225. $cp["UPDATE"]["ERROR"] = 0;
  226. $changeStatutContrat = NULL;
  227. foreach ($_new_salaries as $key => $value) {
  228. $sql = $change = NULL;
  229. if ($key > 0) {
  230. $tmp = self::excel_to_mysql($value);
  231. $salarieByidLocal = self::get_salarieByidLocal($tmp["idLocal"]);
  232. if (isset($salarieByidLocal["idLocal"])) {
  233. $tmp_sql = "";
  234. if ($tmp["loginId"] != $salarieByidLocal["loginId"]) {
  235. $tmp_sql .= "loginId = :loginId, ";
  236. $change = 1;
  237. }
  238. if ($tmp["contrat"] != $salarieByidLocal["contrat"]) {
  239. $tmp_sql .= "contrat = :contrat, ";
  240. $change = 1;
  241. // Indentifier les cas d'arrêt ou de reprise de contrat
  242. if ($tmp["contrat"] == 0 and $salarieByidLocal["contrat"] == 1) {
  243. $changeStatutContrat[$salarieByidLocal["idLocal"]] = "end";
  244. } else {
  245. $changeStatutContrat[$salarieByidLocal["idLocal"]] = "start";
  246. }
  247. // Indentifier les cas d'arrêt ou de reprise de contrat
  248. }
  249. if ($tmp["lieu"] != $salarieByidLocal["lieu"]) {
  250. $tmp_sql .= "lieu = :lieu, ";
  251. $change = 1;
  252. }
  253. if ($tmp["actif"] != $salarieByidLocal["actif"]) {
  254. $change = 1;
  255. } else {
  256. $forSFTP["actif"] = NULL;
  257. }
  258. $tmp_sql .= "actif = :actif, ";
  259. if ($change == 1) {
  260. db::query($sql = "UPDATE " . DB_T_TEMP_SALARIES . " SET " . $tmp_sql . " log = :log WHERE idLocal = :idLocal");
  261. $log = NULL;
  262. if ($tmp["loginId"] != $salarieByidLocal["loginId"]) {
  263. db::bind(':loginId', $tmp["loginId"]);
  264. if ($log == "") {
  265. $log .= "UPDATE ";
  266. }
  267. $log .= "loginId ";
  268. }
  269. if ($tmp["contrat"] != $salarieByidLocal["contrat"]) {
  270. db::bind(':contrat', $tmp["contrat"]);
  271. if ($log == "") {
  272. $log .= "UPDATE ";
  273. }
  274. $log .= "contrat ";
  275. }
  276. if ($tmp["lieu"] != $salarieByidLocal["lieu"]) {
  277. db::bind(':lieu', $tmp["lieu"]);
  278. if ($log == "") {
  279. $log .= "UPDATE ";
  280. }
  281. $log .= "lieu ";
  282. }
  283. if ($tmp["actif"] != $salarieByidLocal["actif"]) {
  284. if ($log == "") {
  285. $log .= "UPDATE ";
  286. }
  287. $log .= "actif ";
  288. }
  289. db::bind(':actif', 1);
  290. if ($change == 1) {
  291. db::bind(':log', $log);
  292. } else {
  293. db::bind(':log', NULL);
  294. }
  295. db::bind(':idLocal', $tmp["idLocal"]);
  296. try {
  297. db::execute();
  298. $cp["UPDATE"]["SUCCESS"]++;
  299. } catch (Exception $ex) {
  300. $cp["UPDATE"]["ERROR"]++;
  301. }
  302. } else {
  303. db::query("UPDATE " . DB_T_TEMP_SALARIES . " SET actif = :actif WHERE idLocal = :idLocal");
  304. db::bind(':actif', 1);
  305. db::bind(':idLocal', $tmp["idLocal"]);
  306. db::execute();
  307. }
  308. } else {
  309. db::query("INSERT INTO " . DB_T_TEMP_SALARIES . " (idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif, new, excel, log) "
  310. . "VALUES (:idLocal, :loginId, :nom, :prenom, :sexe, :contrat, :jourEntree, :lieu, :actif, :new, :excel, :log)");
  311. db::bind(':idLocal', $tmp["idLocal"]);
  312. db::bind(':loginId', $tmp["loginId"]);
  313. db::bind(':nom', $tmp["nom"]);
  314. db::bind(':prenom', $tmp["prenom"]);
  315. db::bind(':sexe', $tmp["sexe"]);
  316. db::bind(':contrat', $tmp["contrat"]);
  317. db::bind(':jourEntree', $tmp["jourEntree"]);
  318. db::bind(':lieu', $tmp["lieu"]);
  319. db::bind(':actif', 1);
  320. db::bind(':new', 1);
  321. db::bind(':excel', $_excel);
  322. db::bind(':log', "INSERT");
  323. try {
  324. db::execute();
  325. $cp["INSERT"]["SUCCESS"]++;
  326. } catch (Exception $ex) {
  327. $cp["INSERT"]["ERROR"]++;
  328. }
  329. }
  330. }
  331. }
  332. ($changeStatutContrat != NULL) ? self::recContratForSFTP($_excel, $changeStatutContrat) : "";
  333. if ($cp["INSERT"]["ERROR"] != 0 or $cp["INSERT"]["ERROR"] != 0) {
  334. alert::recError("Une erreur s'est produite lors de la mise en cache.");
  335. } else {
  336. alert::recSuccess("La mise en cache a été réalisée avec succès.");
  337. }
  338. }
  339. private static function recContratForSFTP(int $_idExcel, array $_data)
  340. {
  341. db::query("UPDATE " . DB_T_EXCEL . " SET "
  342. . "contratForSFTP = :contratForSFTP "
  343. . "WHERE id = :id");
  344. db::bind(':contratForSFTP', json_encode($_data));
  345. db::bind(':id', $_idExcel);
  346. try {
  347. db::execute();
  348. return TRUE;
  349. } catch (Exception $e) {
  350. return FALSE;
  351. }
  352. }
  353. public static function update_salaries(int $_excel)
  354. {
  355. $cp["INSERT"]["SUCCESS"] = 0;
  356. $cp["INSERT"]["ERROR"] = 0;
  357. $cp["DISABLE"]["SUCCESS"] = 0;
  358. $cp["DISABLE"]["ERROR"] = 0;
  359. $cp["UPDATE"]["SUCCESS"] = 0;
  360. $cp["UPDATE"]["ERROR"] = 0;
  361. $cp["forSFTP"] = 0;
  362. $updateContrat = json_decode(self::get_excel_Json_forSFTP($_excel)["contratForSFTP"], TRUE);
  363. $jourSortie = date("Y-m-d 00:00:00");
  364. $dateReprise = date("Y-m-d 00:00:00");
  365. db::query("SELECT idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif, new, log FROM " . DB_T_TEMP_SALARIES);
  366. $row = db::resultset();
  367. if (!empty($row)) {
  368. foreach ($row as $key => $salaries) {
  369. $forSFTP = $reprise = NULL;
  370. if ($salaries["log"] == NULL) {
  371. $forSFTP["action"] = "valide";
  372. $forSFTP["idLocal"] = $salaries["idLocal"];
  373. $forSFTP["loginId"] = $salaries["loginId"];
  374. $forSFTP["contrat"] = $salaries["contrat"];
  375. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  376. $forSFTP["jourSortie"] = NULL;
  377. $forSFTP["repriseContrat"] = NULL;
  378. $forSFTP["actif"] = 1;
  379. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  380. } elseif ($salaries["log"] == "INSERT") {
  381. db::query("INSERT INTO " . DB_T_SALARIES . " (idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, jourSortie, sel, lieu, actif) "
  382. . "VALUES (:idLocal, :loginId, :nom, :prenom, :sexe, :contrat, :jourEntree, :jourSortie, :sel, :lieu, :actif)");
  383. db::bind(':idLocal', $salaries["idLocal"]);
  384. db::bind(':loginId', $salaries["loginId"]);
  385. db::bind(':nom', $salaries["nom"]);
  386. db::bind(':prenom', $salaries["prenom"]);
  387. db::bind(':sexe', $salaries["sexe"]);
  388. db::bind(':contrat', $salaries["contrat"]);
  389. db::bind(':jourEntree', $salaries["jourEntree"]);
  390. db::bind(':jourSortie', NULL);
  391. db::bind(':sel', md5($salaries["idLocal"] . time() . rand(100000000000, 999999999999)));
  392. db::bind(':lieu', $salaries["lieu"]);
  393. db::bind(':actif', $salaries["actif"]);
  394. try {
  395. db::execute();
  396. $cp["INSERT"]["SUCCESS"]++;
  397. } catch (Exception $ex) {
  398. $cp["INSERT"]["ERROR"]++;
  399. }
  400. $forSFTP["action"] = "insert";
  401. $forSFTP["idLocal"] = $salaries["idLocal"];
  402. $forSFTP["loginId"] = $salaries["loginId"];
  403. $forSFTP["contrat"] = $salaries["contrat"];
  404. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  405. $forSFTP["jourSortie"] = NULL;
  406. $forSFTP["repriseContrat"] = NULL;
  407. $forSFTP["actif"] = 1;
  408. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  409. } elseif ($salaries["log"] == "DISABLE") {
  410. db::query("UPDATE " . DB_T_SALARIES . " SET "
  411. . "jourSortie = :jourSortie, "
  412. . "maj = CURRENT_TIMESTAMP(), "
  413. . "actif = :actif "
  414. . "WHERE idLocal = :idLocal");
  415. db::bind(':jourSortie', $jourSortie);
  416. db::bind(':actif', 0);
  417. db::bind(':idLocal', $salaries["idLocal"]);
  418. try {
  419. db::execute();
  420. $cp["DISABLE"]["SUCCESS"]++;
  421. } catch (Exception $ex) {
  422. $cp["DISABLE"]["ERROR"]++;
  423. }
  424. $forSFTP["action"] = "disabled";
  425. $forSFTP["idLocal"] = $salaries["idLocal"];
  426. $forSFTP["loginId"] = $salaries["loginId"];
  427. $forSFTP["contrat"] = $salaries["contrat"];
  428. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  429. $forSFTP["jourSortie"] = $jourSortie;
  430. $forSFTP["repriseContrat"] = NULL;
  431. $forSFTP["actif"] = 0;
  432. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  433. } else {
  434. $forSFTP["action"] = "update";
  435. $forSFTP["idLocal"] = $salaries["idLocal"];
  436. $forSFTP["loginId"] = $salaries["loginId"];
  437. $forSFTP["contrat"] = $salaries["contrat"];
  438. if (is_array($updateContrat) and array_key_exists($salaries["idLocal"], $updateContrat)) {
  439. if ($updateContrat[$salaries["idLocal"]] == "start") {
  440. $forSFTP["jourEntree"] = $dateReprise;
  441. $forSFTP["jourSortie"] = NULL;
  442. $forSFTP["repriseContrat"] = $dateReprise;
  443. $forSFTP["actif"] = 1;
  444. $reprise = $dateReprise;
  445. } elseif ($updateContrat[$salaries["idLocal"]] == "end") {
  446. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  447. $forSFTP["jourSortie"] = $jourSortie;
  448. $forSFTP["repriseContrat"] = NULL;
  449. $forSFTP["actif"] = 0;
  450. }
  451. } else {
  452. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  453. $forSFTP["jourSortie"] = NULL;
  454. $forSFTP["repriseContrat"] = NULL;
  455. $forSFTP["actif"] = $salaries["actif"];
  456. }
  457. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  458. db::query("UPDATE " . DB_T_SALARIES . " SET "
  459. . "loginId = :loginId, "
  460. . "contrat = :contrat, "
  461. . "lieu = :lieu, "
  462. . "repriseContrat = :repriseContrat, "
  463. . "jourSortie = :jourSortie, "
  464. . "maj = CURRENT_TIMESTAMP(), "
  465. . "actif = :actif "
  466. . "WHERE idLocal = :idLocal");
  467. db::bind(':loginId', $salaries["loginId"]);
  468. db::bind(':contrat', $salaries["contrat"]);
  469. db::bind(':lieu', $salaries["lieu"]);
  470. db::bind(':repriseContrat', $reprise);
  471. db::bind(':jourSortie', NULL);
  472. db::bind(':actif', $salaries["actif"]);
  473. db::bind(':idLocal', $salaries["idLocal"]);
  474. try {
  475. db::execute();
  476. $cp["UPDATE"]["SUCCESS"]++;
  477. } catch (Exception $ex) {
  478. $cp["UPDATE"]["ERROR"]++;
  479. }
  480. }
  481. }
  482. if ($cp["INSERT"]["SUCCESS"] == 1) {
  483. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salarié traité.");
  484. } elseif ($cp["INSERT"]["SUCCESS"] > 1) {
  485. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salariés traités.");
  486. }
  487. if ($cp["DISABLE"]["SUCCESS"] == 1) {
  488. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salarié traité.");
  489. } elseif ($cp["DISABLE"]["SUCCESS"] > 1) {
  490. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salariés traités.");
  491. }
  492. if ($cp["UPDATE"]["SUCCESS"] == 1) {
  493. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salarié traité.");
  494. } elseif ($cp["UPDATE"]["SUCCESS"] > 1) {
  495. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salariés traités.");
  496. }
  497. if ($cp["INSERT"]["ERROR"] == 1) {
  498. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salarié non traité.");
  499. } elseif ($cp["INSERT"]["ERROR"] > 1) {
  500. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salariés non traités.");
  501. }
  502. if ($cp["DISABLE"]["ERROR"] == 1) {
  503. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salarié non traité.");
  504. } elseif ($cp["DISABLE"]["ERROR"] > 1) {
  505. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salariés non traités.");
  506. }
  507. if ($cp["UPDATE"]["ERROR"] == 1) {
  508. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salarié non traité.");
  509. } elseif ($cp["UPDATE"]["ERROR"] > 1) {
  510. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salariés non traités.");
  511. }
  512. (self::recForSFTP($SFTP, $_excel)) ? alert::recSuccess("Les données d'exportation pour ProWeb ont été enregistrées") : alert::recError("Les données d'exportation pour ProWeb n'ont pas pu être enregistrées");
  513. }
  514. }
  515. private static function recForSFTP(array $_array, int $_idExcel)
  516. {
  517. $json = json_encode($_array);
  518. db::query("UPDATE " . DB_T_EXCEL . " SET "
  519. . "forSFTP = :forSFTP ,"
  520. . "md5forSFTP = :md5forSFTP "
  521. . "WHERE id = :id");
  522. db::bind(':forSFTP', $json);
  523. db::bind(':md5forSFTP', md5($json));
  524. db::bind(':id', $_idExcel);
  525. try {
  526. db::execute();
  527. return TRUE;
  528. } catch (Exception $e) {
  529. return FALSE;
  530. }
  531. }
  532. public static function create_rapport()
  533. {
  534. $log = NULL;
  535. db::query("SELECT idLocal, loginId, nom, prenom, contrat, jourEntree, lieu, excel, log FROM " . DB_T_TEMP_SALARIES . " WHERE log IS NOT NULL");
  536. $row = db::resultset();
  537. if ($row != NULL) {
  538. foreach ($row as $key => $salaries) {
  539. if ($salaries["log"] == "INSERT") {
  540. $log["json"][] = array(
  541. "action" => "INSERT",
  542. "excel" => $salaries["excel"],
  543. "idLocal" => $salaries["idLocal"],
  544. "loginId" => $salaries["loginId"],
  545. "nom" => $salaries["nom"],
  546. "prenom" => $salaries["prenom"],
  547. "jourEntree" => $salaries["jourEntree"],
  548. "contrat" => $salaries["contrat"],
  549. "lieu" => $salaries["lieu"]
  550. );
  551. } elseif ($salaries["log"] == "DISABLE") {
  552. $log["json"][] = array(
  553. "action" => "DISABLE",
  554. "excel" => $salaries["excel"],
  555. "idLocal" => $salaries["idLocal"],
  556. "loginId" => $salaries["loginId"],
  557. "nom" => $salaries["nom"],
  558. "prenom" => $salaries["prenom"],
  559. "jourEntree" => $salaries["jourEntree"],
  560. "contrat" => $salaries["contrat"],
  561. "lieu" => $salaries["lieu"]
  562. );
  563. } else {
  564. $tmp_log = array("action" => "UPDATE", "excel" => $salaries["excel"], "nom" => $salaries["nom"], "prenom" => $salaries["prenom"]);
  565. $tmp = explode(" ", $salaries["log"]);
  566. foreach ($tmp as $key => $value) {
  567. if ($key > 0) {
  568. switch ($value) {
  569. case "loginId":
  570. $tmp_log["loginId"] = $salaries["loginId"];
  571. break;
  572. case "contrat":
  573. $tmp_log["contrat"] = $salaries["contrat"];
  574. break;
  575. case "lieu":
  576. $tmp_log["lieu"] = $salaries["lieu"];
  577. break;
  578. }
  579. }
  580. }
  581. $log["json"][] = $tmp_log;
  582. }
  583. }
  584. $log["json"] = json_encode($log["json"]);
  585. $log["excel"] = $salaries["excel"];
  586. } else {
  587. $log["json"] = NULL;
  588. $log["excel"] = NULL;
  589. }
  590. return $log;
  591. }
  592. public static function count_tmp_salaries()
  593. {
  594. db::query("SELECT COUNT(*) AS nb FROM " . DB_T_TEMP_SALARIES);
  595. return db::single()["nb"];
  596. }
  597. public static function dataForSFTP()
  598. {
  599. $lastExcel = self::lastExcel_forSFTP();
  600. $forSFTP = self::get_excel_Json_forSFTP($lastExcel);
  601. $finalSalarie = NULL;
  602. $csv = "OD_" . date("d-m-Y") . ".csv";
  603. $tmpSFTP = fopen(SFTP_LOCAL . $csv, "w");
  604. fputcsv($tmpSFTP, array("loginId", "jourSortie"), ";");
  605. foreach (json_decode($forSFTP["forSFTP"], TRUE) as $salarie) {
  606. $tmpSalarie = NULL;
  607. if (isset($salarie["loginId"]) and $salarie["loginId"] != "" and isset($salarie["jourSortie"])) {
  608. $tmpSalarie["loginId"] = $salarie["loginId"];
  609. $tmpSalarie["jourSortie"] = $salarie["jourSortie"];
  610. fputcsv($tmpSFTP, $tmpSalarie, ";");
  611. }
  612. }
  613. self::recDateForSFTP($lastExcel);
  614. }
  615. private static function recDateForSFTP(int $_idExcel)
  616. {
  617. db::query("UPDATE " . DB_T_EXCEL . " SET "
  618. . "createForSFTP = CURRENT_TIMESTAMP() "
  619. . "WHERE id = :id");
  620. db::bind(':id', $_idExcel);
  621. try {
  622. db::execute();
  623. return TRUE;
  624. } catch (Exception $e) {
  625. return FALSE;
  626. }
  627. }
  628. public static function ifSubmitLastForSFTP()
  629. {
  630. $lastExcel = self::lastExcel();
  631. $forSFTP = self::get_excel_Json_forSFTP($lastExcel);
  632. return (@$forSFTP["md5forSFTP"] != NULL and @$forSFTP["createForSFTP"] == NULL) ? TRUE : FALSE;
  633. }
  634. public static function checkSalarieByMatricule(string $_string)
  635. {
  636. db::query("SELECT "
  637. . "id, "
  638. . "nom, "
  639. . "prenom, "
  640. . "contrat, "
  641. . "actif "
  642. . "FROM " . DB_T_SALARIES . " "
  643. . "WHERE idLocal = :idLocal");
  644. db::bind(':idLocal', intval($_string));
  645. $salarie = db::single();
  646. if (isset($salarie["id"])) {
  647. if ($salarie["actif"] == 0) {
  648. $return["error"] = "<div>Ce matricule n'est plus sous contrat Capgemini Consulting.</div>";
  649. $return["class"] = "danger";
  650. } elseif ($salarie["contrat"] == 0) {
  651. $return["error"] = "<div>Ce matricule est en suspension de contrat chez Capgemini Consulting mais peut-être pris en charge par le CSE.</div>";
  652. $return["class"] = "success";
  653. } else {
  654. $return["success"] = "<div>Ce matricule est sous contrat Capgemini Consulting.</div>";
  655. $return["class"] = "success";
  656. }
  657. $return["identity"] = $salarie["prenom"] . " " . $salarie["nom"];
  658. } else {
  659. $return["error"] = "<div>Ce matricule n'est pas ou plus rattaché à Capgemini Consulting.</div>";
  660. $return["class"] = "danger";
  661. }
  662. return $return;
  663. }
  664. }