Esempio n. 1
0
        private void LlenarGrid()
        {
            double subtotal = 0.0, descuento = 0.0, igv = 0, montoigv = 0.0, total = 0.0;

            try
            {
                v = VentaServices.Intancia.VentaDetalle(this.id_venta);
                List <entDetalleVenta> det = v.detalleventa;
                for (int i = 0; i < det.Count; i++)
                {
                    String[] fila = new String[] { det[i].producto.Codigo_Prod, det[i].producto.Nombre_Prod, det[i].producto.Precio_Prod.ToString("0.00"),
                                                   det[i].Cantidad_Det.ToString(), det[i].PrecProd_Det.ToString("0.00"), (det[i].Cantidad_Det * det[i].PrecProd_Det).ToString("0.00") };
                    ListViewItem item = new ListViewItem(fila);
                    lstDetalle.Items.Add(item);
                    subtotal += (det[i].Cantidad_Det * det[i].PrecProd_Det);
                }
                descuento = v.Descuento_Venta;
                total    += subtotal - descuento;
                igv       = v.Igv_Venta;
                //double igvSub = Convert.ToDouble("1,"+igv);
                //double igvMon = igv / 100;
                subtotal          = Convert.ToDouble(subtotal / Convert.ToDouble("1," + igv));
                montoigv          = subtotal * Convert.ToDouble("0," + igv);
                txtSubtotal.Text  = "s/ " + subtotal.ToString("0.00");
                txtDescuento.Text = "s/ " + descuento.ToString("0.00");
                txtIgv.Text       = igv.ToString() + "%";
                txtMontoIgv.Text  = "s/ " + montoigv.ToString("0.00");
                txtTotal.Text     = "s/ " + total.ToString("0.00");
                txtDescuento.Text = descuento.ToString("0.00");
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
 public void VerificarGuardadoVenta(entVenta v)
 {
     if (v.cliente.Id_Cliente == 0)
     {
         throw new ApplicationException("Debe tener un cliente seleccionado");
     }
     if (v.detalleventa.Count == 0)
     {
         throw new ApplicationException("Debe selecionar como mínimo un producto");
     }
 }
Esempio n. 3
0
        public List <entVenta> ListarVenta(String fechadesde, String fechahasta, int idSucursal)
        {
            SqlCommand      cmd   = null;
            List <entVenta> Lista = null;
            SqlDataReader   dr    = null;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spListaVenta", cn);
                cmd.Parameters.AddWithValue("@prmfinicio", fechadesde);
                cmd.Parameters.AddWithValue("@prmfin", fechahasta);
                cmd.Parameters.AddWithValue("@prmidsucursal", idSucursal);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr    = cmd.ExecuteReader();
                Lista = new List <entVenta>();
                while (dr.Read())
                {
                    entVenta v = new entVenta();
                    v.Id_Venta          = Convert.ToInt32(dr["Id_Venta"]);
                    v.Codigo_Venta      = dr["Codigo_Venta"].ToString();
                    v.Estado_Venta      = dr["Estado_Venta"].ToString();
                    v.Correlativo_Venta = dr["Correlativo_Venta"].ToString();
                    v.FechaVenta        = Convert.ToDateTime(dr["FechaVenta"]);
                    v.Igv_Venta         = Convert.ToInt32(dr["Igv_Venta"]);
                    v.Total             = Convert.ToDouble(dr["Total"].ToString());
                    v.Descuento_Venta   = Convert.ToDouble(dr["Descuento_Venta"]);
                    v.Utilidad          = Convert.ToDouble(dr["Utilidad"]);
                    v.Inversion         = Convert.ToDouble(dr["Inversion"]);

                    entTipComprobante tc = new entTipComprobante();
                    tc.Id_TipCom      = Convert.ToInt32(dr["Id_TipCom"]);
                    tc.Nombre_TipCom  = dr["Nombre_TipCom"].ToString();
                    v.tipocomprobante = tc;

                    entTipoPago tp = new entTipoPago();
                    tp.Id_TipPago = Convert.ToInt32(dr["Id_TipPago"]);
                    v.tipopago    = tp;
                    Lista.Add(v);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cmd.Connection.Close(); }
            return(Lista);
        }
Esempio n. 4
0
        public int GuardarVenta(entVenta v, int id_tipdocventa, String serie)
        {
            try
            {
                if (v.cliente.Id_Cliente == 0)
                {
                    throw new ApplicationException("Debe tener un cliente seleccionado");
                }
                if (v.detalleventa.Count == 0)
                {
                    throw new ApplicationException("Debe selecionar como mínimo un producto");
                }

                String Cadxml = "";
                Cadxml += "<venta ";
                Cadxml += "idcliente='" + v.cliente.Id_Cliente + "' ";
                Cadxml += "idusuario='" + v.usuario.Id_Usuario + "' ";
                Cadxml += "idsucursal='" + v.sucursal.Id_Suc + "' ";
                Cadxml += "istipcom='" + v.tipocomprobante.Id_TipCom + "' ";
                Cadxml += "idmoneda='" + v.moneda.Id_Moneda + "' ";
                Cadxml += "idtipopago='" + v.tipopago.Id_TipPago + "' ";
                Cadxml += "igv='" + v.Igv_Venta + "' ";
                Cadxml += "serie='" + serie + "' ";
                Cadxml += "descuento='" + v.Descuento_Venta.ToString().Replace(",", ".") + "' ";
                Cadxml += "descripcion='" + v.Desc_Venta.ToString() + "'>";

                foreach (entDetalleVenta dt in v.detalleventa)
                {
                    Cadxml += "<detalle ";
                    Cadxml += "idproducto='" + dt.Id_Prod_Det + "' ";
                    Cadxml += "precioprod='" + dt.PrecProd_Det.ToString().Replace(",", ".") + "' ";
                    Cadxml += "cantidad='" + dt.Cantidad_Det + "'/>";
                }
                Cadxml += "</venta>";
                Cadxml  = "<root>" + Cadxml + "</root>";
                int i = VentaRepository.Instancia.GuardarVenta(Cadxml, id_tipdocventa);
                if (i <= 0)
                {
                    throw new ApplicationException("Ocurrio un erro al guardar venta actual");
                }
                return(i);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 5
0
 public entVenta VentaDetalle(int id_venta)
 {
     try
     {
         entVenta v = VentaRepository.Instancia.LstVentaDetalle(id_venta);
         if (v == null)
         {
             throw new ApplicationException("Ocurrio un error al tratar de mostrar detalle");
         }
         //else if (v.detalleventa.Count == 0 || v.detalleventa == null) { throw new ApplicationException("No se encontraron items");return v; }
         return(v);
     }
     catch (Exception)
     {
         throw;
     }
 }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult r = MessageBox.Show("¿Desea guardar esta nota de venta?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (r == DialogResult.Yes)
                {
                    SoloNumCeldaGrid();
                    EscribirNuevoMonto();
                    ActualizarMontosDgv();
                    CargarSerie_correlativo();
                    entVenta v = new entVenta();

                    entCliente c = new entCliente();
                    c.Id_Cliente = LocalBD.Instancia.ReturnIdClienteNV(0, 0);
                    v.cliente    = c;

                    v.usuario = u;

                    entSucursal s = new entSucursal();
                    s.Id_Suc   = LocalBD.Instancia.IdSucursal;
                    v.sucursal = s;

                    entTipComprobante tc = new entTipComprobante();
                    tc.Id_TipCom      = serie.tipocom.Id_TipCom;
                    v.tipocomprobante = tc;

                    entMoneda m = new entMoneda();
                    m.Id_Moneda = Convert.ToInt32(CboMoneda.SelectedValue);
                    v.moneda    = m;

                    entTipoPago tp = new entTipoPago();
                    tp.Id_TipPago = Convert.ToInt32(cboTipoPago.SelectedValue);
                    v.tipopago    = tp;

                    v.Igv_Venta       = 0;
                    v.Descuento_Venta = Convert.ToDouble(txtDescuento.Text);

                    List <entDetalleVenta> Detalle = new List <entDetalleVenta>();
                    foreach (DataGridViewRow row in dgvDetalleNotaVenta.Rows)
                    {
                        entDetalleVenta dt = new entDetalleVenta();
                        dt.Id_Prod_Det  = Convert.ToInt32(row.Cells[0].Value);
                        dt.PrecProd_Det = Convert.ToDouble(row.Cells[3].Value);
                        dt.Cantidad_Det = Convert.ToInt32(row.Cells[2].Value);
                        Detalle.Add(dt);
                    }
                    v.detalleventa = Detalle;
                    v.Desc_Venta   = rtxtDescripcion.Text;
                    CargarSerie_correlativo();
                    int result = negVenta.Intancia.GuardarVenta(v, serie.tipocom.Id_TipCom, serie.Numero_Serie);
                    MessageBox.Show("Nota de venta guardo de manera correcta!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dgvDetalleNotaVenta.Enabled = false; ControlBotones(true, false, false, false); btnAgregarItem.Enabled = false; btnAnular.Enabled = true;
                    ac.BloquearText(this.gbCliente, false); ac.BloquearText(this.panel1, false);
                    // lblMontoEnletras.Text = "Son: " + ac.enletras(txtTotal.Text).ToLower() + " Soles";
                }
            }
            catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 7
0
        public entVenta LstVentaDetalle(int id_venta)
        {
            SqlCommand             cmd = null;
            IDataReader            idr = null;
            entVenta               v   = null;
            List <entDetalleVenta> det = null;

            try
            {
                SqlConnection cn = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spMostrarCabeceraVenta", cn);
                cmd.Parameters.AddWithValue("@prmid_venta", id_venta);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                idr = cmd.ExecuteReader();
                if (idr.Read())
                {
                    v = new entVenta();
                    v.Codigo_Venta      = idr["Codigo_Venta"].ToString();
                    v.Serie_Venta       = Convert.ToInt32(idr["Serie_Venta"].ToString());
                    v.Correlativo_Venta = idr["Correlativo_Venta"].ToString();
                    v.Igv_Venta         = Convert.ToInt32(idr["Igv_Venta"]);
                    v.FechaVenta        = Convert.ToDateTime(idr["FechaVenta"]);
                    v.Estado_Venta      = idr["Estado_Venta"].ToString();
                    v.Descuento_Venta   = Convert.ToDouble(idr["Descuento_Venta"]);
                    v.Desc_Venta        = idr["Desc_Venta"].ToString();

                    entCliente c = new entCliente();
                    c.Nombre_Cliente    = idr["Nombre_Cliente"].ToString();
                    c.NumeroDoc_Cliente = idr["NumeroDoc_Cliente"].ToString();
                    entTipoDocumento td = new entTipoDocumento();
                    td.Nombre_TipDoc = idr["Nombre_TipDoc"].ToString();
                    c.tipodocumento  = td;
                    v.cliente        = c;

                    entSucursal s = new entSucursal();
                    s.Direccion_Suc = idr["Direccion_Suc"].ToString();
                    v.sucursal      = s;

                    entUsuario u = new entUsuario();
                    u.Nombre_Usuario = idr["Nombre_Usuario"].ToString();
                    v.usuario        = u;

                    entTipComprobante tc = new entTipComprobante();
                    tc.Nombre_TipCom  = idr["Nombre_TipCom"].ToString();
                    v.tipocomprobante = tc;

                    entMoneda m = new entMoneda();
                    m.Descripcion_Moneda = idr["Descripcion_Moneda"].ToString();
                    v.moneda             = m;

                    entTipoPago tp = new entTipoPago();
                    tp.Descripcion_TipPago = idr["Descripcion_TipPago"].ToString();
                    v.tipopago             = tp;

                    if (idr.NextResult())
                    {
                        det = new List <entDetalleVenta>();
                        while (idr.Read())
                        {
                            entDetalleVenta d = new entDetalleVenta();
                            d.PrecProd_Det = Convert.ToDouble(idr["PrecProd_Det"]);
                            d.Cantidad_Det = Convert.ToInt32(idr["Cantidad_Det"]);
                            entProducto p = new entProducto();
                            p.Codigo_Prod = idr["Codigo_Prod"].ToString();
                            p.Nombre_Prod = idr["Nombre_Prod"].ToString();
                            p.Precio_Prod = Convert.ToDouble(idr["Precio_Prod"]);
                            d.producto    = p;
                            det.Add(d);
                        }
                        v.detalleventa = det;
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally { cmd.Connection.Close(); } return(v);
        }
Esempio n. 8
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult r = MessageBox.Show("¿Desea Registrar la Venta?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (r == DialogResult.Yes)
                {
                    SoloNumCeldaGrid();
                    EscribirNuevoMonto();
                    ActualizarMontosDgv();
                    entVenta venta = new entVenta();

                    entCliente cliente = new entCliente();
                    cliente.Id_Cliente = LocalBD.Instancia.ReturnIdCliente(0, 0);
                    venta.cliente      = cliente;

                    entUsuario usuario = new entUsuario();
                    usuario       = us;
                    venta.usuario = usuario;

                    entSucursal sucursal = new entSucursal();
                    sucursal.Id_Suc = LocalBD.Instancia.IdSucursal;
                    venta.sucursal  = sucursal;

                    entTipComprobante tipocomprobante = new entTipComprobante();
                    tipocomprobante.Id_TipCom = 1;
                    venta.tipocomprobante     = tipocomprobante;

                    entMoneda moneda = new entMoneda();
                    moneda.Id_Moneda = Convert.ToInt32(CboMoneda.SelectedValue);
                    venta.moneda     = moneda;

                    entTipoPago tipoPago = new entTipoPago();
                    tipoPago.Id_TipPago = Convert.ToInt32(cboTipoPago.SelectedValue);
                    venta.tipopago      = tipoPago;

                    venta.Igv_Venta       = 0;
                    venta.Descuento_Venta = 0.0;

                    List <entDetalleVenta> Detalle = new List <entDetalleVenta>();
                    foreach (DataGridViewRow row in dgvDetalleBoleta.Rows)
                    {
                        entDetalleVenta dt = new entDetalleVenta();
                        dt.Id_Prod_Det  = Convert.ToInt32(row.Cells[0].Value);
                        dt.PrecProd_Det = Convert.ToDouble(row.Cells[3].Value);
                        dt.Cantidad_Det = Convert.ToInt32(row.Cells[2].Value);
                        Detalle.Add(dt);
                    }
                    venta.detalleventa = Detalle;
                    venta.Desc_Venta   = "";
                    Stock();
                    CargarSerie_correlativo();
                    int result = VentaServices.Intancia.GuardarVenta(venta, 1, serie.Numero_Serie);


                    //var stock= negVenta.Equals.Resta
                    MessageBox.Show("Se guardo de manera correcta!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    dgvDetalleBoleta.Enabled = false; ControlBotones(true, false, false, false); btnAgregarItem.Enabled = false; btnAnular.Enabled = true; btnCrearFactura.Enabled = true;
                    ac.BloquearText(this.gbCliente, false); ac.BloquearText(this.panel1, false);
                    lblMontoEnletras.Text = "Son: " + ac.enletras(txtTotal.Text).ToLower() + " Pesos";
                }
            }
            catch (ApplicationException ae) { MessageBox.Show(ae.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }