Exemplo n.º 1
0
        /// <summary>
        /// 匹配逻辑:
        /// 1.如果发货时扫描了条码,就按条码匹配,条码匹配上Hu.ShipQty=Hu.Qty;如果条码匹配不上,就按物料匹配,物料匹配上Hu.ShipQty=0;
        ///   如果ipDetail上匹配的条码总数量大于ipDetail.Qty,则把Hu.ShipQty=0的拿出来再重新按物料匹配一次.
        /// 2.如果发货没有扫描条码,就按物料匹配.
        /// </summary>
        /// <param name="hu"></param>
        private void MatchIpMaster(Hu hu)
        {
            if (hu == null)
            {
                throw new BusinessException("条码不存在");
            }
            hu.CurrentQty = hu.Qty;

            if (!string.IsNullOrEmpty(hu.Location))
            {
                throw new BusinessException("条码{0}在库存中,不能收货", hu.HuId);
            }
            var matchHu = this.hus.Where(h => h.HuId.Equals(hu.HuId, StringComparison.OrdinalIgnoreCase));

            if (this.isCancel)
            {
                if (matchHu == null || matchHu.Count() == 0)
                {
                    throw new BusinessException("没有需要取消匹配条码:{0}", hu.HuId);
                }
                else if (matchHu.Count() == 1)
                {
                    //var _hu = _hus.Single();
                    //this.hus.Remove(_hu);
                }
                else
                {
                    throw new Exception("匹配了多个条码");
                }
            }
            else
            {
                if (matchHu != null && matchHu.Count() > 0)
                {
                    throw new BusinessException("条码重复扫描!");
                }
            }
            if (hu.IsFreeze)
            {
                throw new BusinessException("条码被冻结!");
            }

            if (!Utility.HasPermission(user.Permissions, null, false, true, hu.Region, null))
            {
                throw new BusinessException("没有此条码的权限");
            }

            var ipDetails = this.ipMaster.IpDetails;
            if (!base.isCancel)
            {
                #region 增加
                if (hu.Status == HuStatus.Location)
                {
                    throw new BusinessException("在库存中的条码不能被收货");
                }

                string huId = hu.HuId;

                if (this.ipMaster.IsReceiveScanHu)
                {
                    var isNeedRematch = false;
                    var matchedHuDetailInputs = new List<IpDetailInput>();
                    //首先匹配条码,如果条码匹配的话就调整ipDetail的数量RemainReceivedQty
                    //只有在条码完全匹配并且数量不满足收货的情况下产生IpDetailInputs的全部调整
                    var ipDetailInputMatchHuIds = this.ipMaster.IpDetailInputs.Where(id => id.HuId.Equals(hu.HuId, StringComparison.OrdinalIgnoreCase)).ToList();
                    if (ipDetailInputMatchHuIds.Count != 0)
                    {
                        var ipDetailInput = ipDetailInputMatchHuIds.First();
                        //var ipDetailMatchQty = this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id && i.UnitCount ==hu.UnitCount && i.ManufactureParty==hu.ManufactureParty && i.RemainReceivedQty > hu.Qty).ToList();
                        var ipDetailMatchHu = this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id).Single();
                        if (ipDetailMatchHu.RemainReceivedQty < hu.Qty)
                        {
                            isNeedRematch = true;
                            //将该零件号未匹配条码的先移开
                            foreach (var ipDetail in this.ipMaster.IpDetails.Where(i => i.Item == hu.Item))
                            {
                                matchedHuDetailInputs.AddRange(this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && i.IsOriginal == true).ToList());
                                var matchTotal = this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && i.IsMatchedHu == true).ToList().Sum(n => n.ReceiveQty);
                                ipDetail.RemainReceivedQty = ipDetail.Qty - ipDetail.ReceivedQty - matchTotal;
                                ipDetail.CurrentQty = ipDetail.Qty - ipDetail.ReceivedQty - matchTotal;
                            }
                            this.ipMaster.IpDetailInputs = matchedHuDetailInputs.ToArray();

                        }
                        //将满足的条码先放进去
                        ipDetailInput.ReceiveQty = hu.Qty;
                        ipDetailInput.LotNo = hu.LotNo;
                        ipDetailInput.IsMatchedHu = true;
                        ipDetailMatchHu.RemainReceivedQty = ipDetailMatchHu.Qty - hu.Qty;

                        ipDetailMatchHu.CurrentQty = ipDetailMatchHu.Qty - hu.Qty;
                        //this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id).Single().CurrentQty -= hu.Qty;

                        //如果条码匹配上并且其他的零件也没有溢出那么直接返回
                        if (isNeedRematch == false)
                        {
                            base.hus.Insert(0, hu);
                            this.gvListDataBind();
                            return;
                        }
                    }

                    //以下为非条码匹配的标准流程
                    List<Hu> inputHus = new List<Hu>();
                    List<Hu> needRemoveHus = new List<Hu>();
                    //如果有条码被从已经匹配的地方挪出来,那么这个物料除了条码已经匹配上的,其他全部重新匹配
                    if (isNeedRematch == true)
                    {
                        var matchedInputHus = (from h in this.hus
                                               from detailInput in this.ipMaster.IpDetailInputs
                                               where h.HuId == detailInput.HuId
                                               && detailInput.IsMatchedHu
                                               select h).ToList();

                        foreach (var item in this.hus)
                        {
                            if (matchedInputHus.All(m => m.HuId != item.HuId))
                            {
                                inputHus.Add(item);
                            }
                        }
                    }
                    else
                    {
                        inputHus.Add(hu);
                    }

                    //循环条码做非条码匹配
                    foreach (Hu inputHu in inputHus)
                    {
                        //var matchIpDetail = new IpDetail();
                        //匹配零件,供应商,质量状态   强制收货不考虑包装
                        var matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item == inputHu.Item &&
                            //i.UnitCount == inputHu.UnitCount &&
                                                        i.ManufactureParty == inputHu.ManufactureParty &&
                                                        i.RemainReceivedQty >= inputHu.Qty &&
                                                        i.QualityType == inputHu.QualityType).ToList();

                        if (matchIpDetailsFirst.Count() > 0)
                        {
                            var matchIpDetail = matchIpDetailsFirst.First();

                            var ipDetailInput = new IpDetailInput();
                            ipDetailInput.HuId = inputHu.HuId;
                            ipDetailInput.Id = matchIpDetail.Id;
                            ipDetailInput.ReceiveQty = inputHu.Qty;
                            matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                            matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                            List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                            ipDetailProcess.Add(ipDetailInput);
                            this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                            needRemoveHus.Add(inputHu);
                        }
                    }

                    foreach (var item in needRemoveHus)
                    {
                        inputHus.Remove(item);
                    }
                    needRemoveHus = new List<Hu>();

                    //如果inputHus没有全部匹配,接下来匹配零件,质量状态
                    if (inputHus.Count > 0)
                    {
                        foreach (Hu inputHu in inputHus)
                        {
                            var matchIpDetail = new IpDetail();
                            //再匹配零件,质量状态  强制收货不考虑包装
                            var matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item.Equals(inputHu.Item, StringComparison.OrdinalIgnoreCase) &&
                                //i.UnitCount == inputHu.UnitCount &&
                                //i.ManufactureParty.Equals(inputHu.ManufactureParty, StringComparison.OrdinalIgnoreCase) &&
                                                            i.RemainReceivedQty >= inputHu.Qty &&
                                                            i.QualityType == inputHu.QualityType);

                            if (matchIpDetailsFirst.Count() > 0)
                            {
                                matchIpDetail = matchIpDetailsFirst.First();

                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.HuId = inputHu.HuId;
                                ipDetailInput.Id = matchIpDetail.Id;
                                ipDetailInput.ReceiveQty = inputHu.Qty;
                                matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                                matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                                List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                                ipDetailProcess.Add(ipDetailInput);
                                this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                                needRemoveHus.Add(inputHu);
                            }
                        }
                        foreach (var item in needRemoveHus)
                        {
                            inputHus.Remove(item);
                        }
                    }

                    //如果还有未匹配成功的就报错
                    if (inputHus.Count > 0)
                    {
                        if (isNeedRematch == false)
                        {
                            throw new BusinessException("条码{0}无法满足送货单{1}明细的收货条件", hu.HuId, this.ipMaster.IpNo);
                        }
                        else
                        {
                            throw new BusinessException("物料{0}无法满足送货单{1}明细的收货条件", hu.Item, this.ipMaster.IpNo);
                        }
                    }
                    this.hus.Add(hu);
                }
                else
                {
                    throw new BusinessException("收货不需要扫描条码");
                }
                #endregion
            }
            else
            {
                this.CancelHu(hu);
            }

            this.gvListDataBind();
        }
