Ejemplo n.º 1
0
        private List <ProformaDetalle> manageDetalles(List <ProformaDetalle> detallesFromExcel)
        {
            //return detallesFromExcel;
            ProformaDetalle        datosProforma       = detallesFromExcel[0];
            List <ProformaDetalle> detallesProformados = detallesFromExcel.FindAll(detalle =>
            {
                return(detalle.tipo.Equals(TIPODETPROFORM));
            });
            List <ProformaDetalle> detallesReales = detallesFromExcel.FindAll(detalle =>
            {
                return(detalle.tipo.Equals(TIPODETPROREAL));
            });
            List <ProformaDetalle> detallesProforma = new List <ProformaDetalle>();

            if (datosProforma.id_proforma > 0) //es una proforma guardada
            {
                detallesProforma = _proformaDetalleDataAccessLayer.GetProformaDetalle(datosProforma.id_proforma);
                applyValuesFrom(detallesProformados, detallesProforma, datosProforma.mes_inicio);
            }
            else //no es una proforma guardada
            {
                detallesProforma = _proformaDataAccessLayer.manageBuildProforma(datosProforma.centro_costo_id,
                                                                                datosProforma.anio, datosProforma.tipo_proforma_id, datosProforma.tipo_captura_id);

                string proyeccion = _proformaDataAccessLayer.ObtenerDatosCC(datosProforma.centro_costo_id).proyeccion;
                if (proyeccion.Equals(ProyeccionMetodo))
                {
                    applyValuesFrom(detallesReales, detallesProforma, 0);
                }

                applyValuesFrom(detallesProformados, detallesProforma, datosProforma.mes_inicio);
            }

            return(detallesProforma);
        }
Ejemplo n.º 2
0
        private bool evaluaDetalleTotal(ProformaDetalle detalleTotal, List <ProformaDetalle> allDetalles)
        {
            var evaluado    = false;
            var aritmeticas = new Dictionary <string, string>();

            aritmeticas["enero_monto"]       = detalleTotal.aritmetica;
            aritmeticas["febrero_monto"]     = detalleTotal.aritmetica;
            aritmeticas["marzo_monto"]       = detalleTotal.aritmetica;
            aritmeticas["abril_monto"]       = detalleTotal.aritmetica;
            aritmeticas["mayo_monto"]        = detalleTotal.aritmetica;
            aritmeticas["junio_monto"]       = detalleTotal.aritmetica;
            aritmeticas["julio_monto"]       = detalleTotal.aritmetica;
            aritmeticas["agosto_monto"]      = detalleTotal.aritmetica;
            aritmeticas["septiembre_monto"]  = detalleTotal.aritmetica;
            aritmeticas["octubre_monto"]     = detalleTotal.aritmetica;
            aritmeticas["noviembre_monto"]   = detalleTotal.aritmetica;
            aritmeticas["diciembre_monto"]   = detalleTotal.aritmetica;
            aritmeticas["ejercicio"]         = detalleTotal.aritmetica;
            aritmeticas["acumulado"]         = detalleTotal.aritmetica;
            aritmeticas["anios_posteriores"] = detalleTotal.aritmetica;
            aritmeticas["total"]             = detalleTotal.aritmetica;
            NumberFormatInfo nfi  = new NumberFormatInfo();
            List <String>    keys = new List <string>();

            foreach (var key in aritmeticas.Keys)
            {
                keys.Add(key);
            }
            allDetalles.ForEach(detalle =>
            {
                var detalleClave = detalle.clave_rubro;
                if (detalleTotal.aritmetica.Contains(detalleClave))
                {
                    foreach (var key in keys)
                    {
                        aritmeticas[key] = aritmeticas[key].Replace(detalleClave,
                                                                    ((Double)detalle[key + "_resultado"]).ToString(nfi));
                    }
                }
            });
            DataTable dt = new DataTable();

            foreach (var key in keys)
            {
                try
                {
                    detalleTotal[key + "_resultado"] = ToDouble(dt.Compute(aritmeticas[key], ""));
                    evaluado = true;
                }
                catch (Exception e)
                {
                    logger.Error(e, "Error de evaluacion de la expresion");
                    evaluado = false;
                    break;
                }
            }

            return(evaluado);
        }
Ejemplo n.º 3
0
 private void applyValuesFrom(List <ProformaDetalle> source, List <ProformaDetalle> target, int mesInicio)
 {
     source.ForEach(dProformado =>
     {
         ProformaDetalle dFound = target.Find(it => it.rubro_id == dProformado.rubro_id);
         setDatosProformadosEnDetalle(dProformado, dFound, mesInicio);
     });
 }
Ejemplo n.º 4
0
 private void setDatosProformadosEnDetalle(ProformaDetalle profomado, ProformaDetalle original, int mesInicio)
 {
     foreach (KeyValuePair <string, Int32> entry in getPonderacionCampos())
     {
         if (entry.Value > mesInicio)
         {
             original[entry.Key] = profomado[entry.Key];
         }
     }
 }
