2
0

salaries.class.php 30 KB

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