Exemplo n.º 2
0
        protected override void DoSubmit()
        {
            try
            {

                if ((this.orderMasters == null || this.orderMasters.Count == 0)
                    && (this.ipMaster == null))
                {
                    throw new BusinessException("请先扫描订单或送货单。");
                }

                if (this.ipMaster == null)
                {
                    List<OrderDetail> orderDetailList = new List<OrderDetail>();
                    List<OrderDetailInput> orderDetailInputList = new List<OrderDetailInput>();

                    //2012-06-09 丁丁说后台可以接受多个KIT收货。
                    //if (this.orderMasters.Count > 1)
                    //{
                    //    if (this.orderMasters.Where(o => o.OrderStrategy == FlowStrategy.KIT).Count() > 0)
                    //    {
                    //        throw new BusinessException("KIT单不能合并收货。");
                    //    }
                    //}

                    foreach (var om in orderMasters)
                    {
                        if (om.OrderDetails != null)
                        {
                            orderDetailList.AddRange(om.OrderDetails);
                            //foreach (var od in om.OrderDetails)
                            //{
                            //    if (od.OrderDetailInputs != null)
                            //    {
                            //        orderDetailInputList.AddRange(od.OrderDetailInputs);
                            //    }
                            //}
                        }
                    }

                    if (orderDetailList.Any(od => od.CurrentQty > 0))
                    {
                        DialogResult dr = MessageBox.Show("本次收货有未收完的明细,是否继续?", "未全部收货", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        if (dr == DialogResult.No)
                        {
                            return;
                        }
                    }

                    foreach (var orderDetail in orderDetailList)
                    {
                        if (orderDetail.OrderDetailInputs != null)
                        {
                            orderDetailInputList.AddRange(orderDetail.OrderDetailInputs);
                        }
                    }

                    //if (this.orderMasters[0].OrderStrategy == FlowStrategy.KIT && this.orderMasters[0].Status == OrderStatus.InProcess)
                    //{
                    //    this.smartDeviceService.DoReceiveKit(this.orderMasters[0].OrderNo, this.effDate, base.user.Code);
                    //}

                    if (orderDetailInputList.Count == 0)
                    {
                        throw new BusinessException("没有扫描条码");
                    }
                    //if (this.orderMasters[0].OrderStrategy == FlowStrategy.KIT && this.orderMasters[0].Status == OrderStatus.Submit
                    //    && this.orderMasters[0].OrderDetails.Count(o => o.CurrentQty != 0) > 0)
                    //{
                    //    throw new BusinessException("必须满足KIT单收货数。");
                    //}
                    this.smartDeviceService.DoReceiveOrder(orderDetailInputList.ToArray(), this.effDate, base.user.Code);

                }
                else
                {
                    List<IpDetailInput> ipDetailInputList = new List<IpDetailInput>();

                    if (this.ipMaster.IpDetails.Any(od => od.CurrentQty > 0))
                    {
                        DialogResult dr = MessageBox.Show("本次收货有未收完的明细,是否继续?", "未全部收货", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                        if (dr == DialogResult.No)
                        {
                            return;
                        }
                    }
                    if (this.ipMaster.Type == IpType.KIT)
                    {
                        foreach (var ipDetail in this.ipMaster.IpDetails)
                        {
                            if (ipDetail.RemainReceivedQty > 0)
                            {
                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.Id = ipDetail.Id;
                                ipDetailInput.ReceiveQty = ipDetail.Qty;
                                ipDetailInputList.Add(ipDetailInput);
                            }
                        }
                        ipDetailInputList.AddRange(this.ipMaster.IpDetailInputs);
                    }
                    else if (this.isScanOne == false)
                    {
                        foreach (var ipDetailInput in this.ipMaster.IpDetailInputs)
                        {
                            ipDetailInput.ReceiveQty = ipDetailInput.Qty;
                            ipDetailInputList.Add(ipDetailInput);
                        }
                    }
                    else
                    {
                        ipDetailInputList = this.ipMaster.IpDetailInputs.ToList();
                    }
                    if (ipDetailInputList.Count == 0)
                    {
                        throw new BusinessException("没有扫描条码");
                    }
                    this.smartDeviceService.DoReceiveIp(ipDetailInputList.ToArray(), this.effDate, base.user.Code);
                }
                this.Reset();
                base.lblMessage.Text = "收货成功";
            }
            catch (Exception ex)
            {
                this.isMark = true;
                this.tbBarCode.Text = string.Empty;
                //this.tbBarCode.Focus();
                Utility.ShowMessageBox(ex.Message);
            }
        }
Exemplo n.º 3
0
 /// <remarks/>
 public System.IAsyncResult BeginDoReceiveIp(IpDetailInput[] ipDetailInputList, System.Nullable<System.DateTime> effDate, string userCode, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("DoReceiveIp", new object[] {
                 ipDetailInputList,
                 effDate,
                 userCode}, callback, asyncState);
 }
Exemplo n.º 4
0
 public void DoReceiveIp(IpDetailInput[] ipDetailInputList, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] System.Nullable<System.DateTime> effDate, string userCode) {
     this.Invoke("DoReceiveIp", new object[] {
                 ipDetailInputList,
                 effDate,
                 userCode});
 }
Exemplo n.º 5
0
        /// <summary>
        /// 匹配逻辑:
        /// 1.如果发货时扫描了条码,就按条码匹配,条码匹配上Hu.ShipQty=Hu.Qty;如果条码匹配不上,就按物料匹配,物料匹配上Hu.ShipQty=0;
        ///   如果ipDetail上匹配的条码总数量大于ipDetail.Qty,则把Hu.ShipQty=0的拿出来再重新按物料匹配一次.
        /// 2.如果发货没有扫描条码,就按物料匹配.
        /// </summary>
        /// <param name="hu"></param>
        private void MatchIpMaster(Hu hu)
        {
            if (hu == null)
            {
                throw new BusinessException("条码不存在");
            }

            hu.CurrentQty = hu.Qty;
            var matchHu = this.hus.Where(h => h.HuId.Equals(hu.HuId, StringComparison.OrdinalIgnoreCase));

            #region 取消条码
            if (this.isCancel)
            {
                if (matchHu == null || matchHu.Count() == 0)
                {
                    throw new BusinessException("没有需要取消匹配条码:{0}", hu.HuId);
                }
                else if (matchHu.Count() == 1)
                {
                    this.CancelHu(hu);
                }
                else
                {
                    throw new Exception("匹配了多个条码");
                }
            }
            #endregion
            #region 检查条码并匹配收货条件。
            else
            {
                #region 检查条码
                if (hu.IsFreeze)
                {
                    throw new BusinessException("条码被冻结!");
                }
                //if (!Utility.HasPermission(user.Permissions, null, true, false, hu.Region, null))
                //{
                //    throw new BusinessException("没有此条码的权限");
                //}
                if (hu.Status == HuStatus.Location)
                {
                    throw new BusinessException("在库存中的条码不能被收货");
                }

                if (matchHu != null && matchHu.Count() > 0)
                {
                    throw new BusinessException("条码重复扫描!");
                }
                #endregion

                var ipDetails = this.ipMaster.IpDetails;

                string huId = hu.HuId;

                if (this.ipMaster.Type == IpType.KIT)
                {
                    if (false)//(this.ipMaster.PartyFrom == this.smartDeviceService.GetEntityPreference(CodeEnum.WMSAnjiRegion) || this.ipMaster.OrderType == OrderType.ScheduleLine || this.ipMaster.OrderType == OrderType.Procurement)
                    {
                        throw new BusinessException("外部KIT单收货不需要扫描条码");
                    }
                    else
                    {
                        this.Reset();
                        throw new BusinessException("内部KIT单不需要扫描送货单。");
                    }
                }

                if (this.ipMaster.Type == IpType.SEQ)
                {
                    //如果在途库存上全部有条码,全部匹配条码,否则全部按物料匹配
                    if (this.ipMaster.IpDetails.All(i => i.RemainReceivedQty == 0))
                    {
                        throw new BusinessException("排序送货单{0}已收满。", this.ipMaster.IpNo);
                    }
                    if (this.ipMaster.IpDetailInputs.Where(i => !string.IsNullOrEmpty(i.HuId) && i.IsOriginal == true).Count() > 0)
                    {
                        //通过在途条码匹配
                        if (this.ipMaster.IpDetailInputs.All(i => i.HuId != hu.HuId))
                        {
                            throw new BusinessException("条码{0}不是排序单所需的物料。", hu.HuId);
                        }
                        else
                        {
                            var matchedIpDetailInput = this.ipMaster.IpDetailInputs.FirstOrDefault(i => i.HuId == hu.HuId);
                            matchedIpDetailInput.ReceiveQty = hu.Qty;
                            var ipDetail = this.ipMaster.IpDetails.FirstOrDefault(i => i.Id == matchedIpDetailInput.Id);
                            ipDetail.RemainReceivedQty = ipDetail.RemainReceivedQty - hu.Qty;
                            ipDetail.CurrentQty = ipDetail.CurrentQty - hu.Qty;
                            ipDetail.Carton++;
                        }
                    }
                    else
                    {
                        if (!this.ipMaster.IsReceiveScanHu)
                        {
                            throw new BusinessException("按数量收货不需要扫描条码,直接按确定收货。");
                        }
                        //通过物料号,单包装,供应商和质量状态匹配
                        int minSeq = this.ipMaster.IpDetails.Where(i => i.RemainReceivedQty > 0).Min(i => i.Sequence);
                        var needMatchIpDetail = this.ipMaster.IpDetails.FirstOrDefault(i => i.Sequence == minSeq);
                        if (needMatchIpDetail.Item == hu.Item
                            //&& needMatchIpDetail.UnitCount == hu.UnitCount
                            //&& needMatchIpDetail.ManufactureParty == hu.ManufactureParty
                            && needMatchIpDetail.QualityType == hu.QualityType)
                        {
                            var ipDetailInput = new IpDetailInput();
                            ipDetailInput.HuId = hu.HuId;
                            ipDetailInput.Id = needMatchIpDetail.Id;
                            ipDetailInput.LotNo = hu.LotNo;
                            ipDetailInput.ReceiveQty = hu.Qty;
                            needMatchIpDetail.RemainReceivedQty = needMatchIpDetail.RemainReceivedQty - hu.Qty;
                            needMatchIpDetail.CurrentQty = needMatchIpDetail.CurrentQty - hu.Qty;
                            needMatchIpDetail.Carton++;
                            List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                            ipDetailProcess.Add(ipDetailInput);
                            this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                        }

                    }
                    this.hus.Add(hu);
                    this.isScanOne = true;
                }
                else
                {
                    //如果发货和收货都扫描条码,严格匹配条码
                    if (this.ipMaster.IsShipScanHu && this.ipMaster.IsReceiveScanHu)
                    {
                        var ipDetailInput = this.ipMaster.IpDetailInputs.FirstOrDefault(id => id.HuId.Equals(hu.HuId, StringComparison.OrdinalIgnoreCase));
                        if (ipDetailInput == null)
                        {
                            throw new BusinessException("在送货单{0}明细中没有条码{1}。", this.ipMaster.IpNo, hu.HuId);
                        }
                        var ipDetail = this.ipMaster.IpDetails.Single(i => i.Id == ipDetailInput.Id);

                        ipDetailInput.ReceiveQty = hu.Qty;
                        ipDetailInput.LotNo = hu.LotNo;
                        ipDetailInput.IsMatchedHu = true;

                        ipDetail.RemainReceivedQty -= hu.Qty;
                        ipDetail.CurrentQty -= hu.Qty;
                        ipDetail.Carton++;

                        base.hus.Insert(0, hu);
                        this.gvListDataBind();
                        return;
                    }

                    var isNeedRematch = false;
                    var matchedHuDetailInputs = new List<IpDetailInput>();
                    //首先匹配条码,如果条码匹配的话就调整ipDetail的数量RemainReceivedQty
                    //只有在条码完全匹配并且数量不满足收货的情况下产生IpDetailInputs的全部调整
                    var ipDetailInputMatchHuIds = this.ipMaster.IpDetailInputs.Where(id => id.HuId.Equals(hu.HuId, StringComparison.OrdinalIgnoreCase)).ToList();
                    if (ipDetailInputMatchHuIds.Count != 0)
                    {
                        var ipDetailInput = ipDetailInputMatchHuIds.First();
                        //var ipDetailMatchQty = this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id && i.UnitCount ==hu.UnitCount && i.ManufactureParty==hu.ManufactureParty && i.RemainReceivedQty > hu.Qty).ToList();
                        var ipDetailMatchHu = this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id).Single();
                        if (ipDetailMatchHu.RemainReceivedQty < hu.Qty)
                        {
                            isNeedRematch = true;
                            //将该物料号未匹配条码的先移开
                            foreach (var ipDetail in this.ipMaster.IpDetails.Where(i => i.Item == hu.Item))
                            {
                                matchedHuDetailInputs.AddRange(this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && i.IsOriginal == true).ToList());
                                var matchTotal = this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && i.IsMatchedHu == true).ToList().Sum(n => n.ReceiveQty);
                                ipDetail.RemainReceivedQty = ipDetail.Qty - ipDetail.ReceivedQty - matchTotal;
                                ipDetail.CurrentQty = ipDetail.Qty - ipDetail.ReceivedQty - matchTotal;
                            }
                            this.ipMaster.IpDetailInputs = matchedHuDetailInputs.ToArray();

                        }
                        //将满足的条码先放进去
                        ipDetailInput.ReceiveQty = hu.Qty;
                        ipDetailInput.LotNo = hu.LotNo;
                        ipDetailInput.IsMatchedHu = true;

                        ipDetailMatchHu.RemainReceivedQty = ipDetailMatchHu.RemainReceivedQty - hu.Qty;
                        ipDetailMatchHu.CurrentQty = ipDetailMatchHu.CurrentQty - hu.Qty;
                        ipDetailMatchHu.Carton++;
                        //this.ipMaster.IpDetails.Where(i => i.Id == ipDetailInput.Id).Single().CurrentQty -= hu.Qty;

                        //如果条码匹配上并且其他的物料也没有溢出那么直接返回
                        if (isNeedRematch == false)
                        {
                            base.hus.Insert(0, hu);
                            this.gvListDataBind();
                            return;
                        }
                    }

                    //以下为非条码匹配的标准流程
                    #region  标准匹配流程
                    List<Hu> inputHus = new List<Hu>();
                    List<Hu> needRemoveHus = new List<Hu>();
                    //如果有条码被从已经匹配的地方挪出来,那么这个物料除了条码已经匹配上的,其他全部重新匹配
                    if (isNeedRematch == true)
                    {
                        var matchedInputHus = (from h in this.hus
                                               from detailInput in this.ipMaster.IpDetailInputs
                                               where h.HuId == detailInput.HuId
                                               && detailInput.IsMatchedHu
                                               select h).ToList();

                        foreach (var item in this.hus)
                        {
                            if (matchedInputHus.All(m => m.HuId != item.HuId))
                            {
                                inputHus.Add(item);
                            }
                        }
                    }
                    else
                    {
                        inputHus.Add(hu);
                    }

                    //循环条码做非条码匹配
                    foreach (Hu inputHu in inputHus)
                    {
                        //var matchIpDetail = new IpDetail();
                        //匹配物料,包装,供应商,质量状态(没有手动修改单包装的)
                        var matchIpDetailsFirst = new List<IpDetail>();
                        matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item == inputHu.Item &&
                                                        i.Uom == inputHu.Uom &&
                            //i.UnitCount == inputHu.UnitCount &&
                                                        //i.ManufactureParty == inputHu.ManufactureParty &&
                                                        i.RemainReceivedQty >= inputHu.Qty &&
                                                        i.QualityType == inputHu.QualityType &&
                                                        i.IsChangeUnitCount == false).ToList();

                        if (matchIpDetailsFirst.Count() > 0)
                        {
                            var matchIpDetail = matchIpDetailsFirst.First();

                            var ipDetailInput = new IpDetailInput();
                            ipDetailInput.HuId = inputHu.HuId;
                            ipDetailInput.Id = matchIpDetail.Id;
                            ipDetailInput.LotNo = inputHu.LotNo;
                            ipDetailInput.ReceiveQty = inputHu.Qty;
                            matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                            matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                            matchIpDetail.Carton++;
                            List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                            ipDetailProcess.Add(ipDetailInput);
                            this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                            needRemoveHus.Add(inputHu);
                        }

                        //匹配物料,供应商,质量状态(手动修改单包装的)
                        matchIpDetailsFirst = new List<IpDetail>();
                        matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item == inputHu.Item &&
                                                        i.Uom == inputHu.Uom &&
                                                        //i.ManufactureParty == inputHu.ManufactureParty &&
                                                        i.RemainReceivedQty >= inputHu.Qty &&
                                                        i.QualityType == inputHu.QualityType &&
                                                        i.IsChangeUnitCount == true).ToList();

                        if (matchIpDetailsFirst.Count() > 0)
                        {
                            var matchIpDetail = matchIpDetailsFirst.First();

                            var ipDetailInput = new IpDetailInput();
                            ipDetailInput.HuId = inputHu.HuId;
                            ipDetailInput.Id = matchIpDetail.Id;
                            ipDetailInput.LotNo = inputHu.LotNo;
                            ipDetailInput.ReceiveQty = inputHu.Qty;
                            matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                            matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                            matchIpDetail.Carton++;
                            List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                            ipDetailProcess.Add(ipDetailInput);
                            this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                            needRemoveHus.Add(inputHu);
                        }
                    }

                    foreach (var item in needRemoveHus)
                    {
                        inputHus.Remove(item);
                    }
                    needRemoveHus = new List<Hu>();

                    //如果inputHus没有全部匹配,接下来匹配物料,包装,质量状态
                    if (inputHus.Count > 0)
                    {
                        foreach (Hu inputHu in inputHus)
                        {
                            //var matchIpDetail = new IpDetail();
                            //再匹配物料,质量状态
                            var matchIpDetailsFirst = new List<IpDetail>();
                            matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item.Equals(inputHu.Item, StringComparison.OrdinalIgnoreCase) &&
                                //i.UnitCount == inputHu.UnitCount &&
                                                            i.Uom == inputHu.Uom &&
                                //i.ManufactureParty.Equals(inputHu.ManufactureParty, StringComparison.OrdinalIgnoreCase) &&
                                                            i.RemainReceivedQty >= inputHu.Qty &&
                                                            i.QualityType == inputHu.QualityType &&
                                                            i.IsChangeUnitCount == false).ToList();

                            if (matchIpDetailsFirst.Count() > 0)
                            {
                                var matchIpDetail = matchIpDetailsFirst.First();

                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.HuId = inputHu.HuId;
                                ipDetailInput.Id = matchIpDetail.Id;
                                ipDetailInput.LotNo = inputHu.LotNo;
                                ipDetailInput.ReceiveQty = inputHu.Qty;
                                matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                                matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                                matchIpDetail.Carton++;
                                List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                                ipDetailProcess.Add(ipDetailInput);
                                this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                                needRemoveHus.Add(inputHu);
                            }

                            //再匹配物料,包装,质量状态
                            matchIpDetailsFirst = new List<IpDetail>();
                            matchIpDetailsFirst = this.ipMaster.IpDetails.Where(i => i.Item.Equals(inputHu.Item, StringComparison.OrdinalIgnoreCase) &&
                                                            i.Uom == inputHu.Uom &&
                                //i.UnitCount == inputHu.UnitCount &&
                                //i.ManufactureParty.Equals(inputHu.ManufactureParty, StringComparison.OrdinalIgnoreCase) &&
                                                            i.RemainReceivedQty >= inputHu.Qty &&
                                                            i.QualityType == inputHu.QualityType &&
                                                            i.IsChangeUnitCount == true).ToList();

                            if (matchIpDetailsFirst.Count() > 0)
                            {
                                var matchIpDetail = matchIpDetailsFirst.First();

                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.HuId = inputHu.HuId;
                                ipDetailInput.Id = matchIpDetail.Id;
                                ipDetailInput.LotNo = inputHu.LotNo;
                                ipDetailInput.ReceiveQty = inputHu.Qty;
                                matchIpDetail.RemainReceivedQty = matchIpDetail.RemainReceivedQty - inputHu.Qty;
                                matchIpDetail.CurrentQty = matchIpDetail.CurrentQty - inputHu.Qty;
                                matchIpDetail.Carton++;
                                List<IpDetailInput> ipDetailProcess = this.ipMaster.IpDetailInputs.ToList();
                                ipDetailProcess.Add(ipDetailInput);
                                this.ipMaster.IpDetailInputs = ipDetailProcess.ToArray();
                                needRemoveHus.Add(inputHu);
                            }
                        }
                        foreach (var item in needRemoveHus)
                        {
                            inputHus.Remove(item);
                        }
                    }

                    //如果还有未匹配成功的就报错
                    if (inputHus.Count > 0)
                    {
                        if (isNeedRematch == false)
                        {
                            throw new BusinessException("条码{0}不满足送货单{1}明细行的收货条件", hu.HuId, this.ipMaster.IpNo);
                        }
                        else
                        {
                            throw new BusinessException("物料{0}不满足送货单{1}明细行的收货条件", hu.Item, this.ipMaster.IpNo);
                        }
                    }
                    #endregion
                }
                this.hus.Add(hu);
            }
            #endregion

            this.gvListDataBind();
        }