Ejemplo n.º 5
0
        public List <ProformaDetalle> getAjustes(Int64 idCC, int anio, Int64 idTipoCaptura)
        {
            logger.Info("getAjustes <-- start");
            List <ProformaDetalle> proformaDetalles = new List <ProformaDetalle>();

            if (idTipoCaptura == TipoCapturaContable) //Los ajustes solo son para contable
            {
                Dictionary <string, string> mesValor = getPonderacionMeses();
                DataRow dr = _queryExecuter.ExecuteQueryUniqueresult(
                    "select cc.desc_id  as idcc,em.desc_id as idem from centro_costo cc  join empresa em on  em.id=cc.empresa_id where cc.id =@idCC",
                    new NpgsqlParameter("@idCC", idCC));

                Object empresaId = dr["idem"];
                Object centroId  = dr["idcc"];

                DataTable ajustesDt = _queryExecuterSql.ExecuteQuerySQL("select ingreso, directo, indirecto, mes " +
                                                                        " from Tb_Ajustes_registro " +
                                                                        " where empresa = @empresaId" +
                                                                        " and centrocosto = @centroId" +
                                                                        " and anio =@anio",
                                                                        new SqlParameter("@empresaId", empresaId),
                                                                        new SqlParameter("@centroId", centroId),
                                                                        new SqlParameter("@anio", empresaId)
                                                                        );
                DataRow dataRow =
                    _queryExecuter.ExecuteQueryUniqueresult("select modelo_negocio_id from centro_costo where id=@idCC"
                                                            , new NpgsqlParameter("@idCC", idCC));
                List <Rubros> rubroses = GetRubrosFromModeloId(ToInt64(dataRow["modelo_negocio_id"]), false);
                rubroses.ForEach(rubro =>
                {
                    ProformaDetalle detalle = new ProformaDetalle();
                    detalle.rubro_id        = rubro.id;
                    detalle.tipo_cuenta     = rubro.tipo_cuenta;
                    proformaDetalles.Add(detalle);
                });
                proformaDetalles.ForEach(detalle =>
                {
                    foreach (DataRow ajusteRow in ajustesDt.Rows)
                    {
                        Object mesData = ajusteRow["mes"];
                        if (mesData != null)
                        {
                            if (detalle.tipo_cuenta != null && detalle.tipo_cuenta.Trim().Length > 0)
                            {
                                detalle[mesValor[mesData.ToString()]] = ToDouble(ajusteRow[detalle.tipo_cuenta]);
                            }
                        }
                    }
                });
            }
            logger.Info("ajustes encotrados='{0}'", proformaDetalles.Count);
            return(proformaDetalles);
        }
Ejemplo n.º 6
0
        //Calculo de años posteriores
        public List <ProformaDetalle> GetEjercicioPosterior(int anio, Int64 idCenCos, Int64 idModNeg, Int64 idTipoCaptura, Int64 idTipoProforma)
        {
            string consulta = "";

            consulta +=
                " select prf.centro_costo_id, prf.modelo_negocio_id, prf.tipo_captura_id, prf.tipo_proforma_id, prf.anio, ";
            consulta += " 	coalesce (";
            consulta += " 	sum(det.enero_monto_resultado) + ";
            consulta += " 	sum(det.febrero_monto_resultado) + ";
            consulta += " 	sum(det.marzo_monto_resultado) + ";
            consulta += " 	sum(det.abril_monto_resultado) + ";
            consulta += " 	sum(det.mayo_monto_resultado) + ";
            consulta += " 	sum(det.junio_monto_resultado) + ";
            consulta += " 	sum(det.julio_monto_resultado) + ";
            consulta += " 	sum(det.agosto_monto_resultado) + ";
            consulta += " 	sum(det.septiembre_monto_resultado) + ";
            consulta += " 	sum(det.octubre_monto_resultado) + ";
            consulta += " 	sum(det.noviembre_monto_resultado) + ";
            consulta += " 	sum(det.diciembre_monto_resultado) ";
            consulta += " 	, 0) as anios_posteriores_resultado, det.rubro_id as rubro_id ";
            consulta += " 	from proforma_detalle det ";
            consulta += " 	inner join proforma prf on det.id_proforma = prf.id ";
            consulta += " 	where prf.anio > "+ anio;      // Anios posteriores a la proforma actual
            consulta += " 	and prf.centro_costo_id = "+ idCenCos;
            consulta += " 	and prf.modelo_negocio_id = "+ idModNeg;
            consulta += " 	and prf.tipo_captura_id = "+ idTipoCaptura;
            // consulta += "    and prf.tipo_proforma_id = " + idTipoProforma;
            consulta += " 	and prf.activo = 'true' ";
            consulta +=
                " 	group by prf.centro_costo_id, prf.modelo_negocio_id, prf.tipo_captura_id, prf.tipo_proforma_id, prf.anio, det.rubro_id ";


            List <ProformaDetalle> lstProfDetalleAniosPost = new List <ProformaDetalle>();
            DataTable dataTable = _queryExecuter.ExecuteQuery(consulta.Trim());

            foreach (DataRow rdr in dataTable.Rows)
            {
                ProformaDetalle proforma_detalle_anios_post = new ProformaDetalle();
                proforma_detalle_anios_post.centro_costo_id   = ToInt64(rdr["centro_costo_id"]);
                proforma_detalle_anios_post.modelo_negocio_id = ToInt64(rdr["modelo_negocio_id"]);
                proforma_detalle_anios_post.tipo_captura_id   = ToInt64(rdr["tipo_captura_id"]);
                proforma_detalle_anios_post.tipo_proforma_id  = ToInt64(rdr["tipo_proforma_id"]);
                proforma_detalle_anios_post.anio = ToInt32(rdr["anio"]);
                proforma_detalle_anios_post.anios_posteriores_resultado = ToDouble(rdr["anios_posteriores_resultado"]);
                proforma_detalle_anios_post.rubro_id = ToInt64(rdr["rubro_id"]);
                lstProfDetalleAniosPost.Add(proforma_detalle_anios_post);
            }


            return(lstProfDetalleAniosPost);
        }
Ejemplo n.º 7
0
 private void renderDatosOcultos(ExcelRange cells, int posY, ProformaDetalle det)
 {
     applyStyleOculto(makeCellValue(cells, posY, pos_id_proforma, det.id_proforma));
     applyStyleOculto(makeCellValue(cells, posY, pos_mes_inicio, det.mes_inicio));
     applyStyleOculto(makeCellValue(cells, posY, pos_centro_costo_id, det.centro_costo_id));
     applyStyleOculto(makeCellValue(cells, posY, pos_anio, det.anio));
     applyStyleOculto(makeCellValue(cells, posY, pos_tipo_proforma_id, det.tipo_proforma_id));
     applyStyleOculto(makeCellValue(cells, posY, pos_tipo_captura_id, det.tipo_captura_id));
     applyStyleOculto(makeCellValue(cells, posY, pos_idInterno, det.idInterno));
     applyStyleOculto(makeCellValue(cells, posY, pos_clave_rubro, det.clave_rubro));
     applyStyleOculto(makeCellValue(cells, posY, pos_rubro_id, det.rubro_id));
     applyStyleOculto(makeCellValue(cells, posY, pos_tipo, det.tipo == null ? "" : det.tipo));
     applyStyleOculto(makeCellValue(cells, posY, pos_estilo, det.estilo));
     applyStyleOculto(makeCellValue(cells, posY, pos_aritmetica, det.aritmetica == null ? "" : det.aritmetica));
     applyStyleOculto(makeCellValue(cells, posY, pos_id_detalle, det.id));
     applyStyleOculto(makeCellValue(cells, posY, pos_es_total_ingresos, det.es_total_ingresos));
 }
