UsersProfilesController.php 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Hash;
  7. use Illuminate\Support\Carbon;
  8. class UsersProfilesController extends Controller{
  9. private $responseController;
  10. private $encryptionController;
  11. private $functionsController;
  12. private $moduleCode = 'S002V01M02USPE';
  13. public function __construct(){
  14. $this->responseController = new ResponseController();
  15. $this->encryptionController = new EncryptionController();
  16. $this->functionsController = new FunctionsController();
  17. }
  18. public function getUsers($idUser, $line){
  19. DB::enableQueryLog();
  20. $idUser = $this->encryptionController->decrypt($idUser);
  21. if(!$idUser){
  22. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  23. }
  24. $usr = DB::table('S002V01TUSUA')->where([
  25. ['USUA_IDUS', '=', $idUser],
  26. ['USUA_NULI', '=', $line],
  27. ])->first();
  28. if(is_null($usr)){
  29. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  30. }
  31. $users = DB::table('S002V01TUSUA')->select([
  32. 'USUA_IDUS as IDUSUARIO',
  33. 'USUA_NOMB as NOMBRE',
  34. 'USUA_APPA as APEPAT',
  35. 'USUA_APMA as APEMAT',
  36. 'USUA_COEL as EMAIL',
  37. DB::raw("CONCAT(PERF_NOPE, ' (', PERF_IDPE, ')') AS PERFIL"),
  38. DB::raw("IF(ISNULL(PACO_IDPC), FALSE, TRUE) AS TIENE_PANEL"),
  39. DB::raw("IF(ISNULL(PACO_IDPC), '-', CONCAT(PACO_NPCO, ' (', PACO_IDPC, ')')) AS PANEL_CONTROL"),
  40. 'USUA_ESTA as ESTATUS',
  41. 'BIAC_FECO as ULCON'
  42. ])->join('S002V01TPERF', 'USUA_PERF', '=', 'PERF_IDPE')
  43. ->leftJoin('S002V01TBIAC', 'USUA_ULCO', '=', 'BIAC_IDCO')
  44. ->leftJoin('S002V01TPACO', 'USUA_PCRE', '=', 'PACO_IDPC')
  45. ->where('USUA_NULI', '=', $line)->get()->all();
  46. foreach($users as $key=>$user){
  47. $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
  48. $user->TIENE_PANEL = $user->TIENE_PANEL == 1;
  49. $users[$key] = $user;
  50. }
  51. $now = $this->functionsController->now();
  52. $nowStr = $now->toDateTimeString();
  53. $actions = DB::getQueryLog();
  54. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  55. $idac = $this->functionsController->registerActivity(
  56. $line,
  57. $this->moduleCode,
  58. 'S002V01F01ADUS',
  59. 'S002V01P01COUS',
  60. 'Consulta',
  61. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
  62. $idUser,
  63. $nowStr,
  64. 'S002V01S01GEUS'
  65. );
  66. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  67. return $this->responseController->makeresponse(false, "EXITO", $users);
  68. }
  69. public function getUser($id, $idUser, $line){
  70. DB::enableQueryLog();
  71. $idUser = $this->encryptionController->decrypt($idUser);
  72. if(!$idUser){
  73. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no fue encriptado correctamente.', [], 400);
  74. }
  75. $usr = DB::table('S002V01TUSUA')->where([
  76. ['USUA_IDUS', '=', $idUser],
  77. ['USUA_NULI', '=', $line],
  78. ])->first();
  79. if(is_null($usr)){
  80. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe.', [], 400);
  81. }
  82. $id = $this->encryptionController->decrypt($id);
  83. if(!$id){
  84. return $this->responseController->makeResponse(true, "El ID del usuario consultado no está encriptado correctamente.", [], 400);
  85. }
  86. $user = DB::table('S002V01TUSUA')->select(
  87. 'USUA_IDUS AS IDUSUARIO',
  88. 'USUA_NOMB AS NOMBRE',
  89. 'USUA_APPA AS APEPAT',
  90. 'USUA_APMA AS APEMAT',
  91. 'USUA_COEL AS EMAIL',
  92. 'USUA_PERF AS PERFIL',
  93. 'PERF_NOPE AS PERFNOMB',
  94. 'USUA_ESTA AS ESTATUS',
  95. )->where([
  96. ['USUA_IDUS', '=', $id],
  97. ['USUA_NULI', '=', $line],
  98. ])->join('S002V01TPERF', 'PERF_IDPE', '=', 'USUA_PERF')->first();
  99. if(is_null($user)){
  100. return $this->responseController->makeResponse(true, "El usuario consultado no existe.", [], 404);
  101. }
  102. $user->IDUSUARIO = $this->encryptionController->encrypt($user->IDUSUARIO);
  103. $user->PERFIL = $this->encryptionController->encrypt($user->PERFIL);
  104. $now = $this->functionsController->now();
  105. $nowStr = $now->toDateTimeString();
  106. $actions = DB::getQueryLog();
  107. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  108. $nameCons = $this->functionsController->joinName($user->NOMBRE, $user->APEPAT, $user->APEMAT);
  109. $idac = $this->functionsController->registerActivity(
  110. $line,
  111. $this->moduleCode,
  112. 'S002V01F01ADUS',
  113. 'S002V01P01COUS',
  114. 'Consulta',
  115. "El usuario $name (" . $usr->USUA_IDUS . ") consultó al usuario $nameCons (" . $user->IDUSUARIO . ").",
  116. $idUser,
  117. $nowStr,
  118. 'S002V01S01GEUS'
  119. );
  120. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  121. return $this->responseController->makeresponse(false, "EXITO", $user);
  122. }
  123. public function getProfiles($idUser, $line){
  124. DB::enableQueryLog();
  125. $idUser = $this->encryptionController->decrypt($idUser);
  126. if(!$idUser){
  127. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  128. }
  129. $usr = DB::table('S002V01TUSUA')->where([
  130. ['USUA_IDUS', '=', $idUser],
  131. ['USUA_NULI', '=', $line]
  132. ])->first();
  133. if(is_null($usr)){
  134. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  135. }
  136. $profiles = DB::table('S002V01TPERF')->select(
  137. 'PERF_IDPE AS IDPERFIL',
  138. 'PERF_NOPE AS NOMBREPERFIL',
  139. 'PERF_PERM AS PERMISOS',
  140. 'PERF_ESTA AS ESTADO',
  141. 'PERF_USRE AS USRREG',
  142. 'PERF_FERE AS FECREG',
  143. 'PERF_USMO AS USRMOD',
  144. 'PERF_FEMO AS FECMOD',
  145. )->where('PERF_NULI', '=', $line)->orderBy('PERF_IDPE', 'desc')->get()->all();
  146. foreach($profiles as $key=>$profile){
  147. $relatedUsers = DB::table('S002V01TUSUA')->where([
  148. ['USUA_NULI', '=', $line],
  149. ['USUA_PERF', '=', $profile->IDPERFIL]
  150. ])->get()->all();
  151. $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
  152. $profile->PERMISOS = $this->encryptionController->encrypt($profile->PERMISOS);
  153. $usrReg = DB::table('S002V01TUSUA')->where([
  154. ['USUA_NULI', '=', $line],
  155. ['USUA_IDUS', '=', $profile->USRREG]
  156. ])->first();
  157. $usrRegName = $this->functionsController->joinName($usrReg->USUA_NOMB, $usrReg->USUA_APPA, $usrReg->USUA_APMA);
  158. $profile->USRREG = $usrRegName . " (" . $profile->USRREG . ")";
  159. if(!is_null($profile->USRMOD)){
  160. $usrMod = DB::table('S002V01TUSUA')->where([
  161. ['USUA_NULI', '=', $line],
  162. ['USUA_IDUS', '=', $profile->USRMOD]
  163. ])->first();
  164. $usrModName = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  165. $profile->USRMOD = $usrModName . " (" . $profile->USRMOD . ")";
  166. }
  167. $profile->USUARIOS_RELACIONADOS = count($relatedUsers);
  168. $profiles[$key] = $profile;
  169. }
  170. $now = $this->functionsController->now();
  171. $nowStr = $now->toDateTimeString();
  172. $actions = DB::getQueryLog();
  173. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  174. $idac = $this->functionsController->registerActivity(
  175. $line,
  176. $this->moduleCode,
  177. 'S002V01F01ADPE',
  178. 'S002V01P01COPE',
  179. 'Consulta',
  180. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los perfiles registrados.",
  181. $idUser,
  182. $nowStr,
  183. 'S002V01S02GEPE'
  184. );
  185. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  186. return $this->responseController->makeresponse(false, "EXITO", $profiles);
  187. }
  188. public function getProfile($idProfile, $idUser, $line){
  189. DB::enableQueryLog();
  190. $idUser = $this->encryptionController->decrypt($idUser);
  191. if(!$idUser){
  192. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  193. }
  194. $usr = DB::table('S002V01TUSUA')->where([
  195. ['USUA_IDUS', '=', $idUser],
  196. ['USUA_NULI', '=', $line],
  197. ])->first();
  198. if(is_null($usr)){
  199. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  200. }
  201. $idProfile = $this->encryptionController->decrypt($idProfile);
  202. if(!$idProfile){
  203. return $this->responseController->makeResponse(true, "El ID del perfil no está encriptado correctamente.", [], 401);
  204. }
  205. $profile = DB::table('S002V01TPERF')->select(
  206. 'PERF_IDPE AS IDPERFIL',
  207. 'PERF_NOPE AS NOMBREPERFIL',
  208. 'PERF_ESTA AS ESTATUS',
  209. 'PERF_PERM AS PERMISOS',
  210. )->where([
  211. ['PERF_IDPE', '=', $idProfile],
  212. ['PERF_NULI', '=', $line],
  213. ])->first();
  214. if(is_null($profile)){
  215. return $this->responseController->makeResponse(true, "El perfil consultado no existe.", [], 404);
  216. }
  217. $profile->IDPERFIL = $this->encryptionController->encrypt($profile->IDPERFIL);
  218. $profilePermissions = json_decode($profile->PERMISOS, true);
  219. $permissions = [];
  220. $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
  221. $moduleIndex = 0;
  222. foreach($modules as $module){
  223. $submodules = DB::table('S002V01TSUBM')->where([
  224. ['SUBM_IDMO', '=', $module->MODU_IDMO],
  225. ['SUBM_NULI', '=', $line]
  226. ])->get()->all();
  227. $permissionsPerSubmodule = [];
  228. $submoduleIndex = 0;
  229. foreach($submodules as $submodule){
  230. $functions = DB::table('S002V01TFUNC')->where([
  231. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  232. ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
  233. ['FUNC_NULI', '=', $line],
  234. ])->get()->all();
  235. $permissionsPerFunction = [];
  236. $functionIndex = 0;
  237. foreach($functions as $function){
  238. $screens = DB::table('S002V01TPANT')->where([
  239. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  240. ['PANT_NULI', '=', $line],
  241. ])->get()->all();
  242. $permissionsPerScreen = [];
  243. $screenIndex = 0;
  244. foreach($screens as $screen){
  245. $screenAccess = 0;
  246. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
  247. $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
  248. }
  249. $permissionsPerScreen[] = [
  250. 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
  251. 'name' => $screen->PANT_NOMB,
  252. 'access' => $screenAccess
  253. ];
  254. $screenIndex++;
  255. }
  256. $functionAcces = 0;
  257. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'])){
  258. $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['children'][$functionIndex]['access'];
  259. }
  260. $permissionsPerFunction[] = [
  261. 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
  262. 'name' => $function->FUNC_NOMB,
  263. 'access' => $functionAcces,
  264. 'children' => $permissionsPerScreen,
  265. ];
  266. $functionIndex++;
  267. }
  268. $submoduleAccess = 0;
  269. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'])){
  270. $submoduleAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$submoduleIndex]['access'];
  271. }
  272. $permissionsPerSubmodule[] = [
  273. 'id' => $this->encryptionController->encrypt($submodule->SUBM_IDSM),
  274. 'name' => $submodule->SUBM_NOMB,
  275. 'access' => $submoduleAccess,
  276. 'children' => $permissionsPerFunction,
  277. ];
  278. $submoduleIndex++;
  279. }
  280. $functions = DB::table('S002V01TFUNC')->where([
  281. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  282. ['FUNC_IDSM', '=', null],
  283. ['FUNC_NULI', '=', $line],
  284. ])->get()->all();
  285. $permissionsPerFunction = [];
  286. $functionIndex = 0;
  287. foreach($functions as $function){
  288. $screens = DB::table('S002V01TPANT')->where([
  289. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  290. ['PANT_NULI', '=', $line],
  291. ])->get()->all();
  292. $permissionsPerScreen = [];
  293. $screenIndex = 0;
  294. foreach($screens as $screen){
  295. $screenAccess = 0;
  296. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'])){
  297. $screenAccess = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['children'][$screenIndex]['access'];
  298. }
  299. $permissionsPerScreen[] = [
  300. 'id' => $this->encryptionController->encrypt($screen->PANT_IDPA),
  301. 'name' => $screen->PANT_NOMB,
  302. 'access' => $screenAccess
  303. ];
  304. $screenIndex++;
  305. }
  306. $functionAcces = 0;
  307. if(isset($profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'])){
  308. $functionAcces = $profilePermissions['permissions'][$moduleIndex]['children'][$functionIndex]['access'];
  309. }
  310. $permissionsPerFunction[] = [
  311. 'id' => $this->encryptionController->encrypt($function->FUNC_IDFU),
  312. 'name' => $function->FUNC_NOMB,
  313. 'access' => $functionAcces,
  314. 'children' => $permissionsPerScreen,
  315. ];
  316. $functionIndex++;
  317. }
  318. $permissionsArr = [];
  319. foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
  320. foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
  321. $moduleAccess = $profilePermissions['permissions'][$moduleIndex]['access'];
  322. $permissions[] = [
  323. 'id' => $this->encryptionController->encrypt($module->MODU_IDMO),
  324. 'name' => $module->MODU_NOMO,
  325. 'access' => $moduleAccess,
  326. 'children' => $permissionsArr,
  327. ];
  328. $moduleIndex++;
  329. }
  330. $now = $this->functionsController->now();
  331. $nowStr = $now->toDateTimeString();
  332. $profile->PERMISOS = ['permissions' => $permissions];
  333. $actions = DB::getQueryLog();
  334. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  335. $idac = $this->functionsController->registerActivity(
  336. $line,
  337. $this->moduleCode,
  338. 'S002V01F01ADPE',
  339. 'S002V01P01COPE',
  340. 'Consulta',
  341. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el perfil " . $profile->NOMBREPERFIL . " (" . $profile->IDPERFIL . ").",
  342. $idUser,
  343. $nowStr,
  344. 'S002V01S02GEPE'
  345. );
  346. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  347. return $this->responseController->makeresponse(false, "EXITO", $profile);
  348. }
  349. public function updateUser(Request $request){
  350. DB::enableQueryLog();
  351. $validator = Validator::make($request->all(), [
  352. 'id' => 'required|string',
  353. 'name' => 'required|string|max:50',
  354. 'fApe' => 'required|string|max:50',
  355. 'email' => 'required|string|email',
  356. 'perf' => 'required|string',
  357. 'id_user' => 'required|string',
  358. 'linea' => 'required|integer'
  359. ]);
  360. if($validator->fails()){
  361. return $this->responseController->makeResponse(
  362. true,
  363. "Se encontraron uno o más errores.",
  364. $this->responseController->makeErrors(
  365. $validator->errors()->messages()
  366. ),
  367. 401
  368. );
  369. }
  370. $user = $request->all();
  371. $idUser = $this->encryptionController->decrypt($user['id']);
  372. if(!$idUser){
  373. return $this->responseController->makeResponse(true, "El ID del usuario que desea modificar no está encriptado correctamente.", [], 400);
  374. }
  375. $usrMod = DB::table('S002V01TUSUA')->where([
  376. ['USUA_IDUS', '=', $idUser],
  377. ['USUA_NULI', '=', $user['linea']],
  378. ])->first();
  379. if(is_null($usrMod)){
  380. return $this->responseController->makeResponse(true, 'El usuario que desea modificar no exise.', [], 404);
  381. }
  382. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  383. if(!$idUserMod){
  384. return $this->responseController->makeResponse(true, "El ID del usuario que modifica no está encriptado correctamente.", [], 400);
  385. }
  386. $usr = DB::table('S002V01TUSUA')->where([
  387. ['USUA_IDUS', '=', $idUserMod],
  388. ['USUA_NULI', '=', $user['linea']],
  389. ])->first();
  390. if(is_null($usr)){
  391. return $this->responseController->makeResponse(true, 'El usuario que realiza la solicitud no existe', [], 404);
  392. }
  393. if($idUser == $idUserMod){
  394. return $this->responseController->makeResponse(true, "El usuario no puede modificar su propio registro.", [], 401);
  395. }
  396. $idProfile = $this->encryptionController->decrypt($user['perf']);
  397. if(!$idProfile){
  398. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
  399. }
  400. $profile = DB::table('S002V01TPERF')->where([
  401. ['PERF_IDPE', '=', $idProfile],
  402. ['PERF_NULI', '=', $user['linea']]
  403. ])->first();
  404. if(is_null($profile)){
  405. return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
  406. }else if($profile->PERF_ESTA == 'Eliminado'){
  407. return $this->responseController->makeResponse(true, 'El perfil seleccionado está eliminado.', [], 404);
  408. }
  409. $now = $this->functionsController->now();
  410. $nowStr = $now->toDateTimeString();
  411. $correos = DB::table('S002V01TUSUA')->where([
  412. ['USUA_COEL', '=', $user['email']],
  413. ['USUA_IDUS', '!=', $idUser]
  414. ])->get()->all();
  415. if(count($correos) > 0){
  416. return $this->responseController->makeResponse(true, "El nuevo correo electrónico ya está registrado en la base.", [], 401);
  417. }
  418. DB::table('S002V01TUSUA')->where([
  419. ['USUA_IDUS', '=', $idUser],
  420. ['USUA_NULI', '=', $user['linea']]
  421. ])->update([
  422. 'USUA_NOMB' => $user['name'],
  423. 'USUA_APPA' => $user['fApe'],
  424. 'USUA_APMA' => array_key_exists('sApe', $user) ? $user['sApe'] : null,
  425. 'USUA_COEL' => $user['email'],
  426. 'USUA_PERF' => $idProfile,
  427. 'USUA_USMO' => $idUserMod,
  428. 'USUA_FEMO' => $nowStr
  429. ]);
  430. $actions = DB::getQueryLog();
  431. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  432. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  433. $idac = $this->functionsController->registerActivity(
  434. $user['linea'],
  435. $this->moduleCode,
  436. 'S002V01F01ADUS',
  437. 'S002V01P02RAUS',
  438. 'Actualización',
  439. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  440. $idUser,
  441. $nowStr,
  442. 'S002V01S01GEUS'
  443. );
  444. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  445. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  446. }
  447. public function createUser(Request $request){
  448. DB::enableQueryLog();
  449. $validator = Validator::make($request->all(), [
  450. 'id_user' => 'required|string',
  451. 'linea' => 'required|integer',
  452. 'name' => 'required|string|max:50',
  453. 'fApe' => 'required|string|max:50',
  454. 'perf' => 'required|string',
  455. 'email' => 'required|string|email',
  456. 'password' => 'required|string|min:8|confirmed',
  457. ]);
  458. if($validator->fails()){
  459. return $this->responseController->makeResponse(
  460. true,
  461. "Se encontraron uno o más errores.",
  462. $this->responseController->makeErrors(
  463. $validator->errors()->messages()
  464. ),
  465. 401
  466. );
  467. }
  468. $user = $request->all();
  469. $idUsre = $this->encryptionController->decrypt($user['id_user']);
  470. if(!$idUsre){
  471. return $this->responseController->makeResponse(true, "El ID del usuario que registra no está encriptado correctamente.", [], 400);
  472. }
  473. $usr = DB::table('S002V01TUSUA')->where([
  474. ['USUA_IDUS', '=', $idUsre],
  475. ['USUA_NULI', '=', $user['linea']]
  476. ])->first();
  477. if(is_null($usr)){
  478. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  479. }else if($usr->USUA_ESTA == 'Eliminado'){
  480. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
  481. }else if($usr->USUA_ESTA == 'Inactivo'){
  482. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
  483. }
  484. $idProfile = $this->encryptionController->decrypt($user['perf']);
  485. if(!$idProfile){
  486. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente.", [], 400);
  487. }
  488. $profile = DB::table('S002V01TPERF')->where([
  489. ['PERF_IDPE', '=', $idProfile],
  490. ['PERF_NULI', '=', $user['linea']]
  491. ])->first();
  492. if(is_null($profile)){
  493. return $this->responseController->makeResponse(true, 'El perfil seleccionado no existe.', [], 404);
  494. }else if($usr->USUA_ESTA == 'Eliminado'){
  495. return $this->responseController->makeResponse(true, "El perfil seleccionado está eliminado.", [], 401);
  496. }
  497. $email = DB::table('S002V01TUSUA')->where([
  498. ['USUA_COEL', '=', $user['email']],
  499. ['USUA_NULI', '=', $user['linea']]
  500. ])->get()->first();
  501. if(!is_null($email)){
  502. return $this->responseController->makeResponse(true, "El correo electrónico ya se encuentra registrado.", [], 401);
  503. }
  504. $passEnc = Hash::make($user['password']);
  505. $apemat = isset($user['sApe']) ? $user['sApe'] : null;
  506. $now = $this->functionsController->now();
  507. $nowStr = $now->toDateTimeString();
  508. $idUser = DB::table('S002V01TUSUA')->insertGetId([
  509. 'USUA_NULI' => $user['linea'],
  510. 'USUA_NOMB' => $user['name'],
  511. 'USUA_APPA' => $user['fApe'],
  512. 'USUA_APMA' => $apemat,
  513. 'USUA_PERF' => $idProfile,
  514. 'USUA_PCRE' => 0,
  515. 'USUA_CONT' => $passEnc,
  516. 'USUA_COEL' => $user['email'],
  517. 'USUA_USRE' => $idUsre,
  518. 'USUA_FERE' => $nowStr,
  519. ]);
  520. $actions = DB::getQueryLog();
  521. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  522. $nameReg = $this->functionsController->joinName($user['name'], $user['fApe'], $apemat);
  523. $idac = $this->functionsController->registerActivity(
  524. $user['linea'],
  525. $this->moduleCode,
  526. 'S002V01F01ADUS',
  527. 'S002V01P02RAUS',
  528. 'Registro',
  529. "El usuario $name (" . $usr->USUA_IDUS . ") registró al usuario $nameReg ($idUser).",
  530. $idUsre,
  531. $nowStr,
  532. 'S002V01S01GEUS'
  533. );
  534. $this->functionsController->registerLog($actions, $idUsre, $nowStr, $idac, $user['linea']);
  535. return $this->responseController->makeResponse(false, "EXITO: Registro correcto.");
  536. }
  537. public function blockUser(Request $request){
  538. DB::enableQueryLog();
  539. $validator = Validator::make($request->all(), [
  540. 'id' => 'required|string',
  541. 'estatus' => 'required|in:Activo,Inactivo',
  542. 'id_user' => 'required|string',
  543. 'linea' => 'required|integer'
  544. ]);
  545. if($validator->fails()){
  546. return $this->responseController->makeResponse(
  547. true,
  548. "Se encontraron uno o más errores.",
  549. $this->responseController->makeErrors(
  550. $validator->errors()->messages()
  551. ),
  552. 401
  553. );
  554. }
  555. $user = $request->all();
  556. $idUser = $this->encryptionController->decrypt($user['id']);
  557. if(!$idUser){
  558. return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
  559. }
  560. $usr = DB::table('S002V01TUSUA')->where([
  561. ['USUA_IDUS', '=', $idUser],
  562. ['USUA_NULI', '=', $user['linea']],
  563. ])->first();
  564. if(is_null($usr)){
  565. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  566. }
  567. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  568. if(!$idUserMod){
  569. return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
  570. }
  571. if($idUser == $idUserMod){
  572. return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo", [], 400);
  573. }
  574. $usrMod = DB::table('S002V01TUSUA')->where([
  575. ['USUA_IDUS', '=', $idUserMod],
  576. ['USUA_NULI', '=', $user['linea']],
  577. ])->first();
  578. if(is_null($usrMod)){
  579. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  580. }
  581. $now = $this->functionsController->now();
  582. $nowStr = $now->toDateTimeString();
  583. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUserMod)->update([
  584. 'USUA_ESTA' => $user['estatus'],
  585. 'USUA_USMO' => $idUser,
  586. 'USUA_FEMO' => $nowStr
  587. ]);
  588. $actions = DB::getQueryLog();
  589. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  590. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  591. $tipoAccion = $user['estatus'] == 'Activo' ? 'desbloqueó' : 'bloqueó';
  592. $idac = $this->functionsController->registerActivity(
  593. $user['linea'],
  594. $this->moduleCode,
  595. 'S002V01F02BDAC',
  596. '-',
  597. 'Actualización',
  598. "El usuario $name (" . $usr->USUA_IDUS . ") $tipoAccion al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  599. $idUser,
  600. $nowStr,
  601. 'S002V01S01GEUS'
  602. );
  603. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  604. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  605. }
  606. public function updatePass(Request $request){
  607. DB::enableQueryLog();
  608. $validator = Validator::make($request->all(), [
  609. 'id' => 'required|string',
  610. 'password' => 'required|string|min:8|confirmed',
  611. 'id_user' => 'required|string',
  612. 'linea' => 'required|integer'
  613. ]);
  614. if($validator->fails()){
  615. return $this->responseController->makeResponse(
  616. true,
  617. "Se encontraron uno o más errores.",
  618. $this->responseController->makeErrors(
  619. $validator->errors()->messages()
  620. ),
  621. 401
  622. );
  623. }
  624. $user = $request->all();
  625. $idUser = $this->encryptionController->decrypt($user['id']);
  626. if(!$idUser){
  627. return $this->responseController->makeResponse(true, "El id del usuario que desea modificar no está encriptado correctamente.", [], 400);
  628. }
  629. $usrMod = DB::table('S002V01TUSUA')->where([
  630. ['USUA_IDUS', '=', $idUser],
  631. ['USUA_NULI', '=', $user['linea']],
  632. ])->first();
  633. if(is_null($usrMod)){
  634. return $this->responseController->makeResponse(true, 'El usuario que desea modificar no existe', [], 400);
  635. }
  636. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  637. if(!$idUserMod){
  638. return $this->responseController->makeResponse(true, "El id del usuario que modifica no está encriptado correctamente.", [], 400);
  639. }
  640. if($idUser == $idUserMod){
  641. return $this->responseController->makeResponse(true, "El usuario no puede modificarse a sí mismo.", [], 401);
  642. }
  643. $usr = DB::table('S002V01TUSUA')->where([
  644. ['USUA_IDUS', '=', $idUserMod],
  645. ['USUA_NULI', '=', $user['linea']],
  646. ])->first();
  647. if(is_null($usr)){
  648. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  649. }
  650. $lastPass = $usr->USUA_CONT;
  651. if(Hash::check($user['password'], $lastPass)){
  652. return $this->responseController->makeResponse(true, "La contraseña nueva es igual a la anterior.", [], 401);
  653. }
  654. $newPass = Hash::make($user['password']);
  655. $now = $this->functionsController->now();
  656. $nowStr = $now->toDateTimeString();
  657. DB::table('S002V01TUSUA')->where([
  658. ['USUA_IDUS', '=', $idUser],
  659. ['USUA_NULI', '=', $user['linea']],
  660. ])->update([
  661. 'USUA_CONT' => $newPass,
  662. 'USUA_USMO' => $idUserMod,
  663. 'USUA_FEMO' => $nowStr
  664. ]);
  665. $actions = DB::getQueryLog();
  666. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  667. $idac = $this->functionsController->registerActivity(
  668. $user['linea'],
  669. $this->moduleCode,
  670. 'S002V01F01ADUS',
  671. 'S002V01P01COUS',
  672. 'Consulta',
  673. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los usuarios registrados.",
  674. $idUser,
  675. $nowStr,
  676. 'S002V01S01GEUS'
  677. );
  678. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  679. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  680. }
  681. public function deleteUser(Request $request){
  682. DB::enableQueryLog();
  683. $validator = Validator::make($request->all(), [
  684. 'id' => 'required|string',
  685. 'id_user' => 'required|string',
  686. 'linea' => 'required|integer'
  687. ]);
  688. if($validator->fails()){
  689. return $this->responseController->makeResponse(
  690. true,
  691. "Se encontraron uno o más errores.",
  692. $this->responseController->makeErrors(
  693. $validator->errors()->messages()
  694. ),
  695. 401
  696. );
  697. }
  698. $user = $request->all();
  699. $idUser = $this->encryptionController->decrypt($user['id']);
  700. if(!$idUser){
  701. return $this->responseController->makeResponse(true, "El id del usuario que desea eliminar no está encriptado correctamente", [], 400);
  702. }
  703. $usr = DB::table('S002V01TUSUA')->where([
  704. ['USUA_IDUS', '=', $idUser],
  705. ['USUA_NULI', '=', $user['linea']]
  706. ])->first();
  707. if(is_null($usr)){
  708. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  709. }
  710. $idUserMod = $this->encryptionController->decrypt($user['id_user']);
  711. if(!$idUserMod){
  712. return $this->responseController->makeResponse(true, "El id del usuario que elimina no está encriptado correctamente", [], 400);
  713. }
  714. if($idUser == $idUserMod){
  715. return $this->responseController->makeResponse(true, "El usuario no puede eliminarse a sí mismo", [], 401);
  716. }
  717. $usrMod = DB::table('S002V01TUSUA')->where([
  718. ['USUA_IDUS', '=', $idUserMod],
  719. ['USUA_NULI', '=', $user['linea']]
  720. ])->first();
  721. if(is_null($usrMod)){
  722. return $this->responseController->makeResponse(true, 'El usuario que desea eliminar no está registrado', [], 404);
  723. }
  724. $now = $this->functionsController->now();
  725. $nowStr = $now->toDateTimeString();
  726. DB::table('S002V01TUSUA')->where('USUA_IDUS', '=', $idUser)->update([
  727. 'USUA_ESTA' => 'Eliminado',
  728. 'USUA_USMO' => $idUserMod,
  729. 'USUA_FEMO' => $nowStr
  730. ]);
  731. $actions = DB::getQueryLog();
  732. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  733. $nameMod = $this->functionsController->joinName($usrMod->USUA_NOMB, $usrMod->USUA_APPA, $usrMod->USUA_APMA);
  734. $idac = $this->functionsController->registerActivity(
  735. $user['linea'],
  736. $this->moduleCode,
  737. 'S002V01F04ELUS',
  738. '-',
  739. 'Eliminación',
  740. "El usuario $name (" . $usr->USUA_IDUS . ") eleimnó al usuario $nameMod (" . $usrMod->USUA_IDUS . ").",
  741. $idUser,
  742. $nowStr,
  743. 'S002V01S01GEUS'
  744. );
  745. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $user['linea']);
  746. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  747. }
  748. public function getModules($idUser, $line){
  749. DB::enableQueryLog();
  750. $idUser = $this->encryptionController->decrypt($idUser);
  751. if(!$idUser){
  752. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  753. }
  754. $usr = DB::table('S002V01TUSUA')->where([
  755. ['USUA_IDUS', '=', $idUser],
  756. ['USUA_NULI', '=', $line]
  757. ])->first();
  758. if(is_null($usr)){
  759. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  760. }
  761. $modules = DB::table('S002V01TMODU')->select(
  762. 'MODU_IDMO as IDMODULO',
  763. 'MODU_NOMO as NOMBREMODULO',
  764. 'MODU_ICON as ICONOMODULO',
  765. )->where('MODU_NULI', '=', $line)->get()->all();
  766. foreach($modules as $key=>$module){
  767. $module->IDMODULO = $this->encryptionController->encrypt($module->IDMODULO);
  768. $modules[$key] = $module;
  769. }
  770. $now = $this->functionsController->now();
  771. $nowStr = $now->toDateTimeString();
  772. $actions = DB::getQueryLog();
  773. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  774. $idac = $this->functionsController->registerActivity(
  775. $line,
  776. '-',
  777. '-',
  778. '-',
  779. 'Consulta',
  780. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los módulos del sistema.",
  781. $idUser,
  782. $nowStr
  783. );
  784. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  785. return $this->responseController->makeresponse(false, "EXITO", $modules);
  786. }
  787. public function getMenu($idUser, $line){
  788. DB::enableQueryLog();
  789. $idUser = $this->encryptionController->decrypt($idUser);
  790. if(!$idUser){
  791. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  792. }
  793. $usr = DB::table('S002V01TUSUA')->where([
  794. ['USUA_IDUS', '=', $idUser],
  795. ['USUA_NULI', '=', $line]
  796. ])->first();
  797. if(is_null($usr)){
  798. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  799. }
  800. $modules = DB::table('S002V01TMODU')->select(
  801. 'MODU_IDMO as IDMODULO',
  802. 'MODU_NOMO as NOMBREMODULO',
  803. 'MODU_ICON as ICONOMODULO',
  804. )->get()->all();
  805. $mods = [];
  806. foreach($modules as $module){
  807. $submodules = DB::table('S002V01TSUBM')->select(
  808. 'SUBM_IDSM as IDSUBMODULO',
  809. 'SUBM_NOMB as NOMBRESUBMODULO',
  810. 'SUBM_ICON AS ICONOSUBMODULO'
  811. )->where('SUBM_IDMO', '=', $module->IDMODULO)->get()->all();
  812. $menusMod = DB::table('S002V01TFUNC')->select(
  813. 'FUNC_IDFU AS IDFUNCION',
  814. 'FUNC_NOMB AS NOMBREFUNCION',
  815. 'FUNC_ICON AS ICONOFUNCION'
  816. )->where([
  817. ['FUNC_IDMO', '=', $module->IDMODULO],
  818. ['FUNC_IDSM', '=', null]
  819. ])->get()->all();
  820. $module->SUBMODULES = [];
  821. foreach($submodules as $submodule){
  822. $menus = DB::table('S002V01TFUNC')->select(
  823. 'FUNC_IDFU AS IDFUNCION',
  824. 'FUNC_NOMB AS NOMBREFUNCION',
  825. 'FUNC_ICON AS ICONOFUNCION'
  826. )->where([
  827. ['FUNC_IDMO', '=', $module->IDMODULO],
  828. ['FUNC_IDSM', '=', $submodule->IDSUBMODULO]
  829. ])->get()->all();
  830. $menuInd = 0;
  831. foreach($menus as $funcion){
  832. $pantallas = DB::table('S002V01TPANT')->select(
  833. 'PANT_IDPA AS IDPANTALLA',
  834. 'PANT_NOMB AS NOMBREPANTALLA'
  835. )->where([
  836. ['PANT_IDFU', '=', $funcion->IDFUNCION],
  837. ['PANT_NULI', '=', $line]
  838. ])->get()->all();
  839. $menus[$menuInd]->PANTALLAS = $pantallas;
  840. $menuInd++;
  841. }
  842. $submodule->FUNCIONES = [];
  843. foreach($menus as $menu){
  844. $submodule->FUNCIONES[] = $menu;
  845. }
  846. $module->SUBMODULES[] = $submodule;
  847. }
  848. $menModInd = 0;
  849. foreach($menusMod as $funcion){
  850. $pantallas = DB::table('S002V01TPANT')->select(
  851. 'PANT_IDPA AS IDPANTALLA',
  852. 'PANT_NOMB AS NOMBREPANTALLA'
  853. )->where([
  854. ['PANT_IDFU', '=', $funcion->IDFUNCION],
  855. ['PANT_NULI', '=', $line]
  856. ])->get()->all();
  857. $menusMod[$menModInd]->PANTALLAS = $pantallas;
  858. $menModInd++;
  859. }
  860. $module->MENUS = $menusMod;
  861. $mods[] = $module;
  862. }
  863. $now = $this->functionsController->now();
  864. $nowStr = $now->toDateTimeString();
  865. $actions = DB::getQueryLog();
  866. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  867. $idac = $this->functionsController->registerActivity(
  868. $line,
  869. '-',
  870. '-',
  871. '-',
  872. 'Consulta',
  873. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el menú del sistema.",
  874. $idUser,
  875. $nowStr
  876. );
  877. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  878. return $this->responseController->makeResponse(false, "EXITO", $mods);
  879. }
  880. public function buildInitialPermissions($idUser, $line){
  881. DB::enableQueryLog();
  882. $idUser = $this->encryptionController->decrypt($idUser);
  883. if(!$idUser){
  884. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  885. }
  886. $usr = DB::table('S002V01TUSUA')->where([
  887. ['USUA_IDUS', '=', $idUser],
  888. ['USUA_NULI', '=', $line],
  889. ])->first();
  890. if(is_null($usr)){
  891. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 400);
  892. }
  893. $permissions = [];
  894. //Se obtienen todos los modulos
  895. $modules = DB::table('S002V01TMODU')->where('MODU_NULI', '=', $line)->get()->all();
  896. //se consultan los submodulos de cada modulo
  897. foreach($modules as $module){
  898. $submodules = DB::table('S002V01TSUBM')->where([
  899. ['SUBM_IDMO', '=', $module->MODU_IDMO],
  900. ['SUBM_NULI', '=', $line]
  901. ])->get()->all();
  902. $permissionsPerSubmodule = [];
  903. $hasSubmodules = false;
  904. foreach($submodules as $submodule){
  905. //Se consultan las funciones
  906. $functions = DB::table('S002V01TFUNC')->where([
  907. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  908. ['FUNC_IDSM', '=', $submodule->SUBM_IDSM],
  909. ['FUNC_NULI', '=', $line],
  910. ])->get()->all();
  911. $permissionsPerFunction = [];
  912. foreach($functions as $function){
  913. $screens = DB::table('S002V01TPANT')->where([
  914. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  915. ['PANT_NULI', '=', $line],
  916. ])->get()->all();
  917. $permissionsPerScreen = [];
  918. foreach($screens as $screen){
  919. $permissionsPerScreen[] = [
  920. 'id' => $screen->PANT_IDPA,
  921. 'name' => $screen->PANT_NOMB,
  922. 'access' => 0
  923. ];
  924. }
  925. $permissionsPerFunction[] = [
  926. 'id' => $function->FUNC_IDFU,
  927. 'name' => $function->FUNC_NOMB,
  928. 'access' => 0,
  929. 'children' => $permissionsPerScreen,
  930. ];
  931. }
  932. $permissionsPerSubmodule[] = [
  933. 'id' => $submodule->SUBM_IDSM,
  934. 'name' => $submodule->SUBM_NOMB,
  935. 'access' => 0,
  936. 'children' => $permissionsPerFunction,
  937. ];
  938. $hasSubmodules = true;
  939. }
  940. //Se consultan las funciones
  941. $functions = DB::table('S002V01TFUNC')->where([
  942. ['FUNC_IDMO', '=', $module->MODU_IDMO],
  943. ['FUNC_IDSM', '=', null],
  944. ['FUNC_NULI', '=', $line],
  945. ])->get()->all();
  946. $permissionsPerFunction = [];
  947. foreach($functions as $function){
  948. $screens = DB::table('S002V01TPANT')->where([
  949. ['PANT_IDFU', '=', $function->FUNC_IDFU],
  950. ['PANT_NULI', '=', $line],
  951. ])->get()->all();
  952. $permissionsPerScreen = [];
  953. foreach($screens as $screen){
  954. $permissionsPerScreen[] = [
  955. 'id' => $screen->PANT_IDPA,
  956. 'name' => $screen->PANT_NOMB,
  957. 'access' => 0
  958. ];
  959. }
  960. $permissionsPerFunction[] = [
  961. 'id' => $function->FUNC_IDFU,
  962. 'name' => $function->FUNC_NOMB,
  963. 'access' => 0,
  964. 'children' => $permissionsPerScreen,
  965. ];
  966. }
  967. $permissionsArr = [];
  968. foreach($permissionsPerSubmodule as $perm){ $permissionsArr[] = $perm; }
  969. foreach($permissionsPerFunction as $perm){ $permissionsArr[] = $perm; }
  970. $permissions[] = [
  971. 'id' => $module->MODU_IDMO,
  972. 'name' => $module->MODU_NOMO,
  973. 'access' => 0,
  974. 'children' => $permissionsArr,
  975. ];
  976. }
  977. $now = $this->functionsController->now();
  978. $nowStr = $now->toDateTimeString();
  979. $actions = DB::getQueryLog();
  980. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  981. $idac = $this->functionsController->registerActivity(
  982. $line,
  983. $this->moduleCode,
  984. 'S002V01F01ADPE',
  985. 'S002V01P02REPE',
  986. 'Consulta',
  987. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el arreglo de permisos iniciales.",
  988. $idUser,
  989. $nowStr,
  990. 'S002V01S02GEPE'
  991. );
  992. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  993. return $this->responseController->makeresponse(false, "EXITO", ['permissions' => $permissions]);
  994. }
  995. public function updateProfile(Request $request){
  996. DB::enableQueryLog();
  997. $validator = Validator::make($request->all(), [
  998. 'id_user' => 'required|string',
  999. 'linea' => 'required|integer',
  1000. 'id' => 'required|string',
  1001. 'name' => 'required|string|max:50',
  1002. 'permissions' => 'required|json',
  1003. ]);
  1004. if($validator->fails()){
  1005. return $this->responseController->makeResponse(
  1006. true,
  1007. "Se encontraron uno o más errores.",
  1008. $this->responseController->makeErrors(
  1009. $validator->errors()->messages()
  1010. ),
  1011. 401
  1012. );
  1013. }
  1014. $info = $request->all();
  1015. $idUser = $this->encryptionController->decrypt($info['id_user']);
  1016. if(!$idUser){
  1017. return $this->responseController->makeResponse(true, "El ID del usuario que realizó la solicitud no fue encriptado correctamente", [], 400);
  1018. }
  1019. $usr = DB::table('S002V01TUSUA')->where([
  1020. ['USUA_IDUS', '=', $idUser],
  1021. ['USUA_NULI', '=', $info['linea']],
  1022. ])->first();
  1023. if(is_null($usr)){
  1024. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1025. }
  1026. $idPerf = $this->encryptionController->decrypt($info['id']);
  1027. if(!$idPerf){
  1028. return $this->responseController->makeResponse(true, "El ID del perfil solicitado no fue encriptado correctamente", [], 400);
  1029. }
  1030. $perf = DB::table('S002V01TPERF')->where([
  1031. ['PERF_IDPE', '=', $idPerf],
  1032. ['PERF_NULI', '=', $info['linea']],
  1033. ])->first();
  1034. if(is_null($perf)){
  1035. return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 400);
  1036. }
  1037. $now = $this->functionsController->now();
  1038. $nowStr = $now->toDateTimeString();
  1039. DB::table('S002V01TPERF')->where([
  1040. ['PERF_IDPE', '=', $idPerf],
  1041. ['PERF_NULI', '=', $info['linea']],
  1042. ])->update([
  1043. 'PERF_PERM' => $info['permissions'],
  1044. 'PERF_NOPE' => $info['name'],
  1045. 'PERF_USMO' => $idUser,
  1046. 'PERF_FEMO' => $nowStr
  1047. ]);
  1048. $actions = DB::getQueryLog();
  1049. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1050. $idac = $this->functionsController->registerActivity(
  1051. $info['linea'],
  1052. $this->moduleCode,
  1053. 'S002V01F01ADPE',
  1054. 'S002V01P02REPE',
  1055. 'Actualización',
  1056. "El usuario $name (" . $usr->USUA_IDUS . ") actualizó el perfil " . $perf->PERF_NOPE . "(" . $perf->PERF_NOPE . ").",
  1057. $idUser,
  1058. $nowStr,
  1059. 'S002V01S02GEPE'
  1060. );
  1061. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $info['linea']);
  1062. return $this->responseController->makeResponse(false, "EXITO: Actualización correcta.");
  1063. }
  1064. public function deleteProfile(Request $request){
  1065. DB::enableQueryLog();
  1066. $validator = Validator::make($request->all(), [
  1067. 'id' => 'required|string',
  1068. 'id_user' => 'required|string',
  1069. 'linea' => 'required|integer'
  1070. ]);
  1071. if($validator->fails()){
  1072. return $this->responseController->makeResponse(
  1073. true,
  1074. "Se encontraron uno o más errores.",
  1075. $this->responseController->makeErrors(
  1076. $validator->errors()->messages()
  1077. ),
  1078. 401
  1079. );
  1080. }
  1081. $profile = $request->all();
  1082. $idUser = $this->encryptionController->decrypt($profile['id_user']);
  1083. if(!$idUser){
  1084. return $this->responseController->makeResponse(true, "El ID del usuario que solicitó la acción no está encriptado correctamente", [], 401);
  1085. }
  1086. $usr = DB::table('S002V01TUSUA')->where([
  1087. ['USUA_IDUS', '=', $idUser],
  1088. ['USUA_NULI', '=', $profile['linea']],
  1089. ])->first();
  1090. if(is_null($usr)){
  1091. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1092. }
  1093. $idProf = $this->encryptionController->decrypt($profile['id']);
  1094. if(!$idProf){
  1095. return $this->responseController->makeResponse(true, "El ID del perfil seleccionado no está encriptado correctamente", [], 401);
  1096. }
  1097. $perf = DB::table('S002V01TPERF')->where([
  1098. ['PERF_IDPE', '=', $idProf],
  1099. ['PERF_NULI', '=', $profile['linea']],
  1100. ])->first();
  1101. if(is_null($perf)){
  1102. return $this->responseController->makeResponse(true, 'El perfil solicitado no existe', [], 404);
  1103. }
  1104. $users = DB::table('S002V01TUSUA')->where([
  1105. ['USUA_PERF', '=', $idProf],
  1106. ['USUA_NULI', '=', $profile['linea']]
  1107. ])->get()->all();
  1108. if(count($users) > 0){
  1109. return $this->responseController->makeResponse(true, "El perfil seleccionado no se puede eliminar porque hay usuarios asociados a él.", [], 401);
  1110. }
  1111. $now = $this->functionsController->now();
  1112. $nowStr = $now->toDateTimeString();
  1113. DB::table('S002V01TPERF')->where([
  1114. ['PERF_IDPE', '=', $idProf],
  1115. ['PERF_NULI', '=', $profile['linea']],
  1116. ])->update([
  1117. 'PERF_ESTA' => 'Eliminado',
  1118. 'PERF_USMO' => $idUser,
  1119. 'PERF_FEMO' => $nowStr
  1120. ]);
  1121. $actions = DB::getQueryLog();
  1122. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1123. $idac = $this->functionsController->registerActivity(
  1124. $profile['linea'],
  1125. $this->moduleCode,
  1126. 'S002V01F01ADPE',
  1127. '-',
  1128. 'Eliminación',
  1129. "El usuario $name (" . $usr->USUA_IDUS . ") eliminó el perfil " . $perf->PERF_NOPE . "($idProf).",
  1130. $idUser,
  1131. $nowStr,
  1132. 'S002V01S02GEPE'
  1133. );
  1134. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
  1135. return $this->responseController->makeResponse(false, "EXITO: Eliminación correcta.");
  1136. }
  1137. public function createProfile(Request $request){
  1138. DB::enableQueryLog();
  1139. $validator = Validator::make($request->all(), [
  1140. 'id_user' => 'required|string',
  1141. 'linea' => 'required|integer',
  1142. 'name' => 'required|string|min:8|max:50',
  1143. 'permissions' => 'required|json'
  1144. ]);
  1145. if($validator->fails()){
  1146. return $this->responseController->makeResponse(
  1147. true,
  1148. "Se encontraron uno o más errores.",
  1149. $this->responseController->makeErrors(
  1150. $validator->errors()->messages()
  1151. ),
  1152. 401
  1153. );
  1154. }
  1155. $profile = $request->all();
  1156. $idUser = $this->encryptionController->decrypt($profile['id_user']);
  1157. if(!$idUser){
  1158. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente.', [], 400);
  1159. }
  1160. $usr = DB::table('S002V01TUSUA')->where([
  1161. ['USUA_IDUS', '=', $idUser],
  1162. ['USUA_NULI', '=', $profile['linea']]
  1163. ])->first();
  1164. if(is_null($usr)){
  1165. return $this->responseController->makeResponse(true, 'El usuario que realizó la solicitud no está registrado', [], 404);
  1166. }else if($usr->USUA_ESTA == 'Eliminado'){
  1167. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está eliminado.", [], 401);
  1168. }else if($usr->USUA_ESTA == 'Inactivo'){
  1169. return $this->responseController->makeResponse(true, "El usuario que realiza el registro está boloqueado.", [], 401);
  1170. }
  1171. $now = $this->functionsController->now();
  1172. $nowStr = $now ->toDateTimeString();
  1173. $newPerf = DB::table('S002V01TPERF')->insertGetId([
  1174. 'PERF_NULI' => $profile['linea'],
  1175. 'PERF_NOPE' => $profile['name'],
  1176. 'PERF_PERM' => $profile['permissions'],
  1177. 'PERF_USRE' => $idUser,
  1178. 'PERF_FERE' => $nowStr
  1179. ]);
  1180. $actions = DB::getQueryLog();
  1181. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1182. $idac = $this->functionsController->registerActivity(
  1183. $profile['linea'],
  1184. $this->moduleCode,
  1185. 'S002V01F01ADPE',
  1186. 'S002V01P02REPE',
  1187. 'Registro',
  1188. "El usuario $name (" . $usr->USUA_IDUS . ") registró el perfil $profile[name] ($newPerf).",
  1189. $idUser,
  1190. $nowStr,
  1191. 'S002V01S02GEPE'
  1192. );
  1193. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $profile['linea']);
  1194. return $this->responseController->makeResponse(false, 'EXITO');
  1195. }
  1196. public function getModule($idMod, $idUser, $line){
  1197. DB::enableQueryLog();
  1198. $idUser = $this->encryptionController->decrypt($idUser);
  1199. if(!$idUser){
  1200. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  1201. }
  1202. $usr = DB::table('S002V01TUSUA')->where([
  1203. ['USUA_IDUS', '=', $idUser],
  1204. ['USUA_NULI', '=', $line]
  1205. ])->first();
  1206. if(is_null($usr)){
  1207. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1208. }
  1209. $idMod = $this->encryptionController->decrypt($idMod);
  1210. if(!$idMod){
  1211. return $this->responseController->makeResponse(true, 'El módulo solicitado no fue encriptado correctamente', [], 400);
  1212. }
  1213. $module = DB::table('S002V01TMODU')->select(
  1214. 'MODU_IDMO as IDMODULO',
  1215. 'MODU_NOMO as NOMBREMODULO',
  1216. )->where([
  1217. ['MODU_NULI', '=', $line],
  1218. ['MODU_IDMO', '=', $idMod]
  1219. ])->first();
  1220. if(is_null($module)){
  1221. return $this->responseController->makeResponse(true, 'El módulo consultado no está registrado', [], 404);
  1222. }
  1223. $module->IDMODULO = $this->encryptionController->encrypt($module->IDMODULO);
  1224. $now = $this->functionsController->now();
  1225. $actions = DB::getQueryLog();
  1226. $nowStr = $now->toDateTimeString();
  1227. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1228. $idac = $this->functionsController->registerActivity(
  1229. $line,
  1230. '-',
  1231. '-',
  1232. '-',
  1233. 'Consulta',
  1234. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el módulo " . $idMod . " del sistema.",
  1235. $idUser,
  1236. $nowStr
  1237. );
  1238. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1239. return $this->responseController->makeresponse(false, "EXITO", $module);
  1240. }
  1241. public function getSubmodules($idMod, $idUser, $line){
  1242. DB::enableQueryLog();
  1243. $idUser = $this->encryptionController->decrypt($idUser);
  1244. if(!$idUser){
  1245. return $this->responseController->makeResponse(true, 'El ID del usuario que realizó la solicitud no está encriptado correctamente', [], 400);
  1246. }
  1247. $usr = DB::table('S002V01TUSUA')->where([
  1248. ['USUA_IDUS', '=', $idUser],
  1249. ['USUA_NULI', '=', $line]
  1250. ])->first();
  1251. if(is_null($usr)){
  1252. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1253. }
  1254. $idMod = $this->encryptionController->decrypt($idMod);
  1255. if(!$idMod){
  1256. return $this->responseController->makeResponse(true, 'El ID del módulo no fue encriptado correctamente', [], 400);
  1257. }
  1258. $mod = DB::table('S002V01TMODU')->where([
  1259. ['MODU_NULI', '=', $line],
  1260. ['MODU_IDMO', '=', $idMod]
  1261. ])->first();
  1262. if(is_null($mod)){
  1263. return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
  1264. }
  1265. $submodules = DB::table('S002V01TSUBM')->where([
  1266. ['SUBM_NULI', '=', $line],
  1267. ['SUBM_IDMO', '=', $idMod],
  1268. ])->select([
  1269. 'SUBM_IDSM AS IDSUBMODULO',
  1270. 'SUBM_NOMB AS NOMBRESUBMODULO',
  1271. 'SUBM_ICON AS ICONOSUBMODULO',
  1272. 'SUBM_IMAG AS IMAGENSUBMODULO',
  1273. ])->get()->all();
  1274. foreach($submodules as $key=>$submodule){
  1275. $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
  1276. $submodules[$key] = $submodule;
  1277. }
  1278. $now = $this->functionsController->now();
  1279. $nowStr = $now->toDateTimeString();
  1280. $actions = DB::getQueryLog();
  1281. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1282. $idac = $this->functionsController->registerActivity(
  1283. $line,
  1284. '-',
  1285. '-',
  1286. '-',
  1287. 'Consulta',
  1288. "El usuario $name (" . $usr->USUA_IDUS . ") consultó los submódulos del módulo '" . $mod->MODU_NOMO . "'.",
  1289. $idUser,
  1290. $nowStr
  1291. );
  1292. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1293. return $this->responseController->makeResponse(false, 'EXITO', $submodules);
  1294. }
  1295. public function getSubmodule($idMod, $idSub, $idUser, $line){
  1296. DB::enableQueryLog();
  1297. $idUser = $this->encryptionController->decrypt($idUser);
  1298. if(!$idUser){
  1299. return $this->responseController->makeResponse(true, 'El ID del usuario que consulta no fue encriptado correctamente', [], 400);
  1300. }
  1301. $usr = DB::table('S002V01TUSUA')->where([
  1302. ['USUA_IDUS', '=', $idUser],
  1303. ['USUA_NULI', '=', $line]
  1304. ])->first();
  1305. if(is_null($usr)){
  1306. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no existe', [], 404);
  1307. }
  1308. $idMod = $this->encryptionController->decrypt($idMod);
  1309. if(!$idMod){
  1310. return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
  1311. }
  1312. $module = DB::table('S002V01TMODU')->where([
  1313. ['MODU_NULI', '=', $line],
  1314. ['MODU_IDMO', '=', $idMod]
  1315. ])->first();
  1316. if(is_null($module)){
  1317. return $this->responseController->makeResponse(true, 'El módulo consultado no existe', [], 404);
  1318. }
  1319. $idSub = $this->encryptionController->decrypt($idSub);
  1320. if(!$idSub){
  1321. return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
  1322. }
  1323. $submodule = DB::table('S002V01TSUBM')->select(
  1324. 'SUBM_IDSM as IDSUBMODULO',
  1325. 'SUBM_NOMB as NOMBRESUBMODULO',
  1326. )->where([
  1327. ['SUBM_NULI', '=', $line],
  1328. ['SUBM_IDSM', '=', $idSub],
  1329. ['SUBM_IDMO', '=', $idMod],
  1330. ])->first();
  1331. if(is_null($submodule)){
  1332. return $this->responseController->makeResponse(true, 'El submódulo consultado no existe', [], 404);
  1333. }
  1334. $submodule->IDSUBMODULO = $this->encryptionController->encrypt($submodule->IDSUBMODULO);
  1335. $now = $this->functionsController->now();
  1336. $actions = DB::getQueryLog();
  1337. $nowStr = $now->toDateTimeString();
  1338. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1339. $idac = $this->functionsController->registerActivity(
  1340. $line,
  1341. '-',
  1342. '-',
  1343. '-',
  1344. 'Consulta',
  1345. "El usuario $name (" . $usr->USUA_IDUS . ") consultó el submódulo " . $idSub . " del sistema.",
  1346. $idUser,
  1347. $nowStr
  1348. );
  1349. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1350. return $this->responseController->makeresponse(false, "EXITO", $submodule);
  1351. }
  1352. public function getFunction($idMod, $idSub, $idFun, $idUser, $line){
  1353. DB::enableQueryLog();
  1354. $idMod = $this->encryptionController->decrypt($idMod);
  1355. if(!$idMod){
  1356. return $this->responseController->makeResponse(true, 'El módulo no fue encriptado correctamente', [], 400);
  1357. }
  1358. $idSub = $this->encryptionController->decrypt($idSub);
  1359. if(!$idSub){
  1360. return $this->responseController->makeResponse(true, 'El submódulo no fue encriptado correctamente', [], 400);
  1361. }
  1362. $idFun = $this->encryptionController->decrypt($idFun);
  1363. if(!$idFun){
  1364. return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
  1365. }
  1366. $idUser = $this->encryptionController->decrypt($idUser);
  1367. if(!$idUser){
  1368. return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
  1369. }
  1370. $usr = DB::table('S002V01TUSUA')->where([
  1371. ['USUA_IDUS', '=', $idUser],
  1372. ['USUA_NULI', '=', $line]
  1373. ])->first();
  1374. if(is_null($usr)){
  1375. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1376. }
  1377. $function = DB::table('S002V01TFUNC')->select(
  1378. 'FUNC_IDFU as IDFUNCION',
  1379. 'FUNC_NOMB as NOMBREFUNCION',
  1380. )->where([
  1381. ['FUNC_NULI', '=', $line],
  1382. ['FUNC_IDFU', '=', $idFun],
  1383. ['FUNC_IDMO', '=', $idMod],
  1384. ['FUNC_IDSM', '=', $idSub],
  1385. ])->first();
  1386. $now = $this->functionsController->now();
  1387. $nowStr = $now->toDateTimeString();
  1388. $actions = DB::getQueryLog();
  1389. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1390. $idac = $this->functionsController->registerActivity(
  1391. $line,
  1392. '-',
  1393. '-',
  1394. '-',
  1395. 'Consulta',
  1396. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la función " . $idFun . " del sistema.",
  1397. $idUser,
  1398. $nowStr
  1399. );
  1400. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1401. return $this->responseController->makeresponse(false, "EXITO", [
  1402. 'NOMBREFUNCION' => is_null($function) ? '-' : $function->NOMBREFUNCION
  1403. ]);
  1404. }
  1405. public function getScreen($idFun, $idPan, $idUser, $line){
  1406. DB::enableQueryLog();
  1407. $idFun = $this->encryptionController->decrypt($idFun);
  1408. if(!$idFun){
  1409. return $this->responseController->makeResponse(true, 'La función no fue encriptada correctamente', [], 400);
  1410. }
  1411. $idPan = $this->encryptionController->decrypt($idPan);
  1412. if(!$idPan){
  1413. return $this->responseController->makeResponse(true, 'La pantalla no fue encriptada correctamente', [], 400);
  1414. }
  1415. $idUser = $this->encryptionController->decrypt($idUser);
  1416. if(!$idUser){
  1417. return $this->responseController->makeResponse(true, 'El id del usuario que consulta no fue encriptado correctamente', [], 400);
  1418. }
  1419. $usr = DB::table('S002V01TUSUA')->where([
  1420. ['USUA_IDUS', '=', $idUser],
  1421. ['USUA_NULI', '=', $line]
  1422. ])->first();
  1423. if(is_null($usr)){
  1424. return $this->responseController->makeResponse(true, 'El usuario que realizó la consulta no está registrado', [], 404);
  1425. }
  1426. $screen = DB::table('S002V01TPANT')->select(
  1427. 'PANT_IDFU as IDPANTALLA',
  1428. 'PANT_NOMB as NOMBREPANTALLA',
  1429. )->where([
  1430. ['PANT_NULI', '=', $line],
  1431. ['PANT_IDPA', '=', $idPan],
  1432. ['PANT_IDFU', '=', $idFun],
  1433. ])->first();
  1434. $now = $this->functionsController->now();
  1435. $nowStr = $now->toDateTimeString();
  1436. $actions = DB::getQueryLog();
  1437. $name = $this->functionsController->joinName($usr->USUA_NOMB, $usr->USUA_APPA, $usr->USUA_APMA);
  1438. $idac = $this->functionsController->registerActivity(
  1439. $line,
  1440. '-',
  1441. '-',
  1442. '-',
  1443. 'Consulta',
  1444. "El usuario $name (" . $usr->USUA_IDUS . ") consultó la pantalla " . $idPan . " del sistema.",
  1445. $idUser,
  1446. $nowStr
  1447. );
  1448. $this->functionsController->registerLog($actions, $idUser, $nowStr, $idac, $line);
  1449. return $this->responseController->makeresponse(false, "EXITO", [
  1450. 'NOMBREPANTALLA' => is_null($screen) ? '-' : $screen->NOMBREPANTALLA
  1451. ]);
  1452. }
  1453. }