Exemplo n.º 6
0
        protected override void DoSubmit()
        {
            if ((this.orderMasters == null || this.orderMasters.Count == 0)
                && (this.ipMaster == null))
            {
                throw new BusinessException("请先扫描订单或送货单。");
            }

            #region 要货单收货的逻辑
            //ORD收货
            if (this.ipMaster == null)
            {
                List<OrderDetail> orderDetailList = new List<OrderDetail>();
                List<OrderDetailInput> orderDetailInputList = new List<OrderDetailInput>();

                ////2012-06-09 丁丁说后台可以接受多个KIT收货。最后讨论的是只有安吉或者外部的才会合并 在前面做判断即可
                //if (this.orderMasters.Count > 1)
                //{
                //    if (this.orderMasters.Where(o => o.OrderStrategy == FlowStrategy.KIT).Count() > 0)
                //    {
                //        throw new BusinessException("KIT单不能合并收货。");
                //    }
                //}

                foreach (var om in orderMasters)
                {
                    if (om.OrderDetails != null)
                    {
                        orderDetailList.AddRange(om.OrderDetails);
                    }
                }

                //if (orderDetailList.Any(od => od.CurrentQty > 0))
                //{
                //    DialogResult dr = MessageBox.Show("本次收货有未收完的明细,是否继续?", "未全部收货", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                //    if (dr == DialogResult.No)
                //    {
                //        this.isMark = true;
                //        //this.tbBarCode.Focus();
                //        return;
                //    }
                //}

                if (this.isScanOne == false)
                {
                    foreach (var orderDetail in orderDetailList)
                    {
                        if (orderDetail.OrderedQty - orderDetail.ReceivedQty > 0)
                        {
                            var orderDetailInput = new OrderDetailInput();
                            orderDetailInput.Id = orderDetail.Id;
                            orderDetailInput.ReceiveQty = orderDetail.OrderedQty - orderDetail.ReceivedQty;
                            orderDetailInputList.Add(orderDetailInput);
                        }
                    }
                }
                else
                {
                    foreach (var orderDetail in orderDetailList)
                    {
                        if (orderDetail.OrderDetailInputs != null)
                        {
                            orderDetailInputList.AddRange(orderDetail.OrderDetailInputs);
                        }
                    }
                }

                //if (this.orderMasters[0].OrderStrategy == FlowStrategy.KIT && this.orderMasters[0].Status == OrderStatus.InProcess)
                //{
                //    this.smartDeviceService.DoReceiveKit(this.orderMasters[0].OrderNo, this.effDate, base.user.Code);
                //}

                if (orderDetailInputList.Count == 0)
                {
                    throw new BusinessException("没有扫描条码");
                }
                //if (this.orderMasters[0].OrderStrategy == FlowStrategy.KIT && this.orderMasters[0].Status == OrderStatus.Submit
                //    && this.orderMasters[0].OrderDetails.Count(o => o.CurrentQty != 0) > 0)
                //{
                //    throw new BusinessException("必须满足KIT单收货数。");
                //}
                this.smartDeviceService.DoReceiveOrder(orderDetailInputList.ToArray(), this.effDate, base.user.Code);

            }
            #endregion

            #region ASN收货逻辑
            //ASN收货
            else
            {
                List<IpDetailInput> ipDetailInputList = new List<IpDetailInput>();

                if (this.ipMaster.IpDetails.Any(od => od.CurrentQty > 0))
                {
                    DialogResult dr = MessageBox.Show("本次收货有未收完的明细,是否继续?", "未全部收货", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                    if (dr == DialogResult.No)
                    {
                        this.isMark = true;
                        //this.tbBarCode.Focus();
                        return;
                    }
                }
                //安吉或者外部直送的排序单,全部需要扫描
                if (this.ipMaster.Type == IpType.SEQ)
                {
                    ////如果是外部的直送的排序单,必须扫描全部关键件
                    //if (this.ipMaster.PartyFrom == this.smartDeviceService.GetEntityPreference(CodeEnum.WMSAnjiRegion) || this.ipMaster.OrderType == OrderType.ScheduleLine || this.ipMaster.OrderType == OrderType.Procurement)
                    //{
                    //    foreach (var ipDetail in this.ipMaster.IpDetails)
                    //    {
                    //        //确认关键全部扫描,将条码传给后(排序单所有零件都是关键件)
                    //        if (this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId)).Count() == 0)
                    //        {
                    //            throw new BusinessException("安吉或者外部直送排序单需扫描全部关键件。");
                    //        }

                    //        var ipDetailInput = this.ipMaster.IpDetailInputs.FirstOrDefault(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId));
                    //        ipDetailInputList.Add(ipDetailInput);
                    //    }
                    //}
                    ////内部排序要么全部扫描要么全部不扫描
                    //else
                    //{
                    //如果扫了一个必须全部扫描
                    if (this.isScanOne == true)
                    {
                        foreach (var ipDetail in this.ipMaster.IpDetails)
                        {
                            if (this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId)).Count() == 0)
                            {
                                throw new BusinessException("已扫入一个或多个条码,需将剩下的条码全部扫描。");
                            }

                            var ipDetailInput = this.ipMaster.IpDetailInputs.FirstOrDefault(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId));
                            ipDetailInputList.Add(ipDetailInput);
                        }
                    }
                    else
                    {
                        foreach (var ipDetail in this.ipMaster.IpDetails)
                        {
                            //所有零件都直接填充数量传到后台
                            if (ipDetail.RemainReceivedQty > 0)
                            {
                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.Id = ipDetail.Id;
                                ipDetailInput.ReceiveQty = ipDetail.Qty;
                                ipDetailInputList.Add(ipDetailInput);
                            }
                        }
                    }
                    //}
                }
                //如果是KIT需要区分内部和外部,外部的KIT不需要扫描条码,内部的必须扫描全部关键件。
                if (this.ipMaster.Type == IpType.KIT)
                {
                    //外部送货的KIT单
                    if (this.ipMaster.PartyFrom == this.smartDeviceService.GetEntityPreference(CodeEnum.WMSAnjiRegion) || this.ipMaster.OrderType == OrderType.ScheduleLine || this.ipMaster.OrderType == OrderType.Procurement)
                    {
                        foreach (var ipDetail in this.ipMaster.IpDetails)
                        {
                            //所有零件都直接填充数量传到后台
                            if (ipDetail.RemainReceivedQty > 0)
                            {
                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.Id = ipDetail.Id;
                                ipDetailInput.ReceiveQty = ipDetail.Qty;
                                ipDetailInputList.Add(ipDetailInput);
                            }
                        }
                        //ipDetailInputList.AddRange(this.ipMaster.IpDetailInputs);
                    }
                    //内部移库的KIT单
                    else
                    {
                        foreach (var ipDetail in this.ipMaster.IpDetails)
                        {
                            //确认关键全部扫描,将条码传给后台
                            if (ipDetail.IsScanHu == true)
                            {
                                if (this.ipMaster.IpDetailInputs.Where(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId)).Count() == 0)
                                {
                                    throw new BusinessException("内部KIT单需要扫描全部关键件");
                                }

                                var ipDetailInput = this.ipMaster.IpDetailInputs.FirstOrDefault(i => i.Id == ipDetail.Id && !string.IsNullOrEmpty(i.HuId));
                                ipDetailInputList.Add(ipDetailInput);
                            }
                            //非关键件直接填充数量
                            else if (ipDetail.RemainReceivedQty > 0)
                            {
                                var ipDetailInput = new IpDetailInput();
                                ipDetailInput.Id = ipDetail.Id;
                                ipDetailInput.ReceiveQty = ipDetail.Qty;
                                ipDetailInputList.Add(ipDetailInput);
                            }
                        }
                        //ipDetailInputList.AddRange(this.ipMaster.IpDetailInputs); 
                    }
                }
                //如果普通收货没有有扫描条码的,全部按数量收货
                if (this.isScanOne == false && this.ipMaster.IpDetailInputs.Count() == 0 && this.ipMaster.Type != IpType.KIT && this.ipMaster.Type != IpType.SEQ)
                {
                    foreach (var ipDetail in this.ipMaster.IpDetails)
                    {
                        if (ipDetail.Qty - ipDetail.ReceivedQty > 0)
                        {
                            var ipDetailInput = new IpDetailInput();
                            ipDetailInput.Id = ipDetail.Id;
                            ipDetailInput.ReceiveQty = ipDetail.Qty - ipDetail.ReceivedQty;
                            ipDetailInputList.Add(ipDetailInput);
                        }
                    }
                }
                else
                {
                    foreach (var ipDetailInput in this.ipMaster.IpDetailInputs)
                    {
                        //ipDetailInput.ReceiveQty = ipDetailInput.ReceiveQty;
                        if (ipDetailInput.ReceiveQty > 0)
                        {
                            ipDetailInputList.Add(ipDetailInput);
                        }
                    }
                }
                if (ipDetailInputList.Count == 0)
                {
                    this.Reset();
                    throw new BusinessException("本次收货出现错误,请重新收货");
                }
                this.smartDeviceService.DoReceiveIp(ipDetailInputList.ToArray(), this.effDate, base.user.Code);
            #endregion

            }

            this.Reset();
            base.lblMessage.Text = "收货成功";
        }