Ejemplo n.º 8
0
        public List <ProformaDetalle> buildProformaFromTemplate(List <Rubros> rubroses, Int64 idCC, int anio,
                                                                Int64 idTipoProforma, Int64 idTipoCaptura)
        {
            List <Rubros>          rubrosesreoder = reorderConceptos(rubroses);
            List <ProformaDetalle> detalles       = new List <ProformaDetalle>();

            Int32 mesInicio = getMesInicio(idTipoProforma);

            rubrosesreoder.ForEach(actual =>
            {
                ProformaDetalle detalle   = new ProformaDetalle();
                detalle.mes_inicio        = mesInicio;
                detalle.modelo_negocio_id = actual.id_modelo_neg;
                detalle.anio             = anio;
                detalle.centro_costo_id  = idCC;
                detalle.tipo_proforma_id = idTipoProforma;
                detalle.tipo_captura_id  = idTipoCaptura;

                detalle.activo                     = true;
                detalle.rubro_id                   = actual.id;
                detalle.nombre_rubro               = actual.nombre;
                detalle.clave_rubro                = actual.clave;
                detalle.hijos                      = actual.hijos;
                detalle.enero_monto_resultado      = 0;
                detalle.febrero_monto_resultado    = 0;
                detalle.marzo_monto_resultado      = 0;
                detalle.abril_monto_resultado      = 0;
                detalle.mayo_monto_resultado       = 0;
                detalle.junio_monto_resultado      = 0;
                detalle.julio_monto_resultado      = 0;
                detalle.agosto_monto_resultado     = 0;
                detalle.septiembre_monto_resultado = 0;
                detalle.octubre_monto_resultado    = 0;
                detalle.noviembre_monto_resultado  = 0;
                detalle.diciembre_monto_resultado  = 0;
                detalle.ejercicio_resultado        = 0;
                detalle.aritmetica                 = actual.aritmetica;
                detalle.es_total_ingresos          = actual.es_total_ingresos;
                detalles.Add(detalle);
            });
            return(detalles);
        }
Ejemplo n.º 9
0
        private void sumColumnsForDetalle(ProformaDetalle detalle, string targetColumn,
                                          string[] columnsNames)
        {
            var suma = 0.0;

            for (var j = 0; j < columnsNames.Length; j++)
            {
                var colName = columnsNames[j];
                try
                {
                    suma += ToDouble(detalle[colName]);
                }
                catch (Exception e)
                {
                    logger.Warn("La columna " + colName + "del detalle " + detalle.nombre_rubro + ", no es numero");
                }
            }

            detalle[targetColumn] = suma;
        }
Ejemplo n.º 10
0
        private ProformaDetalle transform(ExcelRange cells, int posRow)
        {
            ProformaDetalle det = new ProformaDetalle();

            det.nombre_rubro      = cells[posRow, pos_nrubro].Value.ToString();
            det.es_total_ingresos = ToBoolean(cells[posRow, pos_es_total_ingresos].Value);
            cells[posRow, pos_total].Calculate();
            det.total_resultado     = ToDouble(cells[posRow, pos_total].Value);
            det.acumulado_resultado = ToDouble(cells[posRow, pos_aant].Value);
            det.ejercicio_resultado = ToDouble(cells[posRow, pos_ejercicio].Value);

            foreach (KeyValuePair <string, Int32> entry in getPonderacionCampos())
            {
                int ponderacion   = entry.Value;
                int posicionCelda = ponderacion + (POS_COL_ENERO - 1);
                if (ponderacion > 0)
                {
                    det[entry.Key] = ToDouble(cells[posRow, posicionCelda].Value);
                }
            }

            det.anios_posteriores_resultado = ToDouble(cells[posRow, pos_apost].Value);

            det.id_proforma      = ToInt64(cells[posRow, pos_id_proforma].Value);
            det.mes_inicio       = ToInt32(cells[posRow, pos_mes_inicio].Value);
            det.centro_costo_id  = ToInt64(cells[posRow, pos_centro_costo_id].Value);
            det.anio             = ToInt32(cells[posRow, pos_anio].Value);
            det.tipo_proforma_id = ToInt64(cells[posRow, pos_tipo_proforma_id].Value);
            det.tipo_captura_id  = ToInt64(cells[posRow, pos_tipo_captura_id].Value);
            det.idInterno        = cells[posRow, pos_idInterno].Value.ToString();
            det.clave_rubro      = cells[posRow, pos_clave_rubro].Value.ToString();
            det.rubro_id         = ToInt64(cells[posRow, pos_rubro_id].Value);
            det.tipo             = cells[posRow, pos_tipo].Value.ToString();
            det.estilo           = cells[posRow, pos_estilo].Value.ToString();
            det.aritmetica       = cells[posRow, pos_aritmetica].Value.ToString();
            det.id = ToInt64(cells[posRow, pos_id_detalle].Value);
            det.es_total_ingresos = ToBoolean(cells[posRow, pos_es_total_ingresos].Value);


            return(det);
        }
Ejemplo n.º 11
0
        private void renderDetallePadre(ExcelRange cells, int pos, ProformaDetalle det,
                                        Dictionary <string, Dictionary <string, int> > paresProformaReal)
        {
            Dictionary <string, int> par = paresProformaReal[det.clave_rubro];

            par.Add(TIPODETPROREAL, pos);

            makeCellValue(cells, pos, pos_nrubro, det.nombre_rubro);
            makeCellValue(cells, pos, pos_total, 0);
            makeCellValue(cells, pos, pos_porctotal, 0);
            makeCellValue(cells, pos, pos_aant, det.acumulado_resultado);
            makeCellValue(cells, pos, pos_porcaant, 0);
            makeCellValue(cells, pos, pos_ejercicio, 0);
            makeCellValue(cells, pos, pos_porcejercicio, 0);
            makeCellValue(cells, pos, pos_porcapost, 0);



            foreach (KeyValuePair <string, Int32> entry in getPonderacionCampos())
            {
                int ponderacion   = entry.Value;
                int posicionCelda = ponderacion + (POS_COL_ENERO - 1);
                if (ponderacion > 0)
                {
                    Object valorCelda = 0;
                    makeCellValue(cells, pos, posicionCelda, valorCelda);
                }
            }

            makeCellValue(cells, pos, pos_apost, det.anios_posteriores_resultado);
            for (int i = pos_nrubro; i <= pos_porcapost; i++)
            {
                cells[pos, i].Style.Font.Bold = true;
                setCellColor(cells[pos, i].Style, Color.Black, ColorTranslator.FromHtml("#adc6ea"));
            }

            renderDatosOcultos(cells, pos, det);
        }
