2
0

salaries.class.php 30 KB

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