Пример #1
0
        private void RestaLotes()
        {
            //Resta todos los lotes por partida, tenga en cuenta que si una partida tiene cantidad superior a la
            //suma de las existencias de los lotes, este ultimo quedará en cero y la diferencia no genera error
            //es decir, se puede vender sin lotes, así cómo sin existencias.
            foreach (var p in partidas)
            {
                if (productoController.SelectOne(p.ProductoId).TieneLote)
                {
                    var Lvp = new LoteVentap();
                    Lvp.Cantidad = 0;
                    var lotes = loteController.GetLotesDisponibilidad(p.ProductoId, p.Cantidad);

                    var restante = p.Cantidad;

                    foreach (var l in lotes)
                    {
                        if (restante == 0)
                        {
                            break;
                        }


                        if (restante <= l.StockRestante)
                        {
                            Lvp.ProductoId = p.ProductoId;
                            Lvp.VentaId    = venta.VentaId;
                            Lvp.NoLote     = l.NoLote;

                            Lvp.Cantidad    += restante;
                            l.StockRestante -= restante;
                            restante         = 0;
                            //  loteVentapController.InsertOne(Lvp);
                        }
                        else
                        {
                            Lvp.ProductoId = p.ProductoId;
                            Lvp.VentaId    = venta.VentaId;
                            Lvp.NoLote     = l.NoLote;

                            Lvp.Cantidad   += restante;
                            restante       -= l.StockRestante;
                            l.StockRestante = 0;
                        }
                        //loteVentapController.InsertOne(Lvp);
                    }


                    loteController.UpdateRange(lotes);
                }
            }
        }