Ejemplo n.º 12
0
        private ProformaDetalle ConstruyeDetalleTotal(List <ProformaDetalle> detalles, Rubros rubroTotal,
                                                      double porcentaje)
        {
            string           aritmetica = rubroTotal.aritmetica;
            NumberFormatInfo nfi        = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";
            if (porcentaje != 1.0)
            {
                aritmetica = "(" + aritmetica + ") * " + porcentaje;
            }

            logger.Info(" -> rubro='{0}',aritmetica='{1}'", rubroTotal.nombre, aritmetica);
            var aritmeticas = new Dictionary <string, string>();

            aritmeticas.Add("enero_monto", aritmetica);
            aritmeticas.Add("febrero_monto", aritmetica);
            aritmeticas.Add("marzo_monto", aritmetica);
            aritmeticas.Add("abril_monto", aritmetica);
            aritmeticas.Add("mayo_monto", aritmetica);
            aritmeticas.Add("junio_monto", aritmetica);
            aritmeticas.Add("julio_monto", aritmetica);
            aritmeticas.Add("agosto_monto", aritmetica);
            aritmeticas.Add("septiembre_monto", aritmetica);
            aritmeticas.Add("octubre_monto", aritmetica);
            aritmeticas.Add("noviembre_monto", aritmetica);
            aritmeticas.Add("diciembre_monto", aritmetica);
            aritmeticas.Add("ejercicio", aritmetica);
            aritmeticas.Add("acumulado", aritmetica);
            aritmeticas.Add("total", aritmetica);

            List <String> keys = new List <string>();

            foreach (var key in aritmeticas.Keys)
            {
                keys.Add(key);
            }

            detalles.ForEach(detalle =>
            {
                var claveRubro = detalle.clave_rubro;
                if (aritmetica.Contains(claveRubro))
                {
                    foreach (var key in keys)
                    {
                        aritmeticas[key] = aritmeticas[key]
                                           .Replace(claveRubro, ((Double)detalle[key + "_resultado"]).ToString(nfi));
                    }
                }
            });
            ProformaDetalle detalleTotal = new ProformaDetalle();

            detalleTotal.rubro_id          = rubroTotal.id;
            detalleTotal.nombre_rubro      = rubroTotal.nombre;
            detalleTotal.aritmetica        = aritmetica;
            detalleTotal.clave_rubro       = rubroTotal.clave;
            detalleTotal.hijos             = rubroTotal.hijos;
            detalleTotal.es_total_ingresos = rubroTotal.es_total_ingresos;

            DataTable dt = new DataTable();

            foreach (var key in keys)
            {
                logger.Info("Evaluando expresion='{0}'", aritmeticas[key]);
                detalleTotal[key + "_resultado"] = ToDouble(dt.Compute(aritmeticas[key], ""));
            }

            return(detalleTotal);
        }
