public Empresa GetEmpresaData(Int64 id) { Empresa empresa = new Empresa(); string consulta = " select id , activo , nombre , abrev , bd_name , desc_id,etl,fec_modif,host,puerto_compania,usuario_etl,moneda_id" + " from empresa where id = @id"; DataRow rdr = _queryExecuter.ExecuteQueryUniqueresult(consulta, new NpgsqlParameter("@id", id)); empresa.id = Convert.ToInt32(rdr["id"]); empresa.desc_id = rdr["desc_id"].ToString().Trim(); empresa.activo = Convert.ToBoolean(rdr["activo"]); empresa.nombre = rdr["nombre"].ToString().Trim(); empresa.abrev = rdr["abrev"].ToString().Trim(); empresa.bd_name = rdr["bd_name"].ToString().Trim(); //empresa.contrasenia_etl = rdr["contrasenia_etl"].ToString().Trim(); empresa.etl = Convert.ToBoolean(rdr["etl"]); empresa.fec_modif = Convert.ToDateTime(rdr["fec_modif"]); empresa.host = rdr["host"].ToString().Trim(); empresa.puerto_compania = Convert.ToInt32(rdr["puerto_compania"]); empresa.usuario_etl = rdr["usuario_etl"].ToString().Trim(); empresa.moneda_id = Convert.ToInt32(rdr["moneda_id"]); return(empresa); }
public RelacionUsrEmprUniCentro findById(Int32 id) { DataRow row = _queryExecuter.ExecuteQueryUniqueresult("select * from relacion_usr_emp_uni_cc where id=@id", new NpgsqlParameter("@id", id)); return(transform(row)); }
public void extraeBalanzaAuto() { logger.Info("inicio de extraeBalanzaAuto"); String consultaExistenRegs = "select count(1) as numRegs from balanza"; bool existenRegs = ToInt64(_queryExecuter.ExecuteQueryUniqueresult(consultaExistenRegs)["numRegs"]) > 0; if (!existenRegs) { extraeBalanza(-1, -1); } else { int anioActual = new DateTime().Year; extraeBalanza(anioActual, anioActual); } }
public ProgramacionProceso GetByClave(string clave) { DataRow dataRow = _queryExecuter.ExecuteQueryUniqueresult( "select clave,descripcion,cron_expresion,id_usuario from programacion_proceso where clave=@clave", new NpgsqlParameter("@clave", clave)); return(dataRow != null?transform(dataRow) : null); }
private Boolean existeRubroTotalIngresos(Int64 idModelo, Int64 idRubro) { string query = "select count(1) as numRubrosTotIng from rubro " + " where activo=true " + " and id_modelo_neg=@id_modelo_neg " + " and es_total_ingresos=true "; if (idRubro > 0) { query += " and id<>" + idRubro; } Int32 numRubrosTotIng = ToInt32(_queryExecuter.ExecuteQueryUniqueresult(query, new NpgsqlParameter("@id_modelo_neg", idModelo))["numRubrosTotIng"]); return(numRubrosTotIng > 0); }
public long addProyecto(Proyecto proyecto) { int existentes = Convert.ToInt32(_queryExecuter.ExecuteQueryUniqueresult( "select count(1) as existentes from proyecto where desc_id=@desc_id and activo=true", new NpgsqlParameter("@desc_id", proyecto.desc_id.Trim()))["existentes"]); if (existentes > 0) { throw new DataException("Ya existe un proyecto registrado con el id=" + proyecto.desc_id); } string add = "insert into " + " proyecto " + "(" + "id" + "," + "desc_id" + "," + "estatus" + "," + "nombre" + "," + "responsable" + "," + "fecha_inicio" + "," + "fecha_fin" + "," + "fecha_creacion" + "," + "fecha_modificacion" + "," + "activo" + ") values " + "(nextval('seq_proyecto'),@desc_id,@estatus,@nombre,@responsable,@fecha_inicio,@fecha_fin,@fecha_fin,@fecha_modificacion,@activo)RETURNING id "; try { { NpgsqlCommand cmd = new NpgsqlCommand(add, con); cmd.Parameters.AddWithValue("@desc_id", proyecto.desc_id.Trim()); cmd.Parameters.AddWithValue("@activo", proyecto.activo); cmd.Parameters.AddWithValue("@estatus", proyecto.estatus.Trim()); cmd.Parameters.AddWithValue("@nombre", proyecto.nombre.Trim()); cmd.Parameters.AddWithValue("@responsable", proyecto.responsable.Trim()); cmd.Parameters.AddWithValue("@fecha_inicio", proyecto.fecha_inicio); cmd.Parameters.AddWithValue("@fecha_fin", proyecto.fecha_fin); cmd.Parameters.AddWithValue("@fecha_creacion", DateTime.Now); cmd.Parameters.AddWithValue("@fecha_modificacion", DateTime.Now); con.Open(); int cantFilAfec = cmd.ExecuteNonQuery(); // obtiene la ultima secuencia usada para la insercion del id cmd.CommandText = "SELECT currval('seq_proyecto') AS lastProyecto"; long idproyecto = (long)cmd.ExecuteScalar(); con.Close(); return(idproyecto); } } catch (Exception ex) { con.Close(); throw; } finally { con.Close(); } }
public int addModeloNegocio(Modelo_Negocio modeloNegocio) { var idModelo = _queryExecuter.ExecuteQueryUniqueresult("select nextval('seq_modelo_neg') as idModelo")["idModelo"]; modeloNegocio.id = Convert.ToInt64(idModelo); string addModelo = "insert into " + "modelo_negocio" + "(" + "id" + "," + "nombre" + "," + "tipo_captura_id, " + "activo," + "agrupador" + ") " + "values " + "(" + " @id," + " @nombre," + "@tipo_captura_id," + "@activo," + " @agrupador" + ")"; int cantFilas = _queryExecuter.execute(addModelo, new NpgsqlParameter("@id", modeloNegocio.id), new NpgsqlParameter("@nombre", modeloNegocio.nombre.Trim()), new NpgsqlParameter("@tipo_captura_id", modeloNegocio.tipo_captura_id), new NpgsqlParameter("@activo", modeloNegocio.activo), new NpgsqlParameter("@agrupador", modeloNegocio.agrupador)); foreach (var idUnidad in modeloNegocio.unidades_negocio_ids) { ModeloUnidadNegocio modeloUnidadNegocio = new ModeloUnidadNegocio(); modeloUnidadNegocio.idModelo = modeloNegocio.id; modeloUnidadNegocio.idUnidad = idUnidad; _modeloUnidadNegocioDataAccessLayer.Add(modeloUnidadNegocio); } return(cantFilas); }
public List <ProformaDetalle> BuildProformaFromModeloAsTemplate(CentroCostos cc, int anio, Int64 idTipoProforma, Int64 idTipoCaptura) { DataRow dataRow = _queryExecuter.ExecuteQueryUniqueresult( "select modelo_negocio_id,modelo_negocio_flujo_id from centro_costo where id=" + cc.id); Int64 idModeloAproformar = -1; Int64 tipoCaptura = idTipoCaptura; if (tipoCaptura == TipoCapturaContable) { idModeloAproformar = ToInt64(dataRow["modelo_negocio_id"]); } else if (tipoCaptura == TipoCapturaFlujo) { idModeloAproformar = ToInt64(dataRow["modelo_negocio_flujo_id"]); } if (idModeloAproformar == -1) { throw new ArgumentException( "No se pudo determinar el modelo con el que se proformara. El tipo de captura recibido fue " + tipoCaptura); } List <Rubros> rubroses = GetRubrosFromModeloId(idModeloAproformar, false); List <ProformaDetalle> detallesAniosAnteriores = new List <ProformaDetalle>(); detallesAniosAnteriores = new ProformaDetalleDataAccessLayer().GetAcumuladoAnteriores(cc.id, cc.empresa_id, idModeloAproformar, cc.proyecto_id, anio, idTipoCaptura); List <ProformaDetalle> detallesAniosPosteriores = new ProformaDetalleDataAccessLayer().GetEjercicioPosterior(anio, cc.id, idModeloAproformar, idTipoCaptura, idTipoProforma); List <ProformaDetalle> proformaDetalles = buildProformaFromTemplate(rubroses, cc.id, anio, idTipoProforma, idTipoCaptura); //--> se colocan los anios posteriores manageAniosAnteriores(proformaDetalles, detallesAniosAnteriores); foreach (ProformaDetalle detalle in proformaDetalles) { foreach (ProformaDetalle posterior in detallesAniosPosteriores) { if (detalle.rubro_id == posterior.rubro_id) { detalle.anios_posteriores_resultado = posterior.anios_posteriores_resultado; } } } return(proformaDetalles); }
public byte[] buildReport(ReportesRequest request) { string queryReporte = _queryExecuter.ExecuteQueryUniqueresult("select contenido from reportes where id=" + request.idReporte)["contenido"].ToString(); DataTable dataTableParams = _queryExecuter.ExecuteQuery("select * from reportes_parametros where id_reporte=" + request.idReporte); Dictionary <string, string> claveTipoParam = new Dictionary <string, string>(); foreach (DataRow parametroRow in dataTableParams.Rows) { claveTipoParam.Add(parametroRow["clave"].ToString(), parametroRow["tipo"].ToString()); } foreach (var parametro in request.parametros) { string claveParametro = parametro.Key; string valorParametro = parametro.Value; if (claveTipoParam[claveParametro].Equals("text") || claveTipoParam[claveParametro].Equals("date")) { if (valorParametro.Trim().Length == 0) { valorParametro = "null"; } else { valorParametro = $"'{valorParametro}'"; } } else { if (valorParametro.Trim().Length == 0) { valorParametro = "null"; } } queryReporte = queryReporte.Replace($"${claveParametro}", $"{valorParametro}"); } DataTable dataTable = _queryExecuter.ExecuteQuery(queryReporte); var package = new ExcelPackage(); var workSheet = package.Workbook.Worksheets.Add("Reporte"); workSheet.Cells["A1"].LoadFromDataTable(dataTable, true); ExcelRange rowEncabezado = workSheet.Cells[1, 1, 1, workSheet.Dimension.End.Column]; rowEncabezado.Style.Font.Color.SetColor(Color.White); rowEncabezado.Style.Font.Bold = true; rowEncabezado.Style.Fill.PatternType = ExcelFillStyle.Solid; rowEncabezado.Style.Fill.BackgroundColor.SetColor(Color.Blue); workSheet.Cells[workSheet.Dimension.Address].AutoFitColumns(); return(package.GetAsByteArray()); }
public Proforma GetProforma(Int64 idProforma) { string consulta = ""; consulta += " select "; consulta += " pf.id, pf.anio, pf.modelo_negocio_id, pf.tipo_captura_id, pf.tipo_proforma_id, "; consulta += " pf.centro_costo_id, pf.activo, pf.usuario, pf.fecha_captura,pf.fecha_actualizacion,pf.unidad_id, "; consulta += " upper(concat(py.nombre, ' | ' , mm.nombre, ' | ', tip.nombre)) as nombre_proforma "; consulta += " from proforma pf "; consulta += " inner join modelo_negocio mm on mm.id = pf.modelo_negocio_id "; consulta += " inner join centro_costo cc on cc.id = pf.centro_costo_id "; consulta += " inner join proyecto py on py.id = cc.proyecto_id "; consulta += " inner join tipo_proforma tip on pf.tipo_proforma_id = tip.id "; consulta += " where pf.activo = 'true' "; consulta += " and pf.id = " + idProforma; DataRow rdr = _queryExecuter.ExecuteQueryUniqueresult(consulta); Proforma proforma = new Proforma(); proforma.id = Convert.ToInt64(rdr["id"]); proforma.anio = Convert.ToInt32(rdr["anio"]); proforma.modelo_negocio_id = Convert.ToInt64(rdr["modelo_negocio_id"]); proforma.tipo_captura_id = Convert.ToInt64(rdr["tipo_captura_id"]); proforma.tipo_proforma_id = Convert.ToInt64(rdr["tipo_proforma_id"]); proforma.centro_costo_id = Convert.ToInt64(rdr["centro_costo_id"]); proforma.activo = Convert.ToBoolean(rdr["activo"]); proforma.usuario = Convert.ToInt64(rdr["usuario"]); proforma.unidad_id = Convert.ToInt64(rdr["unidad_id"]); proforma.fecha_captura = Convert.ToDateTime(rdr["fecha_captura"]); if (rdr["fecha_actualizacion"] != DBNull.Value) { proforma.fecha_actualizacion = Convert.ToDateTime(rdr["fecha_actualizacion"]); } proforma.nombre_proforma = Convert.ToString(rdr["nombre_proforma"]); return(proforma); }
private Moneda findIdMonedaByCentroCosto(Int64 idCC) { string query = "select cc.id as idcc,cc.empresa_id as idempresa,m.id as idmoneda, m.clave as claveMoneda " + " from centro_costo cc join empresa e on cc.empresa_id = e.id " + " join moneda m on e.moneda_id = m.id " + " where cc.activo=true and e.activo=true and m.activo=true and cc.id=" + idCC; DataRow res = _queryExecuter.ExecuteQueryUniqueresult(query); if (res == null) { throw new DataException("No se encontro una moneda asociado a la empresa del centro de costro '" + idCC + "'"); } Moneda moneda = new Moneda(); moneda.id = ToInt64(res["idmoneda"]); moneda.clave = res["claveMoneda"].ToString(); return(moneda); }
public ModeloUnidadNegocio findByIdModeloAndIdUnidad(Int64 idModelo, Int64 idUnidad) { DataRow rdr = _queryExecuter.ExecuteQueryUniqueresult( "select id_unidad,id_modelo,activo from modelo_unidad where activo=true " + " and id_modelo=@id_modelo " + " and id_unidad=@id_unidad", new NpgsqlParameter("@id_modelo", idModelo), new NpgsqlParameter("@id_unidad", idUnidad)); ModeloUnidadNegocio modeloUnidadNegocio = new ModeloUnidadNegocio(); modeloUnidadNegocio.idModelo = Convert.ToInt64(rdr["id_modelo"]); modeloUnidadNegocio.idUnidad = Convert.ToInt64(rdr["id_unidad"]); modeloUnidadNegocio.activo = Convert.ToBoolean(rdr["activo"]); return(modeloUnidadNegocio); }
public List <ProformaDetalle> GetProformaDetalle(Int64 idProforma) { string consulta = ""; consulta += " select "; consulta += " det.id, det.id_proforma, det.rubro_id, rub.nombre as nombre_rubro,rub.hijos,rub.aritmetica, rub.clave,rub.es_total_ingresos,"; consulta += " coalesce(ejercicio_resultado, 0) as ejercicio_resultado, "; consulta += " coalesce(enero_monto_resultado, 0) as enero_monto_resultado, "; consulta += " coalesce(febrero_monto_resultado, 0) as febrero_monto_resultado, "; consulta += " coalesce(marzo_monto_resultado, 0) as marzo_monto_resultado, "; consulta += " coalesce(abril_monto_resultado, 0) as abril_monto_resultado, "; consulta += " coalesce(mayo_monto_resultado, 0) as mayo_monto_resultado, "; consulta += " coalesce(junio_monto_resultado, 0) as junio_monto_resultado, "; consulta += " coalesce(julio_monto_resultado, 0) as julio_monto_resultado, "; consulta += " coalesce(agosto_monto_resultado, 0) as agosto_monto_resultado, "; consulta += " coalesce(septiembre_monto_resultado, 0) as septiembre_monto_resultado, "; consulta += " coalesce(octubre_monto_resultado, 0) as octubre_monto_resultado, "; consulta += " coalesce(noviembre_monto_resultado, 0) as noviembre_monto_resultado, "; consulta += " coalesce(diciembre_monto_resultado, 0) as diciembre_monto_resultado, "; consulta += " coalesce(total_resultado, 0) as total_resultado, "; consulta += " coalesce(acumulado_resultado, 0) as acumulado_resultado, "; consulta += " coalesce(valor_tipo_cambio_resultado, 0) as valor_tipo_cambio_resultado "; consulta += " from proforma_detalle det "; consulta += " inner join rubro rub on det.rubro_id = rub.id "; consulta += " where id_proforma = " + idProforma; consulta += " and det.activo = 'true' "; List <ProformaDetalle> lstProformaDetalle = new List <ProformaDetalle>(); DataTable dataTable = _queryExecuter.ExecuteQuery(consulta.Trim()); foreach (DataRow rdr in dataTable.Rows) { ProformaDetalle proforma_detalle = new ProformaDetalle(); proforma_detalle.id = ToInt64(rdr["id"]); proforma_detalle.id_proforma = ToInt64(rdr["id_proforma"]); proforma_detalle.rubro_id = ToInt64(rdr["rubro_id"]); proforma_detalle.nombre_rubro = Convert.ToString(rdr["nombre_rubro"]); proforma_detalle.aritmetica = Convert.ToString(rdr["aritmetica"]); proforma_detalle.es_total_ingresos = ToBoolean(rdr["es_total_ingresos"]); proforma_detalle.ejercicio_resultado = ToDouble(rdr["ejercicio_resultado"]); proforma_detalle.enero_monto_resultado = ToDouble(rdr["enero_monto_resultado"]); proforma_detalle.febrero_monto_resultado = ToDouble(rdr["febrero_monto_resultado"]); proforma_detalle.marzo_monto_resultado = ToDouble(rdr["marzo_monto_resultado"]); proforma_detalle.abril_monto_resultado = ToDouble(rdr["abril_monto_resultado"]); proforma_detalle.mayo_monto_resultado = ToDouble(rdr["mayo_monto_resultado"]); proforma_detalle.junio_monto_resultado = ToDouble(rdr["junio_monto_resultado"]); proforma_detalle.julio_monto_resultado = ToDouble(rdr["julio_monto_resultado"]); proforma_detalle.agosto_monto_resultado = ToDouble(rdr["agosto_monto_resultado"]); proforma_detalle.septiembre_monto_resultado = ToDouble(rdr["septiembre_monto_resultado"]); proforma_detalle.octubre_monto_resultado = ToDouble(rdr["octubre_monto_resultado"]); proforma_detalle.noviembre_monto_resultado = ToDouble(rdr["noviembre_monto_resultado"]); proforma_detalle.diciembre_monto_resultado = ToDouble(rdr["diciembre_monto_resultado"]); proforma_detalle.total_resultado = ToDouble(rdr["total_resultado"]); proforma_detalle.acumulado_resultado = ToDouble(rdr["acumulado_resultado"]); proforma_detalle.valor_tipo_cambio_resultado = ToDouble(rdr["valor_tipo_cambio_resultado"]); //proforma_detalle.activo = ToBoolean(rdr["activo"]); proforma_detalle.hijos = rdr["hijos"].ToString(); proforma_detalle.clave_rubro = rdr["clave"].ToString(); lstProformaDetalle.Add(proforma_detalle); } Proforma pro = _proformaDataAccessLayer.GetProforma(idProforma); Boolean hayPeriodoActivo = _profHelper.existePeridodoActivo(pro.anio, pro.tipo_proforma_id, pro.tipo_captura_id); Int64 idEmpresa = ToInt64(_queryExecuter.ExecuteQueryUniqueresult( "select empresa_id from centro_costo where id =" + pro.centro_costo_id)["empresa_id"]); List <ProformaDetalle> detallesAniosPosteriores = GetEjercicioPosterior(pro.anio, pro.centro_costo_id, pro.modelo_negocio_id, pro.tipo_captura_id, pro.tipo_proforma_id); lstProformaDetalle.ForEach(detalle => { detalle.editable = hayPeriodoActivo; detalle.mes_inicio = _profHelper.getMesInicio(pro.tipo_proforma_id); detalle.modelo_negocio_id = pro.modelo_negocio_id; detalle.anio = pro.anio; detalle.centro_costo_id = pro.centro_costo_id; detalle.tipo_proforma_id = pro.tipo_proforma_id; detalle.tipo_captura_id = pro.tipo_captura_id; detalle.empresa_id = idEmpresa; detalle.unidad_id = pro.unidad_id; detallesAniosPosteriores.ForEach(posterior => { if (detalle.rubro_id == posterior.rubro_id) { detalle.anios_posteriores_resultado = posterior.anios_posteriores_resultado; } }); }); return(_profHelper.reorderConceptos(lstProformaDetalle)); }