EmployeeController.php 83 KB

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