responseController = new ResponseController(); $this->encController = new EncryptionController(); } public function getSymptom($line) { try { $getSymptom = DB::table('S002V01TSINT') ->join('S002V01TLIFA', 'SINT_IDFA', '=', 'LIFA_IDFA') ->join('S002V01TLIME', 'SINT_IDME', '=', 'LIME_IDME') ->where('SINT_NULI', '=', $line) ->get([ 'SINT_NUSI', // NUMERO_SINTOMA 'SINT_COEQ', // CODIGO_EQUIPAMIENTO 'SINT_IDFA', // ID_FALLA 'LIFA_NOFA', // NOMBRE_FALLA 'SINT_CAUS', // CAUSA 'SINT_CLAS', // CLASIFICACION 'SINT_COME', // COMENTARIOS 'SINT_LIVA', // LIMITE_VALOR 'SINT_IDME', // ID_MEDIDA 'LIME_MEDI', // NOMBRE_MEDIDA 'LIME_ACRO', // ACRONIMO_MEDIDA 'SINT_ESTA', // ESTADO 'SINT_USRE', // USUARIO_REGISTRA 'SINT_FERE', // FECHA_REGISTRA 'SINT_USMO', // USUARIO_MODIFICA 'SINT_FEMO', // FECHA_MODIFICA ]); } catch (\Throwable $th) { return $this->responseController->makeResponse(true, "ERR_SYMPTOM_GET000: No se pudo realizar la consulta a la base.", [], 500); } return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getSymptom); } public function registerSymptom(Request $request) { $validator = Validator::make($request->all(), [ 'CODIGO_EQUIPAMIENTO' => 'required|string', 'ID_FALLA' => 'required|string', 'CAUSA' => 'required|string', 'CLASIFICACION' => 'required|string', 'COMENTARIOS' => 'required|string', 'LIMITE_VALOR' => 'required|string', 'ID_MEDIDA' => 'required|string', 'NUMERO_LINEA' => 'required|string', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_SYMPTOM_REG000: Se encontraron uno o más errores.", $this->responseController->makeErrors($validator->errors()->messages()), 401 ); } DB::beginTransaction(); $request = $request->all(); try { $user = $this->encController->decrypt($request['USUARIO']); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG001: No se pudo obtener el usuario.", [], 500); } $line = $request['NUMERO_LINEA']; $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(); // Se valida que exista el ID de la lista de medidas try { $existMeasure = DB::table('S002V01TLIME') ->where('LIME_IDME', '=', $request['ID_MEDIDA']) ->where('LIME_NULI', '=', $line) ->where('LIME_ESTA', '=', 'Activo') ->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG002: Ocurrió al consultar la lista de medidas.", [], 500); } if ( !$existMeasure ) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG003: No existe la medida seleccionada.", [], 500); } // Se valida que exista el ID de la lista de fallas try { $existFailure = DB::table('S002V01TLIFA') ->where('LIFA_IDFA', '=', $request['ID_FALLA']) ->where('LIFA_NULI', '=', $line) ->where('LIFA_ESTA', '=', 'Activo') ->get(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG004: Ocurrió un error al consultar en la base de datos.", [], 500); } if (!$existFailure) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG005: No se pudo encontrar el registro dentro de la base de datos.", [], 500); } $arrInsert = [ 'SINT_COEQ' => trim($request['CODIGO_EQUIPAMIENTO']), 'SINT_IDFA' => trim($request['ID_FALLA']), 'SINT_CAUS' => trim($request['CAUSA']), 'SINT_CLAS' => trim($request['CLASIFICACION']), 'SINT_COME' => trim($request['COMENTARIOS']), 'SINT_LIVA' => trim($request['LIMITE_VALOR']), 'SINT_IDME' => trim($request['ID_MEDIDA']), 'SINT_NULI' => $line, 'SINT_USRE' => $user, 'SINT_FERE' => $currentDate, 'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP') ]; try { $response = DB::table('S002V01TSINT')->insert($arrInsert); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG006: Ocurrió un error al insertar el formulario en la base de datos.", [], 500); } if (!$response) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_REG007: No se pudo insertar el formulario en la base de datos.", [], 500); } DB::commit(); return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso"); } public function updateSymptom(Request $request) { $validator = Validator::make($request->all(), [ 'NUMERO_SINTOMA' => 'required|string', 'CODIGO_EQUIPAMIENTO' => 'required|string', 'ID_FALLA' => 'required|string', 'CAUSA' => 'required|string', 'CLASIFICACION' => 'required|string', 'COMENTARIOS' => 'required|string', 'LIMITE_VALOR' => 'required|string', 'ID_MEDIDA' => 'required|string', 'NUMERO_LINEA' => 'required|string', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_SYMPTOM_UPD000: Se encontraron uno o más errores.", $this->responseController->makeErrors($validator->errors()->messages()), 401 ); } DB::beginTransaction(); $request = $request->all(); try { $user = $this->encController->decrypt($request['USUARIO']); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD001: No se pudo obtener el usuario.", [], 500); } $line = $request['NUMERO_LINEA']; $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(); // Se valida que exista el ID del síntoma try { $exist = DB::table('S002V01TSINT') ->where('SINT_NUSI', '=', $request['NUMERO_SINTOMA']) ->where('SINT_NULI', '=', $line) ->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD002: Ocurrió un error al consultar en la base de datos.", [], 500); } if (!$exist) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD003: No se pudo encontrar el registro dentro de la base de datos.", [], 500); } // Se valida que exista el ID de la lista de medidas try { $existMeasure = DB::table('S002V01TLIME') ->where('LIME_IDME', '=', $request['ID_MEDIDA']) ->where('LIME_NULI', '=', $line) ->where('LIME_ESTA', '=', 'Activo') ->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD004: Ocurrió al consultar la lista de medidas.", [], 500); } if ( !$existMeasure ) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD005: No existe la medida seleccionada.", [], 500); } // Se valida que exista el ID de la lista de fallas try { $existFailure = DB::table('S002V01TLIFA') ->where('LIFA_IDFA', '=', $request['ID_FALLA']) ->where('LIFA_NULI', '=', $line) ->where('LIFA_ESTA', '=', 'Activo') ->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD006: Ocurrió un error al consultar la lista de fallas.", [], 500); } if (!$existFailure) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD007: No existe la falla seleccionada.", [], 500); } $arrUpdate = [ 'SINT_COEQ' => trim($request['CODIGO_EQUIPAMIENTO']), 'SINT_IDFA' => trim($request['ID_FALLA']), 'SINT_CAUS' => trim($request['CAUSA']), 'SINT_CLAS' => trim($request['CLASIFICACION']), 'SINT_COME' => trim($request['COMENTARIOS']), 'SINT_LIVA' => trim($request['LIMITE_VALOR']), 'SINT_IDME' => trim($request['ID_MEDIDA']), 'SINT_USMO' => $user, 'SINT_FEMO' => $currentDate, 'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP') ]; try { $response = DB::table('S002V01TSINT')->where('SINT_NUSI', '=', $request['NUMERO_SINTOMA'])->where('SINT_NULI', '=', $line)->update($arrUpdate); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD008: Ocurrió un error al modificar el formulario en la base de datos.", [], 500); } if (!$response) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_UPD009: No se pudo modificar el formulario en la base de datos.", [], 500); } DB::commit(); return $this->responseController->makeResponse(true, "EXITO: Modificación Exitosa"); } public function deleteSymptom(Request $request) { $validator = Validator::make($request->all(), [ 'NUMERO_SINTOMA' => 'required|string', 'NUMERO_LINEA' => 'required|string', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_SYMPTOM_DEL000: Se encontraron uno o más errores.", $this->responseController->makeErrors($validator->errors()->messages()), 401 ); } DB::beginTransaction(); $request = $request->all(); $idSymptom = trim($request['NUMERO_SINTOMA']); $line = $request['NUMERO_LINEA']; $currentDate = Carbon::now()->timezone('America/Mazatlan')->toDateTimeString(); try { $user = $this->encController->decrypt($request['USUARIO']); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL001: No se pudo obtener el usuario.", [], 500); } try { $exist = DB::table('S002V01TSINT') ->where('SINT_NUSI', '=', $idSymptom) ->where('SINT_NULI', '=', $line) ->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL002: Ocurrió un error al consultar en la base de datos.", [], 500); } if (!$exist) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL003: No se pudo encontrar el registro dentro de la base de datos.", [], 500); } $arrUpdate = [ 'SINT_ESTA' => 'Eliminado', 'SINT_USMO' => $user, 'SINT_FEMO' => $currentDate, 'SINT_FEAR' => DB::raw('CURRENT_TIMESTAMP'), ]; try { $response = DB::table('S002V01TSINT')->where('SINT_NUSI', '=', $idSymptom)->where('SINT_NULI', '=', $line)->update($arrUpdate); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL004: Ocurrió un error al modificar el formulario en la base de datos.", [], 500); } if (!$response) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_SYMPTOM_DEL005: No se pudo modificar el formulario en la base de datos.", [], 500); } DB::commit(); return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa"); } }