| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?php
- class proweb
- {
- public static function getBase()
- {
- db::query("SELECT * FROM " . DB_T_SALARIES_PROWEB);
- return db::resultset();
- }
- public static function getExcelById(int $_id)
- {
- db::query("SELECT * FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
- db::bind(':id', $_id);
- return db::single();
- }
- public static function deleteExcel(int $_id)
- {
- $tmp = self::getExcelById($_id);
- file::delete($tmp["md5"]);
- db::query("DELETE FROM " . DB_T_EXCEL_PROWEB . " WHERE id = :id");
- db::bind(':id', $_id);
- try {
- db::execute();
- return TRUE;
- } catch (Exception $ex) {
- return FALSE;
- }
- }
- public static function getExcel()
- {
- db::query("SELECT * FROM " . DB_T_EXCEL . " ORDER BY id DESC LIMIT 0, 1");
- return db::single();
- }
- public static function convertDateMoisAn(string $datetime)
- {
- $pieces = explode(" ", $datetime);
- $pieces2 = explode("-", $pieces[0]);
- return $pieces2[0] . $pieces2[1];
- }
- public static function convertDateMoisAnJour(string $datetime)
- {
- $pieces = explode(" ", $datetime);
- return $pieces[0];
- }
- public static function archiveExcelValues(array $_array)
- {
- $_return["error"] = 0;
- $_return["errorJson"] = array();
- // ----
- $_return["idProweb"] = $_array[0];
- $_return["nom"] = self::archiveExcelValuesNom($_array[1]);
- $_return["prenom"] = self::archiveExcelValuesPrenom($_array[2]);
- $_return["sexe"] = self::archiveExcelValuesSexe($_array[3]);
- $_return["jourEntree"] = self::archiveExcelValuesDate($_array[4]);
- $_return["jourSortie"] = self::archiveExcelValuesDate($_array[5]);
- $_return["actif"] = self::archiveExcelValuesActif($_array[6]);
- $_return["lieu"] = self::archiveExcelValuesLieu($_array[7]);
- $_return["loginId"] = self::archiveExcelValuesloginId($_array[8]);
- $verifRH = self::checksalarieByLoginId($_return["loginId"], $_return["nom"], $_return["prenom"]);
- if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
- $dateDataRH = intval(self::convertDateMoisAn(self::getExcel()["dateData"]));
- $dateDataProWeb = intval(self::convertDateMoisAn($_return["jourEntree"]));
- } else {
- $dateDataRH = $dateDataProWeb = 0;
- }
- if (empty($verifRH["id"]) and $_return["jourSortie"] == "N/A" and $dateDataRH > $dateDataProWeb) {
- $_return["contrat"] = $_return["actif"] = $_return["RHBase"] = $_return["loginIdRH"] = $_return["jourEntreeRH"] = "N/A";
- array_push($_return["errorJson"], "absent");
- } else {
- $_return["loginIdRH"] = (empty($verifRH["loginId"]) or $verifRH["loginId"] == $_return["loginId"]) ? NULL : $verifRH["loginId"];
- $_return["jourEntreeRH"] = (empty($verifRH["jourEntree"]) or self::convertDateMoisAnJour($verifRH["jourEntree"]) == $_return["jourEntree"]) ? NULL : self::convertDateMoisAnJour($verifRH["jourEntree"]);
- $_return["jourSortie"] = (isset($verifRH["jourSortie"])) ? $verifRH["jourSortie"] : $_return["jourSortie"];
- $_return["RHBase"] = (isset($verifRH["jourSortie"]) or empty($verifRH["id"])) ? 0 : 1;
- $_return["actif"] = (isset($verifRH["jourSortie"]) or empty($verifRH["id"])) ? 0 : 1;
- $_return["contrat"] = (isset($verifRH["contrat"])) ? $verifRH["contrat"] : 0;
- // ----
- if (!self::checkValuesNom($_return["nom"])) {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "nom");
- }
- if (!self::checkValuesPrenom($_return["prenom"])) {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "prenom");
- }
- if (!self::checkValuesloginId($_return["loginId"], $_return["loginIdRH"])) {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "loginId");
- }
- if (!self::checkValuesJourEntree($_return["jourEntree"])) {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "jourEntree");
- }
- if ($_return["jourEntreeRH"] != NULL and $_return["jourEntree"] != "N/A") {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "jourEntree");
- }
- if ($_return["jourEntree"] != "N/A") { // On ignore les nouveaux salariés qui se sont inscrits post import du fichier RH
- if ($dateDataRH > $dateDataProWeb) {
- if (!self::checkValuesRHBase($_return["RHBase"], $_return["actif"], $_return["jourSortie"])) {
- $_return["error"] = 1;
- array_push($_return["errorJson"], "RHBase");
- }
- }
- }
- // if ($_return["contrat"] == 0 AND $_return["jourSortie"] == "N/A") {
- // $_return["error"] = 1;
- // array_push($_return["errorJson"], "contrat");
- // }
- }
- $_return["errorJson"] = (!empty($_return["errorJson"][0])) ? json_encode($_return["errorJson"]) : NULL;
- return $_return;
- }
- // Les initialisations
- private static function archiveExcelValuesDate(string $_string)
- {
- return (!isset($_string) or $_string == "00-00-0000") ? "N/A" : $_string;
- }
- private static function archiveExcelValuesSexe(string $_string)
- {
- return (empty($_string)) ? "N/A" : $_string;
- }
- private static function archiveExcelValuesloginId(string $_string)
- {
- return salaries::clean_accent($_string);
- }
- private static function archiveExcelValuesNom(string $_string)
- {
- return salaries::clean_accent($_string);
- }
- private static function archiveExcelValuesPrenom(string $_string)
- {
- return salaries::clean_accent($_string);
- }
- private static function archiveExcelValuesActif(string $_string)
- {
- if ($_string == "Actif") {
- return 1;
- } elseif ($_string == "Inactif") {
- return 0;
- } else {
- return "N/A";
- }
- }
- private static function archiveExcelValuesLieu(string $_string)
- {
- return (empty($_string)) ? "N/A" : $_string;
- }
- // Les checks
- public static function checkSalarieByLoginId(string $_loginId, string $_nom = NULL, string $_prenom = NULL)
- {
- // Récupération des données de l'excel au format Json
- if ($_nom == NULL) {
- db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId");
- } else {
- db::query("SELECT id, loginId, jourEntree, jourSortie, contrat FROM " . DB_T_SALARIES . " WHERE loginId = :loginId OR (nom = :nom AND prenom = :prenom)");
- db::bind(':nom', $_nom);
- db::bind(':prenom', $_prenom);
- }
- db::bind(':loginId', $_loginId);
- return db::single();
- }
- private static function checkValuesActif(string $_string)
- {
- return ($_string == "N/A") ? FALSE : TRUE;
- }
- private static function checkValuesloginId(string $_idLogin, string $_idLoginRH = NULL)
- {
- if ($_idLoginRH != NULL) {
- if (empty(self::checkSalarieByLoginId($_idLogin)["id"])) {
- return FALSE;
- } elseif (core::checkStringOnly($_idLogin)) {
- return FALSE;
- } elseif (strlen($_idLogin) > 10) {
- return FALSE;
- } elseif (empty($_idLogin)) {
- return FALSE;
- } else {
- return TRUE;
- }
- } else {
- return TRUE;
- }
- }
- private static function checkValuesRHBase(string $_string, int $_actif, string $_sortie)
- {
- return ($_string == 0 and $_actif == 1 and $_sortie == "N/A") ? FALSE : TRUE;
- }
- private static function checkValuesJourEntree(string $_string)
- {
- return ($_string == "N/A") ? FALSE : TRUE;
- }
- private static function checkValuesJourSortie(string $_string, int $_actif)
- {
- return ($_string != "N/A" and $_actif == 1) ? FALSE : TRUE;
- }
- private static function checkValuesNom(string $_string)
- {
- return (empty($_string)) ? FALSE : TRUE;
- }
- private static function checkValuesPrenom(string $_string)
- {
- return (empty($_string)) ? FALSE : TRUE;
- }
- private static function checkValuesSexe(string $_string)
- {
- return ($_string == NULL or ($_string != "M." and $_string != "Mme")) ? FALSE : TRUE;
- }
- private static function checkValuesLieu(string $_string)
- {
- return (empty($_string)) ? FALSE : TRUE;
- }
- public static function downloadExcel(int $_id, string $_file)
- {
- $data = base64_decode(self::getExcelById($_id)["file"]);
- $fileTemp = fopen(DIR_TEMP . $_file, "w");
- file_put_contents(DIR_TEMP . $_file, $data);
- fclose($fileTemp);
- return DIR_TEMP . $_file;
- }
- }
|