public void AgregarFila(VentaProducto ventaProducto) { DataGridViewRow r = ConstruirFila(); SetearFila(r, ventaProducto); AgregarFila(r); }
public bool Save(Venta entity) { Venta venta = new Venta { LocalId = entity.LocalId, ClienteId = entity.ClienteId, Fechaventa = DateTime.Now.ToString("dd/MM/yyyy"), Monto = entity.Monto, Igv = entity.Igv, Descuento = entity.Descuento, Montoneto = entity.Montoneto, Horaentrega = DateTime.Now.ToString("dd/MM/yyyy"), Mediopago = entity.Mediopago, Numerotarjeta = entity.Numerotarjeta, Pagado = entity.Pagado }; try{ context.Ventas.Add(venta); context.SaveChanges(); var ventaId = venta.Id; foreach (var item in entity.VentaProducto) { VentaProducto vntprdct = new VentaProducto { VentaId = ventaId, ProductoId = item.ProductoId, Cantidad = item.Cantidad }; context.VentaProductos.Add(vntprdct); } } catch (System.Exception) { return(false); } return(true); }
//public void Guardar(Producto producto) //{ // _conexion = new ConexionBD(); // _repositorioProducto = new RepositorioProducto(_conexion.AbrirConexion()); // _repositorioProducto.Guardar(producto); // _conexion.CerrarConexion(); //} public void Borrar(VentaProducto ventaProducto) { _conexion = new ConexionBD(); _repositorioVentaProducto = new RepositorioVentaProducto(_conexion.AbrirConexion()); _repositorioVentaProducto.Borrar(ventaProducto); _conexion.CerrarConexion(); }
}//insertarApartado /// <summary> /// Este realizará una inserción a la realción de esa tabla /// </summary> /// <param name="vp"></param> /// <returns>Boolean</returns> public Boolean insertarApartadoProducto(VentaProducto vp) { SqlConnection connection = new SqlConnection(this.stringConeccion); String sqlStoreProcedure = "sp_insertarApartadoProducto"; SqlCommand cmdInsertar = new SqlCommand(sqlStoreProcedure, connection); cmdInsertar.CommandType = System.Data.CommandType.StoredProcedure; //@id_producto int, @id_categoria int, @total float, @fecha date, @hora time ,@id_cliente varchar(15) cmdInsertar.Parameters.Add(new SqlParameter("@id_producto", vp.IdProduco)); cmdInsertar.Parameters.Add(new SqlParameter("@id_categoria", vp.IdCategoria)); cmdInsertar.Parameters.Add(new SqlParameter("@total", vp.Total)); cmdInsertar.Parameters.Add(new SqlParameter("@fecha", vp.Fecha)); cmdInsertar.Parameters.Add(new SqlParameter("@hora", vp.Hora)); cmdInsertar.Parameters.Add(new SqlParameter("@id_cliente", vp.IdCliente)); cmdInsertar.Connection.Open(); if (cmdInsertar.ExecuteNonQuery() > 0) { cmdInsertar.Connection.Close(); return true; } else { cmdInsertar.Connection.Close(); return false; }//if-else }//insertar venta
public async Task <IActionResult> Edit(int id, [Bind("VentaProductoID,FacturaID,ProductoID,Cantidad,Precio")] VentaProducto ventaProducto) { if (id != ventaProducto.VentaProductoID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(ventaProducto); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VentaProductoExists(ventaProducto.VentaProductoID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FacturaID"] = new SelectList(_context.Factura, "FacturaID", "FacturaID", ventaProducto.FacturaID); ViewData["ProductoID"] = new SelectList(_context.Producto, "ProductoID", "ProductoID", ventaProducto.ProductoID); return(View(ventaProducto)); }
private void CargarDetalle(int ventaID) { VentaProducto vp = new VentaProducto(); List <VentaProducto> lvp = vp.ObtenerDetalleVenta(ventaID); gridDetalles.DataSource = lvp; gridDetalles.DataBind(); if (lvp != null) { int Total = 0, IVA = 0, TotalFinal = 0; for (int i = 0; i < lvp.Count; i++) { Total = Total + (lvp[i].Cantidad * lvp[i].PrecioUnitario); } IVA = ((Total * 19) / 100); TotalFinal = Total + IVA; lbNeto.Text = Total.ToString(); lbIva.Text = IVA.ToString(); lbTotal.Text = TotalFinal.ToString(); } else { lbTotal.Text = "0"; lbIva.Text = "0"; lbNeto.Text = "0"; } }
public bool Existe(VentaProducto producto) { //try //{ // SqlCommand comando; // if (producto.Producto.ProductoID == 0 ) // { // string cadenaComando = "SELECT ProductoID, VentaProducto FROM VentasProductos WHERE VentaProducto=@nombre"; // comando = new SqlCommand(cadenaComando, conexion); // comando.Parameters.AddWithValue("@nombre", producto.producto); // } // else // { // string cadenaComando = "SELECT ProductoID, VentaProducto FROM VentasProductos WHERE VentaProducto=@nombre AND ProductoID<>@id"; // comando = new SqlCommand(cadenaComando, conexion); // comando.Parameters.AddWithValue("@nombre", producto.producto); // comando.Parameters.AddWithValue("@id", producto.ProductoID); // } // SqlDataReader reader = comando.ExecuteReader(); // return reader.HasRows; //} //catch (Exception e) //{ // throw new Exception(e.Message); //} return(false); }
public async Task <VentaProductoOutput> GetVentaProductoById(int idVenta) { VentaProducto ventaProducto = await _ventaProductoRepository.GetCategoriaById(idVenta); VentaProductoOutput ventaProductoOutput = _mapper.Map <VentaProductoOutput>(ventaProducto); return(ventaProductoOutput); }
public void InsertarVentaProducto(VentaProducto venta) { using (var dbc = new SPC_BD()) { dbc.VentaProducto.Add(venta); dbc.SaveChanges(); } }
public void EliminarVentaProducto(int id) { using (var dbc = new SPC_BD()) { VentaProducto colocacion = dbc.VentaProducto.Find(id); dbc.VentaProducto.Remove(colocacion); dbc.SaveChanges(); } }
public void ActualizarVentaProducto(VentaProducto venta) { using (var dbc = new SPC_BD()) { dbc.Entry(venta).State = EntityState.Modified; dbc.SaveChanges(); } }
public async Task EliminarCategoriaAsync(int idVenta) { VentaProducto venta = new VentaProducto() { Codigo = idVenta }; _db.Entry(venta).State = EntityState.Deleted; }
private void SetearFila(DataGridViewRow r, VentaProducto ventaProducto) { //r.Cells[CmnProducto.Index].Value = ventaProducto.Producto.producto; r.Cells[CmnCantidad.Index].Value = ventaProducto.Cantidad; r.Cells[CmnTipoEnvase.Index].Value = ventaProducto.TipoEnvase.tipoEnvase; r.Cells[CmnPrecioUnitario.Index].Value = ventaProducto.Precio; r.Cells[cmnPesoTotal.Index].Value = decimal.Parse(ventaProducto.TipoEnvase.Capacidad.capacidad) * ventaProducto.Cantidad; r.Tag = ventaProducto; }
/// <summary> /// Metodo para obtener listado de ventaProducto por codigo de la venta a la BD /// </summary> /// <param name="codVenta"> codigo de la venta</param> /// <returns>array VentaProducto</returns> public VentaProducto[] ListadoVentasProducto(int codVenta) { MySqlCommand cmd = null; VentaProducto[] ventaProductos = null; try { conexion.Open(); cmd = new MySqlCommand(OBTENER_LISTADO_VENTA_PRODUCTO, conexion); cmd.Parameters.AddWithValue("@cod_venta", codVenta); MySqlDataReader rs = cmd.ExecuteReader(); List <VentaProducto> lista = new List <VentaProducto>(); while (rs.Read()) { VentaProducto vp = new VentaProducto(); vp.Codigo = rs.GetInt32("codigo"); vp.PrecioUnidad = rs.GetDouble("precio_unidad"); vp.Cantidad = rs.GetInt32("cantidad"); Venta v = new Venta(); v.Codigo = rs.GetInt32("cod_venta"); vp.Venta = v; Producto p = new Producto(); p.Codigo = rs.GetInt32("cod_producto"); vp.Producto = p; lista.Add(vp); } if (lista != null && lista.Count > 0) { ventaProductos = lista.ToArray(); } return(ventaProductos); } catch (Exception) { return(null); } finally { if (conexion != null) { conexion.Close(); } } }
public async Task <IActionResult> Create([Bind("VentaProductoID,FacturaID,ProductoID,Cantidad,Precio")] VentaProducto ventaProducto) { if (ModelState.IsValid) { _context.Add(ventaProducto); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FacturaID"] = new SelectList(_context.Factura, "FacturaID", "FacturaID", ventaProducto.FacturaID); ViewData["ProductoID"] = new SelectList(_context.Producto, "ProductoID", "ProductoID", ventaProducto.ProductoID); return(View(ventaProducto)); }
/// <summary> /// Evento agregar producto a la venta /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAgregar_Click(object sender, EventArgs e) { Productos formProductos = new Productos(true); formProductos.ShowDialog(); Producto p = formProductos.ProductoDevolver; if (p != null) { List <VentaProducto> tempProduct = null; VentaProducto vp = null; bool existe = false; if (venta.Productos != null && venta.Productos.Length > 0) { //Comprobar si el producto ya esta en la lista tempProduct = venta.Productos.ToList(); foreach (VentaProducto ventaP in venta.Productos) { if (ventaP.Producto.Codigo == p.Codigo) { existe = true; break; } } } else { tempProduct = new List <VentaProducto>(); } if (!existe) { vp = new VentaProducto(); vp.Producto = p; vp.PrecioUnidad = p.Precio; vp.Cantidad = 1; tempProduct.Add(vp); venta.Productos = tempProduct.ToArray(); CargarProductos(); } else { MessageBox.Show("El producto ya existe", "Error al añadir producto", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task AgregarEditarVentaProductoAsync(VentaProductoInput ventaProducto) { if (ventaProducto.Codigo.GetValueOrDefault(0) > 0) { VentaProducto ventaProducto1 = await _ventaProductoRepository.GetCategoriaById(ventaProducto.Codigo.Value, trackear : true); _mapper.Map <VentaProductoInput, VentaProducto>(ventaProducto, ventaProducto1); } else { VentaProducto registroVenta1 = _mapper.Map <VentaProducto>(ventaProducto); await _ventaProductoRepository.AgregarEditarCategiriasAsync(registroVenta1); } await _ventaProductoRepository.SaveChangesAsync(); }
public void Borrar(VentaProducto ventaProducto) { try { string cadenaComando = "DELETE FROM VentasProductos WHERE VentaID=@venta"; SqlCommand comando = new SqlCommand(cadenaComando, conexion); //comando.Parameters.AddWithValue("@id", ventaProducto.Producto.ProductoID); comando.Parameters.AddWithValue("@venta", ventaProducto.Venta.VentaID); comando.ExecuteNonQuery(); } catch (Exception e) { throw new Exception(e.Message); } }
public static List <VentaProducto> getReporteVentaSinFiltro(string orden) { string CadenaConexion = ConfigurationManager.ConnectionStrings["DB"].ConnectionString; SqlConnection cn = new SqlConnection(CadenaConexion); List <VentaProducto> ventaReporte = new List <VentaProducto>(); try { cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.Parameters.Clear(); cmd.CommandText = "SELECT c.nombre, c.mail, p.nombre as NombreProducto, pxv.cantidad, pxv.montoParcial,v.id_Venta, v.fecha, v.montoTotal FROM Cliente c INNER JOIN Venta v ON c.id_Cliente = v.id_Cliente INNER JOIN ProductoXventa pxv ON pxv.id_Venta = v.id_Venta INNER JOIN Producto p ON pxv.id_Producto = p.id_Producto order by " + orden; SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { VentaProducto Vp = new VentaProducto(); Vp.id_Venta = (int)dr["id_Venta"]; Vp.fechaVenta = (DateTime)dr["fecha"]; Vp.montoTotal = (int)dr["montoTotal"]; Vp.nombreCliente = dr["nombre"].ToString(); Vp.mailCliente = dr["mail"].ToString(); Vp.cantidad = (int)dr["cantidad"]; Vp.montoParcial = (int)dr["montoParcial"]; Vp.nombreProducto = dr["NombreProducto"].ToString(); ventaReporte.Add(Vp); } dr.Close(); } catch (Exception ex) { throw; } finally { if (cn != null && cn.State == ConnectionState.Open) { cn.Close(); } } return(ventaReporte); }
//public bool Existe(Producto producto) //{ // try // { // _conexion = new ConexionBD(); // repositorioVenta = new RepositorioVenta(_conexion.AbrirConexion()); // repositorioTipoEnvase = new RepositorioTipoEnvase(_conexion.AbrirConexion()); // _repositorioProducto = new RepositorioProducto(_conexion.AbrirConexion()); // var existe = _repositorioProducto.Existe(producto); // _conexion.CerrarConexion(); // return existe; // } // catch (Exception e) // { // throw new Exception(e.Message); // } //} public bool EstaRelacionado(VentaProducto ventaProducto) { try { _conexion = new ConexionBD(); repositorioVenta = new RepositorioVenta(_conexion.AbrirConexion()); repositorioTipoEnvase = new RepositorioTipoEnvase(_conexion.AbrirConexion()); _repositorioProducto = new RepositorioProducto(_conexion.AbrirConexion()); var relacionado = _repositorioVentaProducto.EstaRelacionado(ventaProducto); _conexion.CerrarConexion(); return(relacionado); } catch (Exception e) { throw new Exception(e.Message); } }
private VentaProducto ConstruirProducto(SqlDataReader reader) { VentaProducto ventaproducto = new VentaProducto(); //repositorioProducto = new RepositorioProducto(conexion); //ventaproducto.Producto = repositorioProducto.GetProductoPorId(reader.GetDecimal(0)); repositorioVenta = new RepositorioVenta(conexion); ventaproducto.Venta = repositorioVenta.GetVentaPorId(reader.GetDecimal(1)); repositorioTipoEnvase = new RepositorioTipoEnvase(conexion); ventaproducto.TipoEnvase = repositorioTipoEnvase.GetTipoEnvasePorId(reader.GetDecimal(2)); repositorioVenta = new RepositorioVenta(conexion); ventaproducto.Cantidad = reader.GetDecimal(3); ventaproducto.Precio = reader.GetDecimal(4); return(ventaproducto); }
public void Guardar(VentaProducto ventaProducto) { try { string cadenaComando = "INSERT INTO VentasProductos ( VentaID, Cantidad, TipoEnvaseID, Precio)" + " VALUES (@Venta, @Cantidad ,@TipoEnvase, @precio)"; var comando = new SqlCommand(cadenaComando, conexion); comando.Parameters.AddWithValue("@Venta", ventaProducto.Venta.VentaID); //comando.Parameters.AddWithValue("@producto", ventaProducto.Producto.ProductoID); comando.Parameters.AddWithValue("@Cantidad", ventaProducto.Cantidad); comando.Parameters.AddWithValue("@TipoEnvase", ventaProducto.TipoEnvase.TipoEnvaseID); comando.Parameters.AddWithValue("@precio", ventaProducto.Precio); comando.ExecuteNonQuery(); } catch (Exception e) { throw new Exception(e.Message); } //try //{ // string cadenaComando = "UPDATE VentasProductos SET VentaID=@Venta,ProductoID=@producto,Cantidad=@cantidad, TipoEnvaseID=@tipo, Precio= @precio " + // " WHERE ProductoID=@id AND VentaID=@vID"; // SqlCommand comando = new SqlCommand(cadenaComando, conexion); // comando.Parameters.AddWithValue("@Venta", ventaProducto.Venta.VentaID); // comando.Parameters.AddWithValue("@producto", ventaProducto.Producto.ProductoID); // comando.Parameters.AddWithValue("@cantidad", ventaProducto.Cantidad); // comando.Parameters.AddWithValue("@tipo", ventaProducto.TipoEnvase.TipoEnvaseID); // comando.Parameters.AddWithValue("@precio", ventaProducto.Precio); // comando.Parameters.AddWithValue("@id", ventaProducto.Producto.ProductoID); // comando.Parameters.AddWithValue("@vID", ventaProducto.Venta.VentaID); // comando.ExecuteNonQuery(); //} //catch (Exception e) //{ // throw new Exception(e.Message); //} }
private void button1_Click(object sender, EventArgs e) { if (ValidarDatos()) { var ventasProductos = new VentaProducto(); ventasProductos.Cantidad = decimal.Parse(textBoxCantidad.Text); ventasProductos.Precio = decimal.Parse(textBoxPrecio.Text); //ventasProductos.Producto =(Producto) ComboBoxProducto.SelectedItem; ventasProductos.TipoEnvase = (TipoEnvase)ComboBoxTipoEnvase.SelectedItem; //if (VerificarRepetido(ventasProductos.Producto)) //{ // lista.Add(ventasProductos); // AgregarFila(ventasProductos); //} lista.Add(ventasProductos); AgregarFila(ventasProductos); ActualizarTotal(); } }
public List <VentaProducto> GetLista() { List <VentaProducto> lista = new List <VentaProducto>(); try { string cadenaComando = "SELECT VentaID, ProductoID, Cantidad, TipoEnvaseID FROM VentasProductos "; SqlCommand comando = new SqlCommand(cadenaComando, conexion); SqlDataReader reader = comando.ExecuteReader(); while (reader.Read()) { VentaProducto producto = ConstruirProducto(reader); lista.Add(producto); } reader.Close(); return(lista); } catch (Exception e) { throw new Exception(e.Message); } }
public bool Add(VentaProducto ventaProducto) { try { _clientDbContext.Add(ventaProducto); _clientDbContext.SaveChanges(); var maxID = _clientDbContext.Sold.Max(x => x.SoldId); VentaProductos2 vp; foreach (var p in ventaProducto.Products) { vp = new VentaProductos2(); vp.SoldId = maxID; vp.ProductId = p.ProductId; _clientDbContext.VentaProducto2.Add(vp); _clientDbContext.SaveChanges(); } return(true); } catch (Exception) { return(false); } }
public VentaProducto GetProductoPorId(decimal id) { VentaProducto p = null; try { string cadenaComando = "SELECT VentaID, ProductoID, Cantidad, TipoEnvaseID, Precio FROM VentasProductos WHERE ProductoID=@id"; SqlCommand comando = new SqlCommand(cadenaComando, conexion); comando.Parameters.AddWithValue("@id", id); SqlDataReader reader = comando.ExecuteReader(); if (reader.HasRows) { reader.Read(); p = ConstruirProducto(reader); } reader.Close(); return(p); } catch (Exception e) { throw new Exception(e.Message); } }
public void Alta(string id_producto, string nroDocumento, string tipoDocumento, string fecha_venta, string fecha_inicio_instalacion, string fecha_fin_instalacion, string legajolider) { VentaProducto venta_nueva = new VentaProducto(id_producto, nroDocumento, tipoDocumento, fecha_venta, fecha_inicio_instalacion, fecha_fin_instalacion, legajolider); venta_nueva.Crear(); }
private void Aceptar() { if (PopupAbierto) { PopupAbierto = false; } else if (MensajeErrorAbierto) { MensajeErrorAbierto = false; } else if (ConfirmacionAbierta) { ConfirmacionAbierta = false; } else { if (dgvListado.Rows.Count > 0) { var lineas = new List <VentaProducto>(); decimal total = 0; decimal costoTotal = 0; for (int i = 0; i <= dgvListado.Rows.Count - 1; i++) { var linea = new VentaProducto(); linea.Cantidad = decimal.Parse(dgvListado.Rows[i].Cells["Cantidad"].Value.ToString()); linea.Eliminado = false; linea.Identifier = Guid.NewGuid(); linea.Precio = Convert.ToDecimal(dgvListado.Rows[i].Cells["Unitario"].Value.ToString().Replace("$", "")); linea.ProductoId = (int)dgvListado.Rows[i].Cells["productoId"].Value; linea.Costo = dgvListado.Rows[i].Cells["Costo"].Value == null ? 0 : Convert.ToDecimal(dgvListado.Rows[i].Cells["Costo"].Value.ToString().Replace("$", "")); var recargo = dgvListado.Rows[i].Cells["Recargo"].Value; linea.EsPromocion = bool.Parse(dgvListado.Rows[i].Cells["EsPromocion"].Value.ToString()); linea.AdicionalPorExcepcion = recargo == null ? (decimal?)null : Convert.ToDecimal(recargo.ToString().Replace("$", "")) * linea.Cantidad; linea.Desincronizado = true; total += Convert.ToDecimal(linea.Cantidad) * linea.Precio.GetValueOrDefault(); costoTotal += Convert.ToDecimal(linea.Cantidad) * linea.Costo; lineas.Add(linea); } ConfirmacionAbierta = true; var frmConfirmar = new frmConfirmarVenta(total); if (frmConfirmar.ShowDialog() == DialogResult.OK) { ConfirmacionAbierta = false; var venta = new Venta { ImporteTotal = total, CostoTotal = costoTotal, Identifier = Guid.NewGuid(), Eliminado = false, CierreCajaId = UsuarioActual.CierreCajaIdActual, FechaVenta = DateTime.Now, VentaProductos = lineas }; venta.CierreCajaId = UsuarioActual.CierreCajaIdActual; var stockRepository = new StockRepository(); var stockTransaccionRepository = new EFRepository <StockTransaccion>(); var seAgregoStock = false; var seAgregoTransaccion = false; //Agrego primero a la coleccion las lineas secundarias correspondientes a promociones var secundarias = new List <VentaProducto>(); foreach (var linea in lineas.Where(l => l.EsPromocion)) { var productos = ProductoPromocionRepository.Listado().Where(p => p.PadreId == linea.ProductoId && !p.Eliminado).ToList(); secundarias.AddRange(productos.Select(p => new VentaProducto() { Cantidad = p.Unidades * linea.Cantidad, ProductoId = p.HijoId })); } lineas.AddRange(secundarias); foreach (var line in lineas) { var stockSt = new StockTransaccion { Cantidad = line.Cantidad * (-1), StockTransaccionTipoId = 1, Identifier = Guid.NewGuid(), Desincronizado = true }; var stock = stockRepository.ObtenerByProducto(line.ProductoId, AppSettings.MaxiKioscoId); if (stock != null) { stockSt.StockId = stock.StockId; stock.StockActual = stock.StockActual - Convert.ToDecimal(line.Cantidad); stockTransaccionRepository.Agregar(stockSt); stockRepository.Modificar(stock); seAgregoTransaccion = true; seAgregoStock = true; } else { stock = new Stock() { Identifier = Guid.NewGuid(), MaxiKioscoId = AppSettings.MaxiKioscoId, ProductoId = line.ProductoId, StockActual = -line.Cantidad, OperacionCreacion = "Venta en DESKTOP", FechaCreacion = DateTime.Now, StockTransacciones = new List <StockTransaccion> { stockSt } }; stockRepository.Agregar(stock); seAgregoStock = true; } } if (seAgregoStock) { stockRepository.Commit(); } if (seAgregoTransaccion) { stockTransaccionRepository.Commit(); } Repository.Agregar(venta); if (Repository.Commit()) { Limpiar(); } else { Mensajes.Guardar(false, "Ha ocurrido un error al registrar la venta. Por favor intente nuevamente"); } ReiniciarVenta(); } } } }
public IActionResult Post([FromBody] VentaProducto value) { return(Ok(_sellService.Add(value))); }
}//obtener una venta /// <summary> /// Método que inserta un producto que se encuentre en una venta /// </summary> /// <param name="vp">Producto que se vendió o se registra en una venta</param> /// <returns>1 si se pudo completar la acción o 0 si hubo un error</returns> public Boolean insertarVentaProducto(VentaProducto vp) { return this.ventaData.insertarVentaProducto(vp); }//insertarVentaProducto