コード例 #1
0
ファイル: OrderMgrImpl.cs プロジェクト: druidwang/Les_parts
        private void GenerateOrderBomDetail(OrderDetail orderDetail, OrderMaster orderMaster)
        {
            if (orderDetail.ScheduleType == CodeMaster.ScheduleType.MES21 || orderDetail.ScheduleType == CodeMaster.ScheduleType.MES22
                || orderDetail.ScheduleType == CodeMaster.ScheduleType.MES23)
            {
                //只记录废品数,无材料消耗
                return;
            }
            if (orderMaster.ProductLineFacility == "EXV")
            {

                //不消耗材料

                return;
            }
            //if (orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Return)
            //{
            //    //直接退成品
            //}

            #region 查找成品单位和Bom单位的转换关系
            //把OrderDetail的收货单位和单位用量转换为BOM单位和单位用量
            //fgUom,fgUnityQty代表接收一个orderDetail.Uom单位(等于订单的收货单位)的FG,等于单位(fgUom)有多少(fgUnityQty)值
            string fgUom = orderDetail.Uom;
            //如果和Bom上的单位不一致,转化为Bom上的单位,不然会导致物料回冲不正确。  

            //查找Bom
            BomMaster bomMaster = FindOrderDetailBom(orderDetail);
            decimal fgUnityQty = 1;

            #region 判断Bom是否有效
            if (!bomMaster.IsActive)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_BomInActive, orderDetail.Bom);
            }
            #endregion

            //订单单位和Bom单位不一致,需要做单位转换
            if (string.Compare(orderDetail.Uom, bomMaster.Uom) != 0)
            {
                fgUom = bomMaster.Uom;
                fgUnityQty = itemMgr.ConvertItemUomQty(orderDetail.Item, orderDetail.Uom, fgUnityQty, fgUom);
            }
            #endregion

            #region 创建OrderBomDetail
            //Item fgItem = genericMgr.FindById<Item>(orderDetail.Item);

            #region 查询Bom明细
            IList<BomDetail> bomDetailList = bomMgr.GetFlatBomDetail(bomMaster, orderMaster.StartTime);
            #endregion

            var itemCodes = bomDetailList.Select(b => b.Item).Distinct();
            #region 查询Bom Item
            IList<Item> bomItemList = this.genericMgr.FindAllIn<Item>("from Item where Code in(?", itemCodes);
            #endregion

            #region 查询工艺流程明细
            //IList<RoutingDetail> routingDetailList = null;
            //if (!string.IsNullOrEmpty(orderDetail.Routing))
            //{
            //    RoutingMaster routing = this.genericMgr.FindById<RoutingMaster>(orderDetail.Routing);
            //    if (!routing.IsActive)
            //    {
            //        throw new BusinessErrorException(Resources.ORD.OrderMaster.Errors_RoutingInActive, orderDetail.Routing);
            //    }
            //    routingDetailList = routingMgr.GetRoutingDetails(orderDetail.Routing, orderMaster.StartTime);
            //}
            #endregion

            #region 查询生产防错明细 SIH客户化是从零件追溯表中取需要扫描的零件。
            IList<string> itemTraceList = this.genericMgr.FindAllIn<string>
                ("select it.Item From ItemTrace as it where it.Item in (?", itemCodes);
            #endregion

            foreach (BomDetail bomDetail in bomDetailList)
            {
                #region 查找物料的来源库位和提前期
                string bomLocFrom = string.Empty;
                //来源库位查找逻辑RoutingDetail-->OrderDetail-->Order-->BomDetail 
                //工序的优先级最大,因为同一个OrderMaster可以有不同的工艺流程,其次OrderMaster,最后BomDetail
                TryLoadOrderOperations(orderDetail);
                if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count > 0)
                {
                    //取RoutingDetail上的
                    OrderOperation orderOperation = orderDetail.OrderOperations.Where(
                            p => p.Op == bomDetail.Operation
                            && p.OpReference == bomDetail.OpReference).SingleOrDefault();

                    if (orderOperation != null)
                    {
                        bomLocFrom = orderOperation.Location;
                    }
                }

                if (string.IsNullOrEmpty(bomLocFrom))
                {
                    //在取OrderDetail上,然后是OrderHead上取
                    //取默认库位FlowDetail-->Flow
                    if (orderDetail.OrderSubType == CodeMaster.OrderSubType.Normal)
                    {
                        if (!string.IsNullOrEmpty(orderDetail.LocationFrom))
                        {
                            bomLocFrom = orderDetail.LocationFrom;
                        }
                        else
                        {
                            bomLocFrom = orderMaster.LocationFrom;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(orderDetail.LocationTo))
                        {
                            bomLocFrom = orderDetail.LocationTo;
                        }
                        else
                        {
                            bomLocFrom = orderMaster.LocationTo;
                        }
                    }
                }

                if (string.IsNullOrEmpty(bomLocFrom))
                {
                    //最后取BomDetail上的Location
                    bomLocFrom = bomDetail.Location;
                }
                #endregion

                #region 创建生产单物料明细
                OrderBomDetail orderBomDetail = new OrderBomDetail();
                Item bomItem = bomItemList.Where(i => i.Code == bomDetail.Item).Single();

                orderBomDetail.Bom = bomDetail.Bom;
                orderBomDetail.Item = bomDetail.Item;
                orderBomDetail.ItemDescription = bomItem.Description;
                orderBomDetail.Uom = bomDetail.Uom;   //Bom单位
                //todo 检查Bom Operation和Routing Operation 不匹配的情况       
                orderBomDetail.Operation = bomDetail.Operation;
                orderBomDetail.OpReference = bomDetail.OpReference;
                if (orderMaster.IsListPrice)
                {
                    orderBomDetail.BomUnitQty = bomDetail.UnitBomQty * fgUnityQty; //单位成品(订单单位),需要消耗物料数量(Bom单位)。
                }
                else
                {
                    orderBomDetail.BomUnitQty = bomDetail.CalculatedQty * fgUnityQty; //单位成品(订单单位),需要消耗物料数量(Bom单位)。
                }
                orderBomDetail.OrderedQty = orderDetail.OrderedQty * orderBomDetail.BomUnitQty;
                orderBomDetail.Location = bomLocFrom;
                orderBomDetail.IsPrint = bomDetail.IsPrint;
                orderBomDetail.IsScanHu = itemTraceList.Contains(orderBomDetail.Item);   //生产防错标记
                orderBomDetail.BackFlushMethod = bomDetail.BackFlushMethod;
                orderBomDetail.FeedMethod = bomDetail.FeedMethod;
                orderBomDetail.IsAutoFeed = bomDetail.IsAutoFeed;
                //orderBomDetail.BackFlushInShortHandle = bomDetail.BackFlushInShortHandle;
                orderBomDetail.EstimateConsumeTime = orderMaster.StartTime;

                //BomDetail的基本单位
                orderBomDetail.BaseUom = bomItem.Uom;
                if (orderBomDetail.BaseUom != orderBomDetail.Uom)
                {
                    orderBomDetail.UnitQty = this.itemMgr.ConvertItemUomQty(orderBomDetail.Item, orderBomDetail.Uom, 1, orderBomDetail.BaseUom);
                }
                else
                {
                    orderBomDetail.UnitQty = 1;
                }

                orderDetail.AddOrderBomDetail(orderBomDetail);
                #endregion

                #region 查找零件消耗提前期,累加所有工序小于等于当前工序的提前期
                if (orderDetail.OrderOperations != null)
                {
                    IList<OrderOperation> orderOperationList = orderDetail.OrderOperations.Where(
                               p => p.Op < bomDetail.Operation
                        //每道工序对应一个工位,不考虑一道工序多工位的情况
                        //|| (p.Operation == bomDetail.Operation              //同道工序多工位的情况
                        //&& string.Compare(p.OpReference, bomDetail.OpReference) <= 0)
                               ).ToList();

                    if (orderOperationList != null && orderOperationList.Count > 0)
                    {
                        foreach (OrderOperation orderOperation in orderOperationList)
                        {
                            //switch (orderOperation.TimeUnit)
                            //{
                            //    case com.Sconit.CodeMaster.TimeUnit.Day:
                            //        orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromDays(orderOperation.LeadTime));
                            //        break;
                            //    case com.Sconit.CodeMaster.TimeUnit.Hour:
                            //        orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromHours(orderOperation.LeadTime));
                            //        break;
                            //    case com.Sconit.CodeMaster.TimeUnit.Minute:
                            //        orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromMinutes(orderOperation.LeadTime));
                            //        break;
                            //    case com.Sconit.CodeMaster.TimeUnit.Second:
                            //        orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromSeconds(orderOperation.LeadTime));
                            //        break;
                            //};
                        }
                    }
                }
                #endregion

                #region 更新生产防错标记
                //if (productionScanDetailList != null && productionScanDetailList.Count > 0)
                //{
                //    ProductionScanDetail productionScanDetail = productionScanDetailList.Where(
                //           p => p.Operation == orderBomDetail.Operation
                //               && p.OpReference == orderBomDetail.OpReference
                //               && p.Item == orderBomDetail.Item).SingleOrDefault();

                //    if (productionScanDetail != null)
                //    {
                //        orderBomDetail.IsScanHu = true;
                //    }
                //    else
                //    {
                //        orderBomDetail.IsScanHu = false;
                //    }
                //}
                #endregion
            }

            #region 委外退货
            if (orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                //更改原材料库位,材料增加              

                //OrderBomDetail orderBomDetail = new OrderBomDetail();
                //orderBomDetail.Item = orderDetail.Item;
                //orderBomDetail.ItemDescription = orderDetail.ItemDescription;
                //orderBomDetail.Uom = orderDetail.Uom;
                //#region 取工序,先取RoutingDetail上最小工序,如果没有取BomDetail的最小工序
                //if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count() > 0)
                //{
                //    //先根据工序排序,在根据工位排序
                //    OrderOperation orderOperation = orderDetail.OrderOperations
                //        .OrderBy(op => op.Operation)
                //        .ThenBy(op => op.OpReference)
                //        .First();
                //    orderBomDetail.Operation = orderOperation.Operation;
                //    orderBomDetail.OpReference = orderOperation.OpReference;
                //}
                //else
                //{
                //    BomDetail bomDetail = bomDetailList.OrderBy(det => det.Operation).ThenBy(det => det.OpReference).First();
                //    orderBomDetail.Operation = bomDetail.Operation;
                //    orderBomDetail.OpReference = bomDetail.OpReference;
                //}
                //#endregion
                //orderBomDetail.BaseUom = orderDetail.BaseUom;
                //orderBomDetail.BomUnitQty = 1;
                //orderBomDetail.OrderedQty = orderDetail.OrderedQty;
                //orderBomDetail.Location = !string.IsNullOrWhiteSpace(orderDetail.LocationTo) ? orderDetail.LocationTo : orderMaster.LocationTo;
                //orderBomDetail.IsPrint = false;
                //orderBomDetail.IsScanHu = orderMaster.IsReceiveScanHu || orderMaster.CreateHuOption == com.Sconit.CodeMaster.CreateHuOption.Receive;  //收获扫描Hu或者收货时创建条码,返工时要扫描成品条码
                //orderBomDetail.BackFlushMethod = com.Sconit.CodeMaster.BackFlushMethod.GoodsReceive;
                //orderBomDetail.FeedMethod = com.Sconit.CodeMaster.FeedMethod.None;
                //orderBomDetail.IsAutoFeed = false;
                ////orderBomDetail.BackFlushInShortHandle = BomDetail.BackFlushInShortHandleEnum.Nothing;
                //orderBomDetail.EstimateConsumeTime = orderMaster.StartTime;   //预计消耗时间等于开始时间
                //orderDetail.AddOrderBomDetail(orderBomDetail);
            }
            #endregion
            #endregion
        }
