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) { $arrResponseCheckUser = $this->resourcesController->checkUserEnc($user, $line); if ($arrResponseCheckUser['error']) { DB::rollBack(); return $this->responseController->makeResponse(true, $arrResponseCheckUser['msg'], [], 401); } 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'; $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' => $failureLogTemp['USUARIO_REGISTRA'], 'FECHA_REGISTRA' => $failureLogTemp['FECHA_REGISTRA'], 'USUARIO_MODIFICA' =>$failureLogTemp['USUARIO_MODIFICA'], 'FECHA_MODIFICA' => $failureLogTemp['FECHA_MODIFICA'], ]; } $responseCheckLatestUpdate = $this->resourcesController->checkLatestUpdate($arrFailureLog, $line); if ($responseCheckLatestUpdate['error']) { return $this->responseController->makeResponse(true, $responseCheckLatestUpdate['msg'], [], 500); } $arrFailureLog = $responseCheckLatestUpdate['response']; 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 ); } if ($_SERVER['SERVER_NAME'] === '192.168.100.105') { $urlPublic = 'http://192.168.100.105:8000/public_files/' . $fileName; } else { $urlPublic = $this->functionsController->getApiURI().'sam/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 = '