Ejemplo n.º 13
0
        public ActionResult AgregaraDocumento(int id)
        {
            try
            {
                Productos producto = db.Productos.Find(id);
                if (producto == null)
                {
                    Session["ListaProductos"] = 1;
                    return(PartialView("_ListaProductosMensajes"));
                }
            }
            catch (Exception)
            {
                Session["ListaProductos"] = 1;
                return(PartialView("_ListaProductosMensajes"));
            }

            try
            {
                var UserID = User.Identity.IsAuthenticated;
                if (!UserID)
                {
                    Session["ListaProductos"] = 3;
                    return(PartialView("_ListaProductosMensajes"));
                }
            }
            catch (Exception)
            {
                throw;
            }

            if (Session["Documento"] == null)
            {
                Session["ListaProductos"] = 2;
                return(PartialView("_ListaProductosMensajes"));
            }
            else
            {
                if (((Documento)Session["Documento"]).TipoDocumento == TipoDocumento.Pedido)
                {
                    int idPedido = ((Documento)Session["Documento"]).NumerosDocumento;
                    int nuevoId  = id;
                    int cant     = 1;

                    Pedidos ped        = db.Pedidos.Find(idPedido);
                    double  totalPagar = 0;
                    double  desc       = 0;
                    double  imp        = 0;

                    PedidoDetalle validacion = null;

                    try
                    {
                        validacion = db.PedidoDetalle.Where(x => x.IdPedido == idPedido && x.IdProducto == nuevoId).First();
                    }
                    catch (Exception)
                    {
                        validacion = null;
                    }

                    if (validacion != null)
                    {
                        validacion.Cantidad       += cant;
                        db.Entry(validacion).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        PedidoDetalle detalle = new PedidoDetalle
                        {
                            IdPedido   = idPedido,
                            IdProducto = nuevoId
                        };
                        detalle.Productos       = db.Productos.Where(x => x.Id == detalle.IdProducto).First();
                        detalle.Cantidad        = cant;
                        detalle.CantidadEnviada = 0;
                        detalle.PrecioUnitario  = detalle.Productos.Precio;
                        detalle.Descuento       = 0;
                        db.PedidoDetalle.Add(detalle);
                        db.SaveChanges();
                    }

                    List <PedidoDetalle> detallesPedido = db.PedidoDetalle.Where(x => x.IdPedido == idPedido).ToList();
                    ped.PedidoDetalle = detallesPedido;

                    foreach (var item in detallesPedido)
                    {
                        double precioBase         = item.PrecioUnitario;
                        double precioConIVA       = precioBase * ((Convert.ToDouble(item.Productos.Impuesto) / 100) + 1);
                        double precioConDescuento = precioConIVA - (precioConIVA * (item.Descuento / 100));
                        double iva       = precioConDescuento - (precioConDescuento / ((Convert.ToDouble(item.Productos.Impuesto) / 100) + 1));
                        double descuento = precioBase - (precioConDescuento - iva);
                        double subTotal  = precioBase + iva - descuento;

                        desc       += descuento * item.Cantidad;
                        imp        += iva * item.Cantidad;
                        totalPagar += subTotal * item.Cantidad;
                    }

                    ped.TotalDescuento  = desc;
                    ped.TotalImpuesto   = imp;
                    ped.TotalPagar      = totalPagar;
                    db.Entry(ped).State = EntityState.Modified;
                    db.SaveChanges();

                    ViewBag.TotalPagar        = ped.TotalPagar;
                    ViewBag.TotalDescuento    = ped.TotalDescuento;
                    ViewBag.TotalImpuesto     = ped.TotalImpuesto;
                    Session["ListaProductos"] = 5;
                    return(PartialView("_ListaProductosMensajes"));
                }
                else
                {
                    int       idProforma = ((Documento)Session["Documento"]).NumerosDocumento;
                    int       nuevoId    = id;
                    int       cant       = 1;
                    Proformas ped        = db.Proformas.Find(idProforma);

                    double totalPagar = 0;
                    double desc       = 0;
                    double imp        = 0;

                    ProformaDetalle validacion = null;
                    try
                    {
                        validacion = db.ProformaDetalle.Where(x => x.IdProforma == idProforma && x.IdProducto == nuevoId).First();
                    }
                    catch (Exception)
                    {
                        validacion = null;
                    }
                    if (validacion != null)
                    {
                        validacion.Cantidad       += cant;
                        db.Entry(validacion).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        ProformaDetalle detalle = new ProformaDetalle
                        {
                            IdProforma = idProforma,
                            IdProducto = nuevoId
                        };
                        detalle.Productos      = db.Productos.Where(x => x.Id == detalle.IdProducto).First();
                        detalle.Cantidad       = cant;
                        detalle.PrecioUnitario = detalle.Productos.Precio;
                        detalle.Descuento      = 0;
                        db.ProformaDetalle.Add(detalle);
                        db.SaveChanges();
                    }
                    List <ProformaDetalle> detallesProforma = db.ProformaDetalle.Where(x => x.IdProforma == idProforma).ToList();
                    foreach (var item in detallesProforma)
                    {
                        desc       += ((item.PrecioUnitario * item.Descuento) / 100) * item.Cantidad;
                        imp        += (item.PrecioUnitario * item.Cantidad) * (double)item.Productos.Impuesto / 100;
                        totalPagar += ((item.PrecioUnitario * item.Cantidad) + imp) - desc;
                    }
                    ped.TotalDescuento  = desc;
                    ped.TotalImpuesto   = imp;
                    ped.TotalPagar      = totalPagar;
                    db.Entry(ped).State = EntityState.Modified;
                    db.SaveChanges();
                    ped.ProformaDetalle       = detallesProforma;
                    ViewBag.TotalPagar        = ped.TotalPagar;
                    ViewBag.TotalDescuento    = ped.TotalDescuento;
                    ViewBag.TotalImpuesto     = ped.TotalImpuesto;
                    Session["ListaProductos"] = 4;
                    return(PartialView("_ListaProductosMensajes", ""));
                }
            }
        }
Ejemplo n.º 14
0
        // Calculo del ejercicio anterior
        public List <ProformaDetalle> GetAcumuladoAnteriores(Int64 idCenCos, Int64 idEmpresa, Int64 idModeloNegocio,
                                                             Int64 idProyecto, int anio, Int64 idTipoCaptura)
        {
            string queryLastproformaAAnt =
                "  select pf.id" +
                "     from proforma pf" +
                " join tipo_proforma tp on pf.tipo_proforma_id = tp.id" +
                " where pf.activo = true" +
                " and pf.anio = @anio" +
                " and pf.empresa_id = @idEmpresa" +
                " and pf.modelo_negocio_id = @idModeloNegocio" +
                " and pf.centro_costo_id = @idCenCos" +
                " and pf.tipo_captura_id = @idTipoCaptura" +
                " order by tp.mes_inicio desc" +
                " limit 1";
            String queryProformaAAnt =
                " select" +
                " total_resultado as acumulado_resultado," +
                " rub.id as rubro_id," +
                " rub.nombre as nombre_rubro," +
                " rub.es_total_ingresos" +
                "     from proforma pf" +
                " join proforma_detalle pd on pd.id_proforma = pf.id" +
                " join rubro rub on rub.id = pd.rubro_id" +
                " join tipo_proforma tp on pf.tipo_proforma_id = tp.id" +
                " where pf.activo = true" +
                " and pf.anio = @anio" +
                " and pf.empresa_id = @idEmpresa" +
                " and pf.modelo_negocio_id = @idModeloNegocio" +
                " and pf.centro_costo_id = @idCenCos" +
                " and pf.tipo_captura_id = @idTipoCaptura" +
                " and pf.id in (" + queryLastproformaAAnt + ")";

            string queryFromMontosAAnt =
                " select  " +
                "	 coalesce ( "+
                "	 sum(cns.enero_total_resultado) + "+
                "	 sum(cns.febrero_total_resultado) + "+
                "	 sum(cns.marzo_total_resultado) + "+
                "	 sum(cns.abril_total_resultado) + "+
                "	 sum(cns.mayo_total_resultado) + "+
                "	 sum(cns.junio_total_resultado) + "+
                "	 sum(cns.julio_total_resultado) + "+
                "	 sum(cns.agosto_total_resultado) + "+
                "	 sum(cns.septiembre_total_resultado) + "+
                "	 sum(cns.octubre_total_resultado) + "+
                "	 sum(cns.noviembre_total_resultado) + "+
                "	 sum(cns.diciembre_total_resultado) "+
                "	 , 0) as acumulado_resultado, cns.rubro_id as rubro_id, rub.nombre as nombre_rubro, rub.es_total_ingresos "+
                "	 from montos_consolidados cns "+
                "	 inner join rubro rub on cns.rubro_id = rub.id "+
                "    where  cns.anio < @anio" +
                "    AND  cns.empresa_id=@idEmpresa" +
                "    AND  cns.modelo_negocio_id=@idModeloNegocio" +
                "    AND  cns.proyecto_id=@idProyecto" +
                "    AND  cns.centro_costo_id=@idCenCos" +
                "    AND  cns.tipo_captura_id=@idTipoCaptura" +
                "    AND  cns.activo=true" +
                "	 group by cns.rubro_id, rub.nombre, rub.es_total_ingresos "+
                "	 order by cns.rubro_id ";


            var res = _queryExecuter.ExecuteQueryUniqueresult(queryLastproformaAAnt,
                                                              new NpgsqlParameter("@anio", anio - 1),
                                                              new NpgsqlParameter("@idEmpresa", idEmpresa),
                                                              new NpgsqlParameter("@idModeloNegocio", idModeloNegocio),
                                                              new NpgsqlParameter("@idCenCos", idCenCos),
                                                              new NpgsqlParameter("@idTipoCaptura", idTipoCaptura));

            if (res != null)
            {
                List <ProformaDetalle> proformaDetalles =
                    new ProformaDetalleDataAccessLayer().GetProformaDetalle(ToInt64(res["id"]));
                new ProformaCalc().recalculateAll(proformaDetalles, true);
                log.Info("Termino proceso");
                new ProformaDataAccessLayer().ActualizaProforma(proformaDetalles);
            }

            DataTable dataTable = _queryExecuter.ExecuteQuery(queryProformaAAnt.Trim(),
                                                              new NpgsqlParameter("@anio", anio - 1),
                                                              new NpgsqlParameter("@idEmpresa", idEmpresa),
                                                              new NpgsqlParameter("@idModeloNegocio", idModeloNegocio),
                                                              new NpgsqlParameter("@idCenCos", idCenCos),
                                                              new NpgsqlParameter("@idTipoCaptura", idTipoCaptura));

            if (dataTable.Rows.Count == 0)
            {
                dataTable = _queryExecuter.ExecuteQuery(queryFromMontosAAnt.Trim(),
                                                        new NpgsqlParameter("@anio", anio),
                                                        new NpgsqlParameter("@idEmpresa", idEmpresa),
                                                        new NpgsqlParameter("@idModeloNegocio", idModeloNegocio),
                                                        new NpgsqlParameter("@idProyecto", idProyecto),
                                                        new NpgsqlParameter("@idCenCos", idCenCos),
                                                        new NpgsqlParameter("@idTipoCaptura", idTipoCaptura)
                                                        );
            }

            List <ProformaDetalle> detallesAAnteriores = new List <ProformaDetalle>();

            foreach (DataRow rdr in dataTable.Rows)
            {
                ProformaDetalle detalle = new ProformaDetalle();
                detalle.acumulado_resultado = ToDouble(rdr["acumulado_resultado"]);
                detalle.rubro_id            = ToInt64(rdr["rubro_id"]);
                detalle.nombre_rubro        = rdr["nombre_rubro"].ToString();
                detalle.es_total_ingresos   = ToBoolean(rdr["es_total_ingresos"]);
                detallesAAnteriores.Add(detalle);
            }

            return(detallesAAnteriores);
        }
