2
0

salaries.class.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. if(!is_int($tmp["idLocal"])) {
  242. alert::recError("Une valeur dans le fichie n'est pas conforme à l'attendu (Ligne " . $key . ")");
  243. self::cleanTmp();
  244. self::excelUpdateInProgress(self::lastExcel(), 0);
  245. return FALSE;
  246. }
  247. $salarieByidLocal = self::getSalarieByidLocal($tmp["idLocal"]);
  248. if (isset($salarieByidLocal["idLocal"])) {
  249. $tmp_sql = "";
  250. if ($tmp["loginId"] != $salarieByidLocal["loginId"]) {
  251. $tmp_sql .= "loginId = :loginId, ";
  252. $change = 1;
  253. }
  254. if ($tmp["contrat"] != $salarieByidLocal["contrat"]) {
  255. $tmp_sql .= "contrat = :contrat, ";
  256. $change = 1;
  257. // Indentifier les cas d'arrêt ou de reprise de contrat
  258. if ($tmp["contrat"] == 0 and $salarieByidLocal["contrat"] == 1) {
  259. $changeStatutContrat[$salarieByidLocal["idLocal"]] = "end";
  260. } else {
  261. $changeStatutContrat[$salarieByidLocal["idLocal"]] = "start";
  262. }
  263. // Indentifier les cas d'arrêt ou de reprise de contrat
  264. }
  265. if ($tmp["lieu"] != $salarieByidLocal["lieu"]) {
  266. $tmp_sql .= "lieu = :lieu, ";
  267. $change = 1;
  268. }
  269. if ($tmp["actif"] != $salarieByidLocal["actif"]) {
  270. $change = 1;
  271. } else {
  272. $forSFTP["actif"] = NULL;
  273. }
  274. $tmp_sql .= "actif = :actif, ";
  275. if ($change == 1) {
  276. db::query($sql = "UPDATE " . DB_T_TEMP_SALARIES . " SET " . $tmp_sql . " log = :log WHERE idLocal = :idLocal");
  277. $log = NULL;
  278. if ($tmp["loginId"] != $salarieByidLocal["loginId"]) {
  279. db::bind(':loginId', $tmp["loginId"]);
  280. if ($log == "") {
  281. $log .= "UPDATE ";
  282. }
  283. $log .= "loginId ";
  284. }
  285. if ($tmp["contrat"] != $salarieByidLocal["contrat"]) {
  286. db::bind(':contrat', $tmp["contrat"]);
  287. if ($log == "") {
  288. $log .= "UPDATE ";
  289. }
  290. $log .= "contrat ";
  291. }
  292. if ($tmp["lieu"] != $salarieByidLocal["lieu"]) {
  293. db::bind(':lieu', $tmp["lieu"]);
  294. if ($log == "") {
  295. $log .= "UPDATE ";
  296. }
  297. $log .= "lieu ";
  298. }
  299. if ($tmp["actif"] != $salarieByidLocal["actif"]) {
  300. if ($log == "") {
  301. $log .= "UPDATE ";
  302. }
  303. $log .= "actif ";
  304. }
  305. db::bind(':actif', 1);
  306. if ($change == 1) {
  307. db::bind(':log', $log);
  308. } else {
  309. db::bind(':log', NULL);
  310. }
  311. db::bind(':idLocal', $tmp["idLocal"]);
  312. try {
  313. db::execute();
  314. $cp["UPDATE"]["SUCCESS"]++;
  315. } catch (Exception $ex) {
  316. $cp["UPDATE"]["ERROR"]++;
  317. }
  318. } else {
  319. db::query("UPDATE " . DB_T_TEMP_SALARIES . " SET actif = :actif WHERE idLocal = :idLocal");
  320. db::bind(':actif', 1);
  321. db::bind(':idLocal', $tmp["idLocal"]);
  322. db::execute();
  323. }
  324. } else {
  325. db::query("INSERT INTO " . DB_T_TEMP_SALARIES . " (idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif, new, excel, log) "
  326. . "VALUES (:idLocal, :loginId, :nom, :prenom, :sexe, :contrat, :jourEntree, :lieu, :actif, :new, :excel, :log)");
  327. db::bind(':idLocal', $tmp["idLocal"]);
  328. db::bind(':loginId', $tmp["loginId"]);
  329. db::bind(':nom', $tmp["nom"]);
  330. db::bind(':prenom', $tmp["prenom"]);
  331. db::bind(':sexe', $tmp["sexe"]);
  332. db::bind(':contrat', $tmp["contrat"]);
  333. db::bind(':jourEntree', $tmp["jourEntree"]);
  334. db::bind(':lieu', $tmp["lieu"]);
  335. db::bind(':actif', 1);
  336. db::bind(':new', 1);
  337. db::bind(':excel', $_excel);
  338. db::bind(':log', "INSERT");
  339. try {
  340. db::execute();
  341. $cp["INSERT"]["SUCCESS"]++;
  342. } catch (Exception $ex) {
  343. $cp["INSERT"]["ERROR"]++;
  344. }
  345. }
  346. }
  347. }
  348. ($changeStatutContrat != NULL) ? self::recContratForSFTP($_excel, $changeStatutContrat) : "";
  349. if ($cp["INSERT"]["ERROR"] != 0 or $cp["INSERT"]["ERROR"] != 0) {
  350. alert::recError("Une erreur s'est produite lors de la mise en cache.");
  351. return TRUE;
  352. } else {
  353. alert::recSuccess("La mise en cache a été réalisée avec succès.");
  354. return TRUE;
  355. }
  356. }
  357. private static function recContratForSFTP(int $_idExcel, array $_data)
  358. {
  359. db::query("UPDATE " . DB_T_EXCEL . " SET "
  360. . "contratForSFTP = :contratForSFTP "
  361. . "WHERE id = :id");
  362. db::bind(':contratForSFTP', json_encode($_data));
  363. db::bind(':id', $_idExcel);
  364. try {
  365. db::execute();
  366. return TRUE;
  367. } catch (Exception $e) {
  368. return FALSE;
  369. }
  370. }
  371. public static function updateSalaries(int $_excel)
  372. {
  373. $cp["INSERT"]["SUCCESS"] = 0;
  374. $cp["INSERT"]["ERROR"] = 0;
  375. $cp["DISABLE"]["SUCCESS"] = 0;
  376. $cp["DISABLE"]["ERROR"] = 0;
  377. $cp["UPDATE"]["SUCCESS"] = 0;
  378. $cp["UPDATE"]["ERROR"] = 0;
  379. $cp["forSFTP"] = 0;
  380. $updateContrat = json_decode(self::getExcelJsonForSFTP($_excel)["contratForSFTP"], TRUE);
  381. $jourSortie = date("Y-m-d 00:00:00");
  382. $dateReprise = date("Y-m-d 00:00:00");
  383. db::query("SELECT idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, lieu, actif, new, log FROM " . DB_T_TEMP_SALARIES);
  384. $row = db::resultset();
  385. if (!empty($row)) {
  386. foreach ($row as $key => $salaries) {
  387. $forSFTP = $reprise = NULL;
  388. if ($salaries["log"] == NULL) {
  389. $forSFTP["action"] = "valide";
  390. $forSFTP["idLocal"] = $salaries["idLocal"];
  391. $forSFTP["loginId"] = $salaries["loginId"];
  392. $forSFTP["contrat"] = $salaries["contrat"];
  393. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  394. $forSFTP["jourSortie"] = NULL;
  395. $forSFTP["repriseContrat"] = NULL;
  396. $forSFTP["actif"] = 1;
  397. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  398. } elseif ($salaries["log"] == "INSERT") {
  399. db::query("INSERT INTO " . DB_T_SALARIES . " (idLocal, loginId, nom, prenom, sexe, contrat, jourEntree, jourSortie, sel, lieu, actif) "
  400. . "VALUES (:idLocal, :loginId, :nom, :prenom, :sexe, :contrat, :jourEntree, :jourSortie, :sel, :lieu, :actif)");
  401. db::bind(':idLocal', $salaries["idLocal"]);
  402. db::bind(':loginId', $salaries["loginId"]);
  403. db::bind(':nom', $salaries["nom"]);
  404. db::bind(':prenom', $salaries["prenom"]);
  405. db::bind(':sexe', $salaries["sexe"]);
  406. db::bind(':contrat', $salaries["contrat"]);
  407. db::bind(':jourEntree', $salaries["jourEntree"]);
  408. db::bind(':jourSortie', NULL);
  409. db::bind(':sel', md5($salaries["idLocal"] . time() . rand(100000000000, 999999999999)));
  410. db::bind(':lieu', $salaries["lieu"]);
  411. db::bind(':actif', $salaries["actif"]);
  412. try {
  413. db::execute();
  414. $cp["INSERT"]["SUCCESS"]++;
  415. } catch (Exception $ex) {
  416. $cp["INSERT"]["ERROR"]++;
  417. }
  418. $forSFTP["action"] = "insert";
  419. $forSFTP["idLocal"] = $salaries["idLocal"];
  420. $forSFTP["loginId"] = $salaries["loginId"];
  421. $forSFTP["contrat"] = $salaries["contrat"];
  422. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  423. $forSFTP["jourSortie"] = NULL;
  424. $forSFTP["repriseContrat"] = NULL;
  425. $forSFTP["actif"] = 1;
  426. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  427. } elseif ($salaries["log"] == "DISABLE") {
  428. db::query("UPDATE " . DB_T_SALARIES . " SET "
  429. . "jourSortie = :jourSortie, "
  430. . "maj = CURRENT_TIMESTAMP(), "
  431. . "actif = :actif "
  432. . "WHERE idLocal = :idLocal");
  433. db::bind(':jourSortie', $jourSortie);
  434. db::bind(':actif', 0);
  435. db::bind(':idLocal', $salaries["idLocal"]);
  436. try {
  437. db::execute();
  438. $cp["DISABLE"]["SUCCESS"]++;
  439. } catch (Exception $ex) {
  440. $cp["DISABLE"]["ERROR"]++;
  441. }
  442. $forSFTP["action"] = "disabled";
  443. $forSFTP["idLocal"] = $salaries["idLocal"];
  444. $forSFTP["loginId"] = $salaries["loginId"];
  445. $forSFTP["contrat"] = $salaries["contrat"];
  446. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  447. $forSFTP["jourSortie"] = $jourSortie;
  448. $forSFTP["repriseContrat"] = NULL;
  449. $forSFTP["actif"] = 0;
  450. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  451. } else {
  452. $forSFTP["action"] = "update";
  453. $forSFTP["idLocal"] = $salaries["idLocal"];
  454. $forSFTP["loginId"] = $salaries["loginId"];
  455. $forSFTP["contrat"] = $salaries["contrat"];
  456. if (is_array($updateContrat) and array_key_exists($salaries["idLocal"], $updateContrat)) {
  457. if ($updateContrat[$salaries["idLocal"]] == "start") {
  458. $forSFTP["jourEntree"] = $dateReprise;
  459. $forSFTP["jourSortie"] = NULL;
  460. $forSFTP["repriseContrat"] = $dateReprise;
  461. $forSFTP["actif"] = 1;
  462. $reprise = $dateReprise;
  463. } elseif ($updateContrat[$salaries["idLocal"]] == "end") {
  464. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  465. $forSFTP["jourSortie"] = $jourSortie;
  466. $forSFTP["repriseContrat"] = NULL;
  467. $forSFTP["actif"] = 0;
  468. }
  469. } else {
  470. $forSFTP["jourEntree"] = $salaries["jourEntree"];
  471. $forSFTP["jourSortie"] = NULL;
  472. $forSFTP["repriseContrat"] = NULL;
  473. $forSFTP["actif"] = $salaries["actif"];
  474. }
  475. $SFTP[$cp["forSFTP"]++] = $forSFTP;
  476. db::query("UPDATE " . DB_T_SALARIES . " SET "
  477. . "loginId = :loginId, "
  478. . "contrat = :contrat, "
  479. . "lieu = :lieu, "
  480. . "repriseContrat = :repriseContrat, "
  481. . "jourSortie = :jourSortie, "
  482. . "maj = CURRENT_TIMESTAMP(), "
  483. . "actif = :actif "
  484. . "WHERE idLocal = :idLocal");
  485. db::bind(':loginId', $salaries["loginId"]);
  486. db::bind(':contrat', $salaries["contrat"]);
  487. db::bind(':lieu', $salaries["lieu"]);
  488. db::bind(':repriseContrat', $reprise);
  489. db::bind(':jourSortie', NULL);
  490. db::bind(':actif', $salaries["actif"]);
  491. db::bind(':idLocal', $salaries["idLocal"]);
  492. try {
  493. db::execute();
  494. $cp["UPDATE"]["SUCCESS"]++;
  495. } catch (Exception $ex) {
  496. $cp["UPDATE"]["ERROR"]++;
  497. }
  498. }
  499. }
  500. if ($cp["INSERT"]["SUCCESS"] == 1) {
  501. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salarié traité.");
  502. } elseif ($cp["INSERT"]["SUCCESS"] > 1) {
  503. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salariés traités.");
  504. }
  505. if ($cp["DISABLE"]["SUCCESS"] == 1) {
  506. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salarié traité.");
  507. } elseif ($cp["DISABLE"]["SUCCESS"] > 1) {
  508. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salariés traités.");
  509. }
  510. if ($cp["UPDATE"]["SUCCESS"] == 1) {
  511. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salarié traité.");
  512. } elseif ($cp["UPDATE"]["SUCCESS"] > 1) {
  513. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salariés traités.");
  514. }
  515. if ($cp["INSERT"]["ERROR"] == 1) {
  516. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salarié non traité.");
  517. } elseif ($cp["INSERT"]["ERROR"] > 1) {
  518. alert::recSuccess("SUCCESS : " . $cp["INSERT"]["SUCCESS"] . " salariés non traités.");
  519. }
  520. if ($cp["DISABLE"]["ERROR"] == 1) {
  521. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salarié non traité.");
  522. } elseif ($cp["DISABLE"]["ERROR"] > 1) {
  523. alert::recSuccess("DISABLE : " . $cp["DISABLE"]["SUCCESS"] . " salariés non traités.");
  524. }
  525. if ($cp["UPDATE"]["ERROR"] == 1) {
  526. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salarié non traité.");
  527. } elseif ($cp["UPDATE"]["ERROR"] > 1) {
  528. alert::recSuccess("UPDATE : " . $cp["UPDATE"]["SUCCESS"] . " salariés non traités.");
  529. }
  530. (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");
  531. }
  532. }
  533. private static function recForSFTP(array $_array, int $_idExcel)
  534. {
  535. $json = json_encode($_array);
  536. db::query("UPDATE " . DB_T_EXCEL . " SET "
  537. . "forSFTP = :forSFTP ,"
  538. . "md5forSFTP = :md5forSFTP "
  539. . "WHERE id = :id");
  540. db::bind(':forSFTP', $json);
  541. db::bind(':md5forSFTP', md5($json));
  542. db::bind(':id', $_idExcel);
  543. try {
  544. db::execute();
  545. return TRUE;
  546. } catch (Exception $e) {
  547. return FALSE;
  548. }
  549. }
  550. public static function createRapport()
  551. {
  552. $log = NULL;
  553. db::query("SELECT idLocal, loginId, nom, prenom, contrat, jourEntree, lieu, excel, log FROM " . DB_T_TEMP_SALARIES . " WHERE log IS NOT NULL");
  554. $row = db::resultset();
  555. if ($row != NULL) {
  556. foreach ($row as $key => $salaries) {
  557. if ($salaries["log"] == "INSERT") {
  558. $log["json"][] = array(
  559. "action" => "INSERT",
  560. "excel" => $salaries["excel"],
  561. "idLocal" => $salaries["idLocal"],
  562. "loginId" => $salaries["loginId"],
  563. "nom" => $salaries["nom"],
  564. "prenom" => $salaries["prenom"],
  565. "jourEntree" => $salaries["jourEntree"],
  566. "contrat" => $salaries["contrat"],
  567. "lieu" => $salaries["lieu"]
  568. );
  569. } elseif ($salaries["log"] == "DISABLE") {
  570. $log["json"][] = array(
  571. "action" => "DISABLE",
  572. "excel" => $salaries["excel"],
  573. "idLocal" => $salaries["idLocal"],
  574. "loginId" => $salaries["loginId"],
  575. "nom" => $salaries["nom"],
  576. "prenom" => $salaries["prenom"],
  577. "jourEntree" => $salaries["jourEntree"],
  578. "contrat" => $salaries["contrat"],
  579. "lieu" => $salaries["lieu"]
  580. );
  581. } else {
  582. $tmp_log = array("action" => "UPDATE", "excel" => $salaries["excel"], "nom" => $salaries["nom"], "prenom" => $salaries["prenom"]);
  583. $tmp = explode(" ", $salaries["log"]);
  584. foreach ($tmp as $key => $value) {
  585. if ($key > 0) {
  586. switch ($value) {
  587. case "loginId":
  588. $tmp_log["loginId"] = $salaries["loginId"];
  589. break;
  590. case "contrat":
  591. $tmp_log["contrat"] = $salaries["contrat"];
  592. break;
  593. case "lieu":
  594. $tmp_log["lieu"] = $salaries["lieu"];
  595. break;
  596. }
  597. }
  598. }
  599. $log["json"][] = $tmp_log;
  600. }
  601. }
  602. $log["json"] = json_encode($log["json"]);
  603. $log["excel"] = $salaries["excel"];
  604. } else {
  605. $log["json"] = NULL;
  606. $log["excel"] = NULL;
  607. }
  608. return $log;
  609. }
  610. public static function countTmpSalaries()
  611. {
  612. db::query("SELECT COUNT(*) AS nb FROM " . DB_T_TEMP_SALARIES);
  613. return db::single()["nb"];
  614. }
  615. public static function dataForSFTP()
  616. {
  617. $lastExcel = self::lastExcelForSFTP();
  618. $forSFTP = self::getExcelJsonForSFTP($lastExcel);
  619. $finalSalarie = NULL;
  620. $csv = "OD_" . date("d-m-Y") . ".csv";
  621. $tmpSFTP = fopen(SFTP_LOCAL . $csv, "w");
  622. fputcsv($tmpSFTP, array("loginId", "jourSortie"), ";");
  623. foreach (json_decode($forSFTP["forSFTP"], TRUE) as $salarie) {
  624. $tmpSalarie = NULL;
  625. if (isset($salarie["loginId"]) and $salarie["loginId"] != "" and isset($salarie["jourSortie"])) {
  626. $tmpSalarie["loginId"] = $salarie["loginId"];
  627. $tmpSalarie["jourSortie"] = $salarie["jourSortie"];
  628. fputcsv($tmpSFTP, $tmpSalarie, ";");
  629. }
  630. }
  631. self::recDateForSFTP($lastExcel);
  632. }
  633. private static function recDateForSFTP(int $_idExcel)
  634. {
  635. db::query("UPDATE " . DB_T_EXCEL . " SET "
  636. . "createForSFTP = CURRENT_TIMESTAMP() "
  637. . "WHERE id = :id");
  638. db::bind(':id', $_idExcel);
  639. try {
  640. db::execute();
  641. return TRUE;
  642. } catch (Exception $e) {
  643. return FALSE;
  644. }
  645. }
  646. public static function ifSubmitLastForSFTP()
  647. {
  648. $lastExcel = self::lastExcel();
  649. $forSFTP = self::getExcelJsonForSFTP($lastExcel);
  650. return (@$forSFTP["md5forSFTP"] != NULL and @$forSFTP["createForSFTP"] == NULL) ? TRUE : FALSE;
  651. }
  652. public static function checkSalarieByMatricule(string $_string)
  653. {
  654. db::query("SELECT "
  655. . "id, "
  656. . "nom, "
  657. . "prenom, "
  658. . "contrat, "
  659. . "actif "
  660. . "FROM " . DB_T_SALARIES . " "
  661. . "WHERE idLocal = :idLocal");
  662. db::bind(':idLocal', intval($_string));
  663. $salarie = db::single();
  664. if (isset($salarie["id"])) {
  665. if ($salarie["actif"] == 0) {
  666. $return["error"] = "<div>Ce matricule n'est plus sous contrat Capgemini Consulting.</div>";
  667. $return["class"] = "danger";
  668. } elseif ($salarie["contrat"] == 0) {
  669. $return["error"] = "<div>Ce matricule est en suspension de contrat chez Capgemini Consulting mais peut-être pris en charge par le CSE.</div>";
  670. $return["class"] = "success";
  671. } else {
  672. $return["success"] = "<div>Ce matricule est sous contrat Capgemini Consulting.</div>";
  673. $return["class"] = "success";
  674. }
  675. $return["identity"] = $salarie["prenom"] . " " . $salarie["nom"];
  676. } else {
  677. $return["error"] = "<div>Ce matricule n'est pas ou plus rattaché à Capgemini Consulting.</div>";
  678. $return["class"] = "danger";
  679. }
  680. return $return;
  681. }
  682. }