Ejemplo n.º 1
0
        public bool GuardarDocumento(Documento pDocumento)
        {
            var nuevoDocumento = EjecutarNoConsulta("dbo.GuardarDocumento", new List<SqlParameter>()
            {
                new SqlParameter("pTipoDocumento", pDocumento.TipoDocumento),
                new SqlParameter("pFecha1", pDocumento.Fecha1),
                new SqlParameter("pFecha2", pDocumento.Fecha2),
                new SqlParameter("pConsecutivo", pDocumento.Consecutivo),
                new SqlParameter("pSubtotal", pDocumento.Subtotal),
                new SqlParameter("pTotal", pDocumento.Total),
                new SqlParameter("pEsServicio", pDocumento.EsServicio?1:0),
                new SqlParameter("pDescripcionServicio", pDocumento.DescripcionServicio),
                new SqlParameter("pCodigoCuentaServicio", pDocumento.CodigoCuentaServicio),
                new SqlParameter("pIdSocioNegocio", pDocumento.SocioNegocio.IdSocio)
            });
            bool lineasVenta = true;
            if (!pDocumento.EsServicio)
            {
                var idDetalle = ObtenerIdDetalleDocumento(pDocumento.Consecutivo);
                DataTable dataTable = new DataTable("LineaVenta");

                dataTable.Columns.Add("IdArticulo", typeof(int));
                dataTable.Columns.Add("IdDetalle", typeof(int));
                dataTable.Columns.Add("IdBodega", typeof(int));
                dataTable.Columns.Add("Cantidad", typeof(int));
                dataTable.Columns.Add("Impuesto", typeof(double));
                dataTable.Columns.Add("Precio", typeof(double));
                foreach (var lv in pDocumento.LineasVenta)
                {
                    dataTable.Rows.Add(lv.Producto.IdProducto, idDetalle,
                        lv.Bodega.IdBodega, lv.Cantidad, lv.Impuestos, lv.Producto.Precio);
                }
                var param=new SqlParameter();
                param.ParameterName = "LineasVenta";
                param.SqlDbType = SqlDbType.Structured;
                param.Value = dataTable;
                lineasVenta = EjecutarNoConsulta("dbo.AgregarLineasVenta", new List<SqlParameter>()
                {
                    param
                });
            }
            return nuevoDocumento && lineasVenta;
        }
