예제 #1
0
        private Tuple <bool, long, string> Allot(TOut outbound)
        {
            var detailList = wmsoutbound.TOutDs.Where(x => x.HId == outbound.Id).ToArray();

            // 获取分配结果,更新库存记录
            // 支持二次分配, 剩余未分配数 = 期望出库数 - 已分配数
            var allotList = inventoryService.Allot(outbound.WhId, detailList);

            // 生成分配记录
            var r = allotService.Create(outbound.WhId, outbound.Id, outbound.Code, detailList, allotList);

            wmsoutbound.TOutAllots.Add(r);

            //更新出库明细
            //支持二次分配,分配数量进行累加
            foreach (var detail in detailList)
            {
                detail.MatchingQty += allotList.Where(x => x.SkuId == detail.SkuId).Sum(X => X.AllotQty);
            }

            //更新单据状态
            var allMatchingQty = detailList.Sum(x => x.MatchingQty);
            var allQty         = detailList.Sum(x => x.Qty);

            if (allMatchingQty == 0)
            {
                outbound.AllotStatus = -1;
            }
            else if (allQty > allMatchingQty)
            {
                outbound.AllotStatus = 1;
            }
            else
            {
                outbound.AllotStatus = 2;
            }

            outbound.Status = Enum.GetName(typeof(EnumStatus), EnumStatus.Audit);

            //保存
            var r1 = wmsoutbound.SaveChanges() > 0;

            return(new Tuple <bool, long, string>(r1, outbound.Id, ""));
        }