public void AnularVenta(Venta v) { ProductoVendidoNegocio negPV = new ProductoVendidoNegocio(); LoteNegocio negL = new LoteNegocio(); try { List <ProductoVendido> productos = negPV.Listar(v.IdVenta, 1); EliminarLogico(v.IdVenta); foreach (ProductoVendido pv in productos) { negPV.EliminarLogico(pv.IdPxv); negPV.RestaurarStock(pv.IdPxv); negL.ActualizarStock(pv.Producto.IdProducto); } } catch (Exception ex) { throw ex; } }
public bool AnularCompra(Compra c) { LoteNegocio negL = new LoteNegocio(); List <Lote> lotes = negL.Listar(c.IdCompra, 1); foreach (Lote l in lotes) { if (l.UnidadesE != l.UnidadesP) { return(false); } } EliminarLogico(c.IdCompra); foreach (Lote l in lotes) { negL.EliminarLogico(l.IdLote); negL.ActualizarStock(l.Producto.IdProducto); } return(true); }
public void DescontarStock(ProductoVendido pv) { Lote lote; int stockTotal = 0, cantidad; LoteNegocio negL = new LoteNegocio(); List <Lote> lstLotes = new List <Lote>(); AccesoDB conexion = null; try { conexion = new AccesoDB(); conexion.SetearConsulta("SELECT L.IDLOTE, L.UNIDADESE FROM LOTES AS L " + "INNER JOIN COMPRAS AS C ON C.IDCOMPRA = L.IDCOMPRA " + "WHERE L.IDPRODUCTO = @idproducto AND L.ACTIVO = 1 " + "ORDER BY C.FECHACOMPRA DESC"); conexion.Comando.Parameters.Clear(); conexion.Comando.Parameters.AddWithValue("@idproducto", pv.Producto.IdProducto); conexion.AbrirConexion(); conexion.EjecutarConsulta(); while (conexion.Lector.Read()) { lote = new Lote { IdLote = (long)conexion.Lector[0], UnidadesE = (int)conexion.Lector[1] }; stockTotal += lote.UnidadesE; lstLotes.Add(lote); } if (stockTotal >= pv.Cantidad) { int cantV = pv.Cantidad, i = 0; while (cantV > 0) { if (cantV <= lstLotes[i].UnidadesE) { cantidad = cantV; lstLotes[i].UnidadesE -= cantV; cantV = 0; } else { cantidad = lstLotes[i].UnidadesE; cantV -= lstLotes[i].UnidadesE; lstLotes[i].UnidadesE = 0; } ActualizarStock(lstLotes[i]); negL.ActualizarStock(pv.Producto.IdProducto); RegistrarMovimiento(pv.IdPxv, lstLotes[i].IdLote, cantidad); i++; } } return; } catch (Exception ex) { throw ex; } finally { if (conexion.CheckearConexion() == true) { conexion.CerrarConexion(); } } }