Ejemplo n.º 2
0
 public Documento ObtenerDocumento(int pIdDocumento)
 {
     Documento documento=null;
     var ds = EjecutarConsulta("dbo.ObtenerDocumentoCompleto", new List<SqlParameter>()
     {
         new SqlParameter("pIdDocumento", pIdDocumento)
     });
     if (ds != null && ds.Tables != null && ds.Tables[0] != null && ds.Tables[0].Rows != null)
     {
         foreach (DataRow row in ds.Tables[0].Rows)
         {
             if (documento == null)
             {
                 documento = new Documento()
                 {
                     IdDocumento = pIdDocumento,
                     Consecutivo = row["Consecutivo"].ToString(),
                     Fecha1 = DateTime.Parse(row["Fecha"].ToString()),
                     Fecha2 = DateTime.Parse(row["Fecha2"].ToString()),
                     TipoDocumento = row["TipoDocumento"].ToString(),
                     Subtotal = double.Parse(row["Subtotal"].ToString()),
                     Total = double.Parse(row["Total"].ToString()),
                     //AXB.codCuentasCostos, AXB.codCuentasExistencia,
     //AXB.codCuentasVentas, AXB.codCuentaTransitoria
                     LineasVenta = new List<LineaVenta>(){
                         new LineaVenta(){
                             Bodega=new BodegaCV(){
                                 IdBodega=row["IdBodega"]==null?-1:int.Parse(row["IdBodega"].ToString()),
                                 Nombre=row["Bodega"]==null?string.Empty:row["Bodega"].ToString(),
                                 Costo=row["Costo"]==null?-1:double.Parse(row["Costo"].ToString())
                             },
                             Cantidad=int.Parse(row["Cantidad"].ToString()),
                             Impuestos=double.Parse(row["Impuesto"].ToString()),
                             Producto=new ProductoCV(){
                                 IdProducto=int.Parse(row["IdArticulo"].ToString()),
                                 Nombre=row["NombreArticulo"].ToString(),
                                 Descripcion = row["NombreArticulo"].ToString(),
                                 Precio = row["Precio"]==null?-1:double.Parse(row["Precio"].ToString()),
                                 CuentaCostos=row["codCuentasCostos"].ToString(),
                                 CuentaExistencias=row["codCuentasExistencia"].ToString(),
                                 CuentaVentas=row["codCuentasVentas"].ToString(),
                                 CuentaTransitoria=row["codCuentaTransitoria"].ToString()
                             }
                         }
                     },
                     SocioNegocio = new SocNegocio()
                     {
                         IdSocio=int.Parse(row["IdSocioNegocio"].ToString()),
                         Nombre=row["SocioNegocio"].ToString()
                     }
                 };
             } else {
                 documento.LineasVenta.Add(new LineaVenta(){
                     Bodega=new BodegaCV(){
                         IdBodega=row["IdBodega"]==null?-1:int.Parse(row["IdBodega"].ToString()),
                         Nombre=row["Bodega"]==null?string.Empty:row["Bodega"].ToString(),
                         Costo=row["Costo"]==null?-1:double.Parse(row["Costo"].ToString())
                     },
                     Cantidad=int.Parse(row["Cantidad"].ToString()),
                     Impuestos=double.Parse(row["Impuesto"].ToString()),
                     Producto=new ProductoCV(){
                         IdProducto=int.Parse(row["IdArticulo"].ToString()),
                         Nombre=row["NombreArticulo"].ToString(),
                         Descripcion = row["NombreArticulo"].ToString(),
                         Precio = row["Precio"]==null?-1:double.Parse(row["Precio"].ToString()),
                         CuentaCostos = row["codCuentasCostos"].ToString(),
                         CuentaExistencias = row["codCuentasExistencia"].ToString(),
                         CuentaVentas = row["codCuentasVentas"].ToString(),
                         CuentaTransitoria = row["codCuentaTransitoria"].ToString()
                     }
                 });
             }
         }
         foreach (var lv in documento.LineasVenta)
         {
             lv.Total = (lv.Cantidad * lv.Producto.Precio) + ((lv.Impuestos / 100) * lv.Producto.Precio * lv.Cantidad);
         }
     }
     return documento;
 }
Ejemplo n.º 3
0
 public bool GuardarDocumento(Documento pDocumento)
 {
     return LogicaCompraVenta.Instancia.GuardarDocumento(pDocumento);
 }
Ejemplo n.º 4
0
 public bool GuardarDocumentoServicios(Documento pDocumento)
 {
     return EjecutarNoConsulta("dbo.GuardarDocumento", new List<SqlParameter>()
     {
         new SqlParameter("pTipoDocumento", pDocumento.TipoDocumento),
         new SqlParameter("pFecha1", pDocumento.Fecha1),
         new SqlParameter("pFecha2", pDocumento.Fecha2),
         new SqlParameter("pConsecutivo", pDocumento.Consecutivo),
         new SqlParameter("pSubtotal", pDocumento.Subtotal),
         new SqlParameter("pTotal", pDocumento.Total),
         new SqlParameter("pEsServicio", pDocumento.EsServicio?1:0),
         new SqlParameter("pDescripcionServicio", pDocumento.DescripcionServicio),
         new SqlParameter("pCodigoCuentaServicio", pDocumento.CodigoCuentaServicio),
         new SqlParameter("pIdSocioNegocio", pDocumento.SocioNegocio.IdSocio)
     });
 }
