Ejemplo n.º 1
0
        //创建收货记录
        public Tuple <bool, bool, string> CreateRcv(long id, VRcvScan rcv)
        {
            //由于有超收的情况存在,无法判断是否全部收货完毕
            if (string.IsNullOrEmpty(rcv.Barcode))
            {
                return(new Tuple <bool, bool, string>(false, false, "barcode not allow null."));
            }

            //从product获取skuid的信息
            var prodSku = skuService.GetSkuByBarcode(rcv.Barcode);

            if (prodSku == null)
            {
                throw new Exception("barcode is not exists.");
            }
            var sku   = prodSku.Code;
            var skuid = prodSku.Id;

            var skuTotalQty = 0;

            //查询入库单
            var inbound = wmsinbound.TInInbounds.Where(x => x.Id == id).FirstOrDefault();

            //生成收货记录
            var inboundRcv = new TInInboundRcv
            {
                HId     = inbound.Id,
                Carton  = rcv.Carton,
                Barcode = rcv.Barcode,
                QcCode  = rcv.QcCode
            };

            if (inbound.TransCode == "ReturnIn")
            {
                //对preQcDetail进行匹配
                var qcIds = wmsinbound.TInPreQcs
                            .Where(x => x.InBatchCode == inbound.Code)
                            .Select(x => new { x.Id, x.Code })
                            .ToList();
                var qcDetail = wmsinbound.TInPreQcDs
                               .Where(x => x.Barcode == rcv.Barcode && x.QcCode == x.QcCode && qcIds.Any(y => y.Id == x.HId))
                               .FirstOrDefault();

                var qc = qcIds.Where(x => x.Id == qcDetail.HId).FirstOrDefault();
                inboundRcv.NoticeId   = qcDetail.HId;
                inboundRcv.NoticeDId  = qcDetail.Id;
                inboundRcv.NoticeCode = qc.Code;
            }

            var asnId    = inbound.AsnId;
            var totalQty = inbound.Qty;

            TInInboundD inboundDetail = null;

            if (string.IsNullOrEmpty(rcv.Carton))
            {
                inboundDetail = wmsinbound.TInInboundDs.Where(x => x.HId == id && x.Barcode == rcv.Barcode).FirstOrDefault();
            }
            else
            {
                inboundDetail = wmsinbound.TInInboundDs.Where(x => x.HId == id && x.Carton == rcv.Carton && x.Barcode == rcv.Barcode).FirstOrDefault();
            }

            if (asnId > 0)
            {
                //查询到货明细
                var asnDetail = wmsinbound.TInAsnDs.Where(x => x.HId == asnId && x.Barcode == rcv.Barcode)
                                .FirstOrDefault();
                if (asnDetail == null)
                {
                    throw new Exception("barcode" + rcv.Barcode + "not exists.");
                }
                skuTotalQty = asnDetail.Qty;

                // 核对扫描内容是否完整
                DoCheckList(inbound.WhId, inbound.CustId, inbound.BrandId, asnDetail, prodSku);

                //校验数量
                if (inboundDetail != null)
                {
                    //超收校验
                    skuTotalQty = DoCheckQty(asnDetail.Qty, inbound.WhId, inbound.CustId, inbound.BrandId, inboundDetail.Qty);
                    totalQty    = totalQty - asnDetail.Qty + skuTotalQty;
                }
            }
            else
            {
                //盲收校验
                DoCheckBlind(inbound.WhId, inbound.CustId, inbound.BrandId);
            }

            //新增操作
            inbound.RStatus = Enum.GetName(typeof(EnumOperateStatus), EnumOperateStatus.Doing);

            var r = SaveSku(prodSku.Id, prodSku.Code, skuTotalQty, inbound.Id, inboundDetail, inboundRcv);

            return(new Tuple <bool, bool, string>(false, r.Item1, r.Item2));
        }
Ejemplo n.º 2
0
        private Tuple <bool, string> SaveSku(long skuId, string sku, int totalQty, long inboundId, TInInboundD inboundDetail, TInInboundRcv rcv)
        {
            var r = false;

            var data = string.Empty;

            if (inboundDetail == null || (totalQty > 0 && inboundDetail.Qty + 1 <= totalQty) || totalQty == 0)
            {
                //生成入库记录
                if (inboundDetail != null)
                {
                    inboundDetail.Qty += 1;
                    if (inboundDetail.Qty + 1 == totalQty)
                    {
                        r = true;
                    }
                }
                else
                {
                    inboundDetail = new TInInboundD
                    {
                        HId         = inboundId,
                        Carton      = rcv.Carton,
                        SkuId       = skuId,
                        Sku         = sku,
                        Barcode     = rcv.Barcode,
                        Qty         = 1,
                        CreatedBy   = DefaultUser.UserName,
                        CreatedTime = DateTime.UtcNow
                    };
                    wmsinbound.TInInboundDs.Add(inboundDetail);
                }

                //生成扫描记录
                rcv.HId         = inboundId;
                rcv.Sku         = sku;
                rcv.SkuId       = skuId;
                rcv.Qty         = 1;
                rcv.CreatedBy   = DefaultUser.UserName;
                rcv.CreatedTime = DateTime.UtcNow;

                wmsinbound.TInInboundRcvs.Add(rcv);

                try
                {
                    wmsinbound.SaveChanges();
                    if (totalQty > 0)
                    {
                        data = string.Format("{0}/{1}", inboundDetail.Qty, totalQty);
                    }
                    else
                    {
                        data = string.Format("{0}/{1}", inboundDetail.Qty, "盲收");
                    }
                }
                catch (Exception ex)
                {
                    data = ex.InnerException.Message;
                }
                return(new Tuple <bool, string>(r, data));
            }
            else
            {
                if (totalQty > 0)
                {
                    data = string.Format("{0}/{1}", totalQty, totalQty);
                }
                else
                {
                    data = string.Format("{0}/{1}", inboundDetail.Qty, "盲收");
                }
                return(new Tuple <bool, string>(true, data));
            }
        }