コード例 #2
0
        private static void AddBackflushInput(OrderMaster orderMaster, OrderDetail orderDetail, List<BackflushInput> backflushInputList, OrderBomDetail orderBomDetail, OrderDetailInput orderDetailInput, ReceiptDetail receiptDetail, decimal backFlushInputQty)
        {
            BackflushInput backFlushInput = new BackflushInput();

            backFlushInput.ProductLine = orderMaster.Flow;
            backFlushInput.ProductLineFacility = orderMaster.ProductLineFacility;
            backFlushInput.CurrentProductLine = orderMaster.CurrentFlowMaster;
            backFlushInput.OrderNo = orderMaster.OrderNo;
            backFlushInput.OrderType = orderMaster.Type;
            backFlushInput.OrderSubType = orderMaster.SubType;
            backFlushInput.OrderDetailId = orderDetail.Id;
            backFlushInput.OrderDetailSequence = orderDetail.Sequence;
            backFlushInput.OrderBomDetail = orderBomDetail;
            backFlushInput.ReceiptNo = receiptDetail.ReceiptNo;
            backFlushInput.ReceiptDetailId = receiptDetail.Id;
            backFlushInput.ReceiptDetailSequence = receiptDetail.Sequence;
            backFlushInput.FGItem = orderDetail.Item;
            backFlushInput.Item = orderBomDetail.Item;
            backFlushInput.ItemDescription = orderBomDetail.ItemDescription;
            backFlushInput.ReferenceItemCode = orderBomDetail.ReferenceItemCode;
            backFlushInput.Uom = orderBomDetail.Uom;
            backFlushInput.BaseUom = orderBomDetail.BaseUom;
            backFlushInput.UnitQty = orderBomDetail.UnitQty;   //基本单位转换率 = 订单单位/库存单位,转换为库存单位消耗 = 单位用量(订单单位) / 基本单位转换率
            backFlushInput.TraceCode = orderDetailInput.TraceCode;
            //backFlushInput.QualityType = CodeMaster.QualityType.Qualified;
            backFlushInput.FGQualityType = orderDetailInput.QualityType;  //收货成品的质量状态
            //backFlushInput.HuId = orderDetailInput.HuId;
            //backFlushInput.LotNo = orderDetailInput.LotNo;
            backFlushInput.Qty = backFlushInputQty;
            backFlushInput.ReceivedQty = receiptDetail.ReceivedQty;

            if (orderBomDetail.BackFlushMethod == CodeMaster.BackFlushMethod.GoodsReceive)
            {
                #region 按比例回冲
                //backFlushInput.ProductLineLocationDetailList = productLineLocationDetailList.Where(p => p.Item == orderBomDetail.Item).ToList();
                backFlushInput.Operation = orderBomDetail.Operation;
                backFlushInput.OpReference = orderBomDetail.OpReference;
                #endregion
            }
            backflushInputList.Add(backFlushInput);
        }
