responseController = new ResponseController(); $this->encController = new EncryptionController(); $this->functionsController = new FunctionsController(); } public function getMeasures($user, $line) { try { $getMeasures = DB::table('S002V01TLIME') ->where('LIME_NULI', '=', $line) ->get([ 'LIME_IDME AS ID_MEDIDA', 'LIME_NOME AS NOMBRE_MEDIDA', 'LIME_ACME AS ACRONIMO_MEDIDA', 'LIME_ESTA AS ESTADO', 'LIME_USRE AS USUARIO_REGISTRA ', 'LIME_FERE AS FECHA_REGISTRA', 'LIME_USMO AS USUARIO_MODIFICA', 'LIME_FEMO AS FECHA_MODIFICA', ]); } catch (\Throwable $th) { return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_GET000: No se pudo realizar la consulta a la base.", [], 500); } return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getMeasures); } public function getMeasuresActives($user, $line) { try { $getMeasures = DB::table('S002V01TLIME') ->where('LIME_ESTA', '=', 'Activo') ->where('LIME_NULI', '=', $line) ->get([ 'LIME_IDME AS ID_MEDIDA', 'LIME_NOME AS NOMBRE_MEDIDA', 'LIME_ACME AS ACRONIMO_MEDIDA', 'LIME_USRE AS USUARIO_REGISTRA ', 'LIME_FERE AS FECHA_REGISTRA', 'LIME_USMO AS USUARIO_MODIFICA', 'LIME_FEMO AS FECHA_MODIFICA', ]); } catch (\Throwable $th) { return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_GET000: No se pudo realizar la consulta a la base.", [], 500); } return $this->responseController->makeResponse(false, "ÉXITO: Consulta Exitosa", $getMeasures); } public function registerMeasures(Request $request) { $validator = Validator::make($request->all(), [ 'NOMBRE_MEDIDA' => 'required|string', 'ACRONIMO_MEDIDA' => 'required|string', 'NUMERO_LINEA' => 'required|string', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_MEASUREMENT_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_FAILURES_REG001: No se pudo obtener el usuario.", $th->getMessage(), 500); } $now = $this->functionsController->now(); $currentDate = $now->toDateTimeString(); try { $validateRegister = DB::table('S002V01TLIME')->insert([ 'LIME_NOME' => $requestData['NOMBRE_MEDIDA'], 'LIME_ACME' => $requestData['ACRONIMO_MEDIDA'], 'LIME_NULI' => $requestData['NUMERO_LINEA'], 'LIME_USRE' => $user, 'LIME_FERE' => $currentDate, 'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'), ]); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_REG001: Ocurrió un error al insertar el formulario en la base de datos.", $th->getMessage(), 500); } if (!$validateRegister) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_REG002: No se pudo insertar el formulario en la base de datos.", [], 500); } DB::commit(); return $this->responseController->makeResponse(false, "ÉXITO: Registro Exitoso"); } public function updateMeasures(Request $request) { $validator = Validator::make($request->all(), [ 'ID_MEDIDA' => 'required|string', 'NOMBRE_MEDIDA' => 'required|string', 'ACRONIMO_MEDIDA' => 'required|string', 'NUMERO_LINEA' => 'required|string', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_MEASUREMENT_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($request['USUARIO']); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD001: No se pudo obtener el usuario.", $th->getMessage(), 500); } try { $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500); } if (!$validateExists) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD003: No se pudo encontrar el registro dentro de la base de datos.", [], 500); } $now = $this->functionsController->now(); $currentDate = $now->toDateTimeString(); try { $validateUpdate = DB::table('S002V01TLIME') ->where('LIME_IDME', '=', $requestData['ID_MEDIDA']) ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA']) ->update([ 'LIME_NOME' => $requestData['NOMBRE_MEDIDA'], 'LIME_ACME' => $requestData['ACRONIMO_MEDIDA'], 'LIME_USMO' => $user, 'LIME_FEMO' => $currentDate, 'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'), ]); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD004: Ocurrió un error al modificar el formulario en la base de datos.", $th, 500); } if ( !$validateUpdate ) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_UPD005: No se pudo modificar el formulario en la base de datos.", [], 500); } DB::commit(); return $this->responseController->makeResponse(false, "ÉXITO: Modificación Exitosa"); } public function deleteMeasures(Request $request) { $validator = Validator::make($request->all(), [ 'ID_MEDIDA' => 'required|integer', 'NUMERO_LINEA' => 'required|integer', 'USUARIO' => 'required|string', ]); if ($validator->fails()) { return $this->responseController->makeResponse( true, "ERR_MEASUREMENT_DEL000: Se encontraron uno o más errores.", $this->responseController->makeErrors($validator->errors()->messages()), 401 ); } DB::beginTransaction(); $requestData = $request->all(); try { $user = $this->encController->decrypt($request['USUARIO']); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL001: No se pudo obtener el usuario.", [], 500); } try { $validateExists = DB::table('S002V01TLIME')->where('LIME_IDME', '=', $requestData['ID_MEDIDA'])->exists(); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL002: Ocurrió un error al consultar en la base de datos.", $th->getMessage(), 500); } if (!$validateExists) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL003: La medida no existe.", [], 500); } $now = $this->functionsController->now(); $currentDate = $now->toDateTimeString(); try { $validateDelete = DB::table('S002V01TLIME') ->where('LIME_IDME', '=', $requestData['ID_MEDIDA']) ->where('LIME_NULI', '=', $requestData['NUMERO_LINEA']) ->update([ 'LIME_ESTA' => 'Eliminado', 'LIME_USMO' => $user, 'LIME_FEMO' => $currentDate, 'LIME_FEAR' => DB::raw('CURRENT_TIMESTAMP'), ]); } catch (\Throwable $th) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL004: Ocurrió un error al eliminar la medida base de datos.", $th, 500); } if (!$validateDelete) { DB::rollBack(); return $this->responseController->makeResponse(true, "ERR_MEASUREMENT_DEL005: No se pudo eliminar la medida en la base de datos..", [], 500); } DB::commit(); return $this->responseController->makeResponse(false, "ÉXITO: Eliminación Exitosa"); } }