public List <EDetalleVenta> Seleccionar(string Serie, string Numero)
        {
            List <EDetalleVenta> List = new List <EDetalleVenta>();

            try
            {
                DataTable      data       = new DataTable();
                SQLParameter[] parameters = new SQLParameter[2];
                parameters[0] = new SQLParameter("@Serie", Serie, SqlDbType.VarChar);
                parameters[1] = new SQLParameter("@Numero", Numero, SqlDbType.VarChar);
                data          = Conexion.ExecuteProcedureD("USP_S_SeleccionarDetalleVenta", parameters).Tables[0];
                foreach (DataRow row in data.Rows)
                {
                    EDetalleVenta be = new EDetalleVenta
                    {
                        ID       = Convert.ToInt32(row[0]),
                        Serie    = row[1].ToString(),
                        Numero   = row[2].ToString(),
                        Producto = row[3].ToString(),
                        Precio   = Convert.ToDouble(row[4]),
                        Cantidad = Convert.ToInt32(row[5]),
                        Importe  = Convert.ToDouble(row[6])
                    };
                    List.Add(be);
                }
            }
            catch
            {
                Console.WriteLine("No se encontro Procedimiento Almacenado");
            }
            return(List);
        }
 public bool RegistrarDetalleVenta(EDetalleVenta entidad)
 {
     if (Validar(entidad))
     {
         return(detalleVenta.Registrar(entidad));
     }
     else
     {
         return(false);
     }
 }
 public bool Agregar(EDetalleVenta obj)
 {
     SQLParameter[] parameters = new SQLParameter[6];
     parameters[0] = new SQLParameter("@Serie", obj.Serie, SqlDbType.VarChar);
     parameters[1] = new SQLParameter("@Numero", obj.Numero, SqlDbType.VarChar);
     parameters[2] = new SQLParameter("@Producto", obj.Producto, SqlDbType.VarChar);
     parameters[3] = new SQLParameter("@Precio", obj.Precio, SqlDbType.Decimal);
     parameters[4] = new SQLParameter("@Cantidad", obj.Cantidad, SqlDbType.Int);
     parameters[5] = new SQLParameter("@Importe", obj.Importe, SqlDbType.Decimal);
     Response      = Conexion.ExecuteProcedureB("USP_I_AgregarDetalleVenta", parameters);
     return(Response);
 }
        public List <EDetalleVenta> Mostrar(int idVenta)
        {
            var cadena = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString;
            var lista  = new List <EDetalleVenta>();

            using (var cn = new SqlConnection(cadena))
            {
                try
                {
                    if (cn.State == ConnectionState.Closed)
                    {
                        cn.Open();
                    }
                    using (var cmd = cn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "MostarDetalleVenta";

                        cmd.Parameters.AddWithValue("@IdVenta", idVenta);

                        var drd = cmd.ExecuteReader();

                        while (drd.Read())
                        {
                            var enti = new EDetalleVenta()
                            {
                                IdDetVenta   = drd.GetInt32(drd.GetOrdinal("IdDetVenta")),
                                IdVenta      = drd.GetInt32(drd.GetOrdinal("IdVenta")),
                                IdDetIngreso = drd.GetInt32(drd.GetOrdinal("IdDetIngreso")),
                                Articulo     = drd.GetString(drd.GetOrdinal("Articulo")),
                                Cantidad     = drd.GetInt32(drd.GetOrdinal("Cantidad")),
                                PrecioVenta  = drd.GetDecimal(drd.GetOrdinal("PrecioVenta")),
                                Descuento    = drd.GetDecimal(drd.GetOrdinal("Descuento")),
                                Subtotal     = drd.GetDecimal(drd.GetOrdinal("Subtotal"))
                            };
                            lista.Add(enti);
                        }
                    }
                }
                catch (SqlException e)
                {
                    MessageBox.Show(e.Message, "SQL Error Mostrar Detalle venta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (cn.State == ConnectionState.Open)
                    {
                        cn.Close();
                    }
                }
            }
            return(lista);
        }
        public bool Registrar(EDetalleVenta entidad)
        {
            var cadena = ConfigurationManager.ConnectionStrings["Cnn"].ConnectionString;
            int res    = 0;

            using (var cn = new SqlConnection(cadena))
            {
                try
                {
                    if (cn.State == ConnectionState.Closed)
                    {
                        cn.Open();
                    }
                    using (var cmd = cn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "RegistrarDetalleVenta";

                        cmd.Parameters.AddWithValue("@IdVenta", entidad.IdVenta);
                        cmd.Parameters.AddWithValue("@IdDetIngreso", entidad.IdDetIngreso);
                        cmd.Parameters.AddWithValue("@Cantidad", entidad.Cantidad);
                        cmd.Parameters.AddWithValue("@PrecioVenta", entidad.PrecioVenta);
                        cmd.Parameters.AddWithValue("@Descuento", entidad.Descuento);

                        res = cmd.ExecuteNonQuery();
                    }
                }
                catch (SqlException e)
                {
                    MessageBox.Show(e.Message, "SQL Error Registrar Detalle venta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (cn.State == ConnectionState.Open)
                    {
                        cn.Close();
                    }
                }
            }
            if (res == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void CalcularTotalPorIngresoDeProducto()
        {
            EDetalleVenta        detalleProducto      = new EDetalleVenta();
            List <EDetalleVenta> listaDetalleProducto = new List <EDetalleVenta>();
            EVenta lineaDeVenta = new EVenta();

            detalleProducto.Precio   = 20;
            detalleProducto.Cantidad = 5;
            double valorEsperado = 100;

            listaDetalleProducto.Add(detalleProducto);
            lineaDeVenta.ListaDetalleProducto = listaDetalleProducto;

            double total = lineaDeVenta.CalcularTotalPorIngresoDeProducto();

            Assert.AreEqual(valorEsperado, total);
        }
        private bool Validar(EDetalleVenta entidad)
        {
            builder.Clear();

            if (entidad.Cantidad < 0)
            {
                builder.Append("Ingrese una cantidad válida");
            }
            if (entidad.PrecioVenta < 0)
            {
                builder.Append("\nIngrese un precio de venta válido");
            }
            if (entidad.Descuento < 0)
            {
                builder.Append("\nIngrese un descuento válido");
            }

            return(builder.Length == 0);
        }
Esempio n. 8
0
 public void Editar(EDetalleVenta d)
 {
     try
     {
         using (this.dt = new DatoSistemasDataContext())
         {
             this.dt.sp_det_venta_edit(d.Ven_codigo, d.Prod_codigo,
                                       d.Dven_precio, d.Cantidad, d.Dven_descuento, d.Dven_aumento);
         }
     }
     catch (System.Data.SqlClient.SqlException ex)
     {
         Datos.Excepciones.Gestionar(ex, "DetalleVenta");
         throw new Exception(Datos.Excepciones.MensajePersonalizado);
     }
     catch (Exception ex)
     {
         Datos.Excepciones.Gestionar(ex);
         throw new Exception(Datos.Excepciones.MensajePersonalizado);
     }
 }
Esempio n. 9
0
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (entiVenta == null)
                {
                    entiVenta = new EVenta();
                }

                entiVenta.IdCliente       = Convert.ToInt32(lblIdCliente.Text);
                entiVenta.IdTrabajador    = UserCache.IdTrabajador;
                entiVenta.Fecha           = dtpFecha.Value;
                entiVenta.TipoComprobante = cmbComprobante.Text;
                entiVenta.Serie           = txtSerie.Text.Trim();
                entiVenta.Correlativo     = txtCorrelativo.Text.Trim();
                entiVenta.Igv             = Convert.ToDecimal(txtIgv.Text.Trim());

                //Capturamos el IdUltimo
                int idUltimo = venta.RegistrarVenta(entiVenta);
                if (idUltimo > 0)
                {
                    MessageBox.Show("¡Registro de venta con éxito!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //Registramos el Detalle ingreso
                    if (entiDetalle == null)
                    {
                        entiDetalle = new EDetalleVenta();
                    }
                    int numFilas = dgvDetalleVentas.Rows.Count;
                    int contador = 0;

                    for (int i = 0; i < numFilas; i++)
                    {
                        entiDetalle.IdVenta      = idUltimo;
                        entiDetalle.IdDetIngreso = Convert.ToInt32(dgvDetalleVentas.Rows[i].Cells[0].Value.ToString());
                        entiDetalle.Cantidad     = Convert.ToInt32(dgvDetalleVentas.Rows[i].Cells[2].Value.ToString());
                        entiDetalle.PrecioVenta  = Convert.ToDecimal(dgvDetalleVentas.Rows[i].Cells[3].Value.ToString());
                        entiDetalle.Descuento    = Convert.ToInt32(dgvDetalleVentas.Rows[i].Cells[4].Value.ToString());

                        int idDetIngreso = Convert.ToInt32(dgvDetalleVentas.Rows[i].Cells[0].Value.ToString());
                        int cantidad     = Convert.ToInt32(dgvDetalleVentas.Rows[i].Cells[2].Value.ToString());

                        if (detalle.RegistrarDetalleVenta(entiDetalle))
                        {
                            venta.DisminuirStockPorVenta(idDetIngreso, cantidad);
                        }
                        else
                        {
                            contador++;
                        }
                    }

                    if (contador == 0)
                    {
                        MessageBox.Show("¡Detalle de venta registrado con éxito!", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                if (venta.builder.Length != 0)
                {
                    MessageBox.Show(venta.builder.ToString(), "VENTA: Para continuar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (detalle.builder.Length != 0)
                    {
                        MessageBox.Show(detalle.builder.ToString(), "DETALLE VENTA: Para continuar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                MostrarVenta();
                LimpiarVenta();
                Deshabilitar();
                btnNuevo.Enabled = true;
                EliminarFilaDetalleVenta();
            }
        }
        private void GuardarVenta()
        {
            string tipocomprobante  = CbxTipoComprobante.SelectedValue.ToString();
            string ventaserie       = "####";
            string ventacorrelativo = "########";
            NVenta venta            = new NVenta();

            if (venta.ObtenerSerieCorrelativo(tipocomprobante) != null)
            {
                DataRow row = venta.ObtenerSerieCorrelativo(tipocomprobante);
                ventaserie       = row["Serie"].ToString();
                ventacorrelativo = row["Correlativo"].ToString();
            }
            EVenta beVenta = new EVenta
            {
                Cliente         = Convert.ToInt32(LblIDCliente.Text),
                Empleado        = Frm_Principal.AccesoUsernameID,
                TipoComprobante = tipocomprobante,
                Serie           = ventaserie,
                Numero          = ventacorrelativo,
                Fecha           = Convert.ToDateTime(DateTime.Now),
                Hora            = Convert.ToDateTime(DateTime.Now),
                SubTotal        = Venta_SubTotal,
                Igv             = Venta_Igv,
                Total           = Venta_Total,
                Estado          = 1
            };
            NVenta boVenta = new NVenta();

            if (boVenta.Agregar(beVenta) == true)
            {
                if (MLVDetalle.Items.Count > 0)
                {
                    NDetalleVenta boDetalleVenta = new NDetalleVenta();
                    foreach (ListViewItem items in MLVDetalle.Items)
                    {
                        EDetalleVenta beDetalleVenta = new EDetalleVenta
                        {
                            Serie    = beVenta.Serie,
                            Numero   = beVenta.Numero,
                            Producto = items.SubItems[0].Text,
                            Precio   = Convert.ToDouble(items.SubItems[3].Text),
                            Cantidad = Convert.ToInt32(items.SubItems[4].Text),
                            Importe  = Convert.ToDouble(items.SubItems[5].Text)
                        };
                        //Agregar dettalle compra
                        if (boDetalleVenta.Agregar(beDetalleVenta) == true)
                        {
                            int    cantidadfinal      = 0;
                            double costounitariofinal = 0;
                            double costototalfinal    = 0;
                            //Obteniendo Ultimo Movimiento
                            NMovimiento boM   = new NMovimiento();
                            EMovimiento datos = boM.SeleccionarUltimoMovimientoProducto(beDetalleVenta.Producto);
                            if (!string.IsNullOrEmpty(datos.Producto))
                            {
                                //Si hay datos
                                cantidadfinal      = datos.CantidadFinal - beDetalleVenta.Cantidad;
                                costounitariofinal = datos.CostoUnitarioFinal;
                                double costofinaly = Math.Round((costounitariofinal * beDetalleVenta.Cantidad), 2);
                                costototalfinal = datos.CostoTotalFinal - costofinaly;
                                //Movimiento
                                EMovimiento beMovimiento = new EMovimiento
                                {
                                    Fecha                = DateTime.Now,
                                    TipoComprobante      = beVenta.TipoComprobante,
                                    Serie                = beVenta.Serie,
                                    Numero               = beVenta.Numero,
                                    TipoOperacion        = "01",
                                    Producto             = beDetalleVenta.Producto,
                                    CantidadEntrada      = 0,
                                    CostoUnitarioEntrada = 0,
                                    CostoTotalEntrada    = 0,

                                    CantidadSalida      = beDetalleVenta.Cantidad,
                                    CostoUnitarioSalida = costounitariofinal,
                                    CostoTotalSalida    = costofinaly,

                                    CantidadFinal      = cantidadfinal,
                                    CostoUnitarioFinal = costounitariofinal,
                                    CostoTotalFinal    = costototalfinal
                                };
                                NMovimiento boMovimiento = new NMovimiento();
                                if (boMovimiento.Agregar(beMovimiento) == true)
                                {
                                    EInventario beInventario = new EInventario
                                    {
                                        Producto        = beMovimiento.Producto,
                                        ValorUnitario   = beMovimiento.CostoUnitarioFinal,
                                        Existencias     = beMovimiento.CantidadFinal,
                                        ValorInventario = beMovimiento.CostoTotalFinal
                                    };
                                    NInventario boInventario = new NInventario();
                                    boInventario.Modificar(beInventario);
                                }
                            }
                        }
                    }
                }
                //message
                Frm_Buscar_venta frm = Owner as Frm_Buscar_venta;
                frm.Listar();
                Close();
                Frm_Principal.Main.ChangeMessage("La Venta se ingreso correctamente", "Success");
            }
            else
            {
                Frm_Principal.Main.ChangeMessage("Algo salio mal", "Failed");
            }
        }