FailureLogController.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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 = 'C:\inetpub\wwwroot\sam\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. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  548. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  549. } else {
  550. $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
  551. }
  552. $tama = filesize($ubic);
  553. $usac = json_encode([$user]);
  554. $now = $this->functionsController->now();
  555. $currentDate = $now->toDateTimeString();
  556. try {
  557. $validateInsert = DB::table('S002V01TAFAL')->insert([
  558. 'AFAL_NULI' => $line,
  559. 'AFAL_COMO' => $como,
  560. 'AFAL_CLDO' => $cldo,
  561. 'AFAL_FECR' => $fecr,
  562. 'AFAL_NUSE' => $nuse,
  563. 'AFAL_NUVE' => $nuve,
  564. 'AFAL_NOAR' => $noar,
  565. 'AFAL_EXTE' => $exte,
  566. 'AFAL_TAMA' => $tama,
  567. 'AFAL_UBIC' => $ubic,
  568. 'AFAL_USAC' => $usac,
  569. 'AFAL_USRE' => $user,
  570. 'AFAL_FERE' => $currentDate,
  571. ]);
  572. } catch (\Throwable $th) {
  573. return $this->responseController->makeResponse(
  574. true,
  575. "ERR_FAILURELOG_GENERATEXLS006: Ocurrió un error guardar los datos a la tabla final de archivos.",
  576. $th->getMessage(),
  577. 500
  578. );
  579. }
  580. if ( !$validateInsert ) {
  581. return $this->responseController->makeResponse(
  582. true,
  583. "ERR_FAILURELOG_GENERATEXLS007: No se pudo guardar la ficha del proveedor en la base de datos.",
  584. [],
  585. 500
  586. );
  587. }
  588. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  589. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  590. return $arrFailureLog;
  591. }
  592. public function generateSheetFailurePDF($failure, $user, $line){
  593. try {
  594. $failure = $this->encController->decrypt($failure);
  595. } catch (\Throwable $th) {
  596. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF000: Ocurrió un error al obtener la falla.", $th->getMessage(), 500);
  597. }
  598. try {
  599. $user = $this->encController->decrypt($user);
  600. } catch (\Throwable $th) {
  601. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
  602. }
  603. try {
  604. $getFailureLog = DB::table('S002V01TBIFA')
  605. ->where('BIFA_NUFA', '=', $failure)
  606. ->where('BIFA_NULI', '=', $line)
  607. ->where('LIFA_NULI', '=', $line)
  608. ->where('LISI_NULI', '=', $line)
  609. ->where('LIME_NULI', '=', $line)
  610. ->where('BIFA_ESTA', '=', 'Activo')
  611. ->where('LIFA_ESTA', '=', 'Activo')
  612. ->where('LISI_ESTA', '=', 'Activo')
  613. ->where('LIME_ESTA', '=', 'Activo')
  614. ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
  615. ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
  616. ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
  617. ->first([
  618. 'BIFA_NUFA AS NUMERO_FALLA',
  619. 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
  620. 'BIFA_ESFA AS ESTADO_FALLA',
  621. 'LIFA_IDFA AS ID_FALLA',
  622. 'LIFA_NOFA AS NOMBRE_FALLA',
  623. 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
  624. 'LIFA_CAUS AS CAUSA_FALLA',
  625. 'LISI_IDSI AS ID_SINTOMA',
  626. 'LISI_NOSI AS NOMBRE_SINTOMA',
  627. 'LISI_CLAS AS CLASIFICACION_SINTOMA',
  628. 'LISI_CAUS AS CAUSA_SINTOMA',
  629. 'BIFA_FEFA AS FECHA_FALLA',
  630. 'BIFA_FERF AS FECHA_RESOLUCION',
  631. 'BIFA_REPA AS REPARABLE',
  632. 'BIFA_DESO AS SOLUCION',
  633. 'BIFA_COME AS COMENTARIOS',
  634. 'BIFA_VAOB AS VALOR_OBTENIDO',
  635. 'LIME_IDME AS ID_MEDIDA',
  636. 'LIME_NOME AS NOMBRE_MEDIDA',
  637. 'LIME_ACME AS ACRONIMO_MEDIDA',
  638. ]);
  639. } catch (\Throwable $th) {
  640. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
  641. }
  642. $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
  643. // return $arrFailureLog;
  644. $html = '<!DOCTYPE html>
  645. <html lang="en">
  646. <head>
  647. <meta charset="UTF-8">
  648. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  649. <title>Document</title>
  650. <style>
  651. body {
  652. font-family: Arial, Helvetica, sans-serif;
  653. font-size: 8pt;
  654. }
  655. .section-title {
  656. margin: 20px 0;
  657. font-size: 12pt;
  658. }
  659. table {
  660. width: 100%;
  661. }
  662. thead tr th {
  663. text-align: start;
  664. padding: 0 16px;
  665. height: 52px;
  666. border-bottom-width: 1px;
  667. border-bottom-style: solid;
  668. border-bottom-color: #CCC;
  669. }
  670. tbody tr td {
  671. padding: 0 16px;
  672. height: 52px;
  673. border-bottom-width: 1px;
  674. border-bottom-style: solid;
  675. border-bottom-color: #CCC;
  676. }
  677. p {
  678. text-align: justify;
  679. }
  680. </style>
  681. </head>
  682. <body>
  683. <div class="item">
  684. <b>Número de Falla: </b>
  685. <span>'.$arrFailureLog['NUMERO_FALLA'].'</span>
  686. </div>
  687. <div class="item">
  688. <b>Número de Equipamiento: </b>
  689. <span>'.$arrFailureLog['CODIGO_EQUIPAMIENTO'].'</span>
  690. </div>
  691. <div class="item">
  692. <b>Estado de la Falla: </b>
  693. <span>'.$arrFailureLog['ESTADO_FALLA'].'</span>
  694. </div>
  695. <div class="item">
  696. <b>Nombre de la Falla: </b>
  697. <span>'.$arrFailureLog['NOMBRE_FALLA'].' ('.$arrFailureLog['ID_FALLA'].')'.'</span>
  698. </div>
  699. <div class="item">
  700. <b>Nivel de Criticidad de la Falla: </b>
  701. <span>'.$arrFailureLog['NIVEL_CRITICIDAD_FALLA'].'</span>
  702. </div>
  703. <div class="item">
  704. <b>Causa de la Falla: </b>
  705. <span>'.$arrFailureLog['CAUSA_FALLA'].'</span>
  706. </div>
  707. <div class="item">
  708. <b>Nombre del Síntoma: </b>
  709. <span>'.$arrFailureLog['NOMBRE_SINTOMA'].' ('.$arrFailureLog['ID_SINTOMA'].')'.'</span>
  710. </div>
  711. <div class="item">
  712. <b>Clasificación del Síntoma: </b>
  713. <span>'.$arrFailureLog['CLASIFICACION_SINTOMA'].'</span>
  714. </div>
  715. <div class="item">
  716. <b>Causa del Síntoma: </b>
  717. <span>'.$arrFailureLog['CAUSA_SINTOMA'].'</span>
  718. </div>
  719. <div class="item">
  720. <b>Fecha de la Falla: </b>
  721. <span>'.$arrFailureLog['FECHA_FALLA'].'</span>
  722. </div>
  723. <div class="item">
  724. <b>Fecha de la Resolución: </b>
  725. <span>'.$arrFailureLog['FECHA_RESOLUCION'].'</span>
  726. </div>
  727. <div class="item">
  728. <b>Reparable: </b>
  729. <span>'.(($arrFailureLog['REPARABLE'] === 1) ? ('Si') : ('No')).'</span>
  730. </div>
  731. <div class="item">
  732. <b>Valor Obtenido: </b>
  733. <span>'.$arrFailureLog['VALOR_OBTENIDO'].' '.$arrFailureLog['ACRONIMO_MEDIDA'].'</span>
  734. </div>
  735. <div class="item">
  736. <b>Tipo de Medido: </b>
  737. <span>'.$arrFailureLog['NOMBRE_MEDIDA'].'</span>
  738. </div>
  739. <div class="item">
  740. <b>Solución de la Falla: </b>
  741. <span>'.(($arrFailureLog['SOLUCION'] === null || $arrFailureLog['SOLUCION'] === '') ? ('') : ($arrFailureLog['SOLUCION'])).'</span>
  742. </div>
  743. <div class="item">
  744. <b>Comentarios: </b>
  745. <span>'.$arrFailureLog['COMENTARIOS'].'</span>
  746. </div>';
  747. $html .= '</body></html>';
  748. $nuli = $this->resourcesController->formatSecuence($line, 2);
  749. $como = 'ANFA'; // Código del módulo
  750. $cldo = 'IN'; // Código de la clasificación
  751. $fecr = date('ymd'); // Fecha en la se carga el archivo
  752. try {
  753. $arrSecuence = (array) DB::table('S002V01TAFAL')
  754. ->where('AFAL_COMO', '=', $como)
  755. ->where('AFAL_CLDO', '=', $cldo)
  756. ->where('AFAL_NULI', '=', $line)
  757. ->orderBy('AFAL_NUSE', 'desc')
  758. ->first([ 'AFAL_NUSE' ]);
  759. } catch (\Throwable $th) {
  760. return $this->responseController->makeResponse(
  761. true,
  762. "ERR_FAILURELOG_GENERATEPDF003: Ocurrió un error al obtener la información de la secuencia.",
  763. $th->getMessage(),
  764. 500
  765. );
  766. }
  767. $nuse = 1; // Secuencia del documento
  768. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  769. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  770. }
  771. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  772. $nuve = $this->resourcesController->formatSecuence('1', 2);
  773. $noar = 'ficha_de_proveedor_' . $arrFailureLog['NUMERO_FALLA'];
  774. $nuli = $this->resourcesController->formatSecuence($line, 2);
  775. $como = 'GEAD'; // Código del módulo
  776. $cldo = 'IN'; // Código de la clasificación
  777. $fecr = date('ymd'); // Fecha en la se carga el archivo
  778. try {
  779. $arrSecuence = (array) DB::table('S002V01TAFAL')
  780. ->where('AFAL_COMO', '=', $como)
  781. ->where('AFAL_CLDO', '=', $cldo)
  782. ->where('AFAL_NULI', '=', $line)
  783. ->orderBy('AFAL_NUSE', 'desc')
  784. ->first([ 'AFAL_NUSE' ]);
  785. } catch (\Throwable $th) {
  786. return $this->responseController->makeResponse(
  787. true,
  788. "ERR_FAILURELOG_GENERATEPDF004: Ocurrió un error al obtener la información de la secuencia.",
  789. $th->getMessage(),
  790. 500
  791. );
  792. }
  793. $nuse = 1; // Secuencia del documento
  794. if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
  795. $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
  796. }
  797. $nuse = $this->resourcesController->formatSecuence($nuse, 6);
  798. $nuve = $this->resourcesController->formatSecuence('1', 2);
  799. $noar = 'ficha_de_falla_' . $arrFailureLog['NUMERO_FALLA'];
  800. $exte = 'pdf';
  801. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  802. $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
  803. } else {
  804. $filePath = 'C:\inetpub\wwwroot\sam\public_files\\'; // API QA
  805. }
  806. $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
  807. $tempFile = $filePath . $fileName;
  808. $dompdf = new Dompdf();
  809. $dompdf ->loadHtml($html);
  810. $dompdf->setPaper('A4', 'portrait');
  811. $dompdf->render();
  812. $output = $dompdf->output();
  813. file_put_contents($tempFile, $output);
  814. $ubic = Storage::putFile('files', new File($tempFile));
  815. $ubic = str_replace("/", "\\", $ubic);
  816. if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
  817. $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
  818. } else {
  819. $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
  820. }
  821. $tama = filesize($ubic);
  822. $usac = json_encode([$user]);
  823. $now = $this->functionsController->now();
  824. $currentDate = $now->toDateTimeString();
  825. try {
  826. $validateInsert = DB::table('S002V01TAFAL')->insert([
  827. 'AFAL_NULI' => $line,
  828. 'AFAL_COMO' => $como,
  829. 'AFAL_CLDO' => $cldo,
  830. 'AFAL_FECR' => $fecr,
  831. 'AFAL_NUSE' => $nuse,
  832. 'AFAL_NUVE' => $nuve,
  833. 'AFAL_NOAR' => $noar,
  834. 'AFAL_EXTE' => $exte,
  835. 'AFAL_TAMA' => $tama,
  836. 'AFAL_UBIC' => $ubic,
  837. 'AFAL_USAC' => $usac,
  838. 'AFAL_USRE' => $user,
  839. 'AFAL_FERE' => $currentDate,
  840. ]);
  841. } catch (\Throwable $th) {
  842. return $this->responseController->makeResponse(
  843. true,
  844. "ERR_FAILURELOG_GENERATEPDF005: Ocurrió un error guardar los datos a la tabla final de archivos.",
  845. $th->getMessage(),
  846. 500
  847. );
  848. }
  849. if ( !$validateInsert ) {
  850. return $this->responseController->makeResponse(
  851. true,
  852. "ERR_FAILURELOG_GENERATEPDF006: No se pudo guardar la ficha del proveedor en la base de datos.",
  853. [],
  854. 500
  855. );
  856. }
  857. $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
  858. return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
  859. }
  860. public function registerFailureLog(Request $request) {
  861. $validator = Validator::make($request->all(), [
  862. 'CODIGO_EQUIPAMIENTO' => 'required|string',
  863. 'ID_FALLA' => 'required|integer',
  864. // 'ID_SINTOMA' => 'required|integer',
  865. 'FECHA_FALLA' => 'required|string',
  866. 'REPARABLE' => 'required|string',
  867. 'SOLUCION' => 'required|string',
  868. 'COMENTARIOS' => 'required|string',
  869. 'VALOR_OBTENIDO' => 'required|string',
  870. 'ID_MEDIDA' => 'required|string',
  871. 'USUARIO' => 'required|string',
  872. 'NUMERO_LINEA' => 'required|string',
  873. ]);
  874. if ($validator->fails()) {
  875. return $this->responseController->makeResponse(
  876. true,
  877. "ERR_FAILURELOG_REG000: Se encontraron uno o más errores.",
  878. $this->responseController->makeErrors($validator->errors()->messages()),
  879. 401
  880. );
  881. }
  882. DB::beginTransaction();
  883. $requestData = $request->all();
  884. try {
  885. $user = $this->encController->decrypt($requestData['USUARIO']);
  886. } catch (\Throwable $th) {
  887. DB::rollBack();
  888. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  889. }
  890. try {
  891. $validateExistsFailureList = DB::table('S002V01TLIFA')
  892. ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  893. ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
  894. ->where('LIFA_ESTA', '=', 'Activo')
  895. ->exists();
  896. } catch (\Throwable $th) {
  897. DB::rollBack();
  898. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG002: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
  899. }
  900. if ( !$validateExistsFailureList ) {
  901. DB::rollBack();
  902. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG003: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
  903. }
  904. if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
  905. try {
  906. $validateExistsSymptomList = DB::table('S002V01TLISI')
  907. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  908. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  909. ->where('LISI_ESTA', '=', 'Activo')
  910. ->exists();
  911. } catch (\Throwable $th) {
  912. DB::rollBack();
  913. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG004: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
  914. }
  915. if ( !$validateExistsSymptomList ) {
  916. DB::rollBack();
  917. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG005: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
  918. }
  919. }
  920. try {
  921. $validateExistsMeasure = DB::table('S002V01TLIME')
  922. ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
  923. ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
  924. ->where('LIME_ESTA', '=', 'Activo')
  925. ->exists();
  926. } catch (\Throwable $th) {
  927. DB::rollBack();
  928. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG006: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
  929. }
  930. if ( !$validateExistsMeasure ) {
  931. DB::rollBack();
  932. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG007: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
  933. }
  934. try {
  935. $validateExistsEquipment = DB::table('S002V01TEQUI')
  936. ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
  937. ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
  938. ->exists();
  939. } catch (\Throwable $th) {
  940. DB::rollBack();
  941. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG008: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
  942. }
  943. if ( !$validateExistsEquipment ) {
  944. DB::rollBack();
  945. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG009: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
  946. }
  947. $now = $this->functionsController->now();
  948. $currentDate = $now->toDateTimeString();
  949. try {
  950. $validateInsert = DB::table('S002V01TBIFA')->insert([
  951. 'BIFA_NULI' => $requestData['NUMERO_LINEA'],
  952. 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
  953. 'BIFA_IDFA' => $requestData['ID_FALLA'],
  954. 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
  955. 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
  956. 'BIFA_REPA' => $requestData['REPARABLE'],
  957. 'BIFA_DESO' => $requestData['SOLUCION'],
  958. 'BIFA_COME' => $requestData['COMENTARIOS'],
  959. 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
  960. 'BIFA_IDME' => $requestData['ID_MEDIDA'],
  961. 'BIFA_USRE' => $user,
  962. 'BIFA_FERE' => $currentDate,
  963. 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  964. ]);
  965. } catch (\Throwable $th) {
  966. DB::rollBack();
  967. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG010: Ocurrió un error al intentar registrar la falla en la base de datos.", $th->getMessage(), 500);
  968. }
  969. if ( !$validateInsert ) {
  970. DB::rollBack();
  971. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG011: No se pudo registrar la falla.", [], 500);
  972. }
  973. DB::commit();
  974. return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
  975. }
  976. public function updateFailureLog(Request $request) {
  977. $validator = Validator::make($request->all(), [
  978. 'NUMERO_FALLA' => 'required|integer',
  979. 'CODIGO_EQUIPAMIENTO' => 'required|string',
  980. 'ID_FALLA' => 'required|integer',
  981. // 'ID_SINTOMA' => 'required|integer',
  982. 'FECHA_FALLA' => 'required|string',
  983. 'REPARABLE' => 'required|string',
  984. 'SOLUCION' => 'required|string',
  985. 'COMENTARIOS' => 'required|string',
  986. 'VALOR_OBTENIDO' => 'required|string',
  987. 'ID_MEDIDA' => 'required|string',
  988. 'USUARIO' => 'required|string',
  989. 'NUMERO_LINEA' => 'required|string',
  990. ]);
  991. if ($validator->fails()) {
  992. return $this->responseController->makeResponse(
  993. true,
  994. "ERR_FAILURELOG_UPD000: Se encontraron uno o más errores.",
  995. $this->responseController->makeErrors($validator->errors()->messages()),
  996. 401
  997. );
  998. }
  999. DB::beginTransaction();
  1000. $requestData = $request->all();
  1001. try {
  1002. $user = $this->encController->decrypt($requestData['USUARIO']);
  1003. } catch (\Throwable $th) {
  1004. DB::rollBack();
  1005. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
  1006. }
  1007. try {
  1008. $validateExistsFailureLog = DB::table('S002V01TBIFA')
  1009. ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1010. ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
  1011. ->where('BIFA_ESTA', '=', 'Activo')
  1012. ->exists();
  1013. } catch (\Throwable $th) {
  1014. DB::rollBack();
  1015. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD002: Ocurrió un error al consultar la bitácora de fallas.", $th->getMessage(), 500);
  1016. }
  1017. if ( !$validateExistsFailureLog ) {
  1018. DB::rollBack();
  1019. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD003: No existe la falla #".$requestData['NUMERO_FALLA']." en la bitácora de fallas.", [], 500);
  1020. }
  1021. try {
  1022. $validateExistsFailureList = DB::table('S002V01TLIFA')
  1023. ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1024. ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
  1025. ->where('LIFA_ESTA', '=', 'Activo')
  1026. ->exists();
  1027. } catch (\Throwable $th) {
  1028. DB::rollBack();
  1029. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD004: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
  1030. }
  1031. if ( !$validateExistsFailureList ) {
  1032. DB::rollBack();
  1033. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD005: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
  1034. }
  1035. if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
  1036. try {
  1037. $validateExistsSymptomList = DB::table('S002V01TLISI')
  1038. ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
  1039. ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
  1040. ->where('LISI_ESTA', '=', 'Activo')
  1041. ->exists();
  1042. } catch (\Throwable $th) {
  1043. DB::rollBack();
  1044. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD006: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
  1045. }
  1046. if ( !$validateExistsSymptomList ) {
  1047. DB::rollBack();
  1048. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD007: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
  1049. }
  1050. }
  1051. try {
  1052. $validateExistsMeasure = DB::table('S002V01TLIME')
  1053. ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
  1054. ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
  1055. ->where('LIME_ESTA', '=', 'Activo')
  1056. ->exists();
  1057. } catch (\Throwable $th) {
  1058. DB::rollBack();
  1059. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD008: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
  1060. }
  1061. if ( !$validateExistsMeasure ) {
  1062. DB::rollBack();
  1063. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD009: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
  1064. }
  1065. try {
  1066. $validateExistsEquipment = DB::table('S002V01TEQUI')
  1067. ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
  1068. ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
  1069. ->exists();
  1070. } catch (\Throwable $th) {
  1071. DB::rollBack();
  1072. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD010: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
  1073. }
  1074. if ( !$validateExistsEquipment ) {
  1075. DB::rollBack();
  1076. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD011: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
  1077. }
  1078. $now = $this->functionsController->now();
  1079. $currentDate = $now->toDateTimeString();
  1080. try {
  1081. $validateUpdate = DB::table('S002V01TBIFA')
  1082. ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
  1083. ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
  1084. ->update([
  1085. 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
  1086. 'BIFA_IDFA' => $requestData['ID_FALLA'],
  1087. 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
  1088. 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
  1089. 'BIFA_REPA' => $requestData['REPARABLE'],
  1090. 'BIFA_DESO' => $requestData['SOLUCION'],
  1091. 'BIFA_COME' => $requestData['COMENTARIOS'],
  1092. 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
  1093. 'BIFA_IDME' => $requestData['ID_MEDIDA'],
  1094. 'BIFA_USMO' => $user,
  1095. 'BIFA_FEMO' => $currentDate,
  1096. 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
  1097. ]);
  1098. } catch (\Throwable $th) {
  1099. DB::rollBack();
  1100. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD012: Ocurrió un error al intentar modificar la falla en la base de datos.", $th->getMessage(), 500);
  1101. }
  1102. if ( !$validateUpdate ) {
  1103. DB::rollBack();
  1104. return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD013: No se pudo modificar la bitácora de falla.", [], 500);
  1105. }
  1106. DB::commit();
  1107. return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
  1108. }
  1109. }