| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244 |
- <?php
- /*
- Desarrollador: Ing. Jean Jairo Benitez Meza
- Ultima Modificación: 21/09/2023
- Módulo: Analisis de Fallas
- */
- namespace App\Http\Controllers;
- use App\Http\Controllers\Controller;
- use App\Http\Controllers\ResponseController;
- use App\Http\Controllers\EncryptionController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Validator;
- use App\Http\Controllers\FunctionsController;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Http\File;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use Dompdf\Dompdf;
- class FailureLogController extends Controller
- {
- private $responseController;
- private $encController;
- private $functionsController;
- private $resourcesController;
- public function __construct( ) {
- $this->responseController = new ResponseController();
- $this->encController = new EncryptionController();
- $this->functionsController = new FunctionsController();
- $this->resourcesController = new ResourcesController();
- }
- public function getFailureLog($user, $line) {
- try {
- $getFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NULI', '=', $line)
- ->where('LIFA_NULI', '=', $line)
- ->where('LISI_NULI', '=', $line)
- ->where('LIME_NULI', '=', $line)
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->get([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- 'BIFA_ESTA AS ESTADO',
- 'BIFA_USRE AS USUARIO_REGISTRA',
- 'BIFA_FERE AS FECHA_REGISTRA',
- 'BIFA_USMO AS USUARIO_MODIFICA',
- 'BIFA_FEMO AS FECHA_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GET000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
- $arrEquipmentCode = array_column($arrFailureLog, 'CODIGO_EQUIPAMIENTO');
- $arrEquipmentCode = array_unique($arrEquipmentCode);
- $count = 0;
- $arrEquipmentFailureLog = array();
- foreach ($arrEquipmentCode as $keyEquipmentCode => $equipmentCode) {
- $lastUpdate = '';
- $lastUser = '';
- $lastState = '';
- $lastClassification = '';
- $amountFailures = 0;
- foreach ($arrFailureLog as $keyFailureLog => $failureLog) {
- if ( $equipmentCode === $failureLog['CODIGO_EQUIPAMIENTO'] ) {
-
- $tempLastUpdate = '';
- $tempLastUser = '';
- if ( is_null($failureLog['FECHA_MODIFICA']) ) {
- $tempLastUpdate = $failureLog['FECHA_REGISTRA'];
- $tempLastUser = $failureLog['USUARIO_REGISTRA'];
- } else {
- $tempLastUpdate = $failureLog['FECHA_MODIFICA'];
- $tempLastUser = $failureLog['USUARIO_MODIFICA'];
- }
- if ($lastUpdate === '') {
- $lastUpdate = $tempLastUpdate;
- $lastUser = $tempLastUser;
- $lastState = $failureLog['ESTADO_FALLA'];
- $lastClassification = $failureLog['NIVEL_CRITICIDAD_FALLA'];
- } else {
- $carTempLastUpdate = Carbon::create($tempLastUpdate);
- $carLastState = Carbon::create($lastUpdate);
- if ($carTempLastUpdate->greaterThan($carLastState)) {
- $lastUpdate = $tempLastUpdate;
- $lastUser = $tempLastUser;
- $lastState = $failureLog['ESTADO_FALLA'];
- $lastClassification = $failureLog['NIVEL_CRITICIDAD_FALLA'];
- }
- }
- $amountFailures ++;
- }
- }
- $arrEquipmentFailureLog[$count]['CODIGO_EQUIPAMIENTO'] = $equipmentCode;
- $arrEquipmentFailureLog[$count]['ULTIMA_MODIFICACION'] = $lastUpdate;
- $arrEquipmentFailureLog[$count]['ULTIMO_USUARIO'] = $lastUser;
- $arrEquipmentFailureLog[$count]['ESTADO_ACTUAL'] = $lastState;
- $arrEquipmentFailureLog[$count]['CLASIFICACION_ACTUAL'] = $lastClassification;
- $arrEquipmentFailureLog[$count]['CANTIDAD_FALLAS'] = $amountFailures;
- $count++;
- }
-
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrEquipmentFailureLog);
- }
- public function getHistoryFailureEquipment($equipment, $user, $line) {
- try {
- $equipment = $this->encController->decrypt($equipment);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT000", $th->getMessage(), 500);
- }
- try {
- $getFailuresLog = DB::table('S002V01TBIFA')
- ->where('BIFA_COEQ', '=', $equipment)
- ->where('BIFA_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->get([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- 'BIFA_USRE AS USUARIO_REGISTRA',
- 'BIFA_FERE AS FECHA_REGISTRA',
- 'BIFA_USMO AS USUARIO_MODIFICA',
- 'BIFA_FEMO AS FECHA_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT001: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLogTemp = json_decode( json_encode( $getFailuresLog ), true );
- $arrFailureLog = array();
- foreach ($arrFailureLogTemp as $keyFailureLogTemp => $failureLogTemp) {
- $numero_falla = $failureLogTemp['NUMERO_FALLA'];
- $nombre_falla = $failureLogTemp['NOMBRE_FALLA'].' ('.$failureLogTemp['ID_FALLA'].')';
- $nivel_criticidad_falla = $failureLogTemp['NIVEL_CRITICIDAD_FALLA'];
- $nombre_sintoma = $failureLogTemp['NOMBRE_SINTOMA'].' ('.$failureLogTemp['ID_SINTOMA'].')';
- $estado_falla = $failureLogTemp['ESTADO_FALLA'];
- $causa = $failureLogTemp['CAUSA_FALLA'];
- $fecha_fala = $failureLogTemp['FECHA_FALLA'];
- $reparable = $failureLogTemp['REPARABLE'] === 1 ? 'Si' : 'No';
- $usuario_registra = is_null($failureLogTemp['USUARIO_MODIFICA']) ? $failureLogTemp['USUARIO_REGISTRA'] : $failureLogTemp['USUARIO_MODIFICA'];
- $fecha_registra = is_null($failureLogTemp['FECHA_MODIFICA']) ? $failureLogTemp['FECHA_REGISTRA'] : $failureLogTemp['FECHA_MODIFICA'];
- $arrFailureLog[] = [
- 'NUMERO_FALLA' => $numero_falla,
- 'NOMBRE_FALLA' => $nombre_falla,
- 'NIVEL_CRITICIDAD_FALLA' => $nivel_criticidad_falla,
- 'ESTADO_FALLA' => $estado_falla,
- 'CAUSA' => $causa,
- 'FECHA_FALLA' => $fecha_fala,
- 'REPARABLE' => $reparable,
- 'USUARIO_REGISTRA' => $usuario_registra,
- 'FECHA_REGISTRA' => $fecha_registra,
- ];
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
-
- }
- public function getDetailsHistoryFailureEquipment($failure, $user, $line) {
- try {
- $failure = $this->encController->decrypt($failure);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_GETHISTORY_GETEQUIPMENT000", $th->getMessage(), 500);
- }
- try {
- $getFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NUFA', '=', $failure)
- ->where('BIFA_NULI', '=', $line)
- ->where('LIFA_NULI', '=', $line)
- ->where('LISI_NULI', '=', $line)
- ->where('LIME_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->first([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_FERF AS FECHA_RESOLUCION',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GETACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
- }
- public function getFailureLogActives($user, $line) {
- try {
- $getFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NULI', '=', $line)
- ->where('LIFA_NULI', '=', $line)
- ->where('LISI_NULI', '=', $line)
- ->where('LIME_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->get([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- 'BIFA_USRE AS USUARIO_REGISTRA',
- 'BIFA_FERE AS FECHA_REGISTRA',
- 'BIFA_USMO AS USUARIO_MODIFICA',
- 'BIFA_FEMO AS FECHA_MODIFICA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GETACTIVE000: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrFailureLog);
- }
- public function getEquipmentByFailure($failure, $user, $line) {
- try {
- $failure = $this->encController->decrypt($failure);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURES_EQUIPMENT000: No se pudo obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $getEquipmentByFailure = DB::table('S002V01TBIFA')
- ->where('BIFA_IDFA', '=', $failure)
- ->where('BIFA_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->get([
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_FERF AS FECHA_REPARACION',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURES_EQUIPMENT001: No se pudo realizar la consulta a la base.",
- $th->getMessage(),
- 500
- );
- }
-
- $arrFaultyEquipment = json_decode(json_encode($getEquipmentByFailure), true);
- $arrEquipmentCode = array_column($arrFaultyEquipment, 'CODIGO_EQUIPAMIENTO');
- $arrEquipmentCode = array_unique($arrEquipmentCode);
- $count = 0;
- $arrEquipmentFailureLog = array();
- foreach ($arrEquipmentCode as $keyEquipmentCode => $equipmentCode) {
- foreach ($arrFaultyEquipment as $keyFaultyEquipment => $faultyEquipment) {
- if ( $equipmentCode === $faultyEquipment['CODIGO_EQUIPAMIENTO'] ) {
- $arrEquipmentFailureLog[$count]['CODIGO_EQUIPAMIENTO'] = $faultyEquipment['CODIGO_EQUIPAMIENTO'];
- $arrEquipmentFailureLog[$count]['DETALLES'][] = [
- 'ESTADO_FALLA' => $faultyEquipment['ESTADO_FALLA'],
- 'FECHA_FALLA' => $faultyEquipment['FECHA_FALLA'],
- 'FECHA_REPARACION' => $faultyEquipment['FECHA_REPARACION'],
- 'VALOR_OBTENIDO' => $faultyEquipment['VALOR_OBTENIDO'],
- 'ID_MEDIDA' => $faultyEquipment['ID_MEDIDA'],
- 'NOMBRE_MEDIDA' => $faultyEquipment['NOMBRE_MEDIDA'],
- 'ACRONIMO_MEDIDA' => $faultyEquipment['ACRONIMO_MEDIDA'],
- ];
- }
- }
- $count++;
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrEquipmentFailureLog);
- }
- public function getAlarmEmissionFromFailures($user, $line) {
- try {
- $getAlarmEmission = DB::table('S002V01TBIFA')
- ->where('BIFA_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('ACTI_NULI', '=', $line)
- ->join('S002V01TACTI', 'ACTI_IDAC', '=', 'BIFA_IDAC')
- ->get([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'ACTI_IDAC AS ID_ACTIVADOR',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'ACTI_PRIO AS PRIORIDAD',
- 'ACTI_TIAC AS TIPO_ACTIVADOR',
- 'ACTI_COAC AS CONDICION_ACTIVADOR',
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURES_ALARM000: No se pudo obtener la información de la base de datos.", $th->getMessage(), 500);
- }
- $arrAlarmEmission = json_decode(json_encode($getAlarmEmission), true);
- foreach ($arrAlarmEmission as $key => $alarmEmission) {
-
- switch ($alarmEmission['PRIORIDAD']) {
- case 1:
- $alarmEmission['PRIORIDAD'] = 'Muy alta';
- break;
- case 2:
- $alarmEmission['PRIORIDAD'] = 'Alta';
- break;
- case 3:
- $alarmEmission['PRIORIDAD'] = 'Media';
- break;
- case 4:
- $alarmEmission['PRIORIDAD'] = 'Baja';
- break;
- }
- $arrAlarmEmission[$key] = $alarmEmission;
- }
- return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $arrAlarmEmission);
- }
- public function generateSheetFailureXLS($failure, $user, $line) {
- try {
- $failure = $this->encController->decrypt($failure);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS000", $th->getMessage(), 500);
- }
- try {
- $user = $this->encController->decrypt($user);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS001", $th->getMessage(), 500);
- }
- try {
- $getFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NUFA', '=', $failure)
- ->where('BIFA_NULI', '=', $line)
- ->where('LIFA_NULI', '=', $line)
- ->where('LISI_NULI', '=', $line)
- ->where('LIME_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->first([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_FERF AS FECHA_RESOLUCION',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEXLS002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
- $spreadsheet = new Spreadsheet();
- $activeWorksheet = $spreadsheet->getActiveSheet()->setTitle($arrFailureLog['NUMERO_FALLA']);
- $activeWorksheet->setCellValue("A1", 'Número de Falla');
- $activeWorksheet->setCellValue("B1", $arrFailureLog['NUMERO_FALLA']);
- $activeWorksheet->getStyle( "A1" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A2", 'Número de Equipamiento');
- $activeWorksheet->setCellValue("B2", $arrFailureLog['CODIGO_EQUIPAMIENTO']);
- $activeWorksheet->getStyle( "A2" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A3", 'Estado de la Falla');
- $activeWorksheet->setCellValue("B3", $arrFailureLog['ESTADO_FALLA']);
- $activeWorksheet->getStyle( "A3" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A4", 'Nombre de la Falla');
- $activeWorksheet->setCellValue("B4", $arrFailureLog['NOMBRE_FALLA'].' ('.$arrFailureLog['ID_FALLA'].')');
- $activeWorksheet->getStyle( "A4" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A5", 'Nivel de Criticidad de la Falla');
- $activeWorksheet->setCellValue("B5", $arrFailureLog['NIVEL_CRITICIDAD_FALLA']);
- $activeWorksheet->getStyle( "A5" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A6", 'Causa de la Falla');
- $activeWorksheet->setCellValue("B6", $arrFailureLog['CAUSA_FALLA']);
- $activeWorksheet->getStyle( "A6" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A7", 'Nombre del Síntoma');
- $activeWorksheet->setCellValue("B7", $arrFailureLog['NOMBRE_SINTOMA'].' ('.$arrFailureLog['ID_SINTOMA'].')');
- $activeWorksheet->getStyle( "A7" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A8", 'Clasificación del Síntoma');
- $activeWorksheet->setCellValue("B8", $arrFailureLog['CLASIFICACION_SINTOMA']);
- $activeWorksheet->getStyle( "A8" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A9", 'Causa del Síntoma');
- $activeWorksheet->setCellValue("B9", $arrFailureLog['CAUSA_SINTOMA']);
- $activeWorksheet->getStyle( "A9" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A10", 'Fecha de la Falla');
- $activeWorksheet->setCellValue("B10", $arrFailureLog['FECHA_FALLA']);
- $activeWorksheet->getStyle( "A10" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A11", 'Fecha de la Resolución');
- $activeWorksheet->setCellValue("B11", $arrFailureLog['FECHA_RESOLUCION']);
- $activeWorksheet->getStyle( "A11" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A12", 'Reparable');
- $activeWorksheet->setCellValue("B12", $arrFailureLog['REPARABLE'] === 1 ? 'Si' : 'No');
- $activeWorksheet->getStyle( "A12" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A13", 'Valor Obtenido');
- $activeWorksheet->setCellValue("B13", $arrFailureLog['VALOR_OBTENIDO'].' '.$arrFailureLog['ACRONIMO_MEDIDA']);
- $activeWorksheet->getStyle( "A13" )->getFont()->setBold(true);
- $activeWorksheet->setCellValue("A14", 'Tipo de Medido');
- $activeWorksheet->setCellValue("B14", $arrFailureLog['NOMBRE_MEDIDA']);
- $activeWorksheet->getStyle( "A14" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A15", 'Solución de la Falla');
- $activeWorksheet->setCellValue("B15", $arrFailureLog['SOLUCION'] === null || $arrFailureLog['SOLUCION'] === '' ? '' : $arrFailureLog['SOLUCION']);
- $activeWorksheet->getStyle( "A15" )->getFont()->setBold(true);
-
- $activeWorksheet->setCellValue("A16", 'Comentarios');
- $activeWorksheet->setCellValue("B16", $arrFailureLog['COMENTARIOS']);
- $activeWorksheet->getStyle( "A16" )->getFont()->setBold(true);
- $activeWorksheet->getColumnDimension("A")->setAutoSize(true);
- $activeWorksheet->getColumnDimension("B")->setAutoSize(true);
- $nuli = $this->resourcesController->formatSecuence($line, 2);
- $como = 'ANFA'; // Código del módulo
- $cldo = 'IN'; // Código de la clasificación
- $fecr = date('ymd'); // Fecha en la se carga el archivo
- try {
- $arrSecuence = (array) DB::table('S002V01TAFAL')
- ->where('AFAL_COMO', '=', $como)
- ->where('AFAL_CLDO', '=', $cldo)
- ->where('AFAL_NULI', '=', $line)
- ->orderBy('AFAL_NUSE', 'desc')
- ->first([ 'AFAL_NUSE' ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEXLS003: Ocurrió un error al obtener la información de la secuencia.",
- $th->getMessage(),
- 500
- );
- }
- $nuse = 1; // Secuencia del documento
- if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
- $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
- }
- $nuse = $this->resourcesController->formatSecuence($nuse, 6);
- $nuve = $this->resourcesController->formatSecuence('1', 2);
- $noar = 'ficha_de_falla_'.$arrFailureLog['NUMERO_FALLA'];
- $exte = 'xlsx';
- if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
- $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
- } else {
- $filePath = 'C:\inetpub\wwwroot\sam\public_files\\'; // API QA
- }
-
- $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
- $tempFile = $filePath.$fileName;
- if ( file_exists( $tempFile ) ) {
- if ( !unlink( $tempFile ) ) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEXLS004: Ocurrió un error al eliminar el siguiente archivo: " . $tempFile,
- [],
- 500
- );
- }
- }
-
- try {
- $writer = new Xlsx($spreadsheet);
- ob_start();
- $writer->save('php://output');
- $base64 = base64_encode(ob_get_clean());
- $validate = \File::put( $tempFile, base64_decode($base64));
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEXLS005: Ocurrió un error al guardar el documento.",
- $th->getMessage(),
- 500
- );
- }
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
- $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
- } else {
- $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
- }
- $tama = filesize($ubic);
- $usac = json_encode([$user]);
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $user,
- 'AFAL_FERE' => $currentDate,
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEXLS006: Ocurrió un error guardar los datos a la tabla final de archivos.",
- $th->getMessage(),
- 500
- );
- }
- if ( !$validateInsert ) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEXLS007: No se pudo guardar la ficha del proveedor en la base de datos.",
- [],
- 500
- );
- }
-
- $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
- return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
- return $arrFailureLog;
- }
- public function generateSheetFailurePDF($failure, $user, $line){
- try {
- $failure = $this->encController->decrypt($failure);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF000: Ocurrió un error al obtener la falla.", $th->getMessage(), 500);
- }
- try {
- $user = $this->encController->decrypt($user);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF001: Ocurrió un error al obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $getFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NUFA', '=', $failure)
- ->where('BIFA_NULI', '=', $line)
- ->where('LIFA_NULI', '=', $line)
- ->where('LISI_NULI', '=', $line)
- ->where('LIME_NULI', '=', $line)
- ->where('BIFA_ESTA', '=', 'Activo')
- ->where('LIFA_ESTA', '=', 'Activo')
- ->where('LISI_ESTA', '=', 'Activo')
- ->where('LIME_ESTA', '=', 'Activo')
- ->join('S002V01TLIFA', 'LIFA_IDFA', '=', 'BIFA_IDFA')
- ->join('S002V01TLISI', 'LISI_IDSI', '=', 'BIFA_IDSI')
- ->join('S002V01TLIME', 'LIME_IDME', '=', 'BIFA_IDME')
- ->first([
- 'BIFA_NUFA AS NUMERO_FALLA',
- 'BIFA_COEQ AS CODIGO_EQUIPAMIENTO',
- 'BIFA_ESFA AS ESTADO_FALLA',
- 'LIFA_IDFA AS ID_FALLA',
- 'LIFA_NOFA AS NOMBRE_FALLA',
- 'LIFA_NIVE AS NIVEL_CRITICIDAD_FALLA',
- 'LIFA_CAUS AS CAUSA_FALLA',
- 'LISI_IDSI AS ID_SINTOMA',
- 'LISI_NOSI AS NOMBRE_SINTOMA',
- 'LISI_CLAS AS CLASIFICACION_SINTOMA',
- 'LISI_CAUS AS CAUSA_SINTOMA',
- 'BIFA_FEFA AS FECHA_FALLA',
- 'BIFA_FERF AS FECHA_RESOLUCION',
- 'BIFA_REPA AS REPARABLE',
- 'BIFA_DESO AS SOLUCION',
- 'BIFA_COME AS COMENTARIOS',
- 'BIFA_VAOB AS VALOR_OBTENIDO',
- 'LIME_IDME AS ID_MEDIDA',
- 'LIME_NOME AS NOMBRE_MEDIDA',
- 'LIME_ACME AS ACRONIMO_MEDIDA',
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_GENERATEPDF002: No se pudo realizar la consulta a la base.", $th->getMessage(), 500);
- }
- $arrFailureLog = json_decode( json_encode( $getFailureLog ), true );
- // return $arrFailureLog;
- $html = '<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- body {
- font-family: Arial, Helvetica, sans-serif;
- font-size: 8pt;
- }
- .section-title {
- margin: 20px 0;
- font-size: 12pt;
- }
- table {
- width: 100%;
- }
- thead tr th {
- text-align: start;
- padding: 0 16px;
- height: 52px;
- border-bottom-width: 1px;
- border-bottom-style: solid;
- border-bottom-color: #CCC;
- }
- tbody tr td {
- padding: 0 16px;
- height: 52px;
- border-bottom-width: 1px;
- border-bottom-style: solid;
- border-bottom-color: #CCC;
- }
- p {
- text-align: justify;
- }
- </style>
- </head>
- <body>
- <div class="item">
- <b>Número de Falla: </b>
- <span>'.$arrFailureLog['NUMERO_FALLA'].'</span>
- </div>
- <div class="item">
- <b>Número de Equipamiento: </b>
- <span>'.$arrFailureLog['CODIGO_EQUIPAMIENTO'].'</span>
- </div>
- <div class="item">
- <b>Estado de la Falla: </b>
- <span>'.$arrFailureLog['ESTADO_FALLA'].'</span>
- </div>
- <div class="item">
- <b>Nombre de la Falla: </b>
- <span>'.$arrFailureLog['NOMBRE_FALLA'].' ('.$arrFailureLog['ID_FALLA'].')'.'</span>
- </div>
- <div class="item">
- <b>Nivel de Criticidad de la Falla: </b>
- <span>'.$arrFailureLog['NIVEL_CRITICIDAD_FALLA'].'</span>
- </div>
- <div class="item">
- <b>Causa de la Falla: </b>
- <span>'.$arrFailureLog['CAUSA_FALLA'].'</span>
- </div>
- <div class="item">
- <b>Nombre del Síntoma: </b>
- <span>'.$arrFailureLog['NOMBRE_SINTOMA'].' ('.$arrFailureLog['ID_SINTOMA'].')'.'</span>
- </div>
- <div class="item">
- <b>Clasificación del Síntoma: </b>
- <span>'.$arrFailureLog['CLASIFICACION_SINTOMA'].'</span>
- </div>
- <div class="item">
- <b>Causa del Síntoma: </b>
- <span>'.$arrFailureLog['CAUSA_SINTOMA'].'</span>
- </div>
- <div class="item">
- <b>Fecha de la Falla: </b>
- <span>'.$arrFailureLog['FECHA_FALLA'].'</span>
- </div>
- <div class="item">
- <b>Fecha de la Resolución: </b>
- <span>'.$arrFailureLog['FECHA_RESOLUCION'].'</span>
- </div>
- <div class="item">
- <b>Reparable: </b>
- <span>'.(($arrFailureLog['REPARABLE'] === 1) ? ('Si') : ('No')).'</span>
- </div>
- <div class="item">
- <b>Valor Obtenido: </b>
- <span>'.$arrFailureLog['VALOR_OBTENIDO'].' '.$arrFailureLog['ACRONIMO_MEDIDA'].'</span>
- </div>
- <div class="item">
- <b>Tipo de Medido: </b>
- <span>'.$arrFailureLog['NOMBRE_MEDIDA'].'</span>
- </div>
- <div class="item">
- <b>Solución de la Falla: </b>
- <span>'.(($arrFailureLog['SOLUCION'] === null || $arrFailureLog['SOLUCION'] === '') ? ('') : ($arrFailureLog['SOLUCION'])).'</span>
- </div>
- <div class="item">
- <b>Comentarios: </b>
- <span>'.$arrFailureLog['COMENTARIOS'].'</span>
- </div>';
- $html .= '</body></html>';
- $nuli = $this->resourcesController->formatSecuence($line, 2);
- $como = 'ANFA'; // Código del módulo
- $cldo = 'IN'; // Código de la clasificación
- $fecr = date('ymd'); // Fecha en la se carga el archivo
- try {
- $arrSecuence = (array) DB::table('S002V01TAFAL')
- ->where('AFAL_COMO', '=', $como)
- ->where('AFAL_CLDO', '=', $cldo)
- ->where('AFAL_NULI', '=', $line)
- ->orderBy('AFAL_NUSE', 'desc')
- ->first([ 'AFAL_NUSE' ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEPDF003: Ocurrió un error al obtener la información de la secuencia.",
- $th->getMessage(),
- 500
- );
- }
- $nuse = 1; // Secuencia del documento
- if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
- $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
- }
- $nuse = $this->resourcesController->formatSecuence($nuse, 6);
- $nuve = $this->resourcesController->formatSecuence('1', 2);
- $noar = 'ficha_de_proveedor_' . $arrFailureLog['NUMERO_FALLA'];
- $nuli = $this->resourcesController->formatSecuence($line, 2);
- $como = 'GEAD'; // Código del módulo
- $cldo = 'IN'; // Código de la clasificación
- $fecr = date('ymd'); // Fecha en la se carga el archivo
- try {
- $arrSecuence = (array) DB::table('S002V01TAFAL')
- ->where('AFAL_COMO', '=', $como)
- ->where('AFAL_CLDO', '=', $cldo)
- ->where('AFAL_NULI', '=', $line)
- ->orderBy('AFAL_NUSE', 'desc')
- ->first([ 'AFAL_NUSE' ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEPDF004: Ocurrió un error al obtener la información de la secuencia.",
- $th->getMessage(),
- 500
- );
- }
- $nuse = 1; // Secuencia del documento
- if ( !empty( $arrSecuence ) && !is_null( $arrSecuence ) ) {
- $nuse = intval( $arrSecuence['AFAL_NUSE'] ) + 1;
- }
- $nuse = $this->resourcesController->formatSecuence($nuse, 6);
- $nuve = $this->resourcesController->formatSecuence('1', 2);
- $noar = 'ficha_de_falla_' . $arrFailureLog['NUMERO_FALLA'];
- $exte = 'pdf';
-
-
- if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
- $filePath = 'C:/ITTEC/SAM/Dev/SistemaMantenimiento/sistema-mantenimiento-back/public/public_files/'; // API JEAN
- } else {
- $filePath = 'C:\inetpub\wwwroot\sam\public_files\\'; // API QA
- }
- $fileName = $nuli.'-'.$como.'-'.$cldo.'-'.$fecr.'-'.$nuse.'='.$nuve.'='.$noar.'.'.$exte;
-
- $tempFile = $filePath . $fileName;
- $dompdf = new Dompdf();
- $dompdf ->loadHtml($html);
- $dompdf->setPaper('A4', 'portrait');
- $dompdf->render();
- $output = $dompdf->output();
- file_put_contents($tempFile, $output);
- $ubic = Storage::putFile('files', new File($tempFile));
- $ubic = str_replace("/", "\\", $ubic);
- if ($_SERVER['SERVER_NAME'] === '192.168.100.105') {
- $ubic = "C:\ITTEC\SAM\Dev\SistemaMantenimiento\sistema-mantenimiento-back\storage\app\\" . $ubic;
- } else {
- $ubic = "C:\inetpub\wwwroot\sam\storage\app\\" . $ubic;
- }
- $tama = filesize($ubic);
- $usac = json_encode([$user]);
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TAFAL')->insert([
- 'AFAL_NULI' => $line,
- 'AFAL_COMO' => $como,
- 'AFAL_CLDO' => $cldo,
- 'AFAL_FECR' => $fecr,
- 'AFAL_NUSE' => $nuse,
- 'AFAL_NUVE' => $nuve,
- 'AFAL_NOAR' => $noar,
- 'AFAL_EXTE' => $exte,
- 'AFAL_TAMA' => $tama,
- 'AFAL_UBIC' => $ubic,
- 'AFAL_USAC' => $usac,
- 'AFAL_USRE' => $user,
- 'AFAL_FERE' => $currentDate,
- ]);
- } catch (\Throwable $th) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEPDF005: Ocurrió un error guardar los datos a la tabla final de archivos.",
- $th->getMessage(),
- 500
- );
- }
- if ( !$validateInsert ) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_GENERATEPDF006: No se pudo guardar la ficha del proveedor en la base de datos.",
- [],
- 500
- );
- }
- $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName;
- return $this->responseController->makeResponse(false, "EXITO: Modificación Exitosa", [ 'url' => $urlPublic ]);
- }
- public function registerFailureLog(Request $request) {
- $validator = Validator::make($request->all(), [
- 'CODIGO_EQUIPAMIENTO' => 'required|string',
- 'ID_FALLA' => 'required|integer',
- // 'ID_SINTOMA' => 'required|integer',
- 'FECHA_FALLA' => 'required|string',
- 'REPARABLE' => 'required|string',
- 'SOLUCION' => 'required|string',
- 'COMENTARIOS' => 'required|string',
- 'VALOR_OBTENIDO' => 'required|string',
- 'ID_MEDIDA' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_REG000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $user = $this->encController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $validateExistsFailureList = DB::table('S002V01TLIFA')
- ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
- ->where('LIFA_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG002: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsFailureList ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG003: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
- }
- if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
- try {
- $validateExistsSymptomList = DB::table('S002V01TLISI')
- ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
- ->where('LISI_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG004: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsSymptomList ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG005: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
- }
- }
- try {
- $validateExistsMeasure = DB::table('S002V01TLIME')
- ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
- ->where('LIME_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG006: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsMeasure ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG007: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
- }
- try {
- $validateExistsEquipment = DB::table('S002V01TEQUI')
- ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG008: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
- }
- if ( !$validateExistsEquipment ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG009: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateInsert = DB::table('S002V01TBIFA')->insert([
- 'BIFA_NULI' => $requestData['NUMERO_LINEA'],
- 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
- 'BIFA_IDFA' => $requestData['ID_FALLA'],
- 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
- 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
- 'BIFA_REPA' => $requestData['REPARABLE'],
- 'BIFA_DESO' => $requestData['SOLUCION'],
- 'BIFA_COME' => $requestData['COMENTARIOS'],
- 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
- 'BIFA_IDME' => $requestData['ID_MEDIDA'],
- 'BIFA_USRE' => $user,
- 'BIFA_FERE' => $currentDate,
- 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG010: Ocurrió un error al intentar registrar la falla en la base de datos.", $th->getMessage(), 500);
- }
- if ( !$validateInsert ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_REG011: No se pudo registrar la falla.", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso");
- }
- public function updateFailureLog(Request $request) {
- $validator = Validator::make($request->all(), [
- 'NUMERO_FALLA' => 'required|integer',
- 'CODIGO_EQUIPAMIENTO' => 'required|string',
- 'ID_FALLA' => 'required|integer',
- // 'ID_SINTOMA' => 'required|integer',
- 'FECHA_FALLA' => 'required|string',
- 'REPARABLE' => 'required|string',
- 'SOLUCION' => 'required|string',
- 'COMENTARIOS' => 'required|string',
- 'VALOR_OBTENIDO' => 'required|string',
- 'ID_MEDIDA' => 'required|string',
- 'USUARIO' => 'required|string',
- 'NUMERO_LINEA' => 'required|string',
- ]);
- if ($validator->fails()) {
- return $this->responseController->makeResponse(
- true,
- "ERR_FAILURELOG_UPD000: Se encontraron uno o más errores.",
- $this->responseController->makeErrors($validator->errors()->messages()),
- 401
- );
- }
- DB::beginTransaction();
- $requestData = $request->all();
- try {
- $user = $this->encController->decrypt($requestData['USUARIO']);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500);
- }
- try {
- $validateExistsFailureLog = DB::table('S002V01TBIFA')
- ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
- ->where('BIFA_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD002: Ocurrió un error al consultar la bitácora de fallas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsFailureLog ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD003: No existe la falla #".$requestData['NUMERO_FALLA']." en la bitácora de fallas.", [], 500);
- }
- try {
- $validateExistsFailureList = DB::table('S002V01TLIFA')
- ->where('LIFA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LIFA_IDFA', '=', $requestData['ID_FALLA'])
- ->where('LIFA_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD004: Ocurrió un error al consultar la lista de fallas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsFailureList ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD005: No existe la falla #".$requestData['ID_FALLA']." en la lista de fallas.", [], 500);
- }
- if ( !is_null($requestData['ID_SINTOMA']) && $requestData['ID_SINTOMA'] !== '' ) {
- try {
- $validateExistsSymptomList = DB::table('S002V01TLISI')
- ->where('LISI_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LISI_IDSI', '=', $requestData['ID_SINTOMA'])
- ->where('LISI_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD006: Ocurrió un error al consultar la lista de síntomas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsSymptomList ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD007: No existe el síntoma #".$requestData['ID_SINTOMA']." en la lista de síntomas.", [], 500);
- }
- }
- try {
- $validateExistsMeasure = DB::table('S002V01TLIME')
- ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])
- ->where('LIME_ESTA', '=', 'Activo')
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD008: Ocurrió un error al consultar la lista de medidas.", $th->getMessage(), 500);
- }
- if ( !$validateExistsMeasure ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD009: No existe la medida #".$requestData['ID_MEDIDA']." en la lista de medidas.", [], 500);
- }
- try {
- $validateExistsEquipment = DB::table('S002V01TEQUI')
- ->where('EQUI_NULI', '=', $requestData['NUMERO_LINEA'])
- ->where('EQUI_COEQ', '=', $requestData['CODIGO_EQUIPAMIENTO'])
- ->exists();
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD010: Ocurrió un error al consultar los equipamientos.", $th->getMessage(), 500);
- }
- if ( !$validateExistsEquipment ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD011: No existe el equipamiento ".$requestData['CODIGO_EQUIPAMIENTO']." en la lista de equipamientos.", [], 500);
- }
- $now = $this->functionsController->now();
- $currentDate = $now->toDateTimeString();
- try {
- $validateUpdate = DB::table('S002V01TBIFA')
- ->where('BIFA_NUFA', '=', $requestData['NUMERO_FALLA'])
- ->where('BIFA_NULI', '=', $requestData['NUMERO_LINEA'])
- ->update([
- 'BIFA_COEQ' => $requestData['CODIGO_EQUIPAMIENTO'],
- 'BIFA_IDFA' => $requestData['ID_FALLA'],
- 'BIFA_IDSI' => $requestData['ID_SINTOMA'],
- 'BIFA_FEFA' => $requestData['FECHA_FALLA'],
- 'BIFA_REPA' => $requestData['REPARABLE'],
- 'BIFA_DESO' => $requestData['SOLUCION'],
- 'BIFA_COME' => $requestData['COMENTARIOS'],
- 'BIFA_VAOB' => $requestData['VALOR_OBTENIDO'],
- 'BIFA_IDME' => $requestData['ID_MEDIDA'],
- 'BIFA_USMO' => $user,
- 'BIFA_FEMO' => $currentDate,
- 'BIFA_FEAR' => DB::raw('CURRENT_TIMESTAMP')
- ]);
- } catch (\Throwable $th) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD012: Ocurrió un error al intentar modificar la falla en la base de datos.", $th->getMessage(), 500);
- }
- if ( !$validateUpdate ) {
- DB::rollBack();
- return $this->responseController->makeResponse(true, "ERR_FAILURELOG_UPD013: No se pudo modificar la bitácora de falla.", [], 500);
- }
- DB::commit();
- return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa");
- }
- }
|