Ejemplo n.º 5
0
        public bool GuardarDocumento(Documento pDocumento)
        {
            var guardadoDocumento=_DataAccess.GuardarDocumento(pDocumento);
            var extras=false;
            var monedaSistema = LogicaNegocio.Instancia.ObtenerMonedasSistema("Sistema");
            if (pDocumento.EsServicio)
            {
                var cuenta = LogicaNegocio.Instancia.ObtenerCuenta("Impuesto Venta por pagar");
                var cuentaIVXPagar = cuenta.Codigo;
                double montoDebe = 0, montoHaber = 0;
                string xml = "<Cuentas>";
                //CxC
                xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                    pDocumento.Total, monedaSistema.Acronimo,
                    pDocumento.SocioNegocio.CuentaAsociada, 1);
                montoDebe += pDocumento.Total;
                //IV x pagar
                xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                    (pDocumento.Total-pDocumento.Subtotal), monedaSistema.Acronimo,
                    cuentaIVXPagar, 0);
                montoHaber += (pDocumento.Total - pDocumento.Subtotal);
                //Ventas
                xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                    pDocumento.Subtotal, monedaSistema.Acronimo,
                    pDocumento.CodigoCuentaServicio, 0);
                montoHaber += pDocumento.Subtotal;
                xml += "</Cuentas>";
                LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                    montoDebe, montoHaber, xml, "FC");
                extras = true;
            }
            if (pDocumento.TipoDocumento.CompareTo("Orden de Compra")==0){
                //Aumenta solicitados
                extras = _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, true, "Solicitado");
            }
            else if (pDocumento.TipoDocumento.CompareTo("Entrada de Mercancias") == 0)
            {
                //Registrar asientos -> Inventario contra Inventario dotacion
                foreach (var item in pDocumento.LineasVenta)
                {
                    string xml = "<Cuentas>";
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            item.Producto.Precio*item.Cantidad, monedaSistema.Acronimo, item.Producto.CuentaExistencias, 1);
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                        item.Producto.Precio * item.Cantidad, monedaSistema.Acronimo, item.Producto.CuentaTransitoria, 0);
                    xml += "</Cuentas>";
                    LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                        item.Producto.Precio * item.Cantidad, item.Producto.Precio * item.Cantidad, xml, "EM");
                }

                //Calcular nuevo costo promedio
                extras = _DataAccess.ModificarCostoArticulo(pDocumento.LineasVenta);

                // Disminuye solicitados y aumenta stock
                extras = extras && _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, true, "Stock");
                if (pDocumento.CreadoDesdeAnterior)
                {
                    extras = extras && _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, false, "Solicitado");
                }
            }
            else if (pDocumento.TipoDocumento.CompareTo("Factura de Proveedores") == 0)
            {

                var cuenta=LogicaNegocio.Instancia.ObtenerCuenta("Impuesto Venta");
                var cuentaIV = cuenta.Codigo;

                if (!pDocumento.CreadoDesdeAnterior)
                {
                    extras = extras && _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, true, "Stock");
                }
                foreach (var item in pDocumento.LineasVenta)
                {
                    string xml = "<Cuentas>";
                    double montoDebe = 0, montoHaber = 0;
                    double total = (item.Producto.Precio*item.Cantidad)*(item.Impuestos/100)+(item.Producto.Precio*item.Cantidad);
                    //CXP
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            total, monedaSistema.Acronimo, pDocumento.SocioNegocio.CuentaAsociada, 0);
                    montoHaber += total;
                    //Inventario o Inventario en dotacion
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                        (item.Producto.Precio * item.Cantidad), monedaSistema.Acronimo,
                        pDocumento.CreadoDesdeAnterior?item.Producto.CuentaTransitoria:item.Producto.CuentaExistencias, 1);
                    montoDebe += (item.Producto.Precio * item.Cantidad);
                    //Impuesto x pagar
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                        (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100), monedaSistema.Acronimo,
                        cuentaIV, 1);
                    montoDebe += (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100);
                    xml += "</Cuentas>";
                    LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                        montoDebe, montoHaber, xml, "FP");
                }
                extras = true;
            }
            else if (pDocumento.TipoDocumento.CompareTo("Orden de Venta") == 0)
            {
                extras = _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, true, "Comprometido");
            }
            else if (pDocumento.TipoDocumento.CompareTo("Entrega de Mercancias") == 0)
            {
                extras = _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, false, "Stock");
                if (pDocumento.CreadoDesdeAnterior)
                {
                    extras = extras && _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, false, "Comprometido");
                }
                foreach (var item in pDocumento.LineasVenta)
                {
                    string xml = "<Cuentas>";
                    double montoDebe = 0, montoHaber = 0;
                    double total = (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100) + (item.Producto.Precio * item.Cantidad);
                    //Costo Ventas
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            item.Bodega.Costo, monedaSistema.Acronimo, item.Producto.CuentaCostos, 1);
                    montoDebe += item.Bodega.Costo;
                    //Inventario
                    xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                        item.Bodega.Costo*item.Cantidad, monedaSistema.Acronimo,
                        item.Producto.CuentaExistencias, 0);
                    montoHaber += item.Bodega.Costo * item.Cantidad;
                    xml += "</Cuentas>";
                    LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                        montoDebe, montoHaber, xml, "EE");
                }
            }
            else if (pDocumento.TipoDocumento.CompareTo("Factura de Clientes") == 0)
            {
                //TODO: remover CXP alambrada
                var cuenta=LogicaNegocio.Instancia.ObtenerCuenta("Impuesto Venta por pagar");
                var cuentaIVXPagar = cuenta.Codigo;

                //Inventario contra costo ventas
                if (!pDocumento.CreadoDesdeAnterior)
                {
                    _DataAccess.ModificarCantidadArticulos(pDocumento.LineasVenta, false, "Stock");
                    foreach (var item in pDocumento.LineasVenta)
                    {
                        string xml = "<Cuentas>";
                        double montoDebe=0, montoHaber =0;
                        double total = (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100) + (item.Producto.Precio * item.Cantidad);
                        //Costo Ventas
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                                item.Bodega.Costo, monedaSistema.Acronimo, item.Producto.CuentaCostos, 1);
                        montoDebe += item.Bodega.Costo;
                        //Inventario
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            item.Bodega.Costo, monedaSistema.Acronimo,
                            item.Producto.CuentaExistencias, 0);
                        montoHaber += item.Bodega.Costo;

                        //CxC
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            total, monedaSistema.Acronimo,
                            pDocumento.SocioNegocio.CuentaAsociada, 1);
                        montoDebe += total;
                        //IV x pagar
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100), monedaSistema.Acronimo,
                            cuentaIVXPagar, 0);
                        montoHaber += (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100);
                        //Ventas
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            (item.Producto.Precio * item.Cantidad), monedaSistema.Acronimo,
                            item.Producto.CuentaVentas, 0);
                        montoHaber += (item.Producto.Precio * item.Cantidad);
                        xml += "</Cuentas>";
                        LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                            montoDebe, montoHaber, xml, "FC");
                    }
                }
                else
                {
                    foreach (var item in pDocumento.LineasVenta)
                    {
                        string xml = "<Cuentas>";
                        double montoDebe = 0, montoHaber = 0;
                        double total = (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100) + (item.Producto.Precio * item.Cantidad);
                        //CxC
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            total, monedaSistema.Acronimo,
                            pDocumento.SocioNegocio.CuentaAsociada, 1);
                        montoDebe += total;
                        //IV x pagar
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100), monedaSistema.Acronimo,
                            cuentaIVXPagar, 0);
                        montoHaber += (item.Producto.Precio * item.Cantidad) * (item.Impuestos / 100);
                        //Ventas
                        xml += string.Format("<Cuenta monto=\"{0}\" moneda=\"{1}\" cuenta=\"{2}\" debe=\"{3}\" />",
                            (item.Producto.Precio * item.Cantidad), monedaSistema.Acronimo,
                            item.Producto.CuentaVentas, 0);
                        montoHaber += (item.Producto.Precio * item.Cantidad);
                        xml += "</Cuentas>";
                        LogicaNegocio.Instancia.AgregarAsiento(pDocumento.Fecha1.ToShortDateString(),
                            montoDebe, montoHaber, xml, "FC");
                    }
                }
                extras = true;
            }
            return extras && guardadoDocumento;
        }