FailureLogController.php 55 KB

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