SymptomListController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 11/04/2023
  5. Módulo: Analisis de Fallas
  6. */
  7. namespace App\Http\Controllers;
  8. use App\Http\Controllers\Controller;
  9. use App\Http\Controllers\ResponseController;
  10. use App\Http\Controllers\EncryptionController;
  11. use App\Http\Controllers\ResourcesController;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Carbon;
  14. use Illuminate\Support\Facades\DB;
  15. use Illuminate\Support\Facades\Validator;
  16. use App\Http\Controllers\FunctionsController;
  17. class SymptomListController extends Controller
  18. {
  19. private $responseController;
  20. private $encController;
  21. private $functionsController;
  22. private $resourcesController;
  23. public function __construct( ) {
  24. $this->responseController = new ResponseController();
  25. $this->encController = new EncryptionController();
  26. $this->functionsController = new FunctionsController();
  27. $this->resourcesController = new ResourcesController();
  28. }
  29. public function getSymptoms($user, $line) {
  30. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  31. if ($arrResponseCheckUser['error']) {
  32. DB::rollBack();
  33. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  34. }
  35. try {
  36. $getSymptom = DB::table('S002V01TLISI')
  37. ->where('LISI_NULI', '=', $line)
  38. ->where('LIME_NULI', '=', $line)
  39. ->where('LIME_ESTA', '=', 'Activo')
  40. ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
  41. ->get([
  42. 'LISI_IDSI AS ID_SINTOMA',
  43. 'LISI_NOSI AS NOMBRE_SINTOMA',
  44. 'LISI_CLAS AS CLASIFICACION',
  45. 'LISI_CAUS AS CAUSA',
  46. 'LISI_DESC AS DESCRIPCION',
  47. 'LISI_SOLU AS SOLUCION',
  48. 'LISI_LIVA AS LIMITE_VALOR',
  49. 'LIME_IDME AS ID_MEDIDA',
  50. 'LIME_NOME AS NOMBRE_MEDIDA',
  51. 'LIME_ACME AS ACRONIMO_MEDIDA',
  52. 'LISI_ESTA AS ESTADO',
  53. 'LISI_USRE AS USUARIO_REGISTRA',
  54. 'LISI_FERE AS FECHA_REGISTRA',
  55. 'LISI_USMO AS USUARIO_MODIFICA',
  56. 'LISI_FEMO AS FECHA_MODIFICA',
  57. ]);
  58. $arrSymtoms = json_decode( json_encode($getSymptom), true );
  59. } catch (\Throwable $th) {
  60. return $this->responseController->makeResponse(
  61. true,
  62. "ERR_SYMPTOM_GET000: No se pudo realizar la consulta a la base.",
  63. $th->getMessage(),
  64. 500
  65. );
  66. }
  67. $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrSymtoms, $line);
  68. if ($responseCheckLatestUpdate['error']) {
  69. return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
  70. }
  71. $arrSymtoms = $responseCheckLatestUpdate['response'];
  72. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
  73. }
  74. public function getSymptomsActives($user, $line) {
  75. try {
  76. $getSymptom = DB::table('S002V01TLISI')
  77. ->where('LISI_NULI', '=', $line)
  78. ->where('LISI_ESTA', '=', 'Activo')
  79. ->where('LIME_NULI', '=', $line)
  80. ->where('LIME_ESTA', '=', 'Activo')
  81. ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
  82. ->get([
  83. 'LISI_IDSI AS ID_SINTOMA',
  84. 'LISI_NOSI AS NOMBRE_SINTOMA',
  85. 'LISI_CLAS AS CLASIFICACION',
  86. 'LISI_CAUS AS CAUSA',
  87. 'LISI_DESC AS DESCRIPCION',
  88. 'LISI_SOLU AS SOLUCION',
  89. 'LISI_LIVA AS LIMITE_VALOR',
  90. 'LIME_IDME AS ID_MEDIDA',
  91. 'LIME_NOME AS NOMBRE_MEDIDA',
  92. 'LIME_ACME AS ACRONIMO_MEDIDA',
  93. 'LISI_ESTA AS ESTADO',
  94. 'LISI_USRE AS USUARIO_REGISTRA',
  95. 'LISI_FERE AS FECHA_REGISTRA',
  96. 'LISI_USMO AS USUARIO_MODIFICA',
  97. 'LISI_FEMO AS FECHA_MODIFICA',
  98. ]);
  99. } catch (\Throwable $th) {
  100. return $this->responseController->makeResponse(
  101. true,
  102. "ERR_SYMPTOM_GETACTIVE000: No se pudo realizar la consulta a la base.",
  103. $th->getMessage(),
  104. 500
  105. );
  106. }
  107. $arrSymtoms = json_decode( json_encode($getSymptom), true );
  108. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
  109. }
  110. public function getSymptomsByEquipment($equipment, $user, $line) {
  111. try {
  112. $equipment = $this->encController->decrypt($equipment);
  113. } catch (\Throwable $th) {
  114. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GETBYEQUIPMENT000: No se pudo obtener el equipamiento.", $th->getMessage(), 500);
  115. }
  116. try {
  117. $getSymptom = DB::table('S002V01TLSEQ')
  118. ->where('LSEQ_NULI', '=', $line)
  119. ->where('LSEQ_ESTA', '=', 'Activo')
  120. ->where('LSEQ_COEQ', '=', $equipment)
  121. ->where('LISI_NULI', '=', $line)
  122. ->where('LISI_ESTA', '=', 'Activo')
  123. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'LSEQ_IDSI')
  124. ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
  125. ->get([
  126. 'LISI_IDSI AS ID_SINTOMA',
  127. 'LISI_NOSI AS NOMBRE_SINTOMA',
  128. 'LISI_CLAS AS CLASIFICACION',
  129. 'LISI_CAUS AS CAUSA',
  130. 'LISI_DESC AS DESCRIPCION',
  131. 'LISI_SOLU AS SOLUCION',
  132. 'LISI_LIVA AS LIMITE_VALOR',
  133. 'LIME_IDME AS ID_MEDIDA',
  134. 'LIME_NOME AS NOMBRE_MEDIDA',
  135. 'LIME_ACME AS ACRONIMO_MEDIDA',
  136. 'LISI_ESTA AS ESTADO',
  137. 'LISI_USRE AS USUARIO_REGISTRA',
  138. 'LISI_FERE AS FECHA_REGISTRA',
  139. 'LISI_USMO AS USUARIO_MODIFICA',
  140. 'LISI_FEMO AS FECHA_MODIFICA',
  141. ]);
  142. } catch (\Throwable $th) {
  143. return $this->responseController->makeResponse(
  144. true,
  145. "ERR_SYMPTOM_GETBYEQUIPMENT001: No se pudo realizar la consulta a la base.",
  146. $th->getMessage(),
  147. 500
  148. );
  149. }
  150. $arrSymtoms = json_decode( json_encode($getSymptom), true );
  151. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymtoms);
  152. }
  153. public function getSymptomById($idSymptom, $user, $line) {
  154. try {
  155. $idSymptom = $this->encController->decrypt($idSymptom);
  156. } catch (\Throwable $th) {
  157. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GETBYID000: No se pudo obtener el ID del síntoma.", $th->getMessage(), 500);
  158. }
  159. try {
  160. $arrSymptom = (array) DB::table('S002V01TLISI')
  161. ->where('LISI_IDSI', '=', $idSymptom)
  162. ->where('LISI_NULI', '=', $line)
  163. ->where('LISI_ESTA', '=', 'Activo')
  164. ->where('LIME_NULI', '=', $line)
  165. ->where('LIME_ESTA', '=', 'Activo')
  166. ->join('S002V01TLIME', 'LIME_IDME', '=', 'LISI_IDME')
  167. ->first([
  168. 'LISI_IDSI AS ID_SINTOMA',
  169. 'LISI_NOSI AS NOMBRE_SINTOMA',
  170. 'LISI_CLAS AS CLASIFICACION',
  171. 'LISI_CAUS AS CAUSA',
  172. 'LISI_DESC AS DESCRIPCION',
  173. 'LISI_SOLU AS SOLUCION',
  174. 'LISI_LIVA AS LIMITE_VALOR',
  175. 'LIME_IDME AS ID_MEDIDA',
  176. 'LIME_NOME AS NOMBRE_MEDIDA',
  177. 'LIME_ACME AS ACRONIMO_MEDIDA',
  178. 'LISI_ESTA AS ESTADO',
  179. 'LISI_USRE AS USUARIO_REGISTRA',
  180. 'LISI_FERE AS FECHA_REGISTRA',
  181. 'LISI_USMO AS USUARIO_MODIFICA',
  182. 'LISI_FEMO AS FECHA_MODIFICA',
  183. ]);
  184. } catch (\Throwable $th) {
  185. return $this->responseController->makeResponse(
  186. true,
  187. "ERR_SYMPTOM_GETBYID001: No se pudo realizar la consulta a la base.",
  188. $th->getMessage(),
  189. 500
  190. );
  191. }
  192. if ( !empty($arrSymptom) ) {
  193. try {
  194. $arrEquipment = DB::table('S002V01TLSEQ')
  195. ->where('LSEQ_IDSI', '=', $idSymptom)
  196. ->where('LSEQ_NULI', '=', $line)
  197. ->where('LSEQ_ESTA', '=', 'Activo')
  198. ->where('EQUI_NULI', '=', $line)
  199. ->join('S002V01TEQUI', 'EQUI_COEQ', '=', 'LSEQ_COEQ')
  200. ->get([
  201. 'EQUI_COEQ AS CODIGO',
  202. 'EQUI_TIPO AS TIPO',
  203. 'EQUI_MODE AS MODELO',
  204. 'EQUI_IDEQ AS ID_EQUIPO',
  205. 'EQUI_ESFU AS ESTADO_FUNCIONAMIENTO',
  206. 'EQUI_ELOR AS ELEMENTO_ORIGEN',
  207. 'EQUI_TICO AS TIPO_CODIGO'
  208. ]);
  209. } catch (\Throwable $th) {
  210. return $this->responseController->makeResponse(
  211. true,
  212. "ERR_SYMPTOM_GETBYID002: No se pudo realizar la consulta a la base.",
  213. $th->getMessage(),
  214. 500
  215. );
  216. }
  217. $arrEquipment = json_decode( json_encode($arrEquipment), true );
  218. foreach ($arrEquipment as $keyEquipment => $equipment) {
  219. $equipment['ID_EQUIPO'] = strval($equipment['ID_EQUIPO']);
  220. $arrEquipment[$keyEquipment] = $equipment;
  221. }
  222. $arrSymptom['EQUIPAMIENTOS'] = $arrEquipment;
  223. try {
  224. $arrFailure = DB::table('S002V01TLFLS')
  225. ->where('LFLS_IDSI', '=', $idSymptom)
  226. ->where('LFLS_NULI', '=', $line)
  227. ->where('LFLS_ESTA', '=', 'Activo')
  228. ->where('LIFA_NULI', '=', $line)
  229. ->where('LIFA_ESTA', '=', 'Activo')
  230. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'LFLS_IDFA')
  231. ->get([
  232. 'LIFA_IDFA AS ID_FALLA',
  233. 'LIFA_NOFA AS NOMBRE_FALLA',
  234. 'LIFA_NIVE AS NIVEL_CRITICIDAD',
  235. 'LIFA_CAUS AS CAUSA_FALLA',
  236. 'LIFA_SOLU AS SOLICION',
  237. 'LIFA_DESC AS DESCRIPCION',
  238. ]);
  239. } catch (\Throwable $th) {
  240. return $this->responseController->makeResponse(
  241. true,
  242. "ERR_SYMPTOM_GETBYID003: No se pudo realizar la consulta a la base.",
  243. $th->getMessage(),
  244. 500
  245. );
  246. }
  247. $arrFailure = json_decode( json_encode($arrFailure), true );
  248. $arrSymptom['FALLAS'] = $arrFailure;
  249. }
  250. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrSymptom);
  251. }
  252. public function registerSymptom(Request $request) {
  253. $validator = Validator::make($request->all(), [
  254. 'NOMBRE_SINTOMA' => 'required|string',
  255. 'CLASIFICACION' => 'required|string',
  256. 'CAUSA' => 'required|string',
  257. 'DESCRIPCION' => 'required|string',
  258. 'SOLUCION' => 'required|string',
  259. 'LIMITE_VALOR' => 'required|string',
  260. 'ID_MEDIDA' => 'required|string',
  261. 'FALLAS' => 'required|array',
  262. 'EQUIPAMIENTOS' => 'required|array',
  263. 'USUARIO' => 'required|string',
  264. 'NUMERO_LINEA' => 'required|integer',
  265. ]);
  266. if ($validator->fails()) {
  267. return $this->responseController->makeResponse(
  268. true,
  269. "ERR_SYMPTOM_REG000: Se encontraron uno o más errores.",
  270. $this->responseController->makeErrors($validator->errors()->messages()),
  271. 401
  272. );
  273. }
  274. DB::beginTransaction();
  275. $requestData = $request->all();
  276. try {
  277. $user = $this->encController->decrypt($requestData['USUARIO']);
  278. } catch (\Throwable $th) {
  279. DB::rollBack();
  280. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  281. }
  282. $now = $this->functionsController->now();
  283. $currentDate = $now->toDateTimeString();
  284. try {
  285. $idSymptom = DB::table('S002V01TLISI')->insertGetId([
  286. 'LISI_NULI' => $requestData['NUMERO_LINEA'],
  287. 'LISI_NOSI' => $requestData['NOMBRE_SINTOMA'],
  288. 'LISI_CLAS' => $requestData['CLASIFICACION'],
  289. 'LISI_CAUS' => $requestData['CAUSA'],
  290. 'LISI_SOLU' => $requestData['SOLUCION'],
  291. 'LISI_DESC' => $requestData['DESCRIPCION'],
  292. 'LISI_LIVA' => $requestData['LIMITE_VALOR'],
  293. 'LISI_IDME' => $requestData['ID_MEDIDA'],
  294. 'LISI_USRE' => $user,
  295. 'LISI_FERE' => $currentDate,
  296. 'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  297. ]);
  298. } catch (\Throwable $th) {
  299. DB::rollBack();
  300. return $this->responseController->makeResponse(
  301. true,
  302. "ERR_SYMPTOM_REG002: Ocurrió un error en el registro de la lista de síntoma en la base de datos.",
  303. $th->getMessage(),
  304. 500
  305. );
  306. }
  307. if ( !$idSymptom ) {
  308. DB::rollBack();
  309. return $this->responseController->makeResponse(
  310. true,
  311. "ERR_SYMPTOM_REG003: No se pudo hacer el registro de la lista de síntoma en la base de datos.",
  312. [],
  313. 500
  314. );
  315. }
  316. foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
  317. try {
  318. $validateRegisterEquipment = DB::table('S002V01TLSEQ')->insert([
  319. 'LSEQ_NULI' => $requestData['NUMERO_LINEA'],
  320. 'LSEQ_IDSI' => $idSymptom,
  321. 'LSEQ_COEQ' => $equipment,
  322. 'LSEQ_USRE' => $user,
  323. 'LSEQ_FERE' => $currentDate,
  324. 'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  325. ]);
  326. } catch (\Throwable $th) {
  327. DB::rollBack();
  328. return $this->responseController->makeResponse(
  329. true,
  330. "ERR_SYMPTOM_REG004: Ocurrió un error al registrar el formulario en la lista de síntomas.",
  331. $th->getMessage(),
  332. 500
  333. );
  334. }
  335. if ( !$validateRegisterEquipment ) {
  336. DB::rollBack();
  337. return $this->responseController->makeResponse(
  338. true,
  339. "ERR_SYMPTOM_REG005: No se pudo registrar el equipamiento $equipment en la lista de síntomas.",
  340. [],
  341. 500
  342. );
  343. }
  344. }
  345. foreach ($requestData['FALLAS'] as $keyFailure => $failure) {
  346. try {
  347. $validateRegisterFailure = DB::table('S002V01TLFLS')->insert([
  348. 'LFLS_NULI' => $requestData['NUMERO_LINEA'],
  349. 'LFLS_IDFA' => $failure,
  350. 'LFLS_IDSI' => $idSymptom,
  351. 'LFLS_USRE' => $user,
  352. 'LFLS_FERE' => $currentDate,
  353. 'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  354. ]);
  355. } catch (\Throwable $th) {
  356. DB::rollBack();
  357. return $this->responseController->makeResponse(
  358. true,
  359. "ERR_SYMPTOM_REG006: Ocurrió un error al registrar el formulario en la lista de síntomas.",
  360. $th->getMessage(),
  361. 500
  362. );
  363. }
  364. if ( !$validateRegisterFailure ) {
  365. DB::rollBack();
  366. return $this->responseController->makeResponse(
  367. true,
  368. "ERR_SYMPTOM_REG007: No se pudo registrar el equipamiento $equipment en la lista de síntomas.",
  369. [],
  370. 500
  371. );
  372. }
  373. }
  374. DB::commit();
  375. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  376. }
  377. public function updateSymptom(Request $request) {
  378. $validator = Validator::make($request->all(), [
  379. 'ID_SINTOMA' => 'required|integer',
  380. 'NOMBRE_SINTOMA' => 'required|string',
  381. 'CLASIFICACION' => 'required|string',
  382. 'CAUSA' => 'required|string',
  383. 'DESCRIPCION' => 'required|string',
  384. 'SOLUCION' => 'required|string',
  385. 'LIMITE_VALOR' => 'required|string',
  386. 'ID_MEDIDA' => 'required|string',
  387. 'FALLAS' => 'required|array',
  388. 'EQUIPAMIENTOS' => 'required|array',
  389. 'USUARIO' => 'required|string',
  390. 'NUMERO_LINEA' => 'required|integer',
  391. ]);
  392. if ($validator->fails()) {
  393. return $this->responseController->makeResponse(
  394. true,
  395. "ERR_SYMPTOM_UPD000: Se encontraron uno o más errores.",
  396. $this->responseController->makeErrors($validator->errors()->messages()),
  397. 401
  398. );
  399. }
  400. DB::beginTransaction();
  401. $requestData = $request->all();
  402. try {
  403. $user = $this->encController->decrypt($requestData['USUARIO']);
  404. } catch (\Throwable $th) {
  405. DB::rollBack();
  406. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  407. }
  408. $now = $this->functionsController->now();
  409. $currentDate = $now->toDateTimeString();
  410. try {
  411. $validateUpdate = DB::table('S002V01TLISI')
  412. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  413. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  414. ->update([
  415. 'LISI_NOSI' => $requestData['NOMBRE_SINTOMA'],
  416. 'LISI_CLAS' => $requestData['CLASIFICACION'],
  417. 'LISI_CAUS' => $requestData['CAUSA'],
  418. 'LISI_SOLU' => $requestData['SOLUCION'],
  419. 'LISI_DESC' => $requestData['DESCRIPCION'],
  420. 'LISI_LIVA' => $requestData['LIMITE_VALOR'],
  421. 'LISI_IDME' => $requestData['ID_MEDIDA'],
  422. 'LISI_USMO' => $user,
  423. 'LISI_FEMO' => $currentDate,
  424. 'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  425. ]);
  426. } catch (\Throwable $th) {
  427. DB::rollBack();
  428. return $this->responseController->makeResponse(
  429. true,
  430. "ERR_SYMPTOM_UPD002: Ocurrió un error en el registro de la lista de síntoma en la base de datos.",
  431. $th->getMessage(),
  432. 500
  433. );
  434. }
  435. if ( !$validateUpdate ) {
  436. DB::rollBack();
  437. return $this->responseController->makeResponse(
  438. true,
  439. "ERR_SYMPTOM_UPD003: Ocurrió un error en la modificación de la lista de síntoma en la base de datos.",
  440. [],
  441. 500
  442. );
  443. }
  444. foreach ($requestData['EQUIPAMIENTOS'] as $keyEquipment => $equipment) {
  445. try {
  446. $validateExists = DB::table('S002V01TLSEQ')
  447. ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
  448. ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
  449. ->where('LSEQ_COEQ', '=', $equipment)
  450. ->exists();
  451. } catch (\Throwable $th) {
  452. DB::rollBack();
  453. return $this->responseController->makeResponse(
  454. true,
  455. "ERR_SYMPTOM_UPD004: Ocurrió un error al consultar el equipamiento.",
  456. $th->getMessage(),
  457. 500
  458. );
  459. }
  460. if ( $validateExists ) {
  461. try {
  462. $validate = DB::table('S002V01TLSEQ')
  463. ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
  464. ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
  465. ->where('LSEQ_COEQ', '=', $equipment)
  466. ->update([
  467. 'LSEQ_ESTA' => 'Activo',
  468. 'LSEQ_USMO' => $user,
  469. 'LSEQ_FEMO' => $currentDate,
  470. 'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  471. ]);
  472. } catch (\Throwable $th) {
  473. DB::rollBack();
  474. return $this->responseController->makeResponse(
  475. true,
  476. "ERR_SYMPTOM_UPD005: Ocurrió un error al modificar el formulario en la lista de falla el equipamiento $equipment.",
  477. $th->getMessage(),
  478. 500
  479. );
  480. }
  481. } else {
  482. try {
  483. $validate = DB::table('S002V01TLSEQ')->insert([
  484. 'LSEQ_NULI' => $requestData['NUMERO_LINEA'],
  485. 'LSEQ_IDSI' => $requestData['ID_SINTOMA'],
  486. 'LSEQ_COEQ' => $equipment,
  487. 'LSEQ_USRE' => $user,
  488. 'LSEQ_FERE' => $currentDate,
  489. 'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  490. ]);
  491. } catch (\Throwable $th) {
  492. DB::rollBack();
  493. return $this->responseController->makeResponse(
  494. true,
  495. "ERR_SYMPTOM_UPD006: Ocurrió un error al registrar el formulario en la lista de falla el equipamiento $equipment.",
  496. $th->getMessage(),
  497. 500
  498. );
  499. }
  500. }
  501. if ( !$validate ) {
  502. DB::rollBack();
  503. return $this->responseController->makeResponse(
  504. true,
  505. "ERR_SYMPTOM_UPD007: No se pudo modificar el equipamiento $equipment en la lista de fallas.",
  506. [],
  507. 500
  508. );
  509. }
  510. }
  511. try {
  512. $getListEquipment = DB::table('S002V01TLSEQ')
  513. ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
  514. ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
  515. ->get([
  516. 'LSEQ_IDLS',
  517. 'LSEQ_IDSI',
  518. 'LSEQ_COEQ',
  519. 'LSEQ_ESTA',
  520. ]);
  521. } catch (\Throwable $th) {
  522. DB::rollBack();
  523. return $this->responseController->makeResponse(
  524. true,
  525. "ERR_SYMPTOM_UPD008: Ocurrió un error al consultar la lista de equipamientos.",
  526. $th->getMessage(),
  527. 500
  528. );
  529. }
  530. $arrListEquipment = json_decode( json_encode($getListEquipment), true );
  531. foreach ($arrListEquipment as $keyListEquipment => $listEquipment) {
  532. if( !in_array($listEquipment['LSEQ_COEQ'], $requestData['EQUIPAMIENTOS']) ) {
  533. try {
  534. $validateDelete = DB::table('S002V01TLSEQ')
  535. ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
  536. ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
  537. ->where('LSEQ_COEQ', '=', $listEquipment['LSEQ_COEQ'])
  538. ->update([
  539. 'LSEQ_ESTA' => 'Eliminado',
  540. 'LSEQ_USMO' => $user,
  541. 'LSEQ_FEMO' => $currentDate,
  542. 'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  543. ]);
  544. } catch (\Throwable $th) {
  545. DB::rollBack();
  546. return $this->responseController->makeResponse(
  547. true,
  548. "ERR_SYMPTOM_UPD009: Ocurrió un error al eliminar de la lista de falla el equipamiento ". $listEquipment['LSEQ_COEQ'].".",
  549. $th->getMessage(),
  550. 500
  551. );
  552. }
  553. if ( !$validateDelete ) {
  554. DB::rollBack();
  555. return $this->responseController->makeResponse(
  556. true,
  557. "ERR_SYMPTOM_UPD010: No se pudo eliminar de la lista de falla el equipamiento ". $listEquipment['LFEQ_COEQ'].".",
  558. [],
  559. 500
  560. );
  561. }
  562. }
  563. }
  564. foreach ($requestData['FALLAS'] as $keyFailure => $failure) {
  565. try {
  566. $validateExists = DB::table('S002V01TLFLS')
  567. ->where('LFLS_IDFA', '=', $failure)
  568. ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
  569. ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
  570. ->exists();
  571. } catch (\Throwable $th) {
  572. DB::rollBack();
  573. return $this->responseController->makeResponse(
  574. true,
  575. "ERR_SYMPTOM_UPD011: Ocurrió un error al consultar la falla.",
  576. $th->getMessage(),
  577. 500
  578. );
  579. }
  580. if ( $validateExists ) {
  581. try {
  582. $validate = DB::table('S002V01TLFLS')
  583. ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
  584. ->where('LFLS_IDFA', '=', $failure)
  585. ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
  586. ->update([
  587. 'LFLS_ESTA' => 'Activo',
  588. 'LFLS_USMO' => $user,
  589. 'LFLS_FEMO' => $currentDate,
  590. 'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  591. ]);
  592. } catch (\Throwable $th) {
  593. DB::rollBack();
  594. return $this->responseController->makeResponse(
  595. true,
  596. "ERR_SYMPTOM_UPD012: Ocurrió un error al modificar el formulario en la lista de falla del síntoma.",
  597. $th->getMessage(),
  598. 500
  599. );
  600. }
  601. } else {
  602. try {
  603. $validate = DB::table('S002V01TLFLS')->insert([
  604. 'LFLS_NULI' => $requestData['NUMERO_LINEA'],
  605. 'LFLS_IDSI' => $requestData['ID_SINTOMA'],
  606. 'LFLS_IDFA' => $failure,
  607. 'LFLS_USRE' => $user,
  608. 'LFLS_FERE' => $currentDate,
  609. 'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  610. ]);
  611. } catch (\Throwable $th) {
  612. DB::rollBack();
  613. return $this->responseController->makeResponse(
  614. true,
  615. "ERR_SYMPTOM_UPD013: Ocurrió un error al registrar el formulario en la lista de falla del síntoma.",
  616. $th->getMessage(),
  617. 500
  618. );
  619. }
  620. }
  621. if ( !$validate ) {
  622. DB::rollBack();
  623. return $this->responseController->makeResponse(
  624. true,
  625. "ERR_SYMPTOM_UPD014: No se pudo modificar la lista de fallas.",
  626. [],
  627. 500
  628. );
  629. }
  630. }
  631. try {
  632. $arrListFaliure = DB::table('S002V01TLFLS')
  633. ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
  634. ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
  635. ->get([
  636. 'LFLS_IDFA',
  637. 'LFLS_IDSI',
  638. 'LFLS_ESTA',
  639. ]);
  640. } catch (\Throwable $th) {
  641. DB::rollBack();
  642. return $this->responseController->makeResponse(
  643. true,
  644. "ERR_SYMPTOM_UPD015: Ocurrió un error al consultar la lista de fallas del síntoma.",
  645. $th->getMessage(),
  646. 500
  647. );
  648. }
  649. $arrListFaliure = json_decode( json_encode($arrListFaliure), true );
  650. foreach ($arrListFaliure as $keyListFaliure => $listFaliure) {
  651. if( !in_array($listFaliure['LFLS_IDFA'], $requestData['FALLAS']) ) {
  652. try {
  653. $validateDelete = DB::table('S002V01TLFLS')
  654. ->where('LFLS_IDFA', '=', $listFaliure['LFLS_IDFA'])
  655. ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
  656. ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
  657. ->update([
  658. 'LFLS_ESTA' => 'Eliminado',
  659. 'LFLS_USMO' => $user,
  660. 'LFLS_FEMO' => $currentDate,
  661. 'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  662. ]);
  663. } catch (\Throwable $th) {
  664. DB::rollBack();
  665. return $this->responseController->makeResponse(
  666. true,
  667. "ERR_SYMPTOM_UPD016: Ocurrió un error al eliminar las falla ".$listFaliure['LFLS_IDFA']." del síntoma.",
  668. $th->getMessage(),
  669. 500
  670. );
  671. }
  672. if ( !$validateDelete ) {
  673. DB::rollBack();
  674. return $this->responseController->makeResponse(
  675. true,
  676. "ERR_SYMPTOM_UPD017: No se pudo eliminar la falla ".$listFaliure['LFLS_IDFA']." del síntoma.",
  677. [],
  678. 500
  679. );
  680. }
  681. }
  682. }
  683. DB::commit();
  684. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  685. }
  686. public function deleteSymptom(Request $request) {
  687. $validator = Validator::make($request->all(), [
  688. 'ID_SINTOMA' => 'required|string',
  689. 'NUMERO_LINEA' => 'required|integer',
  690. 'USUARIO' => 'required|string',
  691. ]);
  692. if ($validator->fails()) {
  693. return $this->responseController->makeResponse(
  694. true,
  695. "ERR_SYMPTOM_DEL000: Se encontraron uno o más errores.",
  696. $this->responseController->makeErrors($validator->errors()->messages()),
  697. 401
  698. );
  699. }
  700. DB::beginTransaction();
  701. $requestData = $request->all();
  702. try {
  703. $user = $this->encController->decrypt($requestData['USUARIO']);
  704. } catch (\Throwable $th) {
  705. DB::rollBack();
  706. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  707. }
  708. $now = $this->functionsController->now();
  709. $currentDate = $now->toDateTimeString();
  710. try {
  711. $exist = DB::table('S002V01TLISI')
  712. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  713. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  714. ->exists();
  715. } catch (\Throwable $th) {
  716. DB::rollBack();
  717. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500);
  718. }
  719. if (!$exist) {
  720. DB::rollBack();
  721. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL003: El archivo no existe.", [], 500);
  722. }
  723. try {
  724. $validateDelete = DB::table('S002V01TLISI')
  725. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  726. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  727. ->update([
  728. 'LISI_ESTA' => 'Eliminado',
  729. 'LISI_USMO' => $user,
  730. 'LISI_FEMO' => $currentDate,
  731. 'LISI_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  732. ]);
  733. } catch (\Throwable $th) {
  734. DB::rollBack();
  735. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL004: Ocurrió un error al eliminar el síntoma de la base de datos.", $th->getMessage(), 500);
  736. }
  737. if ( !$validateDelete ) {
  738. DB::rollBack();
  739. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL005: No se pudo eliminar el síntoma de la base de datos.", [], 500);
  740. }
  741. try {
  742. $validateDelete = DB::table('S002V01TLSEQ')
  743. ->where('LSEQ_IDSI', '=', $requestData['ID_SINTOMA'])
  744. ->where('LSEQ_NULI', '=', $requestData['NUMERO_LINEA'])
  745. ->update([
  746. 'LSEQ_ESTA' => 'Eliminado',
  747. 'LSEQ_USMO' => $user,
  748. 'LSEQ_FEMO' => $currentDate,
  749. 'LSEQ_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  750. ]);
  751. } catch (\Throwable $th) {
  752. DB::rollBack();
  753. return $this->responseController->makeResponse(
  754. true,
  755. "ERR_SYMPTOM_DEL006: Ocurrió un error al eliminar la lista de equipamientos.",
  756. $th->getMessage(),
  757. 500
  758. );
  759. }
  760. if ( !$validateDelete ) {
  761. DB::rollBack();
  762. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL007: No se pudo eliminar la lista de equipamientos.", [], 500);
  763. }
  764. try {
  765. $validateDelete = DB::table('S002V01TLFLS')
  766. ->where('LFLS_IDSI', '=', $requestData['ID_SINTOMA'])
  767. ->where('LFLS_NULI', '=', $requestData['NUMERO_LINEA'])
  768. ->update([
  769. 'LFLS_ESTA' => 'Eliminado',
  770. 'LFLS_USMO' => $user,
  771. 'LFLS_FEMO' => $currentDate,
  772. 'LFLS_FEAR' => DB::raw('CURRENT_TIMESTAMP'),
  773. ]);
  774. } catch (\Throwable $th) {
  775. DB::rollBack();
  776. return $this->responseController->makeResponse(
  777. true,
  778. "ERR_SYMPTOM_DEL008: Ocurrió un error al eliminar la lista de fallas.",
  779. $th->getMessage(),
  780. 500
  781. );
  782. }
  783. if ( !$validateDelete ) {
  784. DB::rollBack();
  785. return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL009: No se pudo eliminar la lista de fallas.", [], 500);
  786. }
  787. DB::commit();
  788. return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa");
  789. }
  790. }