EmployeeController.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Storage;
  7. use Illuminate\Support\Facades\Validator;
  8. use PhpOffice\PhpSpreadsheet\IOFactory;
  9. use Illuminate\Database\Query\Builder;
  10. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  11. use ElephantIO\Client;
  12. use stdClass;
  13. use Throwable;
  14. class EmployeeController extends Controller{
  15. private $responseController;
  16. private $encryptionController;
  17. private $documentManagementController;
  18. private $functionsController;
  19. public function __construct(){
  20. $this->responseController = new ResponseController();
  21. $this->encryptionController = new EncryptionController();
  22. $this->documentManagementController = new DocumentManagementController();
  23. $this->functionsController = new FunctionsController();
  24. }
  25. public function getConsultOfEmployees($idUser, $line) {
  26. DB::enableQueryLog();
  27. $idUser = $this->encryptionController->decrypt($idUser);
  28. if(!$idUser){
  29. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  30. }
  31. $usr = DB::table('S002V01TUSUA')->where([
  32. ['USUA_NULI', '=', $line],
  33. ['USUA_IDUS', '=', $idUser],
  34. ])->first();
  35. if(is_null($usr)){
  36. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  37. }
  38. $employees = DB::table('S002V01TPERS')->select([
  39. 'PERS_IDPE AS ID_EMPLOYEE',
  40. DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
  41. 'PERS_TICO AS CONTRACT_TYPE',
  42. 'PERS_ESPE AS SPECIALITY',
  43. 'PERS_EQTR AS TEAM_ID',
  44. 'EQMA_NOMB AS TEAM_NAME',
  45. 'PERS_FERE AS REGISTER_DATE',
  46. 'PERS_USRE AS REGISTERED_BY_USER',
  47. 'PERS_FEMO AS UPDATE_DATE',
  48. 'PERS_USMO AS UPDATED_BY_USER',
  49. 'PERS_ESTA AS STATUS'
  50. ])->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
  51. ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
  52. ->where('USUA_NULI', '=', $line)->get()->all();
  53. $now = $this->functionsController->now();
  54. $nowStr = $now->toDateTimeString();
  55. $actions = DB::getQueryLog();
  56. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  57. $idac = $this->functionsController->registerActivity(
  58. $line,
  59. 'S002V01M11GPRS',
  60. 'S002V01F01GEPE',
  61. 'S002V01P01COEM',
  62. 'Consulta',
  63. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los empleados registrados.",
  64. $idUser,
  65. $nowStr,
  66. 'S002V01S02GEPE'
  67. );
  68. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  69. return $this->responseController->makeResponse(false, 'EXITO', $employees);
  70. }
  71. public function getEmployeeById($idEmployee, $idUser, $line) {
  72. DB::enableQueryLog();
  73. $idUser = $this->encryptionController->decrypt($idUser);
  74. if(!$idUser){
  75. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  76. }
  77. $usr = DB::table('S002V01TUSUA')->where([
  78. ['USUA_NULI', '=', $line],
  79. ['USUA_IDUS', '=', $idUser],
  80. ])->first();
  81. if(is_null($usr)){
  82. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  83. }
  84. $idEmployee = $this->encryptionController->decrypt($idEmployee);
  85. if(!$idEmployee){
  86. return $this->responseController->makeResponse(true, 'El ID del empleado solicitado no está encriptado correctamente', [], 400);
  87. }
  88. $employee = DB::table('S002V01TPERS')->select([
  89. 'PERS_IDPE AS ID_EMPLOYEE',
  90. DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as EMPLOYEE_NAME'),
  91. 'PERS_IDUS AS USER_ID',
  92. 'EQMA_IDEQ AS WORKTEAM_ID',
  93. 'EQMA_NOMB AS WORKTEAM_NAME',
  94. 'PERS_TICO AS CONTRACT_TYPE',
  95. 'PERS_IDPS AS SUBCONTRATIST_ID',
  96. 'PESU_RASO AS SUBCONTRATIST_NAME',
  97. 'PESU_REFI AS TAX_REGIME',
  98. 'REFI_DRFI AS TAX_REGIME_DESCRIPTION',
  99. 'PERS_ESPE AS SPECIALITY',
  100. 'PERS_EXTR AS FOREIGNER',
  101. 'PERS_XRFC AS RFC',
  102. 'PERS_TAID AS TAX_ID',
  103. 'PERS_IDPA AS COUNTRY',
  104. 'PERS_ENFE AS STATE',
  105. 'PERS_CIUD AS CITY',
  106. 'PERS_LOCA AS TOWN',
  107. 'PERS_COLO AS SETTING',
  108. 'PERS_COPO AS ZIP_CODE',
  109. 'PERS_CALL AS STREET',
  110. 'PERS_NUEX AS EXTERIOR_NUMBER',
  111. 'PERS_NUIN AS INTERIOR_NUMBER',
  112. 'PERS_NOCE AS CONTACT_NAME',
  113. 'PERS_LCEM AS CONTACT_LADA',
  114. 'PERS_NUTC AS CONTACT_TELEPHONE',
  115. 'PERS_DCEM AS CONTACT_ADDRESS',
  116. 'PERS_DOAS AS DOCUMENTS',
  117. 'PERS_ESTA AS STATUS',
  118. 'PERS_USRE AS USRREG',
  119. 'PERS_USMO AS USRMOD',
  120. 'PERS_FERE AS FECREG',
  121. 'PERS_FEMO AS FECMOD',
  122. ])->leftJoin('S002V01TEQMA', 'EQMA_IDEQ', '=', 'PERS_EQTR')
  123. ->leftJoin('S002V01TPESU', 'PESU_IDPS', '=', 'PERS_IDPS')
  124. ->leftJoin('S002V01TREFI', 'REFI_CRFI', '=', 'PESU_REFI')
  125. ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')->where([
  126. ['PERS_NULI', '=', $line],
  127. ['PERS_IDPE', '=', $idEmployee],
  128. ])->first();
  129. $attached = [];
  130. $docsArr = json_decode($employee->DOCUMENTS, true);
  131. foreach($docsArr as $doc){
  132. $docArr = explode('=', $doc['CODE']);
  133. $codeArr = explode('-', $docArr[0]);
  134. $document = DB::table('S002V01TAFAL')->select([
  135. 'AFAL_NOAR AS FILE_NAME',
  136. 'AFAL_EXTE AS FILE_EXTENSION',
  137. 'AFAL_TAMA AS FILE_SIZE',
  138. 'AFAL_ESTA AS FILE_STATUS'
  139. ])->where([
  140. ['AFAL_NULI', '=', $line],
  141. ['AFAL_COMO', '=', $codeArr[1]],
  142. ['AFAL_CLDO', '=', $codeArr[2]],
  143. ['AFAL_FECR', '=', $codeArr[3]],
  144. ['AFAL_NUSE', '=', $codeArr[4]],
  145. ['AFAL_NUVE', '=', $docArr[1]],
  146. ])->first();
  147. $document->FILE_ID = $this->encryptionController->encrypt($doc['CODE']);
  148. $document->FILE_TYPE = $doc['TYPE'];
  149. $attached[] = $document;
  150. }
  151. $employee->DOCUMENTS = json_encode($attached);
  152. $country = DB::table('S002V01TPAIS')->where([
  153. ['PAIS_NULI', '=', $line],
  154. ['PAIS_IDPA', '=', $employee->COUNTRY]
  155. ])->first();
  156. $state = DB::table('S002V01TESTA')->where([
  157. ['ESTA_NULI', '=', $line],
  158. ['ESTA_COES', '=', $employee->STATE],
  159. ['ESTA_COPA', '=', $employee->COUNTRY]
  160. ])->first();
  161. $city = DB::table('S002V01TMUNI')->where([
  162. ['MUNI_NULI', '=', $line],
  163. ['MUNI_COMU', '=', $employee->CITY],
  164. ['MUNI_COES', '=', $employee->STATE],
  165. ])->first();
  166. $town = DB::table('S002V01TLOCA')->where([
  167. ['LOCA_NULI', '=', $line],
  168. ['LOCA_COLO', '=', $employee->TOWN],
  169. ['LOCA_COES', '=', $employee->STATE],
  170. ])->first();
  171. $setting = DB::table('S002V01TCOLO')->where([
  172. ['COLO_NULI', '=', $line],
  173. ['COLO_COCO', '=', $employee->SETTING],
  174. ['COLO_COPO', '=', $employee->ZIP_CODE],
  175. ])->first();
  176. $employee->COUNTRY = $country->PAIS_NOMB . " (" . $employee->COUNTRY . ")";
  177. $employee->STATE = is_null($state) ? $employee->STATE : $state->ESTA_NOES . " (" . $employee->STATE . ")";
  178. $employee->CITY = is_null($city) ? $employee->CITY : $city->MUNI_NOMU . " (" . $employee->CITY . ")";
  179. $employee->TOWN = is_null($town) ? $employee->TOWN : $town->LOCA_NOLO . " (" . $employee->TOWN . ")";
  180. $employee->SETTING = is_null($setting) ? $employee->SETTING : $setting->COLO_NOCO . " (" . $employee->SETTING . ")";
  181. $usrReg = DB::table('S002V01TUSUA')->where([
  182. ['USUA_NULI', '=', $line],
  183. ['USUA_IDUS', '=', $employee->USRREG]
  184. ])->first();
  185. $nameReg = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
  186. $employee->USRREG = "$nameReg (" . $employee->USRREG . ")";
  187. if(!is_null($employee->USRMOD)){
  188. $usrMod = DB::table('S002V01TUSUA')->where([
  189. ['USUA_NULI', '=', $line],
  190. ['USUA_IDUS', '=', $employee->USRMOD]
  191. ])->first();
  192. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  193. $employee->USRMOD = "$nameMod (" . $employee->USRMOD . ")";
  194. }
  195. $now = $this->functionsController->now();
  196. $nowStr = $now->toDateTimeString();
  197. $actions = DB::getQueryLog();
  198. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  199. $idac = $this->functionsController->registerActivity(
  200. $line,
  201. 'S002V01M11GPRS',
  202. 'S002V01F01GEPE',
  203. 'S002V01P03DEEM',
  204. 'Consulta',
  205. "El usuario $name (" . $usr->USUA_IDUS . ") consultó al empleado " . $employee->EMPLOYEE_NAME . " ($idEmployee).",
  206. $idUser,
  207. $nowStr,
  208. 'S002V01S02GEPE'
  209. );
  210. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  211. return $this->responseController->makeResponse(false, 'EXITO', $employee);
  212. }
  213. public function updateToInactiveStatus(Request $request) {
  214. DB::enableQueryLog();
  215. $validator = Validator::make($request->all(), [
  216. 'id_user' => 'required|string',
  217. 'linea' => 'required|integer',
  218. 'id_employee' => 'required|string',
  219. ]);
  220. if($validator->fails()){
  221. return $this->responseController->makeResponse(
  222. true,
  223. "Se encontraron uno o más errores.",
  224. $this->responseController->makeErrors(
  225. $validator->errors()->messages()
  226. ),
  227. 401
  228. );
  229. }
  230. $form = $request->all();
  231. $idUser = $this->encryptionController->decrypt($form['id_user']);
  232. if(!$idUser){
  233. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  234. }
  235. $usr = DB::table('S002V01TUSUA')->where([
  236. ['USUA_NULI', '=', $form['linea']],
  237. ['USUA_IDUS', '=', $idUser]
  238. ])->first();
  239. if(is_null($usr)){
  240. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  241. }
  242. $idEmployee = $this->encryptionController->decrypt($form['id_employee']);
  243. if(!$idEmployee){
  244. return $this->responseController->makeResponse(true, 'El ID del empleado que desea actualizar no fue encriptado correctamente.', [], 400);
  245. }
  246. $employee = DB::table('S002V01TPERS')->where([
  247. ['PERS_NULI', '=', $form['linea']],
  248. ['PERS_IDPE', '=', $idEmployee]
  249. ])->first();
  250. if(is_null($employee)){
  251. return $this->responseController->makeResponse(true, 'El empleado que desea actualizar no existe.', [], 404);
  252. }
  253. if($idUser == $employee->PERS_IDUS){
  254. return $this->responseController->makeResponse(true, 'El usuario no puede eliminarse a sí mismo.', [], 400);
  255. }
  256. $now = $this->functionsController->now();
  257. $nowStr = $now->toDateTimeString();
  258. DB::table('S002V01TPERS')->where([
  259. ['PERS_NULI', '=', $form['linea']],
  260. ['PERS_IDPE', '=', $idEmployee]
  261. ])->update([
  262. 'PERS_ESTA' => 'Eliminado',
  263. 'PERS_USMO' => $idUser,
  264. 'PERS_FEMO' => $nowStr,
  265. ]);
  266. $actions = DB::getQueryLog();
  267. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  268. $idac = $this->functionsController->registerActivity(
  269. $form['linea'],
  270. 'S002V01M11GPRS',
  271. 'S002V01F01GEPE',
  272. 'S002V01P02REEM',
  273. 'Eliminación',
  274. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó al empleado $idEmployee.",
  275. $idUser,
  276. $nowStr,
  277. 'S002V01S02GEPE'
  278. );
  279. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  280. return $this->responseController->makeResponse(false, 'EXITO');
  281. }
  282. public function getContractsOfEveryEmployee($idUser, $line) {
  283. DB::enableQueryLog();
  284. $idUser = $this->encryptionController->decrypt($idUser);
  285. if(!$idUser){
  286. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  287. }
  288. $usr = DB::table('S002V01TUSUA')->where([
  289. ['USUA_NULI', '=', $line],
  290. ['USUA_IDUS', '=', $idUser],
  291. ])->first();
  292. if(is_null($usr)){
  293. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  294. }
  295. $contractsByEmployees = DB::table('S002V01TPERS')->select([
  296. DB::raw("
  297. TRIM(CONCAT(
  298. USUA_NOMB,
  299. ' ',
  300. USUA_APPA,
  301. IF(ISNULL(USUA_APMA), '', CONCAT(' ', USUA_APMA)),
  302. ' <(',
  303. PERS_IDPE,
  304. ')> (',
  305. PERS_IDUS,
  306. ')'
  307. )) AS EMPLOYEE
  308. "),
  309. DB::raw("COUNT(CONT_IDCO) AS CONTRACTS")
  310. ])->leftJoin('S002V01TCONT', 'CONT_IDEM', '=', 'PERS_IDPE')
  311. ->join('S002V01TUSUA', 'USUA_IDUS', '=', 'PERS_IDUS')
  312. ->groupBy('EMPLOYEE')->where([
  313. ['PERS_NULI', '=', $line],
  314. ['PERS_TICO', '=', 'Interno'],
  315. ])->get()->all();
  316. foreach($contractsByEmployees as $key=>$val){
  317. $employeeArr = explode('<', $val->EMPLOYEE);
  318. $employeeName = $employeeArr[0];
  319. $employeeArr = array_reverse($employeeArr);
  320. $employeeArr = explode('>', $employeeArr[0]);
  321. $employeeID = str_replace('(', '', $employeeArr[0]);
  322. $employeeID = str_replace(')', '', $employeeID);
  323. $val->ID_EMPLOYEE = $this->encryptionController->encrypt($employeeID);
  324. $val->EMPLOYEE = $employeeName . join('', $employeeArr);
  325. $contractsByEmployees[$key] = $val;
  326. }
  327. $now = $this->functionsController->now();
  328. $nowStr = $now->toDateTimeString();
  329. $actions = DB::getQueryLog();
  330. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  331. $idac = $this->functionsController->registerActivity(
  332. $line,
  333. 'S002V01M11GPRS',
  334. 'S002V01F02ACEM',
  335. 'S002V01P01HCEM',
  336. 'Consulta',
  337. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos por empleados.",
  338. $idUser,
  339. $nowStr,
  340. 'S002V01S02GEPE'
  341. );
  342. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  343. return $this->responseController->makeResponse(false, 'EXITO', $contractsByEmployees);
  344. }
  345. public function getDetailsOfContractsByEmployee($idEmployee, $idUser, $line) {
  346. DB::enableQueryLog();
  347. $idUser = $this->encryptionController->decrypt($idUser);
  348. if(!$idUser){
  349. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  350. }
  351. $usr = DB::table('S002V01TUSUA')->where([
  352. ['USUA_NULI', '=', $line],
  353. ['USUA_IDUS', '=', $idUser]
  354. ])->first();
  355. if(is_null($usr)){
  356. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  357. }
  358. $idEmployee = $this->encryptionController->decrypt($idEmployee);
  359. if(!$idEmployee){
  360. return $this->responseController->makeResponse(true, 'El ID del empleado no fue encriptado correctamente.', [], 400);
  361. }
  362. $sub = DB::table('S002V01TPERS')->where([
  363. ['PERS_NULI', '=', $line],
  364. ['PERS_IDPE', '=', $idEmployee],
  365. ['PERS_TICO', '=', 'Interno'],
  366. ])->first();
  367. if(is_null($sub)){
  368. return $this->responseController->makeResponse(true, 'El empleado solicitado no existe.', [], 404);
  369. }
  370. $contracts = DB::table('S002V01TCONT')->select([
  371. 'CONT_NOCO AS CONTRACT_NAME',
  372. 'CONT_FEIN AS START_DATE',
  373. 'CONT_FEFI AS END_DATE',
  374. 'CONT_COST AS COST',
  375. ])->where([
  376. ['CONT_NULI', '=', $line],
  377. ['CONT_IDEM', '=', $idEmployee],
  378. ['CONT_TIPO', '=', 'Interno'],
  379. ])->get()->all();
  380. $now = $this->functionsController->now();
  381. $nowStr = $now->toDateTimeString();
  382. $actions = DB::getQueryLog();
  383. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  384. $idac = $this->functionsController->registerActivity(
  385. $line,
  386. 'S002V01M11GPRS',
  387. 'S002V01F02ACEM',
  388. 'S002V01P01HCEM',
  389. 'Consulta',
  390. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los contratos del empleado #$idEmployee.",
  391. $idUser,
  392. $nowStr,
  393. 'S002V01S02GEPE'
  394. );
  395. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  396. return $this->responseController->makeResponse(false, 'EXITO', $contracts);
  397. }
  398. public function getInterventionsByEmployee($idEmployee, $idUser, $line) {
  399. DB::enableQueryLog();
  400. $idUser = $this->encryptionController->decrypt($idUser);
  401. if(!$idUser){
  402. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  403. }
  404. $usr = DB::table('S002V01TUSUA')->where([
  405. ['USUA_NULI', '=', $line],
  406. ['USUA_IDUS', '=', $idUser]
  407. ])->first();
  408. if(is_null($usr)){
  409. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  410. }
  411. $idEmployee = $this->encryptionController->decrypt($idEmployee);
  412. if(!$idEmployee){
  413. return $this->responseController->makeResponse(true, 'El ID del empleado no fue encriptado correctamente.', [], 400);
  414. }
  415. $employee = DB::table('S002V01TPERS')->where([
  416. ['PERS_NULI', '=', $line],
  417. ['PERS_IDPE', '=', $idEmployee],
  418. ])->first();
  419. if(is_null($employee)){
  420. return $this->responseController->makeResponse(true, 'El empleado solicitado no existe.', [], 404);
  421. }
  422. $preventiveOrders = DB::select("
  423. SELECT
  424. DISTINCT(S002V01TOTPR.OTPR_IDOT) AS IDORDEN,
  425. S002V01TOTPR.OTPR_DEIN AS DESCRIPCION,
  426. 'Preventivo' AS TIPOORDEN
  427. FROM
  428. S002V01TOTPR,
  429. JSON_TABLE(OTPR_OPPR, '$[*]' COLUMNS(
  430. OTPR_OPPR_ID INT PATH '$.ID',
  431. OTPR_OPPR_TYPE VARCHAR(100) PATH '$.TYPE'
  432. )) OPPR
  433. WHERE
  434. (OTPR_OPPR_ID = :emp_id AND OTPR_OPPR_TYPE = 'EM')
  435. OR (OTPR_OPPR_ID = :sub_id AND OTPR_OPPR_TYPE = 'SU')
  436. OR (OTPR_OPPR_ID = :team_id AND OTPR_OPPR_TYPE = 'EQ')
  437. ", [
  438. 'emp_id' => $employee->PERS_IDPE,
  439. 'sub_id' => $employee->PERS_IDPS,
  440. 'team_id' => $employee->PERS_EQTR
  441. ]);
  442. //PENDIENTE MANTENIMIENTO CORRECTIVO
  443. $ordersFN = [];
  444. $relatedOrders = [];
  445. foreach($preventiveOrders as $order){
  446. if(!in_array($order->IDORDEN, $relatedOrders)){
  447. $relatedOrders[] = $order->IDORDEN;
  448. $order->IDORDEN = $this->encryptionController->encrypt($order->IDORDEN);
  449. $ordersFN[] = $order;
  450. }
  451. }
  452. $now = $this->functionsController->now();
  453. $nowStr = $now->toDateTimeString();
  454. $actions = DB::getQueryLog();
  455. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  456. $idac = $this->functionsController->registerActivity(
  457. $line,
  458. 'S002V01M11GPRS',
  459. 'S002V01F01GEPE',
  460. 'S002V01P03DEEM',
  461. 'Consulta',
  462. "El usuario $name (" . $usr->USUA_IDUS . ") consultó las órdenes de trabajo relacionadas al empleado #$idEmployee.",
  463. $idUser,
  464. $nowStr,
  465. 'S002V01S02GEPE'
  466. );
  467. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  468. return $this->responseController->makeResponse(false, 'EXITO', $ordersFN);
  469. }
  470. public function getConsultOfEmployeesForLeader($idEmployee, $idUser, $line) {
  471. DB::enableQueryLog();
  472. $idUser = $this->encryptionController->decrypt($idUser);
  473. if(!$idUser){
  474. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  475. }
  476. try {
  477. $idEmployee = $this->encryptionController->decrypt($idEmployee);
  478. } catch (Throwable $th) {
  479. return $this->responseController->makeResponse(true, 'El ID del empleado no se encriptó correctamente', [], 400);
  480. }
  481. $usr = DB::table('S002V01TUSUA')->where([
  482. ['USUA_NULI', '=', $line],
  483. ['USUA_IDUS', '=', $idUser],
  484. ])->first();
  485. if(is_null($usr)){
  486. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  487. }
  488. if ( is_null($idEmployee) || $idEmployee === '') {
  489. $employees = DB::table('S002V01TPERS')
  490. ->select([
  491. 'PERS_IDPE AS ID_EMPLOYEE',
  492. DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
  493. 'PERS_TICO AS CONTRACT_TYPE',
  494. 'PERS_ESPE AS SPECIALITY',
  495. 'PERS_EQTR AS TEAM_ID',
  496. 'EQMA_NOMB AS TEAM_NAME',
  497. 'PERS_FERE AS REGISTER_DATE',
  498. 'PERS_USRE AS REGISTERED_BY_USER',
  499. 'PERS_FEMO AS UPDATE_DATE',
  500. 'PERS_USMO AS UPDATED_BY_USER',
  501. ])
  502. ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
  503. ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
  504. ->where('PERS_ESTA', '=', 'Activo')
  505. ->where('USUA_NULI', '=', $line)
  506. ->get()
  507. ->all();
  508. } else {
  509. $employees = DB::table('S002V01TPERS')
  510. ->select([
  511. 'PERS_IDPE AS ID_EMPLOYEE',
  512. DB::raw('TRIM(CONCAT(USUA_NOMB, " " , USUA_APPA, " ", COALESCE(USUA_APMA,""))) as NAME'),
  513. 'PERS_TICO AS CONTRACT_TYPE',
  514. 'PERS_ESPE AS SPECIALITY',
  515. 'PERS_EQTR AS TEAM_ID',
  516. 'EQMA_NOMB AS TEAM_NAME',
  517. 'PERS_FERE AS REGISTER_DATE',
  518. 'PERS_USRE AS REGISTERED_BY_USER',
  519. 'PERS_FEMO AS UPDATE_DATE',
  520. 'PERS_USMO AS UPDATED_BY_USER',
  521. ])
  522. ->join('S002V01TUSUA', 'PERS_IDUS', '=', 'USUA_IDUS')
  523. ->leftJoin('S002V01TEQMA', 'PERS_EQTR', '=', 'EQMA_IDEQ')
  524. ->where('PERS_ESTA', '=', 'Activo')
  525. ->where('USUA_NULI', '=', $line)
  526. ->where('PERS_IDPE', '!=', $idEmployee)
  527. ->get()
  528. ->all();
  529. }
  530. $now = $this->functionsController->now();
  531. $nowStr = $now->toDateTimeString();
  532. $actions = DB::getQueryLog();
  533. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  534. $idac = $this->functionsController->registerActivity(
  535. $line,
  536. 'S002V01M11GPRS',
  537. 'S002V01F01GEPE',
  538. 'S002V01P01COEM',
  539. 'Consulta',
  540. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los empleados registrados.",
  541. $idUser,
  542. $nowStr,
  543. 'S002V01S02GEPE'
  544. );
  545. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  546. return $this->responseController->makeResponse(false, 'EXITO', $employees);
  547. }
  548. public function storeEmployee(Request $request) {
  549. DB::enableQueryLog();
  550. $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
  551. $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
  552. $request['CONTACT_NAME'] = $this->encryptionController->decrypt($request->CONTACT_NAME) ? $this->encryptionController->decrypt($request->CONTACT_NAME) : 'ENC_ERR';
  553. $request['CONTACT_TELEPHONE'] = $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) ? $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) : 'ENC_ERR';
  554. $request['CONTACT_LADA'] = $this->encryptionController->decrypt($request->CONTACT_LADA) ? $this->encryptionController->decrypt($request->CONTACT_LADA) : 'ENC_ERR';
  555. $request['CONTACT_ADDRESS'] = $this->encryptionController->decrypt($request->CONTACT_ADDRESS) ? $this->encryptionController->decrypt($request->CONTACT_ADDRESS) : 'ENC_ERR';
  556. $validator = Validator::make($request->all(), [
  557. 'id_user' => 'required|string',
  558. 'linea' => 'required|integer',
  559. 'USER_ID' => 'required|string',
  560. 'WORKTEAM_ID' => 'required|string',
  561. 'CONTRACT_TYPE' => 'required|string|in:Subcontratista,Interno',
  562. 'SUBCONTRATIST_ID' => 'required_if:CONTRACT_TYPE,=,Subcontratista|string',
  563. 'SPECIALITY' => 'required|string|max:75',
  564. 'FOREIGNER' => 'required|string|in:Si,No',
  565. 'RFC' => 'required_if:FOREIGNER,=,No|string|max:13',
  566. 'TAX' => 'required_if:FOREIGNER,=,Si|string|max:13',
  567. 'COUNTRY' => 'required|string|max:75',
  568. 'FEDERAL_ENTITY' => 'required|string|max:75',
  569. 'CITY' => 'string|max:75',
  570. 'TOWN' => 'string|max:75',
  571. 'SUBURB' => 'required|string|max:75',
  572. 'POSTAL_CODE' => 'required|string|max:5',
  573. 'STREET' => 'required|string|max:150',
  574. 'EXTERIOR_NUMBER' => 'required|integer',
  575. 'INTERIOR_NUMBER' => 'integer',
  576. 'CONTACT_NAME' => 'required|string|max:150',
  577. 'CONTACT_LADA' => 'required|string|max:10',
  578. 'CONTACT_TELEPHONE' => 'required|string|max:11',
  579. 'CONTACT_ADDRESS' => 'required|string|max:250',
  580. 'ATTACHED' => 'required|json',
  581. ]);
  582. if($validator->fails()){
  583. return $this->responseController->makeResponse(
  584. TRUE,
  585. 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
  586. $this->responseController->makeErrors($validator->errors()->messages()),
  587. 400
  588. );
  589. }
  590. $form = $request->all();
  591. foreach($form as $k=>$v){
  592. if($k == 'INTERIOR_NUMBER' && $v == '0'){
  593. unset($form[$k]);
  594. }else if($v == '-'){
  595. unset($form[$k]);
  596. }
  597. }
  598. $idUser = $this->encryptionController->decrypt($form['id_user']);
  599. if(!$idUser){
  600. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  601. }
  602. $usr = DB::table('S002V01TUSUA')->where([
  603. ['USUA_NULI', '=', $form['linea']],
  604. ['USUA_IDUS', '=', $idUser]
  605. ])->first();
  606. if(is_null($usr)){
  607. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  608. }
  609. $idUserReg = $this->encryptionController->decrypt($form['USER_ID']);
  610. if(!$idUserReg){
  611. return $this->responseController->makeResponse(true, 'El ID del usuario seleccionado no fue encriptado correctamente.', [], 400);
  612. }else if($idUser == $idUserReg){
  613. return $this->responseController->makeResponse(true, 'El usuario no puede registrarse a sí mismo.', [], 400);
  614. }
  615. $usrReg = DB::table('S002V01TUSUA')->where([
  616. ['USUA_NULI', '=', $form['linea']],
  617. ['USUA_IDUS', '=', $idUserReg]
  618. ])->first();
  619. if(is_null($usrReg)){
  620. return $this->responseController->makeResponse(true, 'El usuario seleccionado no existe.', [], 404);
  621. }
  622. $idTeam = null;
  623. if(isset($form['WORKTEAM_ID'])){
  624. $idTeam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
  625. if(!$idTeam){
  626. return $this->responseController->makeResponse(true, 'El ID del equipo seleccionado encriptado correctamente.', [], 400);
  627. }
  628. $team = DB::table('S002V01TEQMA')->where([
  629. ['EQMA_IDEQ', '=', $idTeam],
  630. ['EQMA_NULI', '=', $form['linea']],
  631. ])->first();
  632. if(is_null($team)){
  633. return $this->responseController->makeResponse(true, 'El equipo seleccionado no existe.', [], 404);
  634. }else if($team->EQMA_ESTA == 'Eliminado'){
  635. return $this->responseController->makeResponse(true, 'El equipo seleccionado está eliminado.', [], 404);
  636. }
  637. }
  638. $idSubcontratist = null;
  639. if(isset($form['SUBCONTRATIST_ID'])){
  640. $idSubcontratist = $this->encryptionController->decrypt($form['SUBCONTRATIST_ID']);
  641. if(!$idSubcontratist){
  642. return $this->responseController->makeResponse(true, 'El ID del subcontratista seleccionado no fue encriptado correctamente.', [], 400);
  643. }
  644. $subcontratist = DB::table('S002V01TPESU')->where([
  645. ['PESU_IDPS', '=', $idSubcontratist],
  646. ['PESU_NULI', '=', $form['linea']],
  647. ])->first();
  648. if(is_null($subcontratist)){
  649. return $this->responseController->makeResponse(true, 'El subcontratista seleccionado no existe.', [], 404);
  650. }
  651. }
  652. $rfcx = null;
  653. if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
  654. return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
  655. }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
  656. $rfcx = $form['RFC'];
  657. }
  658. $taid = null;
  659. if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
  660. return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
  661. }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
  662. $taid = $form['TAX'];
  663. }
  664. $country = DB::table('S002V01TPAIS')->where([
  665. ['PAIS_NULI', '=', $form['linea']],
  666. ['PAIS_IDPA', '=', $form['COUNTRY']],
  667. ])->first();
  668. if(is_null($country)){
  669. return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
  670. }
  671. $colo = null;
  672. $ciud = null;
  673. $loca = null;
  674. if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
  675. $state = DB::table('S002V01TESTA')->where([
  676. ['ESTA_NULI', '=', $form['linea']],
  677. ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
  678. ['ESTA_COPA', '=', $form['COUNTRY']],
  679. ])->first();
  680. if(is_null($state)){
  681. return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
  682. }
  683. if($form['COUNTRY'] == 'MEX'){
  684. if(isset($form['CITY'])){
  685. $city = DB::table('S002V01TMUNI')->where([
  686. ['MUNI_NULI', '=', $form['linea']],
  687. ['MUNI_COMU', '=', $form['CITY']],
  688. ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
  689. ])->first();
  690. if(is_null($city)){
  691. return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
  692. }else{
  693. $ciud = $form['CITY'];
  694. }
  695. }
  696. if(isset($form['TOWN'])){
  697. $town = DB::table('S002V01TLOCA')->where([
  698. ['LOCA_NULI', '=', $form['linea']],
  699. ['LOCA_COLO', '=', $form['TOWN']],
  700. ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
  701. ])->first();
  702. if(is_null($town)){
  703. return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
  704. }else{
  705. $loca = $form['TOWN'];
  706. }
  707. }
  708. $setting = DB::table('S002V01TCOLO')->where([
  709. ['COLO_NULI', '=', $form['linea']],
  710. ['COLO_COCO', '=', $form['SUBURB']],
  711. ['COLO_COPO', '=', $form['POSTAL_CODE']],
  712. ])->first();
  713. if(is_null($setting)){
  714. return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
  715. }else{
  716. $colo = $form['SUBURB'];
  717. }
  718. $zipCode = DB::table('S002V01TCOPO')->where([
  719. ['COPO_NULI', '=', $form['linea']],
  720. ['COPO_COPO', '=', $form['POSTAL_CODE']],
  721. ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
  722. ])->first();
  723. if(is_null($zipCode)){
  724. return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
  725. }
  726. }else{
  727. $colo = $form['SUBURB'];
  728. $ciud = $form['CITY'];
  729. $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
  730. }
  731. }else{
  732. $colo = $form['SUBURB'];
  733. $ciud = $form['CITY'];
  734. $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
  735. }
  736. $subArr = DB::table('S002V01TPERS')->where('PERS_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form, $idUserReg) {
  737. $query->where('PERS_IDUS', '=', $idUserReg)
  738. ->orWhere('PERS_XRFC', '=', $form['RFC']);
  739. })->where('PERS_ESTA', '=', 'Activo')->get()->all();
  740. if(count($subArr) > 0){
  741. return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
  742. }
  743. $ladasValues = [];
  744. $ladas = DB::table('S002V01TPAIS')->select([
  745. 'PAIS_LADA AS LADA'
  746. ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
  747. foreach($ladas as $lada){
  748. if($lada->LADA != '' && $lada->LADA != '0'){
  749. $ladasValues[] = $lada->LADA;
  750. }
  751. }
  752. if($form['CONTACT_LADA'] == 'ENC_ERR'){
  753. return $this->responseController->makeResponse(true, "La lada del contacto de emergencia no fue encriptada correctamente.", [], 400);
  754. }else if(!in_array($form['CONTACT_LADA'], $ladasValues)){
  755. return $this->responseController->makeResponse(true, "La lada $form[CONTACT_LADA] no está relacionada a ningún país.", [], 400);
  756. }else if($form['CONTACT_TELEPHONE'] == 'ENC_ERR'){
  757. return $this->responseController->makeResponse(true, 'El número telefónico del contacto de emergencia no fue encriptado correctamente.', [], 400);
  758. }
  759. if($form['CONTACT_ADDRESS'] == 'ENC_ERR'){
  760. return $this->responseController->makeResponse(true, "La dirección del contacto de emergencia no fue encriptada correctamente.", [], 400);
  761. }
  762. if($form['CONTACT_NAME'] == 'ENC_ERR'){
  763. return $this->responseController->makeResponse(true, "El nombre del contacto de emergencia no fue encriptada correctamente.", [], 400);
  764. }
  765. $docsArr = json_decode($form['ATTACHED'], true);
  766. if(count($docsArr) == 0){
  767. return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos está vacío.", [], 400);
  768. }
  769. $authCont = 0;
  770. foreach($docsArr as $doc){
  771. if($doc['type'] == 'AU') $authCont++;
  772. }
  773. if($authCont < 1){
  774. return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos debe contener al menos un documento de autorización.", [], 400);
  775. }
  776. $finalDocsArr = [];
  777. foreach($docsArr as $doc){
  778. $idFileDec = $this->encryptionController->decrypt($doc['id']);
  779. $tempFile = DB::table('S002V01TARTE')->where([
  780. ['ARTE_NULI', '=', $form['linea']],
  781. ['ARTE_IDAR', '=', $idFileDec],
  782. ])->first();
  783. if(is_null($tempFile)){
  784. return $this->responseController->makeResponse(true, "El archivo $doc[name] no está registrado.", [], 404);
  785. }
  786. $classifications = ["AU" => "IN", "OF" => "CO", "CE" => "CE"];
  787. $cldo = $classifications[$doc['type']];
  788. $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], "GPRS", $cldo, $tempFile, $idUser);
  789. if(!$finalFile[0]){
  790. return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
  791. }else{
  792. $finalDocsArr[] = [
  793. 'CODE' => $finalFile[1],
  794. 'TYPE' => $doc['type']
  795. ];
  796. }
  797. }
  798. $now = $this->functionsController->now();
  799. $nowStr = $now->toDateTimeString();
  800. $doas = json_encode($finalDocsArr);
  801. $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
  802. $employeeID = DB::table('S002V01TPERS')->insertGetId([
  803. 'PERS_NULI' => $form['linea'],
  804. 'PERS_IDUS' => $idUserReg,
  805. 'PERS_EQTR' => $idTeam,
  806. 'PERS_TICO' => $form['CONTRACT_TYPE'],
  807. 'PERS_IDPS' => $idSubcontratist,
  808. 'PERS_ESPE' => $form['SPECIALITY'],
  809. 'PERS_EXTR' => $form['FOREIGNER'],
  810. 'PERS_XRFC' => $rfcx,
  811. 'PERS_TAID' => $taid,
  812. 'PERS_IDPA' => $form['COUNTRY'],
  813. 'PERS_ENFE' => $form['FEDERAL_ENTITY'],
  814. 'PERS_CIUD' => $ciud,
  815. 'PERS_LOCA' => $loca,
  816. 'PERS_COLO' => $colo,
  817. 'PERS_COPO' => $form['POSTAL_CODE'],
  818. 'PERS_CALL' => $form['STREET'],
  819. 'PERS_NUEX' => $form['EXTERIOR_NUMBER'],
  820. 'PERS_NUIN' => $nuin,
  821. 'PERS_NOCE' => $form['CONTACT_NAME'],
  822. 'PERS_LCEM' => $form['CONTACT_LADA'],
  823. 'PERS_NUTC' => $form['CONTACT_TELEPHONE'],
  824. 'PERS_DCEM' => $form['CONTACT_ADDRESS'],
  825. 'PERS_DOAS' => $doas,
  826. 'PERS_USRE' => $idUser,
  827. 'PERS_FERE' => $nowStr,
  828. ]);
  829. if ( !is_null($form['EMPLOYEE_BOSS']) && $form['EMPLOYEE_BOSS'] !== '') {
  830. try {
  831. $validateRegister = DB::table('S002V01TCREM')->insert([
  832. 'CREM_IDES' => $employeeID,
  833. 'CREM_IDEJ' => $form['EMPLOYEE_BOSS'],
  834. 'CREM_NULI' => $form['linea'],
  835. 'CREM_USRE' => $idUser,
  836. 'CREM_FERE' => $nowStr,
  837. 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  838. ]);
  839. } catch (Throwable $th) {
  840. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el cronograma.", [], 400);
  841. }
  842. if (!$validateRegister) {
  843. return $this->responseController->makeResponse(true, "No se pudo registrar los empleados en el cronograma.", [], 400);
  844. }
  845. }
  846. $actions = DB::getQueryLog();
  847. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  848. $nameEmp = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
  849. $idac = $this->functionsController->registerActivity(
  850. $form['linea'],
  851. 'S002V01M11GPRS',
  852. 'S002V01F01GEPE',
  853. 'S002V01P02REEM',
  854. 'Registro',
  855. "El usuario $name (" . $usr->USUA_IDUS . ") registró al empleado " . $nameEmp . "($employeeID).",
  856. $idUser,
  857. $nowStr,
  858. 'S002V01S02GEPE'
  859. );
  860. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  861. return $this->responseController->makeResponse(false, 'EXITO');
  862. }
  863. public function updateEmployee(Request $request) {
  864. DB::enableQueryLog();
  865. $request['RFC'] = $this->encryptionController->decrypt($request->RFC) ? $this->encryptionController->decrypt($request->RFC) : 'ENC_ERR';
  866. $request['TAX'] = $this->encryptionController->decrypt($request->TAX) ? $this->encryptionController->decrypt($request->TAX) : 'ENC_ERR';
  867. $request['CONTACT_NAME'] = $this->encryptionController->decrypt($request->CONTACT_NAME) ? $this->encryptionController->decrypt($request->CONTACT_NAME) : 'ENC_ERR';
  868. $request['CONTACT_TELEPHONE'] = $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) ? $this->encryptionController->decrypt($request->CONTACT_TELEPHONE) : 'ENC_ERR';
  869. $request['CONTACT_LADA'] = $this->encryptionController->decrypt($request->CONTACT_LADA) ? $this->encryptionController->decrypt($request->CONTACT_LADA) : 'ENC_ERR';
  870. $request['CONTACT_ADDRESS'] = $this->encryptionController->decrypt($request->CONTACT_ADDRESS) ? $this->encryptionController->decrypt($request->CONTACT_ADDRESS) : 'ENC_ERR';
  871. $validator = Validator::make($request->all(), [
  872. 'id_user' => 'required|string',
  873. 'linea' => 'required|integer',
  874. 'id_employee' => 'required|string',
  875. 'USER_ID' => 'required|string',
  876. 'WORKTEAM_ID' => 'required|string',
  877. 'CONTRACT_TYPE' => 'required|string|in:Subcontratista,Interno',
  878. 'SUBCONTRATIST_ID' => 'required_if:CONTRACT_TYPE,=,Subcontratista|string',
  879. 'SPECIALITY' => 'required|string|max:75',
  880. 'FOREIGNER' => 'required|string|in:Si,No',
  881. 'RFC' => 'required_if:FOREIGNER,=,No|string|max:13',
  882. 'TAX' => 'required_if:FOREIGNER,=,Si|string|max:13',
  883. 'COUNTRY' => 'required|string|max:75',
  884. 'FEDERAL_ENTITY' => 'required|string|max:75',
  885. 'CITY' => 'string|max:75',
  886. 'TOWN' => 'string|max:75',
  887. 'SUBURB' => 'required|string|max:75',
  888. 'POSTAL_CODE' => 'required|string|max:5',
  889. 'STREET' => 'required|string|max:150',
  890. 'EXTERIOR_NUMBER' => 'required|integer',
  891. 'INTERIOR_NUMBER' => 'integer',
  892. 'CONTACT_NAME' => 'required|string|max:150',
  893. 'CONTACT_LADA' => 'required|string|max:10',
  894. 'CONTACT_TELEPHONE' => 'required|string|max:11',
  895. 'CONTACT_ADDRESS' => 'required|string|max:250',
  896. 'ATTACHED' => 'required|json',
  897. ]);
  898. if($validator->fails()){
  899. return $this->responseController->makeResponse(
  900. TRUE,
  901. 'ERR_PERSONAL_REG001: Uno o más errores encontrados',
  902. $this->responseController->makeErrors($validator->errors()->messages()),
  903. 400
  904. );
  905. }
  906. $form = $request->all();
  907. foreach($form as $k=>$v){
  908. if($k == 'INTERIOR_NUMBER' && $v == '0'){
  909. unset($form[$k]);
  910. }else if($v == '-'){
  911. unset($form[$k]);
  912. }
  913. }
  914. $idUser = $this->encryptionController->decrypt($form['id_user']);
  915. if(!$idUser){
  916. return $this->responseController->makeResponse(true, 'El ID de usuario no fue encriptado correctamente.', [], 400);
  917. }
  918. $usr = DB::table('S002V01TUSUA')->where([
  919. ['USUA_NULI', '=', $form['linea']],
  920. ['USUA_IDUS', '=', $idUser]
  921. ])->first();
  922. if(is_null($usr)){
  923. return $this->responseController->makeResponse(true, 'El usuario que realizó la petición no existe.', [], 404);
  924. }
  925. $idEmployee = $this->encryptionController->decrypt($form['id_employee']);
  926. if(!$idEmployee){
  927. return $this->responseController->makeResponse(true, 'El ID del empleado que desea actualizar no fue encriptado correctamente.', [], 400);
  928. }
  929. $employee = DB::table('S002V01TPERS')->where([
  930. ['PERS_NULI', '=', $form['linea']],
  931. ['PERS_IDPE', '=', $idEmployee]
  932. ])->first();
  933. if(is_null($employee)){
  934. return $this->responseController->makeResponse(true, 'El empleado que desea actualizar no existe.', [], 404);
  935. }
  936. $idUserReg = $this->encryptionController->decrypt($form['USER_ID']);
  937. if(!$idUserReg){
  938. return $this->responseController->makeResponse(true, 'El ID del usuario seleccionado no fue encriptado correctamente.', [], 400);
  939. }else if($idUser == $idUserReg){
  940. return $this->responseController->makeResponse(true, 'El usuario no puede registrarse a sí mismo.', [], 400);
  941. }
  942. $usrReg = DB::table('S002V01TUSUA')->where([
  943. ['USUA_NULI', '=', $form['linea']],
  944. ['USUA_IDUS', '=', $idUserReg]
  945. ])->first();
  946. if(is_null($usrReg)){
  947. return $this->responseController->makeResponse(true, 'El usuario seleccionado no existe.', [], 404);
  948. }
  949. $idTeam = null;
  950. if(isset($form['WORKTEAM_ID'])){
  951. $idTeam = $this->encryptionController->decrypt($form['WORKTEAM_ID']);
  952. if(!$idTeam){
  953. return $this->responseController->makeResponse(true, 'El ID del equipo seleccionado encriptado correctamente.', [], 400);
  954. }
  955. $team = DB::table('S002V01TEQMA')->where([
  956. ['EQMA_IDEQ', '=', $idTeam],
  957. ['EQMA_NULI', '=', $form['linea']],
  958. ])->first();
  959. if(is_null($team)){
  960. return $this->responseController->makeResponse(true, 'El equipo seleccionado no existe.', [], 404);
  961. }else if($team->EQMA_ESTA == 'Eliminado'){
  962. return $this->responseController->makeResponse(true, 'El equipo seleccionado está eliminado.', [], 404);
  963. }
  964. }
  965. $idSubcontratist = null;
  966. if(isset($form['SUBCONTRATIST_ID'])){
  967. $idSubcontratist = $this->encryptionController->decrypt($form['SUBCONTRATIST_ID']);
  968. if(!$idSubcontratist){
  969. return $this->responseController->makeResponse(true, 'El ID del subcontratista seleccionado no fue encriptado correctamente.', [], 400);
  970. }
  971. $subcontratist = DB::table('S002V01TPESU')->where([
  972. ['PESU_IDPS', '=', $idSubcontratist],
  973. ['PESU_NULI', '=', $form['linea']],
  974. ])->first();
  975. if(is_null($subcontratist)){
  976. return $this->responseController->makeResponse(true, 'El subcontratista seleccionado no existe.', [], 404);
  977. }
  978. }
  979. $rfcx = null;
  980. if(isset($form['RFC']) && $form['FOREIGNER'] == 'No' && $form['RFC'] == 'ENC_ERR'){
  981. return $this->responseController->makeResponse(true, 'El RFC no fue encriptado correctamente.', [], 400);
  982. }else if(isset($form['RFC']) && $form['RFC'] != 'ENC_ERR'){
  983. $rfcx = $form['RFC'];
  984. }
  985. $taid = null;
  986. if(isset($form['TAX']) && $form['FOREIGNER'] == 'Si' && $form['TAX'] == 'ENC_ERR'){
  987. return $this->responseController->makeResponse(true, 'El TAX ID no fue encriptado correctamente.', [], 400);
  988. }else if(isset($form['TAX']) && $form['TAX'] != 'ENC_ERR'){
  989. $taid = $form['TAX'];
  990. }
  991. $country = DB::table('S002V01TPAIS')->where([
  992. ['PAIS_NULI', '=', $form['linea']],
  993. ['PAIS_IDPA', '=', $form['COUNTRY']],
  994. ])->first();
  995. if(is_null($country)){
  996. return $this->responseController->makeResponse(true, 'El país seleccionado no existe.', [], 404);
  997. }
  998. $colo = null;
  999. $ciud = null;
  1000. $loca = null;
  1001. if($form['COUNTRY'] == 'MEX' || $form['COUNTRY'] == 'USA' || $form['COUNTRY'] == 'CAN'){
  1002. $state = DB::table('S002V01TESTA')->where([
  1003. ['ESTA_NULI', '=', $form['linea']],
  1004. ['ESTA_COES', '=', $form['FEDERAL_ENTITY']],
  1005. ['ESTA_COPA', '=', $form['COUNTRY']],
  1006. ])->first();
  1007. if(is_null($state)){
  1008. return $this->responseController->makeResponse(true, 'El estado seleccionado no existe.', [], 404);
  1009. }
  1010. if($form['COUNTRY'] == 'MEX'){
  1011. if(isset($form['CITY'])){
  1012. $city = DB::table('S002V01TMUNI')->where([
  1013. ['MUNI_NULI', '=', $form['linea']],
  1014. ['MUNI_COMU', '=', $form['CITY']],
  1015. ['MUNI_COES', '=', $form['FEDERAL_ENTITY']],
  1016. ])->first();
  1017. if(is_null($city)){
  1018. return $this->responseController->makeResponse(true, 'El municipio seleccionado no existe.', [], 404);
  1019. }else{
  1020. $ciud = $form['CITY'];
  1021. }
  1022. }
  1023. if(isset($form['TOWN'])){
  1024. $town = DB::table('S002V01TLOCA')->where([
  1025. ['LOCA_NULI', '=', $form['linea']],
  1026. ['LOCA_COLO', '=', $form['TOWN']],
  1027. ['LOCA_COES', '=', $form['FEDERAL_ENTITY']],
  1028. ])->first();
  1029. if(is_null($town)){
  1030. return $this->responseController->makeResponse(true, 'La localidad seleccionada no existe.', [], 404);
  1031. }else{
  1032. $loca = $form['TOWN'];
  1033. }
  1034. }
  1035. $setting = DB::table('S002V01TCOLO')->where([
  1036. ['COLO_NULI', '=', $form['linea']],
  1037. ['COLO_COCO', '=', $form['SUBURB']],
  1038. ['COLO_COPO', '=', $form['POSTAL_CODE']],
  1039. ])->first();
  1040. if(is_null($setting)){
  1041. return $this->responseController->makeResponse(true, 'La colonia seleccionada no existe.', [], 404);
  1042. }else{
  1043. $colo = $form['SUBURB'];
  1044. }
  1045. $zipCode = DB::table('S002V01TCOPO')->where([
  1046. ['COPO_NULI', '=', $form['linea']],
  1047. ['COPO_COPO', '=', $form['POSTAL_CODE']],
  1048. ['COPO_COES', '=', $form['FEDERAL_ENTITY']],
  1049. ])->first();
  1050. if(is_null($zipCode)){
  1051. return $this->responseController->makeResponse(true, 'El código postal seleccionado no existe.', [], 404);
  1052. }
  1053. }else{
  1054. $colo = $form['SUBURB'];
  1055. $ciud = $form['CITY'];
  1056. $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
  1057. }
  1058. }else{
  1059. $colo = $form['SUBURB'];
  1060. $ciud = $form['CITY'];
  1061. $loca = isset($form['TOWN']) ? $form['TOWN'] : null;
  1062. }
  1063. $subArr = DB::table('S002V01TPERS')->where('PERS_NULI', '=', $form['linea'])->where(function(Builder $query) use ($form, $idUserReg) {
  1064. $query->where('PERS_IDUS', '=', $idUserReg)
  1065. ->orWhere('PERS_XRFC', '=', $form['RFC']);
  1066. })->where([
  1067. ['PERS_ESTA', '=', 'Activo'],
  1068. ['PERS_IDPE', '!=', $idEmployee],
  1069. ])->get()->all();
  1070. if(count($subArr) > 0){
  1071. return $this->responseController->makeResponse(true, 'La razón social, el RFC o el correo electrónico ya fueron registrados.', [], 401);
  1072. }
  1073. $ladasValues = [];
  1074. $ladas = DB::table('S002V01TPAIS')->select([
  1075. 'PAIS_LADA AS LADA'
  1076. ])->where('PAIS_NULI', '=', $form['linea'])->get()->all();
  1077. foreach($ladas as $lada){
  1078. if($lada->LADA != '' && $lada->LADA != '0'){
  1079. $ladasValues[] = $lada->LADA;
  1080. }
  1081. }
  1082. if($form['CONTACT_LADA'] == 'ENC_ERR'){
  1083. return $this->responseController->makeResponse(true, "La lada del contacto de emergencia no fue encriptada correctamente.", [], 400);
  1084. }else if(!in_array($form['CONTACT_LADA'], $ladasValues)){
  1085. return $this->responseController->makeResponse(true, "La lada $form[CONTACT_LADA] no está relacionada a ningún país.", [], 400);
  1086. }else if($form['CONTACT_TELEPHONE'] == 'ENC_ERR'){
  1087. return $this->responseController->makeResponse(true, 'El número telefónico del contacto de emergencia no fue encriptado correctamente.', [], 400);
  1088. }
  1089. if($form['CONTACT_ADDRESS'] == 'ENC_ERR'){
  1090. return $this->responseController->makeResponse(true, "La dirección del contacto de emergencia no fue encriptada correctamente.", [], 400);
  1091. }
  1092. if($form['CONTACT_NAME'] == 'ENC_ERR'){
  1093. return $this->responseController->makeResponse(true, "El nombre del contacto de emergencia no fue encriptada correctamente.", [], 400);
  1094. }
  1095. $docsArr = json_decode($form['ATTACHED'], true);
  1096. if(count($docsArr) == 0){
  1097. return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos está vacío.", [], 400);
  1098. }
  1099. $authCont = 0;
  1100. foreach($docsArr as $doc){
  1101. if($doc['type'] == 'AU') $authCont++;
  1102. }
  1103. if($authCont < 1){
  1104. return $this->responseController->makeResponse(true, "El arreglo de archivos adjuntos debe contener al menos un documento de autorización.", [], 400);
  1105. }
  1106. $finalDocsArr = [];
  1107. foreach($docsArr as $doc){
  1108. if(!array_key_exists('isFinalFile', $doc)){
  1109. return $this->responseController->makeResponse(true, "La información del archivo $doc[name] no tiene un formato correcto.", [], 400);
  1110. }
  1111. if($doc['isFinalFile']){
  1112. $finalDocsArr[] = [
  1113. 'CODE' => $doc['name'],
  1114. 'TYPE' => $doc['type']
  1115. ];
  1116. }else{
  1117. $idFileDec = $this->encryptionController->decrypt($doc['id']);
  1118. $tempFile = DB::table('S002V01TARTE')->where([
  1119. ['ARTE_NULI', '=', $form['linea']],
  1120. ['ARTE_IDAR', '=', $idFileDec],
  1121. ])->first();
  1122. if(is_null($tempFile)){
  1123. return $this->responseController->makeResponse(true, "El archivo $doc[name] no está registrado.", [], 404);
  1124. }
  1125. $classifications = ["AU" => "IN", "OF" => "CO", "CE" => "CE"];
  1126. $cldo = $classifications[$doc['type']];
  1127. $finalFile = $this->documentManagementController->moveFinalFile($form['linea'], "GPRS", $cldo, $tempFile, $idUser);
  1128. if(!$finalFile[0]){
  1129. return $this->responseController->makeResponse(true, $finalFile[1], [], 400);
  1130. }else{
  1131. $finalDocsArr[] = [
  1132. 'CODE' => $finalFile[1],
  1133. 'TYPE' => $doc['type']
  1134. ];
  1135. }
  1136. }
  1137. }
  1138. $doas = json_encode($finalDocsArr);
  1139. $nuin = isset($form['INTERIOR_NUMBER']) ? $form['INTERIOR_NUMBER'] : null;
  1140. $now = $this->functionsController->now();
  1141. $nowStr = $now->toDateTimeString();
  1142. DB::table('S002V01TPERS')->where([
  1143. ['PERS_NULI', '=', $form['linea']],
  1144. ['PERS_IDPE', '=', $idEmployee]
  1145. ])->update([
  1146. 'PERS_EQTR' => $idTeam,
  1147. 'PERS_TICO' => $form['CONTRACT_TYPE'],
  1148. 'PERS_IDPS' => $idSubcontratist,
  1149. 'PERS_ESPE' => $form['SPECIALITY'],
  1150. 'PERS_EXTR' => $form['FOREIGNER'],
  1151. 'PERS_XRFC' => $rfcx,
  1152. 'PERS_TAID' => $taid,
  1153. 'PERS_IDPA' => $form['COUNTRY'],
  1154. 'PERS_ENFE' => $form['FEDERAL_ENTITY'],
  1155. 'PERS_CIUD' => $ciud,
  1156. 'PERS_LOCA' => $loca,
  1157. 'PERS_COLO' => $colo,
  1158. 'PERS_COPO' => $form['POSTAL_CODE'],
  1159. 'PERS_CALL' => $form['STREET'],
  1160. 'PERS_NUEX' => $form['EXTERIOR_NUMBER'],
  1161. 'PERS_NUIN' => $nuin,
  1162. 'PERS_NOCE' => $form['CONTACT_NAME'],
  1163. 'PERS_LCEM' => $form['CONTACT_LADA'],
  1164. 'PERS_NUTC' => $form['CONTACT_TELEPHONE'],
  1165. 'PERS_DCEM' => $form['CONTACT_ADDRESS'],
  1166. 'PERS_DOAS' => $doas,
  1167. 'PERS_USMO' => $idUser,
  1168. 'PERS_FEMO' => $nowStr,
  1169. ]);
  1170. if ( !is_null($form['EMPLOYEE_BOSS']) && $form['EMPLOYEE_BOSS'] !== '') {
  1171. try {
  1172. $arrCronograma = (array) DB::table('S002V01TCREM')
  1173. ->where('CREM_IDES', '=', $idEmployee)
  1174. ->where('CREM_IDEJ', '=', $form['EMPLOYEE_BOSS'])
  1175. ->where('CREM_NULI', '=', $form['linea'])
  1176. ->first([
  1177. 'CREM_IDES AS ID_SUBORDINADO',
  1178. 'CREM_IDEJ AS IS_JEFE',
  1179. 'CREM_ESTA AS ESTADO',
  1180. ]);
  1181. } catch (\Throwable $th) {
  1182. return $this->responseController->makeResponse(true, "Ocurrió un error al obtener el cronograma.", [], 400);
  1183. }
  1184. if ( count($arrCronograma) === 0 ) {
  1185. try {
  1186. $validateRegister = DB::table('S002V01TCREM')->insert([
  1187. 'CREM_IDES' => $idEmployee,
  1188. 'CREM_IDEJ' => $form['EMPLOYEE_BOSS'],
  1189. 'CREM_NULI' => $form['linea'],
  1190. 'CREM_USRE' => $idUser,
  1191. 'CREM_FERE' => $nowStr,
  1192. 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1193. ]);
  1194. } catch (Throwable $th) {
  1195. return $this->responseController->makeResponse(true, "Ocurrió un error al registrar el cronograma.", [], 400);
  1196. }
  1197. if (!$validateRegister) {
  1198. return $this->responseController->makeResponse(true, "No se pudo registrar los empleados en el cronograma.", [], 400);
  1199. }
  1200. } else {
  1201. try {
  1202. $validateUpdate = DB::table('S002V01TCREM')
  1203. ->where('CREM_IDES', '=', $idEmployee)
  1204. ->where('CREM_IDEJ', '=', $form['EMPLOYEE_BOSS'])
  1205. ->where('CREM_NULI', '=', $form['linea'])
  1206. ->update([
  1207. 'CREM_ESTA' => 'Activo',
  1208. 'CREM_USMO' => $idUser,
  1209. 'CREM_FEMO' => $nowStr,
  1210. 'CREM_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1211. ]);
  1212. } catch (\Throwable $th) {
  1213. return $this->responseController->makeResponse(true, "Ocurrió un error al modificar el cronograma.", [], 400);
  1214. }
  1215. if (!$validateUpdate) {
  1216. return $this->responseController->makeResponse(true, "No se pudo modificar los empleados en el cronograma.", [], 400);
  1217. }
  1218. }
  1219. }
  1220. $actions = DB::getQueryLog();
  1221. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1222. $nameEmp = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
  1223. $idac = $this->functionsController->registerActivity(
  1224. $form['linea'],
  1225. 'S002V01M11GPRS',
  1226. 'S002V01F01GEPE',
  1227. 'S002V01P02REEM',
  1228. 'Actualización',
  1229. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al empleado " . $nameEmp . "($idEmployee).",
  1230. $idUser,
  1231. $nowStr,
  1232. 'S002V01S02GEPE'
  1233. );
  1234. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $form['linea']);
  1235. return $this->responseController->makeResponse(false, 'EXITO');
  1236. }
  1237. public function getScheduleActivitiesByEmployee($idEmployee, $user, $line) {
  1238. try {
  1239. $idEmployee = $this->encryptionController->decrypt($idEmployee);
  1240. } catch (\Throwable $th) {
  1241. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY000: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
  1242. }
  1243. try {
  1244. $getSheduleActivities = DB::table('S002V01TCOAC')
  1245. ->where('COAC_NULI','=',$line)
  1246. ->where('COAC_ESTA','=','Activo')
  1247. ->where('COAC_IDPE','=',$idEmployee)
  1248. ->get([
  1249. 'COAC_IDAC AS ID_ACTIVIDAD',
  1250. 'COAC_IDPE AS ID_EMPLEADO',
  1251. 'COAC_ACTI AS ACTIVIDAD',
  1252. 'COAC_DESC AS DESCRIPCION',
  1253. 'COAC_TIPO AS TIPO_ACTIVIDAD',
  1254. 'COAC_OTPR AS ID_ORDEN_PREVENTIVO',
  1255. 'COAC_OTCO AS ID_ORDEN_CORRECTIVO',
  1256. 'COAC_FEIN AS FECHA_INICIO',
  1257. 'COAC_HOIN AS HORA_INICIO',
  1258. 'COAC_FEFE AS FECHA_FINAL',
  1259. 'COAC_HOFE AS HORA_FINAL',
  1260. 'COAC_FEFR AS FECHA_FINAL_REAL',
  1261. 'COAC_HOFR AS HORA_FINAL_REAL',
  1262. 'COAC_PERI AS PERIODICIDAD',
  1263. 'COAC_PEPE AS PERIODICIDAD_PERSONALIZADA',
  1264. 'COAC_CLAS AS CLASIFICACION',
  1265. 'COAC_COLO AS COLOR',
  1266. 'COAC_ESTA AS ESTADO',
  1267. 'COAC_FERE AS FECHA_REGISTRA',
  1268. 'COAC_USRE AS USUARIO_REGISTRA',
  1269. 'COAC_FEMO AS FECHA_MODIFICA',
  1270. 'COAC_USMO AS USUARIO_MODIFICA',
  1271. ]);
  1272. } catch (\Throwable $th) {
  1273. DB::rollBack();
  1274. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY001: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
  1275. }
  1276. $arrSheduleActivities = json_decode(json_encode($getSheduleActivities), true);
  1277. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSheduleActivities);
  1278. }
  1279. public function registerActivity(Request $request) {
  1280. $valitador = Validator::make($request->all(), [
  1281. 'ID_EMPLEADO' => 'required|string',
  1282. 'ACTIVIDAD' => 'required|string',
  1283. 'CLASIFICACION' => 'required|string',
  1284. 'DESCRIPCION' => 'required|string',
  1285. 'TIPO_ACTIVIDAD' => 'required|string',
  1286. 'ID_ORDEN' => 'nullable|string',
  1287. 'PERIODICIDAD' => 'nullable|string',
  1288. 'FECHA_INICIO' => 'required|string',
  1289. 'HORA_INICIO' => 'required|string',
  1290. 'FECHA_FINAL' => 'nullable|string',
  1291. 'HORA_FINAL' => 'nullable|string',
  1292. 'PERIODICIDAD_PERSONALIZADA' => 'nullable|string',
  1293. 'COLOR' => 'required|string',
  1294. 'USUARIO' => 'required|string',
  1295. 'NUMERO_LINEA' => 'required|string',
  1296. ]);
  1297. if ($valitador->fails()) {
  1298. return $this->responseController->makeResponse(
  1299. true,
  1300. "ERR_EMPLOYEE_REGACTIVITY000: Se encontraron uno o más errores.",
  1301. $this->responseController->makeErrors($valitador->errors()->messages()),
  1302. 401
  1303. );
  1304. }
  1305. DB::beginTransaction();
  1306. $requestData = $request->all();
  1307. try {
  1308. $user = $this->encryptionController->decrypt($requestData['USUARIO']);
  1309. } catch (\Throwable $th) {
  1310. DB::rollBack();
  1311. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  1312. }
  1313. try {
  1314. $validateUser = DB::table('S002V01TUSUA')
  1315. ->where('USUA_NULI', '=', $requestData['NUMERO_LINEA'])
  1316. ->where('USUA_IDUS', '=', $user)
  1317. ->exists();
  1318. } catch(\Throwable $th) {
  1319. DB::rollBack();
  1320. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY002: Ocurrió al verificar la existencia del usuario.", $th->getMessage(), 404);
  1321. }
  1322. if (!$validateUser) {
  1323. DB::rollBack();
  1324. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY003: El usuario no existe.", [], 404);
  1325. }
  1326. $idPreventiveMaintenance = null;
  1327. $idCorrectiveMaintenance = null;
  1328. if ($requestData['TIPO_ACTIVIDAD'] === 'MP') {
  1329. if (is_null($requestData['ID_ORDEN'])) {
  1330. DB::rollBack();
  1331. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY004: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
  1332. }
  1333. try {
  1334. $validateMaintenance = DB::table('S002V01TOTPR')
  1335. ->where('OTPR_IDOT', '=', $requestData['ID_ORDEN'])
  1336. ->where('OTPR_NULI', '=', $requestData['NUMERO_LINEA'])
  1337. ->exists();
  1338. } catch (\Throwable $th) {
  1339. DB::rollBack();
  1340. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY005: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
  1341. }
  1342. if (!$validateMaintenance) {
  1343. DB::rollBack();
  1344. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY006: La orden de trabajo no existe en la lista de mantenimientos preventivos.", [], 404);
  1345. }
  1346. $idPreventiveMaintenance = $requestData['ID_ORDEN'];
  1347. } else if ($requestData['TIPO_ACTIVIDAD'] === 'MC') {
  1348. if (is_null($requestData['ID_ORDEN'])) {
  1349. DB::rollBack();
  1350. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY007: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
  1351. }
  1352. try {
  1353. $validateMaintenance = DB::table('S002V01TOTCO')
  1354. ->where('OTCO_IDOT ', '=', $requestData['ID_ORDEN'])
  1355. ->where('OTCO_NULI ', '=', $requestData['NUMERO_LINEA'])
  1356. ->exists();
  1357. } catch (\Throwable $th) {
  1358. DB::rollBack();
  1359. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY008: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
  1360. }
  1361. if (!$validateMaintenance) {
  1362. DB::rollBack();
  1363. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY009: La orden de trabajo no existe en la lista de mantenimientos correctivo.", [], 404);
  1364. }
  1365. $idCorrectiveMaintenance = $requestData['ID_ORDEN'];
  1366. } else if ($requestData['TIPO_ACTIVIDAD'] === 'NA' && is_null($requestData['ID_ORDEN']) && !is_null($requestData['PERIODICIDAD']) ) {
  1367. if ($requestData['PERIODICIDAD'] === 'PE' && is_null($requestData['PERIODICIDAD_PERSONALIZADA'])) {
  1368. DB::rollBack();
  1369. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY010: El tipo de periodicidad personalizada debe estar incluida si el tipo de periodicidad está selecciona como Personalizada.", [], 404);
  1370. }
  1371. if ($requestData['PERIODICIDAD'] === 'NR' && (is_null($requestData['FECHA_FINAL']) | is_null($requestData['HORA_FINAL'])) ) {
  1372. DB::rollBack();
  1373. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY011: La fecha y la hora final esperada debe estar incluida en el formulario si la periodicidad está seleccionada como No se repite.", [], 404);
  1374. }
  1375. } else {
  1376. DB::rollBack();
  1377. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY012: El tipo de actividad no es correcto.", [], 404);
  1378. }
  1379. $now = $this->functionsController->now();
  1380. $currentDate = $now->toDateTimeString();
  1381. try {
  1382. $validateInsert = DB::table('S002V01TCOAC')->insert([
  1383. 'COAC_NULI' => $requestData['NUMERO_LINEA'],
  1384. 'COAC_IDPE' => $requestData['ID_EMPLEADO'],
  1385. 'COAC_ACTI' => $requestData['ACTIVIDAD'],
  1386. 'COAC_DESC' => $requestData['DESCRIPCION'],
  1387. 'COAC_TIPO' => $requestData['TIPO_ACTIVIDAD'],
  1388. 'COAC_OTPR' => $idPreventiveMaintenance,
  1389. 'COAC_OTCO' => $idCorrectiveMaintenance,
  1390. 'COAC_FEIN' => $requestData['FECHA_INICIO'],
  1391. 'COAC_HOIN' => $requestData['HORA_INICIO'],
  1392. 'COAC_FEFE' => $requestData['FECHA_FINAL'],
  1393. 'COAC_HOFE' => $requestData['HORA_FINAL'],
  1394. // 'COAC_FEFR' => $requestData[''],
  1395. // 'COAC_HOFR' => $requestData[''],
  1396. 'COAC_PERI' => $requestData['PERIODICIDAD'],
  1397. 'COAC_PEPE' => $requestData['PERIODICIDAD_PERSONALIZADA'],
  1398. 'COAC_CLAS' => $requestData['CLASIFICACION'],
  1399. 'COAC_COLO' => $requestData['COLOR'],
  1400. 'COAC_FERE' => $currentDate,
  1401. 'COAC_USRE' => $user,
  1402. 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1403. ]);
  1404. } catch (\Throwable $th) {
  1405. DB::rollBack();
  1406. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY013: Ocurrió un error al insertar los datos.", $th->getMessage(), 404);
  1407. }
  1408. if (!$validateInsert) {
  1409. DB::rollBack();
  1410. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_REGACTIVITY014: No se pudo insertar los datos en la base de datos.", [], 404);
  1411. }
  1412. DB::commit();
  1413. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  1414. }
  1415. public function updateActivity(Request $request, $idActivity) {
  1416. $valitador = Validator::make($request->all(), [
  1417. // 'ID_ACTIVIDAD' => 'required|integer',
  1418. 'ID_EMPLEADO' => 'required|string',
  1419. 'ACTIVIDAD' => 'required|string',
  1420. 'CLASIFICACION' => 'required|string',
  1421. 'DESCRIPCION' => 'required|string',
  1422. 'TIPO_ACTIVIDAD' => 'required|string',
  1423. 'ID_ORDEN' => 'nullable|string',
  1424. 'PERIODICIDAD' => 'nullable|string',
  1425. 'FECHA_INICIO' => 'required|string',
  1426. 'HORA_INICIO' => 'required|string',
  1427. 'FECHA_FINAL' => 'nullable|string',
  1428. 'HORA_FINAL' => 'nullable|string',
  1429. 'PERIODICIDAD_PERSONALIZADA' => 'nullable|string',
  1430. 'COLOR' => 'required|string',
  1431. 'USUARIO' => 'required|string',
  1432. 'NUMERO_LINEA' => 'required|string',
  1433. ]);
  1434. if ($valitador->fails()) {
  1435. return $this->responseController->makeResponse(
  1436. true,
  1437. "ERR_EMPLOYEE_UPDACTIVITY000: Se encontraron uno o más errores.",
  1438. $this->responseController->makeErrors($valitador->errors()->messages()),
  1439. 401
  1440. );
  1441. }
  1442. DB::beginTransaction();
  1443. $requestData = $request->all();
  1444. try {
  1445. $idActivity = $this->encryptionController->decrypt($idActivity);
  1446. } catch (\Throwable $th) {
  1447. DB::rollBack();
  1448. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY001: Ocurrió un error al desencriptar los datos de la actividad.", $th->getMessage(), 401);
  1449. }
  1450. try {
  1451. $user = $this->encryptionController->decrypt($requestData['USUARIO']);
  1452. } catch (\Throwable $th) {
  1453. DB::rollBack();
  1454. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY002: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  1455. }
  1456. try {
  1457. $validateUser = DB::table('S002V01TUSUA')
  1458. ->where('USUA_NULI', '=', $requestData['NUMERO_LINEA'])
  1459. ->where('USUA_IDUS', '=', $user)
  1460. ->exists();
  1461. } catch(\Throwable $th) {
  1462. DB::rollBack();
  1463. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY003: Ocurrió al verificar la existencia del usuario.", $th->getMessage(), 404);
  1464. }
  1465. if (!$validateUser) {
  1466. DB::rollBack();
  1467. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY004: El usuario no existe.", [], 404);
  1468. }
  1469. $idPreventiveMaintenance = null;
  1470. $idCorrectiveMaintenance = null;
  1471. if ($requestData['TIPO_ACTIVIDAD'] === 'MP') {
  1472. if (is_null($requestData['ID_ORDEN'])) {
  1473. DB::rollBack();
  1474. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY005: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
  1475. }
  1476. try {
  1477. $validateMaintenance = DB::table('S002V01TOTPR')
  1478. ->where('OTPR_IDOT', '=', $requestData['ID_ORDEN'])
  1479. ->where('OTPR_NULI', '=', $requestData['NUMERO_LINEA'])
  1480. ->exists();
  1481. } catch (\Throwable $th) {
  1482. DB::rollBack();
  1483. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY006: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
  1484. }
  1485. if (!$validateMaintenance) {
  1486. DB::rollBack();
  1487. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY007: La orden de trabajo no existe en la lista de mantenimientos preventivos.", [], 404);
  1488. }
  1489. $idPreventiveMaintenance = $requestData['ID_ORDEN'];
  1490. } else if ($requestData['TIPO_ACTIVIDAD'] === 'MC') {
  1491. if (is_null($requestData['ID_ORDEN'])) {
  1492. DB::rollBack();
  1493. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY008: El ID de la orden de mantenimiento no viene incluida en los datos del formulario.", [], 404);
  1494. }
  1495. try {
  1496. $validateMaintenance = DB::table('S002V01TOTCO')
  1497. ->where('OTCO_IDOT ', '=', $requestData['ID_ORDEN'])
  1498. ->where('OTCO_NULI ', '=', $requestData['NUMERO_LINEA'])
  1499. ->exists();
  1500. } catch (\Throwable $th) {
  1501. DB::rollBack();
  1502. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY009: Ocurrió un error al validar la orden de mantenimiento.", $th->getMessage(), 404);
  1503. }
  1504. if (!$validateMaintenance) {
  1505. DB::rollBack();
  1506. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY010: La orden de trabajo no existe en la lista de mantenimientos correctivo.", [], 404);
  1507. }
  1508. $idCorrectiveMaintenance = $requestData['ID_ORDEN'];
  1509. } else if ($requestData['TIPO_ACTIVIDAD'] === 'NA' && is_null($requestData['ID_ORDEN']) && !is_null($requestData['PERIODICIDAD']) ) {
  1510. if ($requestData['PERIODICIDAD'] === 'PE' && is_null($requestData['PERIODICIDAD_PERSONALIZADA'])) {
  1511. DB::rollBack();
  1512. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY011: El tipo de periodicidad personalizada debe estar incluida si el tipo de periodicidad está selecciona como Personalizada.", [], 404);
  1513. }
  1514. if ($requestData['PERIODICIDAD'] === 'NR' && (is_null($requestData['FECHA_FINAL']) | is_null($requestData['HORA_FINAL'])) ) {
  1515. DB::rollBack();
  1516. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY012: La fecha y la hora final esperada debe estar incluida en el formulario si la periodicidad está seleccionada como No se repite.", [], 404);
  1517. }
  1518. } else {
  1519. DB::rollBack();
  1520. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY013: El tipo de actividad no es correcto.", [], 404);
  1521. }
  1522. $now = $this->functionsController->now();
  1523. $currentDate = $now->toDateTimeString();
  1524. try {
  1525. $validateInsert = DB::table('S002V01TCOAC')
  1526. ->where('COAC_IDAC','=',$idActivity)
  1527. ->where('COAC_NULI','=',$requestData['NUMERO_LINEA'])
  1528. ->where('COAC_IDPE','=',$requestData['ID_EMPLEADO'])
  1529. ->update([
  1530. 'COAC_ACTI' => $requestData['ACTIVIDAD'],
  1531. 'COAC_DESC' => $requestData['DESCRIPCION'],
  1532. 'COAC_TIPO' => $requestData['TIPO_ACTIVIDAD'],
  1533. 'COAC_OTPR' => $idPreventiveMaintenance,
  1534. 'COAC_OTCO' => $idCorrectiveMaintenance,
  1535. 'COAC_FEIN' => $requestData['FECHA_INICIO'],
  1536. 'COAC_HOIN' => $requestData['HORA_INICIO'],
  1537. 'COAC_FEFE' => $requestData['FECHA_FINAL'],
  1538. 'COAC_HOFE' => $requestData['HORA_FINAL'],
  1539. // 'COAC_FEFR' => $requestData[''],
  1540. // 'COAC_HOFR' => $requestData[''],
  1541. 'COAC_PERI' => $requestData['PERIODICIDAD'],
  1542. 'COAC_PEPE' => $requestData['PERIODICIDAD_PERSONALIZADA'],
  1543. 'COAC_CLAS' => $requestData['CLASIFICACION'],
  1544. 'COAC_COLO' => $requestData['COLOR'],
  1545. 'COAC_FEMO' => $currentDate,
  1546. 'COAC_USMO' => $user,
  1547. 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1548. ]);
  1549. } catch (\Throwable $th) {
  1550. DB::rollBack();
  1551. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY014: Ocurrió un error al insertar los datos.", $th->getMessage(), 404);
  1552. }
  1553. if (!$validateInsert) {
  1554. DB::rollBack();
  1555. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_UPDACTIVITY015: No se pudo insertar los datos en la base de datos.", [], 404);
  1556. }
  1557. DB::commit();
  1558. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1559. }
  1560. public function deleteActivity(Request $request, $idActivity) {
  1561. $valitador = Validator::make($request->all(), [
  1562. 'USUARIO' => 'required|string',
  1563. 'NUMERO_LINEA' => 'required|string',
  1564. ]);
  1565. if ($valitador->fails()) {
  1566. return $this->responseController->makeResponse(
  1567. true,
  1568. "ERR_EMPLOYEE_DELACTIVITY000: Se encontraron uno o más errores.",
  1569. $this->responseController->makeErrors($valitador->errors()->messages()),
  1570. 401
  1571. );
  1572. }
  1573. DB::beginTransaction();
  1574. $requestData = $request->all();
  1575. try {
  1576. $idActivity = $this->encryptionController->decrypt($idActivity);
  1577. } catch (\Throwable $th) {
  1578. DB::rollBack();
  1579. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY001: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  1580. }
  1581. try {
  1582. $user = $this->encryptionController->decrypt($requestData['USUARIO']);
  1583. } catch (\Throwable $th) {
  1584. DB::rollBack();
  1585. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY002: Ocurrió un error al desencriptar los datos.", $th->getMessage(), 401);
  1586. }
  1587. $now = $this->functionsController->now();
  1588. $currentDate = $now->toDateTimeString();
  1589. try {
  1590. $validateDelete = DB::table('S002V01TCOAC')
  1591. ->where('COAC_NULI', '=', $requestData['NUMERO_LINEA'])
  1592. ->where('COAC_IDAC', '=', $idActivity)
  1593. ->update([
  1594. 'COAC_ESTA' => 'Eliminado',
  1595. 'COAC_FEMO' => $currentDate,
  1596. 'COAC_USMO' => $user,
  1597. 'COAC_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  1598. ]);
  1599. } catch (\Throwable $th) {
  1600. DB::rollBack();
  1601. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY003: Ocurrió un error al eliminar la actividad.", $th->getMessage(), 401);
  1602. }
  1603. if (!$validateDelete) {
  1604. DB::rollBack();
  1605. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_DELACTIVITY004: No se pudo eliminar la actividad.", [], 401);
  1606. }
  1607. DB::commit();
  1608. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1609. }
  1610. public function getScheduleActivitiesByActivity($idActivity, $user, $line) {
  1611. try {
  1612. $idActivity = $this->encryptionController->decrypt($idActivity);
  1613. } catch (\Throwable $th) {
  1614. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY000: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
  1615. }
  1616. try {
  1617. $arrSheduleActivities = (array) DB::table('S002V01TCOAC')
  1618. ->where('COAC_NULI','=',$line)
  1619. ->where('COAC_ESTA','=','Activo')
  1620. ->where('COAC_IDAC','=',$idActivity)
  1621. ->first([
  1622. 'COAC_IDPE AS ID_EMPLEADO',
  1623. 'COAC_ACTI AS ACTIVIDAD',
  1624. 'COAC_DESC AS DESCRIPCION',
  1625. 'COAC_TIPO AS TIPO_ACTIVIDAD',
  1626. 'COAC_OTPR AS ID_ORDEN_PREVENTIVO',
  1627. 'COAC_OTCO AS ID_ORDEN_CORRECTIVO',
  1628. 'COAC_FEIN AS FECHA_INICIO',
  1629. 'COAC_HOIN AS HORA_INICIO',
  1630. 'COAC_FEFE AS FECHA_FINAL',
  1631. 'COAC_HOFE AS HORA_FINAL',
  1632. 'COAC_FEFR AS FECHA_FINAL_REAL',
  1633. 'COAC_HOFR AS HORA_FINAL_REAL',
  1634. 'COAC_PERI AS PERIODICIDAD',
  1635. 'COAC_PEPE AS PERIODICIDAD_PERSONALIZADA',
  1636. 'COAC_CLAS AS CLASIFICACION',
  1637. 'COAC_COLO AS COLOR',
  1638. 'COAC_ESTA AS ESTADO',
  1639. 'COAC_FERE AS FECHA_REGISTRA',
  1640. 'COAC_USRE AS USUARIO_REGISTRA',
  1641. 'COAC_FEMO AS FECHA_MODIFICA',
  1642. 'COAC_USMO AS USUARIO_MODIFICA',
  1643. ]);
  1644. } catch (\Throwable $th) {
  1645. DB::rollBack();
  1646. return $this->responseController->makeResponse(true, "ERR_EMPLOYEE_GETACTIVITY001: Ocurrió un error al ibtener los datos.", $th->getMessage(), 404);
  1647. }
  1648. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSheduleActivities);
  1649. }
  1650. }