Ejemplo n.º 15
0
        // Calculo de la proforma a partir de los montos consolidados
        // El parametro mesInicio define el calculo de la proforma
        //      0 = 0+12 - Cero reales, doce proformados
        //      3 =  3+9 - Tres reales, 9 proformados
        //      6 =  6+6 - Seis reales, 6 proformados
        //      9 =  9+3 - Nueve reales, 3 proformados
        // Los reales se calculan desde los montos consolidados
        // Los proformados se capturan en pantalla
        // El parametreo idTipoCaptura indica si la proforma es:
        //      1 - Contable
        //      2 - Flujo
        //
        public List <ProformaDetalle> GetProformaCalculada(Int64 idCenCos, int mesInicio, Int64 idEmpresa,
                                                           Int64 idModeloNegocio, Int64 idProyecto, int anio, Int64 idTipoCaptura)
        {
            try
            {
                DateTime fechaCarga = _profHelper.getLastFechaMontosConsol(anio, idEmpresa, idModeloNegocio, idProyecto,
                                                                           idCenCos, idTipoCaptura);
                string consulta = "";
                consulta += " select ";
                consulta += "	 mon.id, anio, mes, empresa_id, modelo_negocio_id, ";
                consulta += "	 mon.centro_costo_id, mon.activo, ";
                consulta +=
                    "	 proyecto_id, rub.id as rubro_id, rub.nombre as nombre_rubro, rub.hijos as hijos, rub.es_total_ingresos ,";

                consulta += BuildMontosFieldsQuery(mesInicio);
                consulta += BuildEjercicioFieldQuery(mesInicio);

                consulta += "	 coalesce(valor_tipo_cambio_resultado, 0) as valor_tipo_cambio_resultado ";
                consulta += "	 from montos_consolidados mon ";
                consulta += "	 inner join rubro rub on mon.rubro_id = rub.id ";
                consulta += "	 where date_trunc('SECOND', fecha) = '"+ fechaCarga.ToString("yyyy-MM-dd HH:mm:ss") +
                            "'::timestamp ";
                consulta += "	 and anio = "+ anio;
                consulta += "	 and empresa_id = "+ idEmpresa;
                consulta += "	 and modelo_negocio_id = "+ idModeloNegocio;
                consulta += "	 and proyecto_id = "+ idProyecto;
                consulta += "	 and centro_costo_id = "+ idCenCos;
                consulta += "	 and tipo_captura_id = "+ idTipoCaptura;
                consulta += "	 and mon.activo = 'true' ";
                consulta += "	 order by rub.id ";

                log.Info("ejecutando query:'{0}'", consulta);


                DataTable dataTable = _queryExecuter.ExecuteQuery(consulta.Trim());
                List <ProformaDetalle> lstProformaDetalle = new List <ProformaDetalle>();
                foreach (DataRow rdr in dataTable.Rows)
                {
                    ProformaDetalle proforma_detalle = new ProformaDetalle();
                    proforma_detalle.mes_inicio        = mesInicio;
                    proforma_detalle.id_proforma       = ToInt64(rdr["id"]);
                    proforma_detalle.anio              = ToInt32(rdr["anio"]);
                    proforma_detalle.modelo_negocio_id = ToInt64(rdr["modelo_negocio_id"]);
                    proforma_detalle.empresa_id        = ToInt64(rdr["empresa_id"]);
                    proforma_detalle.centro_costo_id   = ToInt64(rdr["centro_costo_id"]);
                    proforma_detalle.activo            = ToBoolean(rdr["activo"]);
                    proforma_detalle.rubro_id          = ToInt64(rdr["rubro_id"]);
                    proforma_detalle.nombre_rubro      = (rdr["nombre_rubro"]).ToString().Trim();
                    proforma_detalle.hijos             = (rdr["hijos"]).ToString().Trim();

                    foreach (var entry in ProformaHelper.getPonderacionMeses())
                    {
                        string nombreCampo = entry.Value;
                        proforma_detalle[nombreCampo] = ToDouble(rdr[nombreCampo]);
                    }

                    proforma_detalle.ejercicio_resultado = ToDouble(rdr["ejercicio_resultado"]);

                    lstProformaDetalle.Add(proforma_detalle);
                }

                return(lstProformaDetalle);
            }
            catch (ApplicationException e)
            {
                log.Warn(e, "Parece que no hay datos de montos");
                return(new List <ProformaDetalle>());
            }
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        public int UpdateProformaDetalle(ProformaDetalle proformaDetalle)
        {
            string consulta = "";

            consulta += " update proforma_detalle set activo = @activo, ";
            consulta += "    enero_monto_resultado = @enero_monto_resultado, ";
            consulta += "    febrero_monto_resultado = @febrero_monto_resultado, ";
            consulta += "    marzo_monto_resultado = @marzo_monto_resultado, ";
            consulta += "    abril_monto_resultado = @abril_monto_resultado, ";
            consulta += "    mayo_monto_resultado = @mayo_monto_resultado, ";
            consulta += "    junio_monto_resultado = @junio_monto_resultado, ";
            consulta += "    julio_monto_resultado = @julio_monto_resultado, ";
            consulta += "    agosto_monto_resultado = @agosto_monto_resultado, ";
            consulta += "    septiembre_monto_resultado = @septiembre_monto_resultado, ";
            consulta += "    octubre_monto_resultado = @octubre_monto_resultado, ";
            consulta += "    noviembre_monto_resultado = @noviembre_monto_resultado, ";
            consulta += "    diciembre_monto_resultado = @diciembre_monto_resultado, ";
            consulta += "    acumulado_resultado = @acumulado_resultado, ";
            consulta += "    ejercicio_resultado = @ejercicio_resultado, ";
            consulta += "    total_real_resultado = @total_real_resultado, ";
            consulta += "    total_proformado_resultado = @total_proformado_resultado, ";
            consulta += "    total_resultado = @total_resultado ";
            consulta += " where id = @id ";

            try
            {
                {
                    con.Open();
                    NpgsqlCommand cmd = new NpgsqlCommand(consulta.Trim(), con);
                    cmd.Parameters.AddWithValue("@id", proformaDetalle.id);
                    cmd.Parameters.AddWithValue("@enero_monto_resultado", proformaDetalle.enero_monto_resultado);
                    cmd.Parameters.AddWithValue("@febrero_monto_resultado", proformaDetalle.febrero_monto_resultado);
                    cmd.Parameters.AddWithValue("@marzo_monto_resultado", proformaDetalle.marzo_monto_resultado);
                    cmd.Parameters.AddWithValue("@abril_monto_resultado", proformaDetalle.abril_monto_resultado);
                    cmd.Parameters.AddWithValue("@mayo_monto_resultado", proformaDetalle.mayo_monto_resultado);
                    cmd.Parameters.AddWithValue("@junio_monto_resultado", proformaDetalle.junio_monto_resultado);
                    cmd.Parameters.AddWithValue("@julio_monto_resultado", proformaDetalle.julio_monto_resultado);
                    cmd.Parameters.AddWithValue("@agosto_monto_resultado", proformaDetalle.agosto_monto_resultado);
                    cmd.Parameters.AddWithValue("@septiembre_monto_resultado",
                                                proformaDetalle.septiembre_monto_resultado);
                    cmd.Parameters.AddWithValue("@octubre_monto_resultado", proformaDetalle.octubre_monto_resultado);
                    cmd.Parameters.AddWithValue("@noviembre_monto_resultado",
                                                proformaDetalle.noviembre_monto_resultado);
                    cmd.Parameters.AddWithValue("@diciembre_monto_resultado",
                                                proformaDetalle.diciembre_monto_resultado);
                    cmd.Parameters.AddWithValue("@acumulado_resultado", proformaDetalle.acumulado_resultado);
                    cmd.Parameters.AddWithValue("@ejercicio_resultado", proformaDetalle.ejercicio_resultado);
                    cmd.Parameters.AddWithValue("@total_resultado", proformaDetalle.total_resultado);
                    cmd.Parameters.AddWithValue("@total_real_resultado", proformaDetalle.total_real_resultado);
                    cmd.Parameters.AddWithValue("@total_proformado_resultado", proformaDetalle.total_proformado_resultado);
                    cmd.Parameters.AddWithValue("@activo", proformaDetalle.activo);

                    int regActual = cmd.ExecuteNonQuery();
                    return(regActual);
                }
            }

            finally
            {
                con.Close();
            }
        }
Ejemplo n.º 18
0
        public int AddProformaDetalle(ProformaDetalle proforma_detalle)
        {
            string consulta = "";

            consulta += " insert into proforma_detalle ( ";
            consulta += "	 id, id_proforma, rubro_id, activo, ejercicio_resultado, ";
            consulta += "	 enero_monto_resultado, febrero_monto_resultado, ";
            consulta += "	 marzo_monto_resultado, abril_monto_resultado, ";
            consulta += "	 mayo_monto_resultado, junio_monto_resultado, ";
            consulta += "	 julio_monto_resultado, agosto_monto_resultado, ";
            consulta += "	 septiembre_monto_resultado, octubre_monto_resultado, ";
            consulta += "	 noviembre_monto_resultado, diciembre_monto_resultado, ";
            consulta += "	 total_resultado, acumulado_resultado, ";
            consulta += "	 valor_tipo_cambio_resultado,total_real_resultado,total_proformado_resultado ";
            consulta += " ) values ( ";
            consulta += "	 nextval('seq_proforma_detalle'), @id_proforma, @rubro_id, @activo, @ejercicio_resultado, ";
            consulta += "	  @enero_monto_resultado, @febrero_monto_resultado, ";
            consulta += "	  @marzo_monto_resultado, @abril_monto_resultado, ";
            consulta += "	  @mayo_monto_resultado, @junio_monto_resultado, ";
            consulta += "	  @julio_monto_resultado, @agosto_monto_resultado, ";
            consulta += "	  @septiembre_monto_resultado, @octubre_monto_resultado, ";
            consulta += "	  @noviembre_monto_resultado, @diciembre_monto_resultado, ";
            consulta += "	  @total_resultado, @acumulado_resultado, ";
            consulta += "	  @valor_tipo_cambio_resultado,@total_real_resultado,@total_proformado_resultado ";
            consulta += " ) ";

            try
            {
                con.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(consulta.Trim(), con);
                cmd.Parameters.AddWithValue("@id_proforma", proforma_detalle.id_proforma);
                cmd.Parameters.AddWithValue("@rubro_id", proforma_detalle.rubro_id);
                cmd.Parameters.AddWithValue("@activo", proforma_detalle.activo);
                cmd.Parameters.AddWithValue("@ejercicio_resultado", proforma_detalle.ejercicio_resultado);
                cmd.Parameters.AddWithValue("@enero_monto_resultado", proforma_detalle.enero_monto_resultado);
                cmd.Parameters.AddWithValue("@febrero_monto_resultado", proforma_detalle.febrero_monto_resultado);
                cmd.Parameters.AddWithValue("@marzo_monto_resultado", proforma_detalle.marzo_monto_resultado);
                cmd.Parameters.AddWithValue("@abril_monto_resultado", proforma_detalle.abril_monto_resultado);
                cmd.Parameters.AddWithValue("@mayo_monto_resultado", proforma_detalle.mayo_monto_resultado);
                cmd.Parameters.AddWithValue("@junio_monto_resultado", proforma_detalle.junio_monto_resultado);
                cmd.Parameters.AddWithValue("@julio_monto_resultado", proforma_detalle.julio_monto_resultado);
                cmd.Parameters.AddWithValue("@agosto_monto_resultado", proforma_detalle.agosto_monto_resultado);
                cmd.Parameters.AddWithValue("@septiembre_monto_resultado", proforma_detalle.septiembre_monto_resultado);
                cmd.Parameters.AddWithValue("@octubre_monto_resultado", proforma_detalle.octubre_monto_resultado);
                cmd.Parameters.AddWithValue("@noviembre_monto_resultado", proforma_detalle.noviembre_monto_resultado);
                cmd.Parameters.AddWithValue("@diciembre_monto_resultado", proforma_detalle.diciembre_monto_resultado);
                cmd.Parameters.AddWithValue("@total_resultado", proforma_detalle.total_resultado);
                cmd.Parameters.AddWithValue("@acumulado_resultado", proforma_detalle.acumulado_resultado);
                cmd.Parameters.AddWithValue("@valor_tipo_cambio_resultado", proforma_detalle.valor_tipo_cambio_resultado);
                cmd.Parameters.AddWithValue("@total_real_resultado", proforma_detalle.total_real_resultado);
                cmd.Parameters.AddWithValue("@total_proformado_resultado", proforma_detalle.total_proformado_resultado);

                int regInsert = cmd.ExecuteNonQuery();

                return(regInsert);
            }

            finally
            {
                con.Close();
            }
        }
Ejemplo n.º 19
0
        private void renderDetalleHijo(ExcelRange cells, int pos, ProformaDetalle det, int mesInicio,
                                       Dictionary <string, Dictionary <string, int> > paresProformaReal)
        {
            Dictionary <string, int> par = paresProformaReal[det.clave_rubro];

            if (det.tipo.Equals(TIPODETPROFORM))
            {
                par.Add(TIPODETPROFORM, pos);
                makeCellValue(cells, pos, pos_nrubro, det.nombre_rubro + " proform");
                makeCellValue(cells, pos, pos_total, 0.0);
                makeCellValue(cells, pos, pos_porctotal, 0.0);
                makeCellValue(cells, pos, pos_aant, 0.0);
                makeCellValue(cells, pos, pos_porcaant, 0.0);
                makeCellValue(cells, pos, pos_ejercicio, 0.0);
                makeCellValue(cells, pos, pos_porcejercicio, 0.0);
                makeCellValue(cells, pos, pos_porcapost, 0.0);
            }
            else if (det.tipo.Equals(TIPODETPROREAL))
            {
                par.Add(TIPODETPROREAL, pos);
                makeCellValue(cells, pos, pos_nrubro, det.nombre_rubro + " real");
                makeCellValue(cells, pos, pos_total, 0.0);
                makeCellValue(cells, pos, pos_porctotal, 0.0);
                makeCellValue(cells, pos, pos_aant, det.acumulado_resultado);
                makeCellValue(cells, pos, pos_porcaant, 0.0);
                makeCellValue(cells, pos, pos_ejercicio, 0.0);
                makeCellValue(cells, pos, pos_porcejercicio, 0.0);
                makeCellValue(cells, pos, pos_porcapost, 0.0);
            }

            foreach (KeyValuePair <string, Int32> entry in getPonderacionCampos())
            {
                int ponderacion   = entry.Value;
                int posicionCelda = ponderacion + (POS_COL_ENERO - 1);
                if (ponderacion > 0)
                {
                    Object valorCelda = det[entry.Key];
                    if (det.tipo.Equals(TIPODETPROFORM))
                    {
                        if (ponderacion <= mesInicio)
                        {
                            makeCellValue(cells, pos, posicionCelda, 0.0);
                        }
                        else
                        {
                            applyStyleEditable(makeCellValue(cells, pos, posicionCelda, valorCelda));
                        }
                    }
                    else if (det.tipo.Equals(TIPODETPROREAL))
                    {
                        if (ponderacion > mesInicio)
                        {
                            makeCellValue(cells, pos, posicionCelda, 0.0);
                        }
                        else
                        {
                            makeCellValue(cells, pos, posicionCelda, valorCelda);
                        }
                    }
                }
            }

            makeCellValue(cells, pos, pos_apost, det.anios_posteriores_resultado);
            renderDatosOcultos(cells, pos, det);
        }