//Agrega un articculo al detalle. private void AgregarButton_Click(object sender, RoutedEventArgs e) { if (!válidarAgregar()) { return; } Articulos Aux;//Este auxiliar hara los cambios en la base de datos; Aux = ArticulosBLL.Buscar(int.Parse(ArticuloIdComboBox.SelectedValue.ToString())); var detalle = new VentasDetalle { VentaId = int.Parse(VentaIdTextBox.Text), Cantidad = int.Parse(CantidadDetalleTextBox.Text), Subtotal = double.Parse(SubtotalDetalleTextBox.Text), ArticuloId = int.Parse(ArticuloIdComboBox.SelectedValue.ToString()), Articulo = articulo }; Venta.VentasDetalles.Add(detalle); Aux.Stock -= int.Parse(CantidadDetalleTextBox.Text); Venta.Total += double.Parse(SubtotalDetalleTextBox.Text); ArticulosBLL.Guardar(Aux); Cargar(); LimpiarDetalle(); }
public IList <VentasDetalle> listarVentas() { AccesoDatos conexion = new AccesoDatos(); IList <VentasDetalle> lista = new List <VentasDetalle>(); VentasNegocio ven = new VentasNegocio(); try { conexion.setearConsulta("SELECT VE.IDVENTA AS FACTURA,VE.FECHA, CL.APELLIDO + ' ' + CL.NOMBRE AS CLIENTE,US.APELLIDO + ' ' + US.NOMBRE AS VENDEDOR, SUM(AXV.PU * AXV.CANTIDAD) AS TOTAL_FACTURA FROM VENTAS AS VE INNER JOIN CLIENTES AS CL ON VE.IDCLIENTE = CL.IDCLIENTE INNER JOIN USUARIOS AS US ON VE.IDUSUARIO = US.IDUSUARIO INNER JOIN ARTICULOS_X_VENTA AS AXV ON VE.IDVENTA = AXV.IDVENTA INNER JOIN ARTICULOS AS AR ON AXV.IDARTICULO = AR.IDARTICULO GROUP BY VE.IDVENTA, CL.APELLIDO, US.APELLIDO,VE.FECHA,CL.NOMBRE, US.NOMBRE ORDER BY VE.IDVENTA DESC"); conexion.leerConsulta(); while (conexion.Lector.Read()) { VentasDetalle venta = new VentasDetalle(); venta.Factura = conexion.Lector.GetInt32(0); venta.Fecha = conexion.Lector.GetDateTime(1); venta.Cliente = conexion.Lector.GetString(2); venta.Vendedor = conexion.Lector.GetString(3); venta.Total = conexion.Lector.GetDecimal(4); venta.Ventadet = ven.traerPorVenta(venta.Factura); lista.Add(venta); } return(lista); } catch (Exception ex) { throw ex; } }
//—————————————————————————————————————————————————————[ AGREGAR FILA ]————————————————————————————————————————————————————— private void AgregarFilaButton_Click(object sender, RoutedEventArgs e) { var producto = (Productos)ProductoIdComboBox.SelectedItem; var filaDetalle = new VentasDetalle { VentaId = ventas.VentaId, ProductoId = Convert.ToInt32(ProductoIdComboBox.SelectedValue.ToString()), Cantidadv = Convert.ToInt32(CantidadvTextBox.Text), }; //————————————————————————————————[ Calculos Total ]—————————————————————————————— double subtotal = (producto.Precio) * (int.Parse(CantidadvTextBox.Text)); double itbisTotal = ((producto.Itebis) / 100) * subtotal; ventas.Total += Math.Round((subtotal + itbisTotal), 2); //———————————————————————————————————————————————————————————————————————————————— filaDetalle.productos = (Productos)ProductoIdComboBox.SelectedItem; filaDetalle.productos = producto; //———————————————————————————————————————————————————————————————————————————————— ventas.Detalle.Add(filaDetalle); Cargar(); ProductoIdComboBox.SelectedIndex = -1; CantidadvTextBox.Clear(); CantidadvTextBox.Focus(); }
public IList <VentasDetalle> traerPorVenta(Int32 IdVenta) { AccesoDatos conexion = new AccesoDatos(); IList <VentasDetalle> lista = new List <VentasDetalle>(); try { conexion.setearConsulta("SELECT VE.IDVENTA AS FACTURA,VE.FECHA, CL.APELLIDO AS CLIENTE, AR.DESCRIPCION, AXV.PU * AXV.CANTIDAD, US.APELLIDO AS VENDEDOR, AXV.CANTIDAD FROM VENTAS AS VE INNER JOIN CLIENTES AS CL ON VE.IDCLIENTE = CL.IDCLIENTE INNER JOIN USUARIOS AS US ON VE.IDUSUARIO = US.IDUSUARIO INNER JOIN ARTICULOS_X_VENTA AS AXV ON VE.IDVENTA = AXV.IDVENTA INNER JOIN ARTICULOS AS AR ON AXV.IDARTICULO = AR.IDARTICULO WHERE VE.IDVENTA = " + IdVenta.ToString()); conexion.leerConsulta(); while (conexion.Lector.Read()) { VentasDetalle vetVenta = new VentasDetalle(); vetVenta.Factura = conexion.Lector.GetInt32(0); vetVenta.Fecha = conexion.Lector.GetDateTime(1); vetVenta.Cliente = conexion.Lector.GetString(2); vetVenta.Descripcion = conexion.Lector.GetString(3); vetVenta.Total = conexion.Lector.GetDecimal(4); vetVenta.Vendedor = conexion.Lector.GetString(5); vetVenta.Cantidad = conexion.Lector.GetInt32(6); lista.Add(vetVenta); } return(lista); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(int id, [Bind("Id,VentaId,MedicinaId,Precio")] VentasDetalle ventasDetalle) { if (id != ventasDetalle.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ventasDetalle); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VentasDetalleExists(ventasDetalle.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(ventasDetalle)); }
public ActionResult InsertarVenta(string Entidadetalles, int Existencia) { VentasDetalle entidaAUX = null; JObject resultado = null; try { if (Entidadetalles != string.Empty) { entidaAUX = new JavaScriptSerializer().Deserialize <VentasDetalle>(Entidadetalles); if (entidaAUX != null) { if (InsertarEntidad(entidaAUX)) { ActualizarExistencia(entidaAUX.IdArticulo, Existencia); resultado = new JObject(new JProperty("Estatus", "Correcto")); return(Json(resultado.ToString(), JsonRequestBehavior.AllowGet)); } } } } catch (Exception e) { resultado = new JObject(new JProperty("Estatus", "error")); return(Json(resultado.ToString(), JsonRequestBehavior.AllowGet)); } resultado = new JObject(new JProperty("Estatus", "error")); return(Json(resultado.ToString(), JsonRequestBehavior.AllowGet)); }
protected void btnGuardarVentas_Click(object sender, EventArgs e) { Articulos art = new Articulos(); Ventas vent = new Ventas(); VentasDetalle ventDetall = new VentasDetalle(); vent.Monto = Convert.ToDecimal(Session["total"]); //vent.Fecha = Convert.ToDateTime(txtFecha.Text); if (vent.Insertar()) { foreach (DataRow r in dtArt.Rows) { ventDetall.ArticuloId = Convert.ToInt32(r["ArticuloId"]); ventDetall.Ventaid = vent.VentasId; ventDetall.Cantidad = Convert.ToInt32(r["Cantidad"]); ventDetall.Precio = Convert.ToDecimal(txtPrecio.Text); if (vent.Insertar()) { art.reduceExistencia(Convert.ToInt32(r["ArticuloId"]), Convert.ToInt32(r["Cantidad"])); } } } }
public void ModificarTest() { bool paso = false; Ventas venta = new Ventas(); VentasDetalle ventasDetalle = new VentasDetalle(); venta.VentaId = 1; venta.ClienteId = 1; venta.Fecha = DateTime.Now; venta.Comentario = "Primera venta a este cliente"; venta.Descuentos = 0; venta.Fecha = DateTime.Now; venta.Total = 500; venta.TotalGeneral = 590; venta.ITBIS = 90; venta.Tipo = "Credito"; venta.UsuarioId = 1; ventasDetalle.VentasDetalleId = 1; ventasDetalle.VentaId = 1; ventasDetalle.Precio = 500; ventasDetalle.ProductoId = 1; ventasDetalle.Cantidad = 1; venta.VentasDetalle.Add(ventasDetalle); paso = VentasBLL.Modificar(venta); Assert.AreEqual(paso, true); }
protected void agregarButton_Click(object sender, EventArgs e) { List <VentasDetalle> detalles = new List <VentasDetalle>(); if (IsValid) { RepositorioBase <Productos> repositorio = new RepositorioBase <Productos>(); Productos producto = new Productos(); int id = Utils.ToIntObjetos(ProductoDropDownList.SelectedValue); string descripcion = string.Empty;; producto = repositorio.Buscar(id); descripcion = producto.Descripcion; DateTime date = DateTime.Now.Date; int cantidad = Utils.ToInt(CantidadTextBox.Text); decimal precio = Utils.ToDecimal(PrecioTextBox.Text); decimal importe = Utils.ToDecimal(ImporteTextBox.Text); if (Producto()) { return; } Ventas venta = new Ventas(); if (DetalleGridView.Rows.Count != 0) { venta.Detalle = (List <VentasDetalle>)ViewState["Detalle"]; } if (Utils.ToIntObjetos(UsuarioDropDownList.SelectedValue) < 1) { Utils.ShowToastr(this, "No hay Usuarios guardado.", "Error", "error"); return; } if (Utils.ToIntObjetos(ProductoDropDownList.SelectedValue) < 1) { Utils.ShowToastr(this, "No hay Productos guardado.", "Error", "error"); return; } if (Utils.ToInt(IdTextBox.Text) == 0) { VentasDetalle detalle = new VentasDetalle(); venta.Detalle.Add(new VentasDetalle(0, detalle.VentaId, Utils.ToInt(ProductoDropDownList.SelectedValue), descripcion, cantidad, precio, importe)); } else { VentasDetalle detalle = new VentasDetalle(); venta.Detalle.Add(new VentasDetalle(0, Utils.ToInt(IdTextBox.Text), Utils.ToInt(ProductoDropDownList.SelectedValue), descripcion, cantidad, precio, importe)); } ViewState["Detalle"] = venta.Detalle; DetalleGridView.DataSource = ViewState["Detalle"]; DetalleGridView.DataBind(); Total(); } }
public async Task <IActionResult> Create([Bind("Id,VentaId,MedicinaId,Precio")] VentasDetalle ventasDetalle) { if (ModelState.IsValid) { _context.Add(ventasDetalle); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(ventasDetalle)); }
protected void AgregarButton_Click(object sender, EventArgs e) { VentasDetalle ventaDetalle = new VentasDetalle(); Articulos articulo = new Articulos(); if (ArticuloDropDownList.SelectedIndex != 0) { ControlDeBotones(1); articulo.ArticuloId = ArticuloDropDownList.SelectedIndex; articulo.Buscar(articulo.ArticuloId); if (articulo.Existencia > ConvertirValor(CantidadTextBox.Text)) { Ventas venta; if (Session["Venta"] == null) { Session["Venta"] = new Ventas(); } venta = (Ventas)Session["Venta"]; venta.AgregarArticulo(articulo.ArticuloId, ConvertirValor(CantidadTextBox.Text), articulo.Precio); ventaDetalle.Descripcion = articulo.Descripcion; ventaDetalle.Cantidad = ConvertirValor(CantidadTextBox.Text); ventaDetalle.Precio = articulo.Precio; venta.AgregarCantidadArticulo(articulo.Existencia - ventaDetalle.Cantidad, articulo.ArticuloId); Session["Venta"] = venta; GuardatLista(ventaDetalle); DetalleGridView.DataSource = ObtenerLista(); DetalleGridView.DataBind(); venta.Monto += articulo.Precio * ventaDetalle.Cantidad; MontoLabel.Text = venta.Monto.ToString(); ArticuloDropDownList.SelectedIndex = 0; CantidadTextBox.Text = ""; } else { Mensaje("Usted a sobrepasado la cantidad maxima de este articulo"); } } else { Mensaje("Seleccione un articulo"); } }
protected void ButtonAgregar_Click(object sender, EventArgs e) { List <VentasDetalle> detalle = new List <VentasDetalle>(); Ventas venta = new Ventas(); RepositorioBase <Productos> repositorio = new RepositorioBase <Productos>(); Productos productos = new Productos(); int id = ToInt(ProductoDropDownList.SelectedValue); productos = repositorio.Buscar(id); if (IsValid) { if (ToInt(CantidadTextBox.Text) > productos.Inventario) { Utils.ShowToastr(this, "no hay suficiente Productos para la venta!!", "Fallo", "error"); } else { DateTime date = DateTime.Now.Date; int cantidad = Utils.ToInt(CantidadTextBox.Text); int precio = Utils.ToInt(PrecioTextBox.Text); int importe = Utils.ToInt(ImporteTextBox.Text); int productoId = Utils.ToInt(ProductoDropDownList.SelectedValue); string descripcion = ProductoDropDownList.SelectedItem.ToString(); if (VentasGridView.Rows.Count != 0) { venta.Detalle = (List <VentasDetalle>)ViewState["VentasDetalle"]; } VentasDetalle vd = new VentasDetalle(); venta.Detalle.Add(new VentasDetalle(0, vd.VentaId, productoId, descripcion, cantidad, precio, importe)); int x = Convert.ToInt32(CantidadTextBox.Text); productos.Inventario -= x; if (ToInt(CantidadTextBox.Text) == 0) { Utils.ShowToastr(this, "Introduzca una cantidad!!", "Fallo", "error"); } ViewState["VentasDetalle"] = venta.Detalle; VentasGridView.DataSource = ViewState["VentasDetalle"]; VentasGridView.DataBind(); LlenaValores(); } } }
public List <VentasDetalle> GuardatLista(VentasDetalle detalle) { if (Session["Detalle"] == null) { List <VentasDetalle> detalle2 = this.ObtenerNuevaLista(); detalle2.Add(detalle); Session["Detalle"] = detalle2; } else { List <VentasDetalle> detalle2 = (List <VentasDetalle>)Session["Detalle"]; detalle2.Add(detalle); Session["Detalle"] = detalle2; } return((List <VentasDetalle>)Session["Detalle"]); }
public bool InsertarEntidad(VentasDetalle entidadInsert) { StringBuilder sentencia = new StringBuilder(); bool result = false; try { SqlConnection conexion = Obtenerconexion(true); sentencia.AppendLine(" INSERT INTO VTA_VENTADETALLE(IDARTICULO, IDCLIENTE,"); sentencia.AppendLine(" CANTIDAD, TIPOVENTA, FECHA, TOTAL, ACTIVO) "); sentencia.AppendLine(" VALUES(@IDARTICULO,@IDCLIENTE,@CANTIDAD,@TIPOVENTA,@FECHA,@TOTAL,@ACTIVO )"); SqlCommand comando = obtenercomando(conexion, sentencia); comando.Parameters.Add("@IDARTICULO", SqlDbType.Int); comando.Parameters["@IDARTICULO"].Value = entidadInsert.IdArticulo; comando.Parameters.Add("@IDCLIENTE", SqlDbType.Int); comando.Parameters["@IDCLIENTE"].Value = entidadInsert.IdCliente; comando.Parameters.Add("@CANTIDAD", SqlDbType.Int); comando.Parameters["@CANTIDAD"].Value = entidadInsert.Cantidad; comando.Parameters.Add("@TIPOVENTA", SqlDbType.VarChar); comando.Parameters["@TIPOVENTA"].Value = entidadInsert.TipoVenta; comando.Parameters.Add("@FECHA", SqlDbType.Date); comando.Parameters["@FECHA"].Value = DateTime.Now.Date; comando.Parameters.Add("@TOTAL", SqlDbType.Money); comando.Parameters["@TOTAL"].Value = entidadInsert.Importe; comando.Parameters.Add("@ACTIVO", SqlDbType.VarChar); comando.Parameters["@ACTIVO"].Value = entidadInsert.Activo; result = comando.ExecuteNonQuery() > 0 ?true:false; } catch { } return(result); }
protected void LlenaCampos(Ventas v) { VentasDetalle vd = new VentasDetalle(); Articulos art = new Articulos(); IdTextBox.Text = v.VentaId.ToString(); FechaTextBox.Text = v.Fecha; MontoTextBox.Text = v.Monto.ToString(); foreach (var a in v.Detalle) { art.Buscar(a.ArticuloId); DataTable det = (DataTable)ViewState["Detalle"]; det.Rows.Add(a.ArticuloId, art.Descripcion, a.Cantidad, a.Precio); ViewState["Detalle"] = det; ArtGridView.DataSource = (DataTable)ViewState["Detalle"]; ArtGridView.DataBind(); } }
protected void AgregarButton_Click(object sender, EventArgs e) { Ventas ventas; if (Session["Ventas"] == null) { Session["Ventas"] = new Ventas(); } ventas = (Ventas)Session["Ventas"]; VentasDetalle ventasdetalle = new VentasDetalle(); ventasdetalle.Cantidad = int.Parse(CantidadTextBox.Text); ventasdetalle.Precio = float.Parse(PrecioTextBox.Text); ventas.AgregarVentasDetalle(ventasdetalle.Cantidad, ventasdetalle.Precio); Session["Ventas"] = ventas; VentasDetalleGridView.DataSource = ventas.Tipo; VentasDetalleGridView.DataBind(); }
protected void DeleteButton_Click(object sender, EventArgs e) { Ventas v = new Ventas(); Articulos art = new Articulos(); VentasDetalle vd = new VentasDetalle(); int id = 0; int.TryParse(IdTextBox.Text, out id); v.Buscar(id); foreach (var a in v.Detalle) { art.Buscar(a.ArticuloId); art.EditarExistencia(art.ArticuloId, a.Cantidad, false); } if (v.Eliminar()) { Utilitarios.ShowToastr(this, "Eliminado con exito", "Mensaje", "success"); Limpiar(); } }
protected void ButtonAgregar_Click(object sender, EventArgs e) { Ventas venta = new Ventas(); decimal total = 0; VentasDetalle d = new VentasDetalle(); RepositorioBase <Vehiculos> repositorio = new RepositorioBase <Vehiculos>(); if (ValidarD()) { return; } if (Validarr()) { return; } if (Existencia()) { return; } Ventas P = new Ventas(); P = (Ventas)ViewState["Ventas"]; Vehiculos A = new RepositorioBase <Vehiculos>().Buscar(Utils.ToInt(VehiculoDropDownList.SelectedValue)); int idd = Utils.ToInt(VehiculoDropDownList.SelectedValue); foreach (var item in P.Detalle.ToList()) { if (idd == item.VehiculoId) { Utils.ShowToastr(this, "Ya se ha agregado", "Error", "error"); return; } } int id = Utils.ToInt(VehiculoDropDownList.SelectedValue); Vehiculos vehiculos = repositorio.Buscar(id); venta = (Ventas)ViewState["Ventas"]; decimal precio = Convert.ToDecimal(PrecioTextBox.Text); int VehiculoId = Utils.ToInt(VehiculoDropDownList.SelectedValue); var subtotal = vehiculos.Precio = Convert.ToDecimal(PrecioTextBox.Text); string descripcion = VehiculoDropDownList.SelectedItem.ToString(); venta.Detalle.Add(new VentasDetalle(Convert.ToInt32(VentaIdTextBox.Text), VehiculoId, subtotal, descripcion, vehiculos.Vin)); ViewState["Ventas"] = venta; this.BindGrid(); TotalTextBox.Text = total.ToString(); foreach (var item in venta.Detalle) { total += item.Precio; } TotalTextBox.Text = total.ToString(); CalTotal(); }
private ListadoVentasDetalle LlenarListado(int Tipo, string Busqueda) { StringBuilder consulta = new StringBuilder(); SqlConnection conexion = null; SqlCommand comando = null; SqlDataReader reader = null; ListadoVentasDetalle listavents = new ListadoVentasDetalle(); try { conexion = Obtenerconexion(true); consulta.AppendLine("SELECT A.FOLIOVTA,A.IDCLIENTE,B.NOMBRE+' '+ "); consulta.AppendLine("B.APELLIDOPATERNO+' '+B.APELLIDOMATERNO NOMBRECOMPLETO, "); consulta.AppendLine("A.IDARTICULO,A.FECHA,A.ACTIVO,A.TOTAL "); consulta.AppendLine(" FROM VTA_VENTADETALLE A "); consulta.AppendLine(" LEFT JOIN VTA_CLIENTES B ON "); consulta.AppendLine(" B.ID = A.IDCLIENTE "); consulta.AppendLine(" LEFT JOIN VTA_ARTICULOS C ON "); consulta.AppendLine(" C.ID = A.IDARTICULO "); consulta.AppendLine(" WHERE A.ACTIVO='Si' "); if (Tipo == 2) { consulta.AppendLine(" AND A.FOLIOVTA = @BUSQUEDA "); } if (Tipo == 1) { if (!string.IsNullOrEmpty(Busqueda)) { int idcliente = 0; string busqueda = string.Empty; if (!int.TryParse(Busqueda, out idcliente)) { consulta.AppendLine(" AND (B.NOMBRE LIKE @BUSQUEDA OR B.APELLIDOMATERNO "); consulta.AppendLine(" LIKE @BUSQUEDA OR B.APELLIDOPATERNO LIKE @BUSQUEDA) "); } else { consulta.AppendLine(" AND A.IDCLIENTE = @BUSQUEDA "); } } } comando = obtenercomando(conexion, consulta); if (!string.IsNullOrEmpty(Busqueda)) { if (Tipo == 1) { int idcliente = 0; string busqueda = string.Empty; if (!int.TryParse(Busqueda, out idcliente)) { comando.Parameters.Add("@BUSQUEDA", SqlDbType.VarChar); comando.Parameters["@BUSQUEDA"].Value = Busqueda; } else { comando.Parameters.Add("@BUSQUEDA", SqlDbType.Int); comando.Parameters["@BUSQUEDA"].Value = Busqueda; } } else if (Tipo == 2) { comando.Parameters.Add("@BUSQUEDA", SqlDbType.Int); comando.Parameters["@BUSQUEDA"].Value = Busqueda; } } reader = comando.ExecuteReader(); while (reader.Read()) { VentasDetalle Entidad = new VentasDetalle(); int i = 0; Entidad.FolioVta = (reader[i] != DBNull.Value ? reader.GetInt32(i) : 0); i++; Entidad.IdCliente = (reader[i] != DBNull.Value ? reader.GetInt32(i) : 0); i++; Entidad.IdClienteNombre = (reader[i] != DBNull.Value ? reader.GetString(i) : string.Empty); i++; Entidad.IdArticulo = (reader[i] != DBNull.Value ? reader.GetInt32(i) : 0); i++; Entidad.Fecha = (reader[i] != DBNull.Value ? reader.GetDateTime(i) :DateTime.MinValue); i++; Entidad.Activo = (reader[i] != DBNull.Value ? reader.GetString(i) : string.Empty); i++; Entidad.Importe = (reader[i] != DBNull.Value ? Convert.ToDouble(reader.GetDecimal(i)) : 0); i++; listavents.Add(Entidad); } } catch (Exception ex) { //ModelState.AddModelError("errors", ex.Message); } finally { if (conexion != null) { if (conexion.State == ConnectionState.Open) { conexion.Close(); } conexion.Dispose(); conexion = null; } } return(listavents); }
public ContenedorVentas() { ventas = new Ventas(); ventasDetalle = new VentasDetalle(); listaVentas = new List <ListaVentas>(); }