Beispiel #1
0
        public bool DoRecPop()
        {
            if (Location == null || Location == Guid.Empty)
            {
                MSD.AddModelError("NullLocation", "请选择上架货位");
                return(false);
            }
            if (RecQty > (Entity.OrderQty - Entity.RecQty))
            {
                MSD.AddModelError("QtyOver", "实收数量不能大于剩余可收货数量");
                return(false);
            }
            var loc = DC.Set <area_location>().AsNoTracking().Where(r => r.ID == Location.Value).FirstOrDefault();

            if (!loc.isMix.Value)
            {
                var         invs   = DC.Set <inventory>().Where(r => r.LocationID == Location.Value);
                var         InInvs = DC.Set <inventoryIn>().Include("OrderPop.ContractPop").Where(r => invs.Select(x => x.ID).Contains(r.InvID));
                List <Guid> pops   = InInvs.Select(r => r.OrderPop.ContractPop.PopID).ToList();
                pops.Add(Entity.ContractPop.PopID);
                if (pops.Distinct().Count() > 1)
                {
                    MSD.AddModelError("LocNotMix", "货位不可混放,但当前货位已经有其他货品了");
                    return(false);
                }
            }

            inventory inv = new inventory
            {
                ID         = Guid.NewGuid(),
                LocationID = Location.Value,
                Stock      = RecQty,
                PutUser    = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name,
                PutTime    = DateTime.Now
            };
            inventoryIn InvIn = new inventoryIn
            {
                CreateBy   = LoginUserInfo.ITCode,
                CreateTime = DateTime.Now,
                InvID      = inv.ID,
                OrderPopID = Entity.ID,
                InQty      = RecQty
            };

            DC.AddEntity(inv);
            DC.AddEntity(InvIn);
            var OrderPop = DC.Set <order_pop>().Where(r => r.ID == Entity.ID).FirstOrDefault();

            OrderPop.Status  = OrderPop.RecQty + RecQty == OrderPop.OrderQty ? RecStatus.FINISH : RecStatus.ING;
            OrderPop.RecQty += RecQty;
            OrderPop.RecTime = DateTime.Now;
            OrderPop.RecUser = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name;
            DC.UpdateEntity(OrderPop);
            return(DC.SaveChanges() > 0 ? true : false);
        }
Beispiel #2
0
        public override void DoAdd()
        {
            inventory           inv     = DC.Set <inventory>().Where(r => r.ID == Entity.InvID).FirstOrDefault();
            List <inventoryIn>  invIns  = DC.Set <inventoryIn>().Where(r => r.InvID == Entity.InvID).ToList();
            List <inventoryOut> invOuts = DC.Set <inventoryOut>().Include("sp").Where(r => r.InvID == Entity.InvID).ToList();

            if ((Entity.Qty + invOuts.Sum(r => r.sp.AlcQty) - inv.Stock) > 0)
            {
                MSD.AddModelError("OverStock", "超出最大可用量限制");
                return;
            }
            Entity.UserName   = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name;
            Entity.UpdateTime = DateTime.Now;
            if (Entity.Type == RecordType.ADJ)
            {
                inv.Stock       += Entity.Qty;
                Entity.FromLocID = inv.LocationID;
                Entity.ToLocID   = inv.LocationID;
            }
            if (Entity.Type == RecordType.TSF)
            {
                if (Entity.Qty <= 0)
                {
                    MSD.AddModelError("ErroQty", "转移数量不能小于0");
                    return;
                }
                Entity.FromLocID = inv.LocationID;
                if ((inv.Stock - invOuts.Sum(r => r.sp.AlcQty)) == Entity.Qty)
                {
                    inv.LocationID  = Entity.ToLocID.Value;
                    Entity.NewInvID = inv.ID;
                }
                else
                {
                    inv.Stock -= Entity.Qty;
                    inventory NewInv = new inventory
                    {
                        ID         = Guid.NewGuid(),
                        LocationID = Entity.ToLocID.Value,
                        Stock      = Entity.Qty,
                        PutUser    = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name,
                        PutTime    = DateTime.Now
                    };
                    Entity.NewInvID = NewInv.ID;
                    int TsfQty = Entity.Qty;
                    List <inventoryIn> NewInInvs = new List <inventoryIn>();
                    foreach (var item in invIns)
                    {
                        if (TsfQty > 0)
                        {
                            int CurTsfQty = item.InQty > TsfQty ? TsfQty : item.InQty;
                            //如果当前记录库存大于等于转移数量
                            if (item.InQty >= TsfQty)
                            {
                                inventoryIn invIn = new inventoryIn
                                {
                                    ID         = Guid.NewGuid(),
                                    InvID      = NewInv.ID,
                                    OrderPopID = item.OrderPopID,
                                    InQty      = TsfQty
                                };
                                item.InQty -= TsfQty;
                                DC.Set <inventoryIn>().Update(item);
                                NewInInvs.Add(invIn);
                            }
                            //当前记录库存小于等于转移数量
                            else
                            {
                                inventoryIn invIn = new inventoryIn
                                {
                                    ID         = Guid.NewGuid(),
                                    InvID      = NewInv.ID,
                                    OrderPopID = item.OrderPopID,
                                    InQty      = item.InQty
                                };
                                DC.Set <inventoryIn>().Remove(item);
                                NewInInvs.Add(invIn);
                            }
                            item.InQty -= CurTsfQty;
                            TsfQty     -= CurTsfQty;
                        }
                    }
                    DC.Set <inventory>().Add(NewInv);
                    DC.Set <inventoryIn>().AddRange(NewInInvs);
                }
            }
            base.DoAdd();
        }