コード例 #3
0
 public void AddOrderBomDetail(OrderBomDetail orderBomDetail)
 {
     if (OrderBomDetails == null)
     {
         OrderBomDetails = new List<OrderBomDetail>();
     }
     OrderBomDetails.Add(orderBomDetail);
 }
コード例 #4
0
ファイル: OrderMgrImpl.cs プロジェクト: Novthirteen/sih-les
        private void GenerateOrderBomDetail(OrderDetail orderDetail, OrderMaster orderMaster)
        {
            #region 查找成品单位和Bom单位的转换关系
            //把OrderDetail的收货单位和单位用量转换为BOM单位和单位用量
            //fgUom,fgUnityQty代表接收一个orderDetail.Uom单位(等于订单的收货单位)的FG,等于单位(fgUom)有多少(fgUnityQty)值
            string fgUom = orderDetail.Uom;
            decimal fgUnityQty = 1;
            //如果和Bom上的单位不一致,转化为Bom上的单位,不然会导致物料回冲不正确。  

            //查找Bom
            BomMaster orderDetailBom = FindOrderDetailBom(orderDetail);
            #region 判断Bom是否有效
            if (!orderDetailBom.IsActive)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_BomInActive, orderDetail.Bom);
            }
            #endregion

            //订单单位和Bom单位不一致,需要做单位转换
            if (string.Compare(orderDetail.Uom, orderDetailBom.Uom) != 0)
            {
                fgUom = orderDetailBom.Uom;
                fgUnityQty = itemMgr.ConvertItemUomQty(orderDetail.Item, orderDetail.Uom, fgUnityQty, fgUom);
            }
            #endregion

            #region 创建OrderBomDetail
            Item fgItem = genericMgr.FindById<Item>(orderDetail.Item);

            #region 查询Bom明细
            IList<BomDetail> bomDetailList = bomMgr.GetFlatBomDetail(orderDetail.Bom, orderMaster.StartTime);
            #endregion

            #region 查询Bom Item
            IList<Item> bomItemList = null;
            if (bomDetailList != null && bomDetailList.Count > 0)
            {
                string hql = string.Empty;
                IList<object> para = new List<object>();
                foreach (BomDetail bomDetail in bomDetailList)
                {
                    if (hql == string.Empty)
                    {
                        hql = "from Item where Code in(?";
                    }
                    else
                    {
                        hql += ",?";
                    }
                    para.Add(bomDetail.Item);
                }
                hql += ")";

                bomItemList = this.genericMgr.FindAll<Item>(hql, para.ToArray());
            }
            #endregion

            //#region 查询工艺流程明细
            //IList<RoutingDetail> routingDetailList = null;
            //if (!string.IsNullOrEmpty(orderDetail.Routing))
            //{
            //    RoutingMaster routing = this.genericMgr.FindById<RoutingMaster>(orderDetail.Routing);
            //    if (!routing.IsActive)
            //    {
            //        throw new BusinessErrorException(Resources.ORD.OrderMaster.Errors_RoutingInActive, orderDetail.Routing);
            //    }
            //    routingDetailList = routingMgr.GetRoutingDetails(orderDetail.Routing, orderMaster.StartTime);
            //}
            //#endregion

            #region 查询生产防错明细 SIH客户化是从零件追溯表中取需要扫描的零件。
            //string itemTraceHql = "select it.Item From ItemTrace as it";
            //IList<string> itemTraceList = this.genericMgr.FindAll<string>(itemTraceHql);
            //IList<ProductionScanDetail> productionScanDetailList = null;
            //if (!string.IsNullOrEmpty(orderDetail.ProductionScan))
            //{
            //    ProductionScanMaster productionScanMaster = this.genericMgr.FindById<ProductionScanMaster>(orderDetail.ProductionScan);
            //    if (!productionScanMaster.IsActive)
            //    {
            //        throw new BusinessErrorException(Resources.ORD.OrderMaster.Errors_ScanInActive, orderDetail.ProductionScan);
            //    }

            //    DetachedCriteria criteria = DetachedCriteria.For<ProductionScanDetail>();
            //    criteria.Add(Expression.Eq("ProductionScan", orderDetail.ProductionScan));
            //    productionScanDetailList = this.genericMgr.FindAll<ProductionScanDetail>(criteria);
            //}
            #endregion

            foreach (BomDetail bomDetail in bomDetailList)
            {
                #region 查找物料的来源库位和提前期
                string bomLocFrom = string.Empty;
                //来源库位查找逻辑RoutingDetail-->OrderDetail-->Order-->BomDetail 
                //工序的优先级最大,因为同一个OrderMaster可以有不同的工艺流程,其次OrderMaster,最后BomDetail
                TryLoadOrderOperations(orderDetail);
                if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count > 0)
                {
                    //取RoutingDetail上的
                    OrderOperation orderOperation = orderDetail.OrderOperations.Where(
                            p => p.Operation == bomDetail.Operation
                            && p.OpReference == bomDetail.OpReference).SingleOrDefault();

                    if (orderOperation != null)
                    {
                        bomLocFrom = orderOperation.Location;
                    }
                }

                if (string.IsNullOrEmpty(bomLocFrom))
                {
                    //在取OrderDetail上,然后是OrderHead上取
                    //取默认库位FlowDetail-->Flow
                    if (!string.IsNullOrEmpty(orderDetail.LocationFrom))
                    {
                        bomLocFrom = orderDetail.LocationFrom;
                    }
                    else
                    {
                        bomLocFrom = orderMaster.LocationFrom;
                    }
                }

                if (string.IsNullOrEmpty(bomLocFrom))
                {
                    //最后取BomDetail上的Location
                    bomLocFrom = bomDetail.Location;
                }
                #endregion

                #region 创建生产单物料明细
                OrderBomDetail orderBomDetail = new OrderBomDetail();

                Item bomItem = bomItemList.Where(i => i.Code == bomDetail.Item).Single();

                orderBomDetail.Bom = bomDetail.Bom;
                orderBomDetail.Item = bomDetail.Item;
                orderBomDetail.ItemDescription = bomItem.Description;
                orderBomDetail.Uom = bomDetail.Uom;   //Bom单位
                //todo 检查Bom Operation和Routing Operation 不匹配的情况       
                orderBomDetail.Operation = bomDetail.Operation;
                orderBomDetail.OpReference = bomDetail.OpReference;
                //可以考虑增加库存单位的转换系数
                orderBomDetail.BomUnitQty = bomDetail.CalculatedQty * fgUnityQty; //单位成品(订单单位),需要消耗物料数量(Bom单位)。
                orderBomDetail.OrderedQty = orderDetail.OrderedQty * orderBomDetail.BomUnitQty;
                orderBomDetail.Location = bomLocFrom;
                orderBomDetail.IsPrint = bomDetail.IsPrint;
                //orderBomDetail.IsScanHu = itemTraceList.Contains(orderBomDetail.Item);   //生产防错标记
                orderBomDetail.IsScanHu = false;
                orderBomDetail.BackFlushMethod = bomDetail.BackFlushMethod;
                orderBomDetail.FeedMethod = bomDetail.FeedMethod;
                orderBomDetail.IsAutoFeed = bomDetail.IsAutoFeed;
                //orderBomDetail.BackFlushInShortHandle = bomDetail.BackFlushInShortHandle;
                orderBomDetail.EstimateConsumeTime = orderMaster.StartTime;

                //BomDetail的基本单位
                orderBomDetail.BaseUom = bomItem.Uom;
                if (orderBomDetail.BaseUom != orderBomDetail.Uom)
                {
                    orderBomDetail.UnitQty = this.itemMgr.ConvertItemUomQty(orderBomDetail.Item, orderBomDetail.Uom, 1, orderBomDetail.BaseUom);
                }
                else
                {
                    orderBomDetail.UnitQty = 1;
                }

                orderDetail.AddOrderBomDetail(orderBomDetail);
                #endregion

                #region 查找零件消耗提前期,累加所有工序小于等于当前工序的提前期
                if (orderDetail.OrderOperations != null)
                {
                    IList<OrderOperation> orderOperationList = orderDetail.OrderOperations.Where(
                               p => p.Operation < bomDetail.Operation
                        //每道工序对应一个工位,不考虑一道工序多工位的情况
                        //|| (p.Operation == bomDetail.Operation              //同道工序多工位的情况
                        //&& string.Compare(p.OpReference, bomDetail.OpReference) <= 0)
                               ).ToList();

                    if (orderOperationList != null && orderOperationList.Count > 0)
                    {
                        foreach (OrderOperation orderOperation in orderOperationList)
                        {
                            switch (orderOperation.TimeUnit)
                            {
                                case com.Sconit.CodeMaster.TimeUnit.Day:
                                    orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromDays(orderOperation.LeadTime));
                                    break;
                                case com.Sconit.CodeMaster.TimeUnit.Hour:
                                    orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromHours(orderOperation.LeadTime));
                                    break;
                                case com.Sconit.CodeMaster.TimeUnit.Minute:
                                    orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromMinutes(orderOperation.LeadTime));
                                    break;
                                case com.Sconit.CodeMaster.TimeUnit.Second:
                                    orderBomDetail.EstimateConsumeTime = orderBomDetail.EstimateConsumeTime.Add(TimeSpan.FromSeconds(orderOperation.LeadTime));
                                    break;
                            };
                        }
                    }
                }
                #endregion

                #region 更新生产防错标记
                //if (productionScanDetailList != null && productionScanDetailList.Count > 0)
                //{
                //    ProductionScanDetail productionScanDetail = productionScanDetailList.Where(
                //           p => p.Operation == orderBomDetail.Operation
                //               && p.OpReference == orderBomDetail.OpReference
                //               && p.Item == orderBomDetail.Item).SingleOrDefault();

                //    if (productionScanDetail != null)
                //    {
                //        orderBomDetail.IsScanHu = true;
                //    }
                //    else
                //    {
                //        orderBomDetail.IsScanHu = false;
                //    }
                //}
                #endregion
            }

            #region 返工,把自己添加到物料中。
            //回用不需要,回用产出的负数,投入也是负数。
            //为了投入产出报表数据合理
            if (orderMaster.SubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                OrderBomDetail orderBomDetail = new OrderBomDetail();

                orderBomDetail.Item = orderDetail.Item;
                orderBomDetail.ItemDescription = orderDetail.ItemDescription;
                orderBomDetail.Uom = orderDetail.Uom;
                #region 取工序,先取RoutingDetail上最小工序,如果没有取BomDetail的最小工序
                if (orderDetail.OrderOperations != null && orderDetail.OrderOperations.Count() > 0)
                {
                    //先根据工序排序,在根据工位排序
                    OrderOperation orderOperation = orderDetail.OrderOperations
                        .OrderBy(op => op.Operation)
                        .ThenBy(op => op.OpReference)
                        .First();

                    orderBomDetail.Operation = orderOperation.Operation;
                    orderBomDetail.OpReference = orderOperation.OpReference;
                    //orderBomDetail.OpReference = string.Empty;
                }
                else
                {
                    BomDetail bomDetail = bomDetailList.OrderBy(det => det.Operation).ThenBy(det => det.OpReference).First();

                    orderBomDetail.Operation = bomDetail.Operation;
                    orderBomDetail.OpReference = bomDetail.OpReference;
                }
                #endregion
                orderBomDetail.BomUnitQty = 1;
                orderBomDetail.OrderedQty = orderDetail.OrderedQty;
                orderBomDetail.Location = !string.IsNullOrWhiteSpace(orderDetail.LocationTo) ? orderDetail.LocationTo : orderMaster.LocationTo;
                orderBomDetail.IsPrint = false;
                orderBomDetail.IsScanHu = orderMaster.IsReceiveScanHu || orderMaster.CreateHuOption == com.Sconit.CodeMaster.CreateHuOption.Receive;  //收获扫描Hu或者收货时创建条码,返工时要扫描成品条码
                orderBomDetail.BackFlushMethod = com.Sconit.CodeMaster.BackFlushMethod.GoodsReceive;
                orderBomDetail.FeedMethod = com.Sconit.CodeMaster.FeedMethod.None;
                orderBomDetail.IsAutoFeed = false;
                //orderBomDetail.BackFlushInShortHandle = BomDetail.BackFlushInShortHandleEnum.Nothing;
                orderBomDetail.EstimateConsumeTime = orderMaster.StartTime;   //预计消耗时间等于开始时间

                orderDetail.AddOrderBomDetail(orderBomDetail);
            }
            #endregion
            #endregion
        }