SymptomListController.php 34 KB

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