FailureLogController.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <?php
  2. /*
  3. Desarrollador: Ing. Jean Jairo Benitez Meza
  4. Ultima Modificación: 21/09/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. use Illuminate\Support\Facades\Storage;
  17. use Illuminate\Http\File;
  18. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  19. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  20. use Dompdf\Dompdf;
  21. class FailureLogController extends Controller
  22. {
  23. private $responseController;
  24. private $encController;
  25. private $functionsController;
  26. private $resourcesController;
  27. public function __construct( ) {
  28. $this->responseController = new ResponseController();
  29. $this->encController = new EncryptionController();
  30. $this->functionsController = new FunctionsController();
  31. $this->resourcesController = new ResourcesController();
  32. }
  33. public function getFailureLog($user, $line) {
  34. try {
  35. $getFailureLog = DB::table('S002V01TBIFA')
  36. ->where('BIFA_NULI', '=', $line)
  37. ->where('LIFA_NULI', '=', $line)
  38. ->where('LISI_NULI', '=', $line)
  39. ->where('LIME_NULI', '=', $line)
  40. ->where('LIFA_ESTA', '=', 'Activo')
  41. ->where('LISI_ESTA', '=', 'Activo')
  42. ->where('LIME_ESTA', '=', 'Activo')
  43. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  44. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  45. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  46. ->get([
  47. 'BIFA_NUFA AS NUMERO_FALLA',
  48. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  49. 'BIFA_ESFA AS ESTADO_FALLA',
  50. 'LIFA_IDFA AS ID_FALLA',
  51. 'LIFA_NOFA AS NOMBRE_FALLA',
  52. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  53. 'LIFA_CAUS AS CAUSA_FALLA',
  54. 'LISI_IDSI AS ID_SINTOMA',
  55. 'LISI_NOSI AS NOMBRE_SINTOMA',
  56. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  57. 'LISI_CAUS AS CAUSA_SINTOMA',
  58. 'BIFA_FEFA AS FECHA_FALLA',
  59. 'BIFA_REPA AS REPARABLE',
  60. 'BIFA_DESO AS SOLUCION',
  61. 'BIFA_COME AS COMENTARIOS',
  62. 'BIFA_VAOB AS VALOR_OBTENIDO',
  63. 'LIME_IDME AS ID_MEDIDA',
  64. 'LIME_NOME AS NOMBRE_MEDIDA',
  65. 'LIME_ACME AS ACRONIMO_MEDIDA',
  66. 'BIFA_ESTA AS ESTADO',
  67. 'BIFA_USRE AS USUARIO_REGISTRA',
  68. 'BIFA_FERE AS FECHA_REGISTRA',
  69. 'BIFA_USMO AS USUARIO_MODIFICA',
  70. 'BIFA_FEMO AS FECHA_MODIFICA',
  71. ]);
  72. } catch (\Throwable $th) {
  73. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  74. }
  75. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  76. $arrEquipmentCode = array_column($arrFailureLog, 'CODIGO_EQUIPAMIENTO');
  77. $arrEquipmentCode = array_unique($arrEquipmentCode);
  78. $count = 0;
  79. $arrEquipmentFailureLog = array();
  80. foreach ($arrEquipmentCode as $keyEquipmentCode => $equipmentCode) {
  81. $lastUpdate = '';
  82. $lastUser = '';
  83. $lastState = '';
  84. $lastClassification = '';
  85. $amountFailures = 0;
  86. foreach ($arrFailureLog as $keyFailureLog => $failureLog) {
  87. if ( $equipmentCode === $failureLog['CODIGO_EQUIPAMIENTO'] ) {
  88. $tempLastUpdate = '';
  89. $tempLastUser = '';
  90. if ( is_null($failureLog['FECHA_MODIFICA']) ) {
  91. $tempLastUpdate = $failureLog['FECHA_REGISTRA'];
  92. $tempLastUser = $failureLog['USUARIO_REGISTRA'];
  93. } else {
  94. $tempLastUpdate = $failureLog['FECHA_MODIFICA'];
  95. $tempLastUser = $failureLog['USUARIO_MODIFICA'];
  96. }
  97. if ($lastUpdate === '') {
  98. $lastUpdate = $tempLastUpdate;
  99. $lastUser = $tempLastUser;
  100. $lastState = $failureLog['ESTADO_FALLA'];
  101. $lastClassification = $failureLog['NIVEL_CRITICIDAD_FALLA'];
  102. } else {
  103. $carTempLastUpdate = Carbon::create($tempLastUpdate);
  104. $carLastState = Carbon::create($lastUpdate);
  105. if ($carTempLastUpdate->greaterThan($carLastState)) {
  106. $lastUpdate = $tempLastUpdate;
  107. $lastUser = $tempLastUser;
  108. $lastState = $failureLog['ESTADO_FALLA'];
  109. $lastClassification = $failureLog['NIVEL_CRITICIDAD_FALLA'];
  110. }
  111. }
  112. $amountFailures ++;
  113. }
  114. }
  115. $arrEquipmentFailureLog[$count]['CODIGO_EQUIPAMIENTO'] = $equipmentCode;
  116. $arrEquipmentFailureLog[$count]['ULTIMA_MODIFICACION'] = $lastUpdate;
  117. $arrEquipmentFailureLog[$count]['ULTIMO_USUARIO'] = $lastUser;
  118. $arrEquipmentFailureLog[$count]['ESTADO_ACTUAL'] = $lastState;
  119. $arrEquipmentFailureLog[$count]['CLASIFICACION_ACTUAL'] = $lastClassification;
  120. $arrEquipmentFailureLog[$count]['CANTIDAD_FALLAS'] = $amountFailures;
  121. $count++;
  122. }
  123. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrEquipmentFailureLog);
  124. }
  125. public function getHistoryFailureEquipment($equipment, $user, $line) {
  126. $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line);
  127. if ($arrResponseCheckUser['error']) {
  128. DB::rollBack();
  129. return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401);
  130. }
  131. try {
  132. $equipment = $this->encController->decrypt($equipment);
  133. } catch (\Throwable $th) {
  134. return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT000", $th->getMessage(), 500);
  135. }
  136. try {
  137. $getFailuresLog = DB::table('S002V01TBIFA')
  138. ->where('BIFA_COEQ', '=', $equipment)
  139. ->where('BIFA_NULI', '=', $line)
  140. ->where('BIFA_ESTA', '=', 'Activo')
  141. ->where('LIFA_ESTA', '=', 'Activo')
  142. ->where('LISI_ESTA', '=', 'Activo')
  143. ->where('LIME_ESTA', '=', 'Activo')
  144. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  145. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  146. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  147. ->get([
  148. 'BIFA_NUFA AS NUMERO_FALLA',
  149. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  150. 'BIFA_ESFA AS ESTADO_FALLA',
  151. 'LIFA_IDFA AS ID_FALLA',
  152. 'LIFA_NOFA AS NOMBRE_FALLA',
  153. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  154. 'LIFA_CAUS AS CAUSA_FALLA',
  155. 'LISI_IDSI AS ID_SINTOMA',
  156. 'LISI_NOSI AS NOMBRE_SINTOMA',
  157. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  158. 'LISI_CAUS AS CAUSA_SINTOMA',
  159. 'BIFA_FEFA AS FECHA_FALLA',
  160. 'BIFA_REPA AS REPARABLE',
  161. 'BIFA_DESO AS SOLUCION',
  162. 'BIFA_COME AS COMENTARIOS',
  163. 'BIFA_VAOB AS VALOR_OBTENIDO',
  164. 'LIME_IDME AS ID_MEDIDA',
  165. 'LIME_NOME AS NOMBRE_MEDIDA',
  166. 'LIME_ACME AS ACRONIMO_MEDIDA',
  167. 'BIFA_USRE AS USUARIO_REGISTRA',
  168. 'BIFA_FERE AS FECHA_REGISTRA',
  169. 'BIFA_USMO AS USUARIO_MODIFICA',
  170. 'BIFA_FEMO AS FECHA_MODIFICA',
  171. ]);
  172. } catch (\Throwable $th) {
  173. return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  174. }
  175. $arrFailureLogTemp = json_decode( json_encode( $getFailuresLog ), true );
  176. $arrFailureLog = array();
  177. foreach ($arrFailureLogTemp as $keyFailureLogTemp => $failureLogTemp) {
  178. $numero_falla = $failureLogTemp['NUMERO_FALLA'];
  179. $nombre_falla = $failureLogTemp['NOMBRE_FALLA'].' ('.$failureLogTemp['ID_FALLA'].')';
  180. $nivel_criticidad_falla = $failureLogTemp['NIVEL_CRITICIDAD_FALLA'];
  181. $nombre_sintoma = $failureLogTemp['NOMBRE_SINTOMA'].' ('.$failureLogTemp['ID_SINTOMA'].')';
  182. $estado_falla = $failureLogTemp['ESTADO_FALLA'];
  183. $causa = $failureLogTemp['CAUSA_FALLA'];
  184. $fecha_fala = $failureLogTemp['FECHA_FALLA'];
  185. $reparable = $failureLogTemp['REPARABLE'] === 1 ? 'Si' : 'No';
  186. $arrFailureLog[] = [
  187. 'NUMERO_FALLA' => $numero_falla,
  188. 'NOMBRE_FALLA' => $nombre_falla,
  189. 'NIVEL_CRITICIDAD_FALLA' => $nivel_criticidad_falla,
  190. 'ESTADO_FALLA' => $estado_falla,
  191. 'CAUSA' => $causa,
  192. 'FECHA_FALLA' => $fecha_fala,
  193. 'REPARABLE' => $reparable,
  194. 'USUARIO_REGISTRA' => $failureLogTemp['USUARIO_REGISTRA'],
  195. 'FECHA_REGISTRA' => $failureLogTemp['FECHA_REGISTRA'],
  196. 'USUARIO_MODIFICA' =>$failureLogTemp['USUARIO_MODIFICA'],
  197. 'FECHA_MODIFICA' => $failureLogTemp['FECHA_MODIFICA'],
  198. ];
  199. }
  200. $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrFailureLog, $line);
  201. if ($responseCheckLatestUpdate['error']) {
  202. return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500);
  203. }
  204. $arrFailureLog = $responseCheckLatestUpdate['response'];
  205. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
  206. }
  207. public function getDetailsHistoryFailureEquipment($failure, $user, $line) {
  208. try {
  209. $failure = $this->encController->decrypt($failure);
  210. } catch (\Throwable $th) {
  211. return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT000", $th->getMessage(), 500);
  212. }
  213. try {
  214. $getFailureLog = DB::table('S002V01TBIFA')
  215. ->where('BIFA_NUFA', '=', $failure)
  216. ->where('BIFA_NULI', '=', $line)
  217. ->where('LIFA_NULI', '=', $line)
  218. ->where('LISI_NULI', '=', $line)
  219. ->where('LIME_NULI', '=', $line)
  220. ->where('BIFA_ESTA', '=', 'Activo')
  221. ->where('LIFA_ESTA', '=', 'Activo')
  222. ->where('LISI_ESTA', '=', 'Activo')
  223. ->where('LIME_ESTA', '=', 'Activo')
  224. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  225. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  226. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  227. ->first([
  228. 'BIFA_NUFA AS NUMERO_FALLA',
  229. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  230. 'BIFA_ESFA AS ESTADO_FALLA',
  231. 'LIFA_IDFA AS ID_FALLA',
  232. 'LIFA_NOFA AS NOMBRE_FALLA',
  233. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  234. 'LIFA_CAUS AS CAUSA_FALLA',
  235. 'LISI_IDSI AS ID_SINTOMA',
  236. 'LISI_NOSI AS NOMBRE_SINTOMA',
  237. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  238. 'LISI_CAUS AS CAUSA_SINTOMA',
  239. 'BIFA_FEFA AS FECHA_FALLA',
  240. 'BIFA_FERF AS FECHA_RESOLUCION',
  241. 'BIFA_REPA AS REPARABLE',
  242. 'BIFA_DESO AS SOLUCION',
  243. 'BIFA_COME AS COMENTARIOS',
  244. 'BIFA_VAOB AS VALOR_OBTENIDO',
  245. 'LIME_IDME AS ID_MEDIDA',
  246. 'LIME_NOME AS NOMBRE_MEDIDA',
  247. 'LIME_ACME AS ACRONIMO_MEDIDA',
  248. ]);
  249. } catch (\Throwable $th) {
  250. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GETACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  251. }
  252. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  253. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
  254. }
  255. public function getFailureLogActives($user, $line) {
  256. try {
  257. $getFailureLog = DB::table('S002V01TBIFA')
  258. ->where('BIFA_NULI', '=', $line)
  259. ->where('LIFA_NULI', '=', $line)
  260. ->where('LISI_NULI', '=', $line)
  261. ->where('LIME_NULI', '=', $line)
  262. ->where('BIFA_ESTA', '=', 'Activo')
  263. ->where('LIFA_ESTA', '=', 'Activo')
  264. ->where('LISI_ESTA', '=', 'Activo')
  265. ->where('LIME_ESTA', '=', 'Activo')
  266. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  267. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  268. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  269. ->get([
  270. 'BIFA_NUFA AS NUMERO_FALLA',
  271. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  272. 'LIFA_IDFA AS ID_FALLA',
  273. 'LIFA_NOFA AS NOMBRE_FALLA',
  274. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  275. 'LIFA_CAUS AS CAUSA_FALLA',
  276. 'LISI_IDSI AS ID_SINTOMA',
  277. 'LISI_NOSI AS NOMBRE_SINTOMA',
  278. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  279. 'LISI_CAUS AS CAUSA_SINTOMA',
  280. 'BIFA_FEFA AS FECHA_FALLA',
  281. 'BIFA_REPA AS REPARABLE',
  282. 'BIFA_DESO AS SOLUCION',
  283. 'BIFA_COME AS COMENTARIOS',
  284. 'BIFA_VAOB AS VALOR_OBTENIDO',
  285. 'LIME_IDME AS ID_MEDIDA',
  286. 'LIME_NOME AS NOMBRE_MEDIDA',
  287. 'LIME_ACME AS ACRONIMO_MEDIDA',
  288. 'BIFA_USRE AS USUARIO_REGISTRA',
  289. 'BIFA_FERE AS FECHA_REGISTRA',
  290. 'BIFA_USMO AS USUARIO_MODIFICA',
  291. 'BIFA_FEMO AS FECHA_MODIFICA',
  292. ]);
  293. } catch (\Throwable $th) {
  294. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GETACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  295. }
  296. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  297. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
  298. }
  299. public function getEquipmentByFailure($failure, $user, $line) {
  300. try {
  301. $failure = $this->encController->decrypt($failure);
  302. } catch (\Throwable $th) {
  303. DB::rollBack();
  304. return $this->responseController->makeResponse(true, "ERR_FAILURES_EQUIPMENT000: No se pudo obtener el usuario.", $th->getMessage(), 500);
  305. }
  306. try {
  307. $getEquipmentByFailure = DB::table('S002V01TBIFA')
  308. ->where('BIFA_IDFA', '=', $failure)
  309. ->where('BIFA_NULI', '=', $line)
  310. ->where('BIFA_ESTA', '=', 'Activo')
  311. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  312. ->get([
  313. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  314. 'BIFA_ESFA AS ESTADO_FALLA',
  315. 'BIFA_FEFA AS FECHA_FALLA',
  316. 'BIFA_FERF AS FECHA_REPARACION',
  317. 'BIFA_VAOB AS VALOR_OBTENIDO',
  318. 'LIME_IDME AS ID_MEDIDA',
  319. 'LIME_NOME AS NOMBRE_MEDIDA',
  320. 'LIME_ACME AS ACRONIMO_MEDIDA',
  321. ]);
  322. } catch (\Throwable $th) {
  323. return $this->responseController->makeResponse(
  324. true,
  325. "ERR_FAILURES_EQUIPMENT001: No se pudo realizar la consulta a la base.",
  326. $th->getMessage(),
  327. 500
  328. );
  329. }
  330. $arrFaultyEquipment = json_decode(json_encode($getEquipmentByFailure), true);
  331. $arrEquipmentCode = array_column($arrFaultyEquipment, 'CODIGO_EQUIPAMIENTO');
  332. $arrEquipmentCode = array_unique($arrEquipmentCode);
  333. $count = 0;
  334. $arrEquipmentFailureLog = array();
  335. foreach ($arrEquipmentCode as $keyEquipmentCode => $equipmentCode) {
  336. foreach ($arrFaultyEquipment as $keyFaultyEquipment => $faultyEquipment) {
  337. if ( $equipmentCode === $faultyEquipment['CODIGO_EQUIPAMIENTO'] ) {
  338. $arrEquipmentFailureLog[$count]['CODIGO_EQUIPAMIENTO'] = $faultyEquipment['CODIGO_EQUIPAMIENTO'];
  339. $arrEquipmentFailureLog[$count]['DETALLES'][] = [
  340. 'ESTADO_FALLA' => $faultyEquipment['ESTADO_FALLA'],
  341. 'FECHA_FALLA' => $faultyEquipment['FECHA_FALLA'],
  342. 'FECHA_REPARACION' => $faultyEquipment['FECHA_REPARACION'],
  343. 'VALOR_OBTENIDO' => $faultyEquipment['VALOR_OBTENIDO'],
  344. 'ID_MEDIDA' => $faultyEquipment['ID_MEDIDA'],
  345. 'NOMBRE_MEDIDA' => $faultyEquipment['NOMBRE_MEDIDA'],
  346. 'ACRONIMO_MEDIDA' => $faultyEquipment['ACRONIMO_MEDIDA'],
  347. ];
  348. }
  349. }
  350. $count++;
  351. }
  352. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrEquipmentFailureLog);
  353. }
  354. public function getAlarmEmissionFromFailures($user, $line) {
  355. try {
  356. $getAlarmEmission = DB::table('S002V01TBIFA')
  357. ->where('BIFA_NULI', '=', $line)
  358. ->where('BIFA_ESTA', '=', 'Activo')
  359. ->where('ACTI_NULI', '=', $line)
  360. ->join('S002V01TACTI', 'ACTI_IDAC', '=', 'BIFA_IDAC')
  361. ->get([
  362. 'BIFA_NUFA AS NUMERO_FALLA',
  363. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  364. 'ACTI_IDAC AS ID_ACTIVADOR',
  365. 'BIFA_FEFA AS FECHA_FALLA',
  366. 'ACTI_PRIO AS PRIORIDAD',
  367. 'ACTI_TIAC AS TIPO_ACTIVADOR',
  368. 'ACTI_COAC AS CONDICION_ACTIVADOR',
  369. ]);
  370. } catch (\Throwable $th) {
  371. DB::rollBack();
  372. return $this->responseController->makeResponse(true, "ERR_FAILURES_ALARM000: No se pudo obtener la información de la base de datos.", $th->getMessage(), 500);
  373. }
  374. $arrAlarmEmission = json_decode(json_encode($getAlarmEmission), true);
  375. foreach ($arrAlarmEmission as $key => $alarmEmission) {
  376. switch ($alarmEmission['PRIORIDAD']) {
  377. case 1:
  378. $alarmEmission['PRIORIDAD'] = 'Muy alta';
  379. break;
  380. case 2:
  381. $alarmEmission['PRIORIDAD'] = 'Alta';
  382. break;
  383. case 3:
  384. $alarmEmission['PRIORIDAD'] = 'Media';
  385. break;
  386. case 4:
  387. $alarmEmission['PRIORIDAD'] = 'Baja';
  388. break;
  389. }
  390. $arrAlarmEmission[$key] = $alarmEmission;
  391. }
  392. return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrAlarmEmission);
  393. }
  394. public function generateSheetFailureXLS($failure, $user, $line) {
  395. try {
  396. $failure = $this->encController->decrypt($failure);
  397. } catch (\Throwable $th) {
  398. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS000", $th->getMessage(), 500);
  399. }
  400. try {
  401. $user = $this->encController->decrypt($user);
  402. } catch (\Throwable $th) {
  403. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS001", $th->getMessage(), 500);
  404. }
  405. try {
  406. $getFailureLog = DB::table('S002V01TBIFA')
  407. ->where('BIFA_NUFA', '=', $failure)
  408. ->where('BIFA_NULI', '=', $line)
  409. ->where('LIFA_NULI', '=', $line)
  410. ->where('LISI_NULI', '=', $line)
  411. ->where('LIME_NULI', '=', $line)
  412. ->where('BIFA_ESTA', '=', 'Activo')
  413. ->where('LIFA_ESTA', '=', 'Activo')
  414. ->where('LISI_ESTA', '=', 'Activo')
  415. ->where('LIME_ESTA', '=', 'Activo')
  416. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  417. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  418. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  419. ->first([
  420. 'BIFA_NUFA AS NUMERO_FALLA',
  421. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  422. 'BIFA_ESFA AS ESTADO_FALLA',
  423. 'LIFA_IDFA AS ID_FALLA',
  424. 'LIFA_NOFA AS NOMBRE_FALLA',
  425. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  426. 'LIFA_CAUS AS CAUSA_FALLA',
  427. 'LISI_IDSI AS ID_SINTOMA',
  428. 'LISI_NOSI AS NOMBRE_SINTOMA',
  429. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  430. 'LISI_CAUS AS CAUSA_SINTOMA',
  431. 'BIFA_FEFA AS FECHA_FALLA',
  432. 'BIFA_FERF AS FECHA_RESOLUCION',
  433. 'BIFA_REPA AS REPARABLE',
  434. 'BIFA_DESO AS SOLUCION',
  435. 'BIFA_COME AS COMENTARIOS',
  436. 'BIFA_VAOB AS VALOR_OBTENIDO',
  437. 'LIME_IDME AS ID_MEDIDA',
  438. 'LIME_NOME AS NOMBRE_MEDIDA',
  439. 'LIME_ACME AS ACRONIMO_MEDIDA',
  440. ]);
  441. } catch (\Throwable $th) {
  442. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  443. }
  444. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  445. $spreadsheet = new Spreadsheet();
  446. $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrFailureLog['NUMERO_FALLA']);
  447. $activeWorksheet->setCellValue("A1", 'Número de Falla');
  448. $activeWorksheet->setCellValue("B1", $arrFailureLog['NUMERO_FALLA']);
  449. $activeWorksheet->getStyle( "A1" )->getFont()->setBold(true);
  450. $activeWorksheet->setCellValue("A2", 'Número de Equipamiento');
  451. $activeWorksheet->setCellValue("B2", $arrFailureLog['CODIGO_EQUIPAMIENTO']);
  452. $activeWorksheet->getStyle( "A2" )->getFont()->setBold(true);
  453. $activeWorksheet->setCellValue("A3", 'Estado de la Falla');
  454. $activeWorksheet->setCellValue("B3", $arrFailureLog['ESTADO_FALLA']);
  455. $activeWorksheet->getStyle( "A3" )->getFont()->setBold(true);
  456. $activeWorksheet->setCellValue("A4", 'Nombre de la Falla');
  457. $activeWorksheet->setCellValue("B4", $arrFailureLog['NOMBRE_FALLA'].' ('.$arrFailureLog['ID_FALLA'].')');
  458. $activeWorksheet->getStyle( "A4" )->getFont()->setBold(true);
  459. $activeWorksheet->setCellValue("A5", 'Nivel de Criticidad de la Falla');
  460. $activeWorksheet->setCellValue("B5", $arrFailureLog['NIVEL_CRITICIDAD_FALLA']);
  461. $activeWorksheet->getStyle( "A5" )->getFont()->setBold(true);
  462. $activeWorksheet->setCellValue("A6", 'Causa de la Falla');
  463. $activeWorksheet->setCellValue("B6", $arrFailureLog['CAUSA_FALLA']);
  464. $activeWorksheet->getStyle( "A6" )->getFont()->setBold(true);
  465. $activeWorksheet->setCellValue("A7", 'Nombre del Síntoma');
  466. $activeWorksheet->setCellValue("B7", $arrFailureLog['NOMBRE_SINTOMA'].' ('.$arrFailureLog['ID_SINTOMA'].')');
  467. $activeWorksheet->getStyle( "A7" )->getFont()->setBold(true);
  468. $activeWorksheet->setCellValue("A8", 'Clasificación del Síntoma');
  469. $activeWorksheet->setCellValue("B8", $arrFailureLog['CLASIFICACION_SINTOMA']);
  470. $activeWorksheet->getStyle( "A8" )->getFont()->setBold(true);
  471. $activeWorksheet->setCellValue("A9", 'Causa del Síntoma');
  472. $activeWorksheet->setCellValue("B9", $arrFailureLog['CAUSA_SINTOMA']);
  473. $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
  474. $activeWorksheet->setCellValue("A10", 'Fecha de la Falla');
  475. $activeWorksheet->setCellValue("B10", $arrFailureLog['FECHA_FALLA']);
  476. $activeWorksheet->getStyle( "A10" )->getFont()->setBold(true);
  477. $activeWorksheet->setCellValue("A11", 'Fecha de la Resolución');
  478. $activeWorksheet->setCellValue("B11", $arrFailureLog['FECHA_RESOLUCION']);
  479. $activeWorksheet->getStyle( "A11" )->getFont()->setBold(true);
  480. $activeWorksheet->setCellValue("A12", 'Reparable');
  481. $activeWorksheet->setCellValue("B12", $arrFailureLog['REPARABLE'] === 1 ? 'Si' : 'No');
  482. $activeWorksheet->getStyle( "A12" )->getFont()->setBold(true);
  483. $activeWorksheet->setCellValue("A13", 'Valor Obtenido');
  484. $activeWorksheet->setCellValue("B13", $arrFailureLog['VALOR_OBTENIDO'].' '.$arrFailureLog['ACRONIMO_MEDIDA']);
  485. $activeWorksheet->getStyle( "A13" )->getFont()->setBold(true);
  486. $activeWorksheet->setCellValue("A14", 'Tipo de Medido');
  487. $activeWorksheet->setCellValue("B14", $arrFailureLog['NOMBRE_MEDIDA']);
  488. $activeWorksheet->getStyle( "A14" )->getFont()->setBold(true);
  489. $activeWorksheet->setCellValue("A15", 'Solución de la Falla');
  490. $activeWorksheet->setCellValue("B15", $arrFailureLog['SOLUCION'] === null || $arrFailureLog['SOLUCION'] === '' ? '' : $arrFailureLog['SOLUCION']);
  491. $activeWorksheet->getStyle( "A15" )->getFont()->setBold(true);
  492. $activeWorksheet->setCellValue("A16", 'Comentarios');
  493. $activeWorksheet->setCellValue("B16", $arrFailureLog['COMENTARIOS']);
  494. $activeWorksheet->getStyle( "A16" )->getFont()->setBold(true);
  495. $activeWorksheet->getColumnDimension("A")->setAutoSize(true);
  496. $activeWorksheet->getColumnDimension("B")->setAutoSize(true);
  497. $nuli = $this->resourcesController->formatSecuence($line, 2);
  498. $como = 'ANFA'; // Código del módulo
  499. $cldo = 'IN'; // Código de la clasificación
  500. $fecr = date('ymd'); // Fecha en la se carga el archivo
  501. try {
  502. $arrSecuence = (array) DB::table('S002V01TAFAL')
  503. ->where('AFAL_COMO', '=', $como)
  504. ->where('AFAL_CLDO', '=', $cldo)
  505. ->where('AFAL_NULI', '=', $line)
  506. ->orderBy('AFAL_NUSE', 'desc')
  507. ->first([ 'AFAL_NUSE' ]);
  508. } catch (\Throwable $th) {
  509. return $this->responseController->makeResponse(
  510. true,
  511. "ERR_FAILURELOG_GENERATEXLS003: Ocurrió un error al obtener la información de la secuencia.",
  512. $th->getMessage(),
  513. 500
  514. );
  515. }
  516. $nuse = 1; // Secuencia del documento
  517. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  518. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  519. }
  520. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  521. $nuve = $this->resourcesController->formatSecuence('1', 2);
  522. $noar = 'ficha_de_falla_'.$arrFailureLog['NUMERO_FALLA'];
  523. $exte = 'xlsx';
  524. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  525. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  526. } else {
  527. $filePath = 'C:\inetpub\wwwroot\sam\public_files\\'; // API QA
  528. }
  529. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  530. $tempFile = $filePath.$fileName;
  531. if ( file_exists( $tempFile ) ) {
  532. if ( !unlink( $tempFile ) ) {
  533. return $this->responseController->makeResponse(
  534. true,
  535. "ERR_FAILURELOG_GENERATEXLS004: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
  536. [],
  537. 500
  538. );
  539. }
  540. }
  541. try {
  542. $writer = new Xlsx($spreadsheet);
  543. ob_start();
  544. $writer->save('php://output');
  545. $base64 = base64_encode(ob_get_clean());
  546. $validate = \File::put( $tempFile, base64_decode($base64));
  547. } catch (\Throwable $th) {
  548. return $this->responseController->makeResponse(
  549. true,
  550. "ERR_FAILURELOG_GENERATEXLS005: Ocurrió un error al guardar el documento.",
  551. $th->getMessage(),
  552. 500
  553. );
  554. }
  555. $ubic = Storage::putFile('files', new File($tempFile));
  556. $ubic = str_replace("/", "\\", $ubic);
  557. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  558. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  559. } else {
  560. $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
  561. }
  562. $tama = filesize($ubic);
  563. $usac = json_encode([$user]);
  564. $now = $this->functionsController->now();
  565. $currentDate = $now->toDateTimeString();
  566. try {
  567. $validateInsert = DB::table('S002V01TAFAL')->insert([
  568. 'AFAL_NULI' => $line,
  569. 'AFAL_COMO' => $como,
  570. 'AFAL_CLDO' => $cldo,
  571. 'AFAL_FECR' => $fecr,
  572. 'AFAL_NUSE' => $nuse,
  573. 'AFAL_NUVE' => $nuve,
  574. 'AFAL_NOAR' => $noar,
  575. 'AFAL_EXTE' => $exte,
  576. 'AFAL_TAMA' => $tama,
  577. 'AFAL_UBIC' => $ubic,
  578. 'AFAL_USAC' => $usac,
  579. 'AFAL_USRE' => $user,
  580. 'AFAL_FERE' => $currentDate,
  581. ]);
  582. } catch (\Throwable $th) {
  583. return $this->responseController->makeResponse(
  584. true,
  585. "ERR_FAILURELOG_GENERATEXLS006: Ocurrió un error guardar los datos a la tabla final de archivos.",
  586. $th->getMessage(),
  587. 500
  588. );
  589. }
  590. if ( !$validateInsert ) {
  591. return $this->responseController->makeResponse(
  592. true,
  593. "ERR_FAILURELOG_GENERATEXLS007: No se pudo guardar la ficha del proveedor en la base de datos.",
  594. [],
  595. 500
  596. );
  597. }
  598. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  599. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  600. } else {
  601. $urlPublic = $this->functionsController->getApiURI().'sam/public_files/' . $fileName;
  602. }
  603. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  604. return $arrFailureLog;
  605. }
  606. public function generateSheetFailurePDF($failure, $user, $line){
  607. try {
  608. $failure = $this->encController->decrypt($failure);
  609. } catch (\Throwable $th) {
  610. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF000: Ocurrió un error al obtener la falla.", $th->getMessage(), 500);
  611. }
  612. try {
  613. $user = $this->encController->decrypt($user);
  614. } catch (\Throwable $th) {
  615. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  616. }
  617. try {
  618. $getFailureLog = DB::table('S002V01TBIFA')
  619. ->where('BIFA_NUFA', '=', $failure)
  620. ->where('BIFA_NULI', '=', $line)
  621. ->where('LIFA_NULI', '=', $line)
  622. ->where('LISI_NULI', '=', $line)
  623. ->where('LIME_NULI', '=', $line)
  624. ->where('BIFA_ESTA', '=', 'Activo')
  625. ->where('LIFA_ESTA', '=', 'Activo')
  626. ->where('LISI_ESTA', '=', 'Activo')
  627. ->where('LIME_ESTA', '=', 'Activo')
  628. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  629. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  630. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  631. ->first([
  632. 'BIFA_NUFA AS NUMERO_FALLA',
  633. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  634. 'BIFA_ESFA AS ESTADO_FALLA',
  635. 'LIFA_IDFA AS ID_FALLA',
  636. 'LIFA_NOFA AS NOMBRE_FALLA',
  637. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  638. 'LIFA_CAUS AS CAUSA_FALLA',
  639. 'LISI_IDSI AS ID_SINTOMA',
  640. 'LISI_NOSI AS NOMBRE_SINTOMA',
  641. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  642. 'LISI_CAUS AS CAUSA_SINTOMA',
  643. 'BIFA_FEFA AS FECHA_FALLA',
  644. 'BIFA_FERF AS FECHA_RESOLUCION',
  645. 'BIFA_REPA AS REPARABLE',
  646. 'BIFA_DESO AS SOLUCION',
  647. 'BIFA_COME AS COMENTARIOS',
  648. 'BIFA_VAOB AS VALOR_OBTENIDO',
  649. 'LIME_IDME AS ID_MEDIDA',
  650. 'LIME_NOME AS NOMBRE_MEDIDA',
  651. 'LIME_ACME AS ACRONIMO_MEDIDA',
  652. ]);
  653. } catch (\Throwable $th) {
  654. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  655. }
  656. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  657. // return $arrFailureLog;
  658. $html = '<!DOCTYPE html>
  659. <html lang="en">
  660. <head>
  661. <meta charset="UTF-8">
  662. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  663. <title>Document</title>
  664. <style>
  665. body {
  666. font-family: Arial, Helvetica, sans-serif;
  667. font-size: 8pt;
  668. }
  669. .section-title {
  670. margin: 20px 0;
  671. font-size: 12pt;
  672. }
  673. table {
  674. width: 100%;
  675. }
  676. thead tr th {
  677. text-align: start;
  678. padding: 0 16px;
  679. height: 52px;
  680. border-bottom-width: 1px;
  681. border-bottom-style: solid;
  682. border-bottom-color: #CCC;
  683. }
  684. tbody tr td {
  685. padding: 0 16px;
  686. height: 52px;
  687. border-bottom-width: 1px;
  688. border-bottom-style: solid;
  689. border-bottom-color: #CCC;
  690. }
  691. p {
  692. text-align: justify;
  693. }
  694. </style>
  695. </head>
  696. <body>
  697. <div class="item">
  698. <b>Número de Falla: </b>
  699. <span>'.$arrFailureLog['NUMERO_FALLA'].'</span>
  700. </div>
  701. <div class="item">
  702. <b>Número de Equipamiento: </b>
  703. <span>'.$arrFailureLog['CODIGO_EQUIPAMIENTO'].'</span>
  704. </div>
  705. <div class="item">
  706. <b>Estado de la Falla: </b>
  707. <span>'.$arrFailureLog['ESTADO_FALLA'].'</span>
  708. </div>
  709. <div class="item">
  710. <b>Nombre de la Falla: </b>
  711. <span>'.$arrFailureLog['NOMBRE_FALLA'].' ('.$arrFailureLog['ID_FALLA'].')'.'</span>
  712. </div>
  713. <div class="item">
  714. <b>Nivel de Criticidad de la Falla: </b>
  715. <span>'.$arrFailureLog['NIVEL_CRITICIDAD_FALLA'].'</span>
  716. </div>
  717. <div class="item">
  718. <b>Causa de la Falla: </b>
  719. <span>'.$arrFailureLog['CAUSA_FALLA'].'</span>
  720. </div>
  721. <div class="item">
  722. <b>Nombre del Síntoma: </b>
  723. <span>'.$arrFailureLog['NOMBRE_SINTOMA'].' ('.$arrFailureLog['ID_SINTOMA'].')'.'</span>
  724. </div>
  725. <div class="item">
  726. <b>Clasificación del Síntoma: </b>
  727. <span>'.$arrFailureLog['CLASIFICACION_SINTOMA'].'</span>
  728. </div>
  729. <div class="item">
  730. <b>Causa del Síntoma: </b>
  731. <span>'.$arrFailureLog['CAUSA_SINTOMA'].'</span>
  732. </div>
  733. <div class="item">
  734. <b>Fecha de la Falla: </b>
  735. <span>'.$arrFailureLog['FECHA_FALLA'].'</span>
  736. </div>
  737. <div class="item">
  738. <b>Fecha de la Resolución: </b>
  739. <span>'.$arrFailureLog['FECHA_RESOLUCION'].'</span>
  740. </div>
  741. <div class="item">
  742. <b>Reparable: </b>
  743. <span>'.(($arrFailureLog['REPARABLE'] === 1) ? ('Si') : ('No')).'</span>
  744. </div>
  745. <div class="item">
  746. <b>Valor Obtenido: </b>
  747. <span>'.$arrFailureLog['VALOR_OBTENIDO'].' '.$arrFailureLog['ACRONIMO_MEDIDA'].'</span>
  748. </div>
  749. <div class="item">
  750. <b>Tipo de Medido: </b>
  751. <span>'.$arrFailureLog['NOMBRE_MEDIDA'].'</span>
  752. </div>
  753. <div class="item">
  754. <b>Solución de la Falla: </b>
  755. <span>'.(($arrFailureLog['SOLUCION'] === null || $arrFailureLog['SOLUCION'] === '') ? ('') : ($arrFailureLog['SOLUCION'])).'</span>
  756. </div>
  757. <div class="item">
  758. <b>Comentarios: </b>
  759. <span>'.$arrFailureLog['COMENTARIOS'].'</span>
  760. </div>';
  761. $html .= '</body></html>';
  762. $nuli = $this->resourcesController->formatSecuence($line, 2);
  763. $como = 'ANFA'; // Código del módulo
  764. $cldo = 'IN'; // Código de la clasificación
  765. $fecr = date('ymd'); // Fecha en la se carga el archivo
  766. try {
  767. $arrSecuence = (array) DB::table('S002V01TAFAL')
  768. ->where('AFAL_COMO', '=', $como)
  769. ->where('AFAL_CLDO', '=', $cldo)
  770. ->where('AFAL_NULI', '=', $line)
  771. ->orderBy('AFAL_NUSE', 'desc')
  772. ->first([ 'AFAL_NUSE' ]);
  773. } catch (\Throwable $th) {
  774. return $this->responseController->makeResponse(
  775. true,
  776. "ERR_FAILURELOG_GENERATEPDF003: Ocurrió un error al obtener la información de la secuencia.",
  777. $th->getMessage(),
  778. 500
  779. );
  780. }
  781. $nuse = 1; // Secuencia del documento
  782. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  783. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  784. }
  785. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  786. $nuve = $this->resourcesController->formatSecuence('1', 2);
  787. $noar = 'ficha_de_proveedor_' . $arrFailureLog['NUMERO_FALLA'];
  788. $nuli = $this->resourcesController->formatSecuence($line, 2);
  789. $como = 'GEAD'; // Código del módulo
  790. $cldo = 'IN'; // Código de la clasificación
  791. $fecr = date('ymd'); // Fecha en la se carga el archivo
  792. try {
  793. $arrSecuence = (array) DB::table('S002V01TAFAL')
  794. ->where('AFAL_COMO', '=', $como)
  795. ->where('AFAL_CLDO', '=', $cldo)
  796. ->where('AFAL_NULI', '=', $line)
  797. ->orderBy('AFAL_NUSE', 'desc')
  798. ->first([ 'AFAL_NUSE' ]);
  799. } catch (\Throwable $th) {
  800. return $this->responseController->makeResponse(
  801. true,
  802. "ERR_FAILURELOG_GENERATEPDF004: Ocurrió un error al obtener la información de la secuencia.",
  803. $th->getMessage(),
  804. 500
  805. );
  806. }
  807. $nuse = 1; // Secuencia del documento
  808. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  809. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  810. }
  811. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  812. $nuve = $this->resourcesController->formatSecuence('1', 2);
  813. $noar = 'ficha_de_falla_' . $arrFailureLog['NUMERO_FALLA'];
  814. $exte = 'pdf';
  815. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  816. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  817. } else {
  818. $filePath = 'C:\inetpub\wwwroot\sam\public_files\\'; // API QA
  819. }
  820. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  821. $tempFile = $filePath . $fileName;
  822. $dompdf = new Dompdf();
  823. $dompdf ->loadHtml($html);
  824. $dompdf->setPaper('A4', 'portrait');
  825. $dompdf->render();
  826. $output = $dompdf->output();
  827. file_put_contents($tempFile, $output);
  828. $ubic = Storage::putFile('files', new File($tempFile));
  829. $ubic = str_replace("/", "\\", $ubic);
  830. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  831. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  832. } else {
  833. $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
  834. }
  835. $tama = filesize($ubic);
  836. $usac = json_encode([$user]);
  837. $now = $this->functionsController->now();
  838. $currentDate = $now->toDateTimeString();
  839. try {
  840. $validateInsert = DB::table('S002V01TAFAL')->insert([
  841. 'AFAL_NULI' => $line,
  842. 'AFAL_COMO' => $como,
  843. 'AFAL_CLDO' => $cldo,
  844. 'AFAL_FECR' => $fecr,
  845. 'AFAL_NUSE' => $nuse,
  846. 'AFAL_NUVE' => $nuve,
  847. 'AFAL_NOAR' => $noar,
  848. 'AFAL_EXTE' => $exte,
  849. 'AFAL_TAMA' => $tama,
  850. 'AFAL_UBIC' => $ubic,
  851. 'AFAL_USAC' => $usac,
  852. 'AFAL_USRE' => $user,
  853. 'AFAL_FERE' => $currentDate,
  854. ]);
  855. } catch (\Throwable $th) {
  856. return $this->responseController->makeResponse(
  857. true,
  858. "ERR_FAILURELOG_GENERATEPDF005: Ocurrió un error guardar los datos a la tabla final de archivos.",
  859. $th->getMessage(),
  860. 500
  861. );
  862. }
  863. if ( !$validateInsert ) {
  864. return $this->responseController->makeResponse(
  865. true,
  866. "ERR_FAILURELOG_GENERATEPDF006: No se pudo guardar la ficha del proveedor en la base de datos.",
  867. [],
  868. 500
  869. );
  870. }
  871. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  872. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  873. } else {
  874. $urlPublic = $this->functionsController->getApiURI().'sam/public_files/' . $fileName;
  875. }
  876. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  877. }
  878. public function registerFailureLog(Request $request) {
  879. $validator = Validator::make($request->all(), [
  880. 'CODIGO_EQUIPAMIENTO' => 'required|string',
  881. 'ID_FALLA' => 'required|integer',
  882. // 'ID_SINTOMA' => 'required|integer',
  883. 'FECHA_FALLA' => 'required|string',
  884. 'REPARABLE' => 'required|string',
  885. 'SOLUCION' => 'required|string',
  886. 'COMENTARIOS' => 'required|string',
  887. 'VALOR_OBTENIDO' => 'required|string',
  888. 'ID_MEDIDA' => 'required|string',
  889. 'USUARIO' => 'required|string',
  890. 'NUMERO_LINEA' => 'required|string',
  891. ]);
  892. if ($validator->fails()) {
  893. return $this->responseController->makeResponse(
  894. true,
  895. "ERR_FAILURELOG_REG000: Se encontraron uno o más errores.",
  896. $this->responseController->makeErrors($validator->errors()->messages()),
  897. 401
  898. );
  899. }
  900. DB::beginTransaction();
  901. $requestData = $request->all();
  902. try {
  903. $user = $this->encController->decrypt($requestData['USUARIO']);
  904. } catch (\Throwable $th) {
  905. DB::rollBack();
  906. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  907. }
  908. try {
  909. $validateExistsFailureList = DB::table('S002V01TLIFA')
  910. ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  911. ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
  912. ->where('LIFA_ESTA', '=', 'Activo')
  913. ->exists();
  914. } catch (\Throwable $th) {
  915. DB::rollBack();
  916. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG002: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
  917. }
  918. if ( !$validateExistsFailureList ) {
  919. DB::rollBack();
  920. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG003: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
  921. }
  922. if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
  923. try {
  924. $validateExistsSymptomList = DB::table('S002V01TLISI')
  925. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  926. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  927. ->where('LISI_ESTA', '=', 'Activo')
  928. ->exists();
  929. } catch (\Throwable $th) {
  930. DB::rollBack();
  931. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG004: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
  932. }
  933. if ( !$validateExistsSymptomList ) {
  934. DB::rollBack();
  935. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG005: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
  936. }
  937. }
  938. try {
  939. $validateExistsMeasure = DB::table('S002V01TLIME')
  940. ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
  941. ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
  942. ->where('LIME_ESTA', '=', 'Activo')
  943. ->exists();
  944. } catch (\Throwable $th) {
  945. DB::rollBack();
  946. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG006: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
  947. }
  948. if ( !$validateExistsMeasure ) {
  949. DB::rollBack();
  950. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG007: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
  951. }
  952. try {
  953. $validateExistsEquipment = DB::table('S002V01TEQUI')
  954. ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
  955. ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
  956. ->exists();
  957. } catch (\Throwable $th) {
  958. DB::rollBack();
  959. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG008: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
  960. }
  961. if ( !$validateExistsEquipment ) {
  962. DB::rollBack();
  963. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG009: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
  964. }
  965. $now = $this->functionsController->now();
  966. $currentDate = $now->toDateTimeString();
  967. try {
  968. $validateInsert = DB::table('S002V01TBIFA')->insert([
  969. 'BIFA_NULI' => $requestData['NUMERO_LINEA'],
  970. 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
  971. 'BIFA_IDFA' => $requestData['ID_FALLA'],
  972. 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
  973. 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
  974. 'BIFA_REPA' => $requestData['REPARABLE'],
  975. 'BIFA_DESO' => $requestData['SOLUCION'],
  976. 'BIFA_COME' => $requestData['COMENTARIOS'],
  977. 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
  978. 'BIFA_IDME' => $requestData['ID_MEDIDA'],
  979. 'BIFA_USRE' => $user,
  980. 'BIFA_FERE' => $currentDate,
  981. 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  982. ]);
  983. } catch (\Throwable $th) {
  984. DB::rollBack();
  985. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG010: Ocurrió un error al intentar registrar la falla en la base de datos.", $th->getMessage(), 500);
  986. }
  987. if ( !$validateInsert ) {
  988. DB::rollBack();
  989. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG011: No se pudo registrar la falla.", [], 500);
  990. }
  991. DB::commit();
  992. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  993. }
  994. public function updateFailureLog(Request $request) {
  995. $validator = Validator::make($request->all(), [
  996. 'NUMERO_FALLA' => 'required|integer',
  997. 'CODIGO_EQUIPAMIENTO' => 'required|string',
  998. 'ID_FALLA' => 'required|integer',
  999. // 'ID_SINTOMA' => 'required|integer',
  1000. 'FECHA_FALLA' => 'required|string',
  1001. 'REPARABLE' => 'required|string',
  1002. 'SOLUCION' => 'required|string',
  1003. 'COMENTARIOS' => 'required|string',
  1004. 'VALOR_OBTENIDO' => 'required|string',
  1005. 'ID_MEDIDA' => 'required|string',
  1006. 'USUARIO' => 'required|string',
  1007. 'NUMERO_LINEA' => 'required|string',
  1008. ]);
  1009. if ($validator->fails()) {
  1010. return $this->responseController->makeResponse(
  1011. true,
  1012. "ERR_FAILURELOG_UPD000: Se encontraron uno o más errores.",
  1013. $this->responseController->makeErrors($validator->errors()->messages()),
  1014. 401
  1015. );
  1016. }
  1017. DB::beginTransaction();
  1018. $requestData = $request->all();
  1019. try {
  1020. $user = $this->encController->decrypt($requestData['USUARIO']);
  1021. } catch (\Throwable $th) {
  1022. DB::rollBack();
  1023. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  1024. }
  1025. try {
  1026. $validateExistsFailureLog = DB::table('S002V01TBIFA')
  1027. ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1028. ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
  1029. ->where('BIFA_ESTA', '=', 'Activo')
  1030. ->exists();
  1031. } catch (\Throwable $th) {
  1032. DB::rollBack();
  1033. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD002: Ocurrió un error al consultar la bitácora de fallas.", $th->getMessage(), 500);
  1034. }
  1035. if ( !$validateExistsFailureLog ) {
  1036. DB::rollBack();
  1037. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD003: No existe la falla #".$requestData['NUMERO_FALLA']." en la bitácora de fallas.", [], 500);
  1038. }
  1039. try {
  1040. $validateExistsFailureList = DB::table('S002V01TLIFA')
  1041. ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1042. ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
  1043. ->where('LIFA_ESTA', '=', 'Activo')
  1044. ->exists();
  1045. } catch (\Throwable $th) {
  1046. DB::rollBack();
  1047. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD004: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
  1048. }
  1049. if ( !$validateExistsFailureList ) {
  1050. DB::rollBack();
  1051. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD005: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
  1052. }
  1053. if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
  1054. try {
  1055. $validateExistsSymptomList = DB::table('S002V01TLISI')
  1056. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  1057. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  1058. ->where('LISI_ESTA', '=', 'Activo')
  1059. ->exists();
  1060. } catch (\Throwable $th) {
  1061. DB::rollBack();
  1062. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD006: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
  1063. }
  1064. if ( !$validateExistsSymptomList ) {
  1065. DB::rollBack();
  1066. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD007: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
  1067. }
  1068. }
  1069. try {
  1070. $validateExistsMeasure = DB::table('S002V01TLIME')
  1071. ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
  1072. ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
  1073. ->where('LIME_ESTA', '=', 'Activo')
  1074. ->exists();
  1075. } catch (\Throwable $th) {
  1076. DB::rollBack();
  1077. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD008: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
  1078. }
  1079. if ( !$validateExistsMeasure ) {
  1080. DB::rollBack();
  1081. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD009: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
  1082. }
  1083. try {
  1084. $validateExistsEquipment = DB::table('S002V01TEQUI')
  1085. ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
  1086. ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
  1087. ->exists();
  1088. } catch (\Throwable $th) {
  1089. DB::rollBack();
  1090. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD010: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
  1091. }
  1092. if ( !$validateExistsEquipment ) {
  1093. DB::rollBack();
  1094. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD011: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
  1095. }
  1096. $now = $this->functionsController->now();
  1097. $currentDate = $now->toDateTimeString();
  1098. try {
  1099. $validateUpdate = DB::table('S002V01TBIFA')
  1100. ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
  1101. ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1102. ->update([
  1103. 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
  1104. 'BIFA_IDFA' => $requestData['ID_FALLA'],
  1105. 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
  1106. 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
  1107. 'BIFA_REPA' => $requestData['REPARABLE'],
  1108. 'BIFA_DESO' => $requestData['SOLUCION'],
  1109. 'BIFA_COME' => $requestData['COMENTARIOS'],
  1110. 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
  1111. 'BIFA_IDME' => $requestData['ID_MEDIDA'],
  1112. 'BIFA_USMO' => $user,
  1113. 'BIFA_FEMO' => $currentDate,
  1114. 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1115. ]);
  1116. } catch (\Throwable $th) {
  1117. DB::rollBack();
  1118. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD012: Ocurrió un error al intentar modificar la falla en la base de datos.", $th->getMessage(), 500);
  1119. }
  1120. if ( !$validateUpdate ) {
  1121. DB::rollBack();
  1122. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD013: No se pudo modificar la bitácora de falla.", [], 500);
  1123. }
  1124. DB::commit();
  1125. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1126. }
  1127. }