public void AddReceiptDetail(ReceiptDetail receiptDetail)
 {
     if (ReceiptDetails == null)
     {
         ReceiptDetails = new List<ReceiptDetail>();
     }
     ReceiptDetails.Add(receiptDetail);
 }
Beispiel #2
0
        public IList<Hu> CreateHu(ReceiptMaster receiptMaster, ReceiptDetail receiptDetail, DateTime effectiveDate)
        {
            IList<Hu> huList = new List<Hu>();
            decimal remainReceivedQty = receiptDetail.ReceivedQty;
            receiptDetail.LotNo = LotNoHelper.GenerateLotNo(effectiveDate); //取生效日期为批号生成日期
            IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(receiptDetail);

            if (huIdDic != null && huIdDic.Count > 0)
            {
                foreach (string huId in huIdDic.Keys)
                {
                    Hu hu = new Hu();
                    hu.HuId = huId;
                    hu.LotNo = receiptDetail.LotNo;
                    hu.Item = receiptDetail.Item;
                    hu.ItemDescription = receiptDetail.ItemDescription;
                    hu.BaseUom = receiptDetail.BaseUom;
                    hu.Qty = huIdDic[huId];
                    hu.ManufactureParty = receiptMaster.PartyFrom;   //取区域代码为制造商代码
                    hu.ManufactureDate = LotNoHelper.ResolveLotNo(receiptDetail.LotNo);
                    hu.PrintCount = 0;
                    hu.ConcessionCount = 0;
                    hu.ReferenceItemCode = receiptDetail.ReferenceItemCode;
                    hu.UnitCount = receiptDetail.UnitCount;
                    hu.UnitQty = itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, 1, receiptDetail.BaseUom);
                    hu.Uom = receiptDetail.Uom;
                    hu.IsOdd = hu.Qty < receiptDetail.MinUc;
                    hu.OrderNo = receiptDetail.OrderNo;
                    hu.ReceiptNo = receiptMaster.ReceiptNo;
                    hu.Flow = receiptMaster.Flow;
                    hu.IpNo = receiptMaster.IpNo;
                    hu.IsChangeUnitCount = false;
                    hu.Remark = receiptDetail.Remark;
                    hu.Direction = receiptDetail.Direction;
                    hu.Flow = receiptDetail.Flow;
                    hu.Shift = receiptMaster.Shift;
                    //hu.UnitCountDescription = receiptDetail.UnitCountDescription;
                    var item = this.itemMgr.GetCacheItem(receiptDetail.Item);
                    hu.MaterialsGroup = this.GetMaterialsGroupDescrption(item.MaterialsGroup);
                    hu.HuTemplate = receiptMaster.HuTemplate;
                    hu.HuOption = GetHuOption(item);
                    if (item.Warranty > 0)
                    {
                        hu.ExpireDate = hu.ManufactureDate.AddDays(item.Warranty);
                    }
                    if (item.WarnLeadTime > 0)
                    {
                        hu.RemindExpireDate = hu.ManufactureDate.AddDays(item.WarnLeadTime);
                    }
                    this.genericMgr.Create(hu);
                    //this.AsyncSendPrintData(hu);
                    huList.Add(hu);
                }
            }
            return huList;
        }
Beispiel #3
0
        public IList<Hu> CreateHu(ReceiptMaster receiptMaster, ReceiptDetail receiptDetail, DateTime effectiveDate)
        {
            IList<Hu> huList = new List<Hu>();
            decimal remainReceivedQty = receiptDetail.ReceivedQty;
            receiptDetail.LotNo = LotNoHelper.GenerateLotNo(effectiveDate); //取生效日期为批号生成日期
            IDictionary<string, decimal> huIdDic = numberControlMgr.GetHuId(receiptDetail);

            if (huIdDic != null && huIdDic.Count > 0)
            {
                foreach (string huId in huIdDic.Keys)
                {
                    Hu hu = new Hu();
                    hu.HuId = huId;
                    hu.LotNo = receiptDetail.LotNo;
                    hu.Item = receiptDetail.Item;
                    hu.ItemDescription = receiptDetail.ItemDescription;
                    hu.BaseUom = receiptDetail.BaseUom;
                    hu.Qty = huIdDic[huId];
                    hu.ManufactureParty = receiptMaster.PartyFrom;   //取区域代码为制造商代码
                    hu.ManufactureDate = LotNoHelper.ResolveLotNo(receiptDetail.LotNo);
                    hu.PrintCount = 0;
                    hu.ConcessionCount = 0;
                    hu.ReferenceItemCode = receiptDetail.ReferenceItemCode;
                    hu.UnitCount = receiptDetail.UnitCount;
                    hu.UnitQty = itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, 1, receiptDetail.BaseUom);
                    hu.Uom = receiptDetail.Uom;
                    hu.IsOdd = hu.Qty < hu.UnitCount;
                    hu.OrderNo = receiptDetail.OrderNo;
                    hu.ReceiptNo = receiptMaster.ReceiptNo;
                    hu.IsChangeUnitCount = false;
                    //hu.UnitCountDescription = receiptDetail.UnitCountDescription;
                    genericMgr.Create(hu);
                    //创建条码中间表
                    this.CreateBarCode(hu,string.Empty);
                    //this.AsyncSendPrintData(hu);
                    huList.Add(hu);
                }
            }

            return huList;
        }
        public IDictionary<string, decimal> GetHuId(ReceiptDetail receiptDetail)
        {
            decimal uc = receiptDetail.UnitCount;
            if (receiptDetail.ReceivedQty <= receiptDetail.MaxUc && receiptDetail.ReceivedQty > 0)
            {
                uc = receiptDetail.ReceivedQty;
            }

            var HuIds = GetHuId(receiptDetail.LotNo, receiptDetail.Item, receiptDetail.ManufactureParty, receiptDetail.ReceivedQty, uc);

            return HuIds;
        }
Beispiel #5
0
        public PlanBill CreatePlanBill(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput, DateTime effectiveDate)
        {
            PlanBill planBill = new PlanBill();
            planBill.OrderNo = receiptDetail.OrderNo;
            planBill.IpNo = receiptDetail.IpNo;
            //planBill.ExternalIpNo = receiptDetail.ExternalIpNo;
            planBill.ReceiptNo = receiptDetail.ReceiptNo;
            planBill.ExternalReceiptNo = receiptDetail.CurrentExternalReceiptNo;
            if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract
                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods
                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
            {
                planBill.Type = com.Sconit.CodeMaster.BillType.Procurement;
                if (receiptDetail.OrderSubType == CodeMaster.OrderSubType.Normal)
                {
                    planBill.LocationFrom = receiptDetail.LocationTo;
                    planBill.Party = receiptDetail.CurrentPartyFrom;
                    planBill.PartyName = receiptDetail.CurrentPartyFromName;
                }
                else
                {
                    planBill.LocationFrom = receiptDetail.LocationFrom;
                    planBill.Party = receiptDetail.CurrentPartyTo;
                    planBill.PartyName = receiptDetail.CurrentPartyToName;
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution)
            {
                planBill.Type = com.Sconit.CodeMaster.BillType.Distribution;
                if (receiptDetail.OrderSubType == CodeMaster.OrderSubType.Normal)
                {
                    planBill.LocationFrom = receiptDetail.LocationFrom;
                    planBill.Party = receiptDetail.CurrentPartyTo;
                    planBill.PartyName = receiptDetail.CurrentPartyToName;
                }
                else
                {
                    planBill.LocationFrom = receiptDetail.LocationTo;
                    planBill.Party = receiptDetail.CurrentPartyFrom;
                    planBill.PartyName = receiptDetail.CurrentPartyFromName;
                }
            }
            planBill.Item = receiptDetail.Item;
            planBill.ItemDescription = receiptDetail.ItemDescription;

            planBill.Uom = receiptDetail.Uom;
            planBill.UnitCount = receiptDetail.UnitCount;
            planBill.BillTerm = receiptDetail.BillTerm;
            planBill.BillAddress = receiptDetail.BillAddress;
            //planBill.BillAddressDescription = receiptDetail.BillAddressDescription;
            planBill.PriceList = receiptDetail.PriceList;
            planBill.Currency = receiptDetail.Currency;
            planBill.UnitPrice = receiptDetail.UnitPrice.HasValue ? receiptDetail.UnitPrice.Value : 0;
            planBill.IsProvisionalEstimate = receiptDetail.UnitPrice.HasValue ? receiptDetail.IsProvisionalEstimate : false;
            planBill.Tax = receiptDetail.Tax;
            planBill.IsIncludeTax = receiptDetail.IsIncludeTax;
            if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            {
                //planBill.PlanQty = receiptDetailInput.ReceiveQty / receiptDetail.UnitQty;
                planBill.PlanQty = receiptDetailInput.ReceiveQty;
            }
            else
            {
                //planBill.PlanQty = -receiptDetailInput.ReceiveQty / receiptDetail.UnitQty;
                planBill.PlanQty = -receiptDetailInput.ReceiveQty;
            }
            planBill.PlanAmount = planBill.UnitPrice * planBill.PlanQty;
            planBill.UnitQty = receiptDetail.UnitQty;
            planBill.HuId = receiptDetailInput.HuId;
            planBill.EffectiveDate = effectiveDate;
            planBill.Flow = receiptDetail.Flow;
            planBill.ReferenceItemCode = receiptDetail.ReferenceItemCode;

            this.genericMgr.Create(planBill);

            this.RecordPlanBillTransaction(planBill, effectiveDate, receiptDetail.Id, false);

            return planBill;
        }
Beispiel #6
0
 public PlanBill CreatePlanBill(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput)
 {
     return CreatePlanBill(receiptDetail, receiptDetailInput, DateTime.Now);
 }
Beispiel #7
0
        public PlanBill CreatePlanBill(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput, DateTime effectiveDate)
        {
            PlanBill planBill = null;

            #region 寄售查找是否有PlanBill
            if (!(receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement
                || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA))
            {
                planBill = this.genericMgr.FindEntityWithNativeSql<PlanBill>("select * from BIL_PlanBill where Item = ? and BillAddr = ? and BillTerm not in(?,?)",
                    new object[] { receiptDetail.Item, receiptDetail.BillAddress, CodeMaster.OrderBillTerm.NA, CodeMaster.OrderBillTerm.ReceivingSettlement }).FirstOrDefault();

                if (planBill != null)
                {
                    planBill.CurrentVoidQty = 0;
                    planBill.CurrentCancelVoidQty = 0;
                    planBill.CurrentActingQty = 0;
                    planBill.CurrentLocation = null;
                    planBill.CurrentHuId = null;
                    planBill.CurrentActingBill = null;
                    planBill.CurrentBillTransaction = null;

                    if (planBill.BillTerm != receiptDetail.BillTerm)
                    {
                        //throw new BusinessException("物料{0}的结算方式({1})和寄售结算方式({2})不一致。", receiptDetail.Item,
                        //   systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.BillTerm, (int)receiptDetail.BillTerm),
                        //   systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.BillTerm, (int)planBill.BillTerm));
                        throw new BusinessException("物料{0}的结算方式({1})和寄售结算方式({2})不一致。", receiptDetail.Item,
                           systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.OrderBillTerm, (int)receiptDetail.BillTerm),
                           systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.OrderBillTerm, (int)planBill.BillTerm));
                    }
                }

                //if (planBill.Uom != receiptDetail.Uom)
                //{
                //    throw new BusinessException("物料{0}的收货单位{1}和寄售结算的单位{2}不一致。", receiptDetail.Item, receiptDetail.Uom, planBill.Uom);
                //}
            }
            else
            {
                planBill = this.genericMgr.FindEntityWithNativeSql<PlanBill>("select * from BIL_PlanBill where Item = ? and BillAddr = ? and RecNo = ?",
                  new object[] { receiptDetail.Item, receiptDetail.BillAddress, receiptDetail.ReceiptNo }).FirstOrDefault();

                if (planBill != null)
                {
                    planBill.CurrentVoidQty = 0;
                    planBill.CurrentCancelVoidQty = 0;
                    planBill.CurrentActingQty = 0;
                    planBill.CurrentLocation = null;
                    planBill.CurrentHuId = null;
                    planBill.CurrentActingBill = null;
                    planBill.CurrentBillTransaction = null;
                }
            }
            #endregion

            #region 没有PlanBill,创建PlanBill
            if (planBill == null)
            {
                planBill = new PlanBill();
                if (receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement
                    || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA)
                {
                    planBill.OrderNo = receiptDetail.OrderNo;
                    planBill.IpNo = receiptDetail.IpNo;
                    //planBill.ExternalIpNo = receiptDetail.ExternalIpNo;
                    planBill.ReceiptNo = receiptDetail.ReceiptNo;
                    planBill.ExternalReceiptNo = receiptDetail.Id.ToString();
                }
                if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                {
                    planBill.Type = com.Sconit.CodeMaster.BillType.Procurement;
                    if (receiptDetailInput.ReceiveQty > 0)
                    {
                        planBill.Party = receiptDetail.CurrentPartyFrom;
                        planBill.PartyName = receiptDetail.CurrentPartyFromName;
                    }
                    else
                    {
                        planBill.Party = receiptDetail.CurrentPartyTo;
                        planBill.PartyName = receiptDetail.CurrentPartyToName;
                    }
                }
                else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution)
                {
                    planBill.Type = com.Sconit.CodeMaster.BillType.Distribution;
                    if (receiptDetailInput.ReceiveQty > 0)
                    {
                        planBill.Party = receiptDetail.CurrentPartyTo;
                        planBill.PartyName = receiptDetail.CurrentPartyToName;
                    }
                    else
                    {
                        planBill.Party = receiptDetail.CurrentPartyFrom;
                        planBill.PartyName = receiptDetail.CurrentPartyFromName;
                    }
                }
                planBill.Item = receiptDetail.Item;
                planBill.ItemDescription = receiptDetail.ItemDescription;

                planBill.Uom = receiptDetail.Uom;
                planBill.UnitCount = receiptDetail.UnitCount;
                planBill.BillTerm = receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA ? CodeMaster.OrderBillTerm.ReceivingSettlement : receiptDetail.BillTerm;
                planBill.BillAddress = receiptDetail.BillAddress;
                //planBill.BillAddressDescription = receiptDetail.BillAddressDescription;
                planBill.PriceList = receiptDetail.PriceList;
                planBill.Currency = receiptDetail.Currency;
                planBill.UnitPrice = receiptDetail.UnitPrice.HasValue ? receiptDetail.UnitPrice.Value : 0;
                planBill.IsProvisionalEstimate = receiptDetail.UnitPrice.HasValue ? receiptDetail.IsProvisionalEstimate : false;
                planBill.Tax = receiptDetail.Tax;
                planBill.IsIncludeTax = receiptDetail.IsIncludeTax;
                planBill.PlanAmount = 0;
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    //planBill.PlanQty = receiptDetailInput.ReceiveQty / receiptDetail.UnitQty;
                    planBill.PlanQty = receiptDetailInput.ReceiveQty;
                }
                else
                {
                    //planBill.PlanQty = -receiptDetailInput.ReceiveQty / receiptDetail.UnitQty;
                    planBill.PlanQty = -receiptDetailInput.ReceiveQty;
                }
                planBill.UnitQty = receiptDetail.UnitQty;
                //planBill.HuId = receiptDetailInput.HuId;
                //planBill.LocationFrom = receiptDetail.LocationFrom;
                planBill.EffectiveDate = effectiveDate;

                this.genericMgr.Create(planBill);
            }
            #endregion

            #region 有PlanBill,增加待结算数量
            else
            {

                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (planBill.Uom != receiptDetail.Uom)
                    {
                        planBill.PlanQty += this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom);
                    }
                    else
                    {
                        planBill.PlanQty += receiptDetailInput.ReceiveQty;
                    }
                }
                else
                {
                    if (planBill.Uom != receiptDetail.Uom)
                    {
                        planBill.PlanQty -= this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom);
                    }
                    else
                    {
                        planBill.PlanQty -= receiptDetailInput.ReceiveQty;
                    }
                }

                this.genericMgr.Update(planBill);
            }
            #endregion

            #region 收货结算
            if (receiptDetail.BillTerm == CodeMaster.OrderBillTerm.NA
                || receiptDetail.BillTerm == CodeMaster.OrderBillTerm.ReceivingSettlement)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (planBill.Uom != receiptDetail.Uom)
                    {
                        planBill.CurrentActingQty = this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom);
                    }
                    else
                    {
                        planBill.CurrentActingQty = receiptDetailInput.ReceiveQty;
                    }
                }
                else
                {
                    if (planBill.Uom != receiptDetail.Uom)
                    {
                        planBill.CurrentActingQty = -this.itemMgr.ConvertItemUomQty(receiptDetail.Item, receiptDetail.Uom, receiptDetailInput.ReceiveQty, planBill.Uom);
                    }
                    else
                    {
                        planBill.CurrentActingQty = -receiptDetailInput.ReceiveQty;
                    }
                }
                BillTransaction billTransaction = this.SettleBill(planBill, effectiveDate);
                planBill.CurrentActingBill = billTransaction.ActingBill;
                planBill.CurrentBillTransaction = billTransaction.Id;
            }
            #endregion

            return planBill;
        }
        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);
        }
        public IList<InventoryTransaction> InventoryIn(ReceiptDetail receiptDetail, DateTime effectiveDate)
        {
            List<InventoryTransaction> inventoryTransactionList = new List<InventoryTransaction>();
            com.Sconit.CodeMaster.TransactionType? transType = GetTransactionType(receiptDetail);
            if (transType.HasValue)
            {
                #region 收货冲销,如果一个条码对应多条receiptDetailInput,需要先拆箱
                if (receiptDetail.IsVoid)
                {
                    var groupedHuIdList = from det in receiptDetail.ReceiptDetailInputs
                                          where !string.IsNullOrWhiteSpace(det.HuId)
                                          group det by det.HuId into gj
                                          select new
                                          {
                                              HuId = gj.Key,
                                              ReceiptDetailInputList = gj.ToList()
                                          };

                    if (groupedHuIdList != null && groupedHuIdList.Count() > 0)
                    {
                        //已知Bug,如果收货时不结算,两条不同的PlanBill生成条码会强制结算。但是在冲销时不会反结算。
                        #region 循环拆箱
                        foreach (var groupedHuId in groupedHuIdList.Where(g => g.ReceiptDetailInputList.Count() > 1))
                        {
                            InventoryUnPack inventoryUnPack = new InventoryUnPack();

                            inventoryUnPack.HuId = groupedHuId.HuId;
                            inventoryUnPack.CurrentHu = this.huMgr.GetHuStatus(groupedHuId.HuId);
                            IList<InventoryUnPack> inventoryUnPackList = new List<InventoryUnPack>();
                            inventoryUnPackList.Add(inventoryUnPack);
                            this.InventoryUnPack(inventoryUnPackList, effectiveDate);

                            foreach (ReceiptDetailInput receiptDetailInput in groupedHuId.ReceiptDetailInputList)
                            {
                                //把ReceiptDetailInput的HuId和LotNo至空,按数量出库。
                                receiptDetailInput.HuId = null;
                                receiptDetailInput.LotNo = null;
                                receiptDetailInput.IsConsignment = false;
                                receiptDetailInput.PlanBill = null;
                            }
                        }
                        #endregion

                        this.genericMgr.FlushSession();
                    }
                }
                #endregion

                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    if (receiptDetailInput.ReceivedIpLocationDetailList != null && receiptDetailInput.ReceivedIpLocationDetailList.Count > 0)
                    {
                        List<InventoryTransaction> currentReceiptDetailInputInventoryTransactionList = new List<InventoryTransaction>();
                        #region 基于Ip收货,零件的寄售信息都在IpLocationDetail上面
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                            thisReceiptDetailInput.ReceiveQty = (decimal)receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;
                            if (receiptDetail.CurrentIsReceiveScanHu && !string.IsNullOrWhiteSpace(receivedIpLocationDetail.HuId))
                            {
                                thisReceiptDetailInput.HuId = receivedIpLocationDetail.HuId;
                                thisReceiptDetailInput.LotNo = receivedIpLocationDetail.LotNo;
                            }

                            InventoryIO inventoryIO = new InventoryIO();

                            inventoryIO.Location = receiptDetail.LocationTo;
                            inventoryIO.Item = receiptDetail.Item;
                            if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count == 1)
                            {
                                //如果收货扫描条码,并且只有一条发货库存明细,可以直接收为条码
                                //要用收货Input上指定的条码
                                inventoryIO.HuId = thisReceiptDetailInput.HuId;
                                inventoryIO.LotNo = thisReceiptDetailInput.LotNo;
                            }
                            inventoryIO.Qty = receivedIpLocationDetail.ReceivedQty;             //库存单位
                            inventoryIO.QualityType = receivedIpLocationDetail.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                            inventoryIO.IsATP = receivedIpLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                            inventoryIO.IsCreatePlanBill = receivedIpLocationDetail.IsCreatePlanBill;
                            inventoryIO.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            inventoryIO.PlanBill = receivedIpLocationDetail.PlanBill;
                            inventoryIO.ActingBill = receivedIpLocationDetail.ActingBill;
                            inventoryIO.TransactionType = transType.Value;
                            //if (receivedIpLocationDetail.OccupyType == CodeMaster.OccupyType.Inspect)   //只有检验的收货要保留占用,其它收货不用保留
                            //{
                            inventoryIO.OccupyType = receivedIpLocationDetail.OccupyType;
                            inventoryIO.OccupyReferenceNo = receivedIpLocationDetail.OccupyReferenceNo;
                            //}
                            //inventoryIO.IsVoid = receiptDetail.IsVoid;
                            inventoryIO.EffectiveDate = effectiveDate;

                            #region 寄售处理
                            if (!receiptDetail.IsVoid &&
                                (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                               || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                    && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                               || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                            {
                                if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                                {
                                    throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                                }
                                else
                                {
                                    #region 记录待结算
                                    PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);

                                    inventoryIO.IsConsignment = true;
                                    inventoryIO.IsCreatePlanBill = true;
                                    inventoryIO.PlanBill = planBill.Id;
                                    inventoryIO.CurrentPlanBill = planBill;

                                    thisReceiptDetailInput.IsConsignment = true;
                                    thisReceiptDetailInput.IsCreatePlanBill = true;
                                    thisReceiptDetailInput.PlanBill = planBill.Id;
                                    #endregion
                                }
                            }
                            #endregion

                            IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                            #region 记录HuId,LotNo和WMS发货单行号
                            foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                            {
                                if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                                    && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                                {
                                    Hu hu = this.genericMgr.FindById<Hu>(receiptDetailInput.HuId);
                                    currentInventoryTransaction.HuId = hu.HuId;
                                    currentInventoryTransaction.LotNo = hu.LotNo;
                                }
                                currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                            }
                            #endregion

                            RecordLocationTransaction(receiptDetail, thisReceiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                            inventoryTransactionList.AddRange(currentInventoryTransactionList);
                            currentReceiptDetailInputInventoryTransactionList.AddRange(currentInventoryTransactionList);
                        }

                        #region 收货扫描条码,需要装箱创建条码
                        if (receiptDetail.CurrentIsReceiveScanHu && receiptDetailInput.ReceivedIpLocationDetailList.Count > 1
                            && !string.IsNullOrWhiteSpace(receiptDetailInput.HuId))
                        {
                            #region 装箱
                            IList<InventoryPack> inventoryPackList = new List<InventoryPack>();
                            InventoryPack inventoryPack = new InventoryPack();
                            inventoryPack.Location = receiptDetail.LocationTo;
                            inventoryPack.HuId = receiptDetailInput.HuId;
                            inventoryPack.LocationLotDetailIdList = currentReceiptDetailInputInventoryTransactionList.Select(inv => inv.LocationLotDetailId).ToList();

                            inventoryPackList.Add(inventoryPack);
                            this.InventoryPack(inventoryPackList, effectiveDate);
                            #endregion
                        }
                        #endregion
                        #endregion
                    }
                    else
                    {
                        #region 基于ReceiptDetailInput收货
                        InventoryIO inventoryIO = new InventoryIO();

                        inventoryIO.Location = receiptDetail.LocationTo;
                        inventoryIO.Item = receiptDetail.Item;
                        inventoryIO.HuId = receiptDetailInput.HuId;
                        inventoryIO.LotNo = receiptDetailInput.LotNo;
                        inventoryIO.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                        inventoryIO.QualityType = receiptDetailInput.QualityType;     //不合格品的ATP状态一定是false,合格品的状态一定是true,质检不采用ASN发货这里不可能出现
                        inventoryIO.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                        inventoryIO.IsFreeze = false;                       //可能指定移库冻结的零件?
                        inventoryIO.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                        inventoryIO.IsConsignment = receiptDetailInput.IsConsignment;
                        inventoryIO.PlanBill = receiptDetailInput.PlanBill;
                        inventoryIO.ActingBill = receiptDetailInput.ActingBill;
                        inventoryIO.TransactionType = transType.Value;
                        inventoryIO.OccupyType = receiptDetailInput.OccupyType;
                        inventoryIO.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;
                        inventoryIO.IsVoid = receiptDetail.IsVoid;
                        inventoryIO.EffectiveDate = effectiveDate;
                        //inventoryIO.ManufactureParty = ;

                        #region 寄售处理
                        if (!receiptDetail.IsVoid &&
                            (((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                            || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
                            && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                           || (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                                && transType != CodeMaster.TransactionType.RCT_TR)  //差异调整至发货方,不用产生结算
                           || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract))
                        {
                            if (receiptDetailInput.IsConsignment && receiptDetailInput.PlanBill.HasValue)
                            {
                                throw new TechnicalException("Can't create new planbill when receiptDetailInput aready has unsettled planbill.");
                            }

                            #region 记录待结算
                            PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);

                            inventoryIO.IsConsignment = true;
                            inventoryIO.IsCreatePlanBill = true;
                            inventoryIO.PlanBill = planBill.Id;
                            inventoryIO.CurrentPlanBill = planBill;

                            receiptDetailInput.IsConsignment = true;
                            receiptDetailInput.IsCreatePlanBill = true;
                            receiptDetailInput.PlanBill = planBill.Id;
                            #endregion

                            #region 判断是否立即结算
                            //if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)   //委外加工立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (receiptDetail.ReceivedQty < 0)  // 判断寄售负库存是否立即结算
                            //{
                            //    isBillSettle = true;
                            //}
                            //else if (string.IsNullOrWhiteSpace(receiptDetail.LocationTo) == null
                            //    && receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement) //判断目的库位为空的立即结算,如销售收货结算
                            //{
                            //    isBillSettle = true;
                            //}

                            //if (isBillSettle)
                            //{
                            //    //结算
                            //    planBill.CurrentActingQty = planBill.PlanQty;
                            //    BillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);
                            //    inventoryIO.IsConsignment = false;
                            //    receiptDetailInput.IsConsignment = false;
                            //}
                            #endregion
                        }
                        #endregion

                        IList<InventoryTransaction> currentInventoryTransactionList = RecordInventory(inventoryIO);
                        #region 记录WMS发货单行号
                        foreach (InventoryTransaction currentInventoryTransaction in currentInventoryTransactionList)
                        {
                            currentInventoryTransaction.WMSRecSeq = receiptDetailInput.WMSRecSeq;
                        }
                        #endregion
                        RecordLocationTransaction(receiptDetail, receiptDetailInput, effectiveDate, transType.Value, currentInventoryTransactionList);
                        inventoryTransactionList.AddRange(currentInventoryTransactionList);
                        #endregion
                    }
                }

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                    || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 采购退货收货
                if (!receiptDetail.IsVoid)
                {
                    foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                    {
                        foreach (IpLocationDetail receivedIpLocationDetail in receiptDetailInput.ReceivedIpLocationDetailList)
                        {
                            InventoryTransaction inventoryTransaction = new InventoryTransaction();
                            inventoryTransaction.Item = receiptDetail.Item;
                            inventoryTransaction.HuId = receiptDetailInput.HuId;
                            inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                            inventoryTransaction.IsConsignment = receivedIpLocationDetail.IsConsignment;
                            //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                            inventoryTransaction.PlanBill = receivedIpLocationDetail.PlanBill;
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                inventoryTransaction.PlanBillQty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位
                            }
                            //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                            //inventoryTransaction.ActingBillQty = ;
                            inventoryTransaction.Qty = receivedIpLocationDetail.ReceivedQty;  //转换为库存单位,入库位正数
                            inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                            inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                            inventoryTransaction.IsFreeze = false;
                            inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                            inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                            #region 退货收货
                            if (receivedIpLocationDetail.IsConsignment && receivedIpLocationDetail.PlanBill.HasValue)
                            {
                                //如果寄售库存,冲销PlanBill。
                                PlanBill planBill = this.genericMgr.FindById<PlanBill>(receivedIpLocationDetail.PlanBill.Value);
                                planBill.CurrentVoidQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;  //订单单位
                                this.billMgr.VoidPlanBill(planBill);

                                //inventoryTransaction.IsConsignment = false;
                                //inventoryTransaction.PlanBill = null;
                            }
                            else
                            {
                                //非寄售库存产生负数PlanBill,立即结算。
                                ReceiptDetailInput thisReceiptDetailInput = Mapper.Map<ReceiptDetailInput, ReceiptDetailInput>(receiptDetailInput);
                                thisReceiptDetailInput.ReceiveQty = receivedIpLocationDetail.ReceivedQty / receiptDetail.UnitQty;   //订单单位

                                PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, thisReceiptDetailInput, effectiveDate);
                                planBill.CurrentActingQty = planBill.PlanQty;
                                planBill.CurrentLocation = inventoryTransaction.Location;
                                SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                                inventoryTransaction.IsConsignment = false;
                                inventoryTransaction.IsCreatePlanBill = true;
                                inventoryTransaction.PlanBill = planBill.Id;
                                inventoryTransaction.PlanBillQty = 0;
                                inventoryTransaction.ActingBill = billTransaction.ActingBill;
                                inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                            }
                            #endregion

                            inventoryTransactionList.Add(inventoryTransaction);
                        }
                    }
                }
                #endregion

                #region 采购退货收货冲销
                else
                {
                    #region 采购退货收货冲销
                    foreach (ReceiptLocationDetail receiptLocationDetail in receiptDetail.ReceiptLocationDetails)
                    {
                        InventoryTransaction inventoryTransaction = new InventoryTransaction();
                        inventoryTransaction.Item = receiptDetail.Item;
                        inventoryTransaction.HuId = receiptLocationDetail.HuId;
                        inventoryTransaction.LotNo = receiptLocationDetail.LotNo;
                        inventoryTransaction.IsConsignment = receiptLocationDetail.IsConsignment;
                        //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                        inventoryTransaction.PlanBill = receiptLocationDetail.PlanBill;
                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            inventoryTransaction.PlanBillQty = receiptLocationDetail.Qty;  //转换为库存单位
                        }
                        //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                        //inventoryTransaction.ActingBillQty = ;
                        inventoryTransaction.Qty = receiptLocationDetail.Qty;  //转换为库存单位,入库位正数
                        inventoryTransaction.QualityType = receiptLocationDetail.QualityType;
                        inventoryTransaction.IsATP = receiptLocationDetail.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                        inventoryTransaction.IsFreeze = false;
                        inventoryTransaction.OccupyType = receiptLocationDetail.OccupyType;
                        inventoryTransaction.OccupyReferenceNo = receiptLocationDetail.OccupyReferenceNo;

                        if (receiptLocationDetail.IsConsignment && receiptLocationDetail.PlanBill.HasValue)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            planBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;  //退货收货冲销,要反冲销PlanQty。转为订单单位
                            this.billMgr.VoidPlanBill(planBill);
                        }

                        if (receiptLocationDetail.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptLocationDetail.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptLocationDetail.PlanBill);
                            actingBill.CurrentVoidQty = -receiptLocationDetail.Qty / receiptDetail.UnitQty;   //转为订单单位
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptLocationDetail.IsCreatePlanBill);
                        }

                        inventoryTransactionList.Add(inventoryTransaction);
                    }
                    #endregion
                }
                #endregion

                return inventoryTransactionList;
            }
            else if ((receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine
                        || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
                    && receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                    && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
            {
                #region 差异收货调整至供应商
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production
                && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
            {
                #region 原材料回用
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    inventoryTransaction.IsConsignment = false;
                    inventoryTransaction.IsCreatePlanBill = false;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.PlanBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    //inventoryTransaction.ActingBillQty = ;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    //inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    //inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution
                  && receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
            {
                #region 销售收货
                foreach (ReceiptDetailInput receiptDetailInput in receiptDetail.ReceiptDetailInputs)
                {
                    InventoryTransaction inventoryTransaction = new InventoryTransaction();
                    inventoryTransaction.Item = receiptDetail.Item;
                    inventoryTransaction.HuId = receiptDetailInput.HuId;
                    inventoryTransaction.LotNo = receiptDetailInput.LotNo;
                    //inventoryTransaction.IsConsignment = receiptDetailInput.IsConsignment;
                    //inventoryTransaction.IsCreatePlanBill = receiptDetailInput.IsCreatePlanBill;
                    //inventoryTransaction.PlanBill = receiptDetailInput.PlanBill;
                    //inventoryTransaction.ActingBill = receiptDetailInput.ActingBill;
                    inventoryTransaction.Qty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;  //转换为库存单位,入库位正数
                    inventoryTransaction.QualityType = receiptDetailInput.QualityType;
                    inventoryTransaction.IsATP = receiptDetailInput.QualityType == com.Sconit.CodeMaster.QualityType.Qualified;
                    inventoryTransaction.IsFreeze = false;
                    inventoryTransaction.OccupyType = receiptDetailInput.OccupyType;
                    inventoryTransaction.OccupyReferenceNo = receiptDetailInput.OccupyReferenceNo;

                    if (!receiptDetail.IsVoid)
                    {
                        #region 收货
                        PlanBill planBill = this.billMgr.CreatePlanBill(receiptDetail, receiptDetailInput, effectiveDate);
                        inventoryTransaction.IsConsignment = true;
                        inventoryTransaction.IsCreatePlanBill = true;
                        inventoryTransaction.PlanBill = planBill.Id;

                        if (receiptDetail.BillTerm == com.Sconit.CodeMaster.OrderBillTerm.ReceivingSettlement)
                        {
                            planBill.CurrentActingQty = planBill.PlanQty;
                            planBill.CurrentLocation = planBill.LocationFrom;
                            SettleBillTransaction billTransaction = this.billMgr.SettleBill(planBill, effectiveDate);

                            inventoryTransaction.IsConsignment = false;
                            inventoryTransaction.PlanBillQty = 0;
                            inventoryTransaction.ActingBill = billTransaction.ActingBill;
                            inventoryTransaction.ActingBillQty = receiptDetailInput.ReceiveQty * receiptDetail.UnitQty;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 收货冲销
                        if (receiptDetailInput.ActingBill.HasValue)
                        {
                            ActingBill actingBill = this.genericMgr.FindById<ActingBill>(receiptDetailInput.ActingBill);
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            actingBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidSettleBill(actingBill, planBill, receiptDetailInput.IsCreatePlanBill);
                        }
                        else if (receiptDetailInput.IsCreatePlanBill)
                        {
                            PlanBill planBill = this.genericMgr.FindById<PlanBill>(receiptDetailInput.PlanBill);
                            planBill.CurrentVoidQty = -receiptDetailInput.ReceiveQty;
                            this.billMgr.VoidPlanBill(planBill);
                        }
                        #endregion
                    }

                    inventoryTransactionList.Add(inventoryTransaction);
                }
                #endregion
            }
            else
            {
                throw new TechnicalException("未知情况,需要跟踪。");
            }

            return inventoryTransactionList;
        }
 public IList<InventoryTransaction> InventoryIn(ReceiptDetail receiptDetail)
 {
     return InventoryIn(receiptDetail, DateTime.Now);
 }
        private void RecordLocationTransaction(ReceiptDetail receiptDetail, ReceiptDetailInput receiptDetailInput, DateTime effectiveDate,
           com.Sconit.CodeMaster.TransactionType transType, IList<InventoryTransaction> inventoryTransactionList)
        {
            DateTime dateTimeNow = DateTime.Now;
            //根据PlanBill和ActingBill分组,为了不同供应商的库存事务分开
            var groupedInventoryTransactionList = from trans in inventoryTransactionList
                                                  group trans by new
                                                  {
                                                      IsConsignment = trans.IsConsignment,
                                                      PlanBill = trans.PlanBill,
                                                      ActingBill = trans.ActingBill
                                                  }
                                                      into result
                                                      select new
                                                      {
                                                          IsConsignment = result.Key.IsConsignment,
                                                          PlanBill = result.Key.PlanBill,
                                                          ActingBill = result.Key.ActingBill,
                                                          Qty = result.Sum(trans => trans.Qty),
                                                          PlanBillQty = result.Sum(trans => trans.PlanBillQty),
                                                          ActingBillQty = result.Sum(trans => trans.ActingBillQty),
                                                          InventoryTransactionList = result.ToList()
                                                      };

            foreach (var groupedInventoryTransaction in groupedInventoryTransactionList)
            {
                LocationTransaction locationTransaction = new LocationTransaction();

                locationTransaction.OrderNo = receiptDetail.OrderNo;
                locationTransaction.OrderType = receiptDetail.OrderType;
                locationTransaction.OrderSubType = receiptDetail.OrderSubType;
                locationTransaction.OrderDetailSequence = receiptDetail.OrderDetailSequence;
                locationTransaction.OrderDetailId = receiptDetail.OrderDetailId.Value;
                //locationTransaction.OrderBomDetId = 
                locationTransaction.IpNo = receiptDetail.IpNo;
                locationTransaction.IpDetailId = receiptDetail.IpDetailId.HasValue ? receiptDetail.IpDetailId.Value : 0;
                locationTransaction.IpDetailSequence = receiptDetail.IpDetailSequence;
                locationTransaction.ReceiptNo = receiptDetail.ReceiptNo;
                locationTransaction.ReceiptDetailId = receiptDetail.Id;
                locationTransaction.ReceiptDetailSequence = receiptDetail.Sequence;
                //locationTransaction.SequenceNo = 
                //locationTransaction.TraceCode =
                locationTransaction.SequenceNo = receiptDetailInput.SequenceNo;
                locationTransaction.Item = receiptDetail.Item;
                locationTransaction.Uom = receiptDetail.Uom;
                locationTransaction.BaseUom = receiptDetail.BaseUom;
                locationTransaction.Qty = groupedInventoryTransaction.Qty / receiptDetail.UnitQty;
                locationTransaction.UnitQty = receiptDetail.UnitQty;
                locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment;
                if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue)
                {
                    locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value;
                }
                locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty / receiptDetail.UnitQty;
                if (groupedInventoryTransaction.ActingBill.HasValue)
                {
                    locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value;
                }
                locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty / receiptDetail.UnitQty;
                locationTransaction.QualityType = receiptDetail.QualityType;
                locationTransaction.HuId = receiptDetailInput.HuId;
                locationTransaction.LotNo = receiptDetailInput.LotNo;
                locationTransaction.TransactionType = transType;
                locationTransaction.IOType = CodeMaster.TransactionIOType.In;
                locationTransaction.PartyFrom = receiptDetail.CurrentPartyFrom;
                locationTransaction.PartyTo = receiptDetail.CurrentPartyTo;
                locationTransaction.LocationFrom = receiptDetail.LocationFrom;
                locationTransaction.LocationTo = receiptDetail.LocationTo;
                locationTransaction.LocationIOReason = string.Empty;
                locationTransaction.EffectiveDate = effectiveDate;
                locationTransaction.CreateUserId = SecurityContextHolder.Get().Id;
                locationTransaction.CreateDate = dateTimeNow;

                this.genericMgr.Create(locationTransaction);

                RecordLocationTransactionDetail(locationTransaction, groupedInventoryTransaction.InventoryTransactionList);
            }
        }
        private com.Sconit.CodeMaster.TransactionType? GetTransactionType(ReceiptDetail receiptDetail)
        {
            if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Procurement
                || receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.CustomerGoods)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap &&
                        receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        //差异收货调整至发货方(供应商)
                        return null;
                    }
                    else if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_PO;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_PO_VOID;
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    //if (receiptDetail.IsVoid)
                    //{
                    //    //采购退货冲销
                    //    return com.Sconit.CodeMaster.TransactionType.ISS_PO_VOID;
                    //}
                    //else
                    //{
                    //    return null;
                    //}
                    return null;
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.ScheduleLine)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                        && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        //差异收货调整至发货方(供应商)
                        return null;
                    }
                    else if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_SL;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_SL_VOID;
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (receiptDetail.IsVoid)
                    {
                        //采购退货冲销
                        return com.Sconit.CodeMaster.TransactionType.ISS_SL_VOID;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Distribution)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                        && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        //差异收货调整至发货方,作为移库接收
                        return com.Sconit.CodeMaster.TransactionType.RCT_TR;
                    }
                    else
                    {
                        return null;
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_SO;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_SO_VOID;
                    }
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Transfer)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_TR;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_TR_VOID;
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_TR_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_TR_RTN_VOID;
                    }
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContractTransfer)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_STR;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_STR_VOID;
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    if (!receiptDetail.IsVoid)
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_STR_RTN;
                    }
                    else
                    {
                        return com.Sconit.CodeMaster.TransactionType.RCT_STR_RTN_VOID;
                    }
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.Production)
            {

                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    return null;
                }
                else
                {
                    if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                     && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        return null;
                    }
                    else
                    {
                        if (!receiptDetail.IsVoid)
                        {
                            return com.Sconit.CodeMaster.TransactionType.RCT_WO;
                        }
                        else
                        {
                            return com.Sconit.CodeMaster.TransactionType.RCT_WO_VOID;
                        }
                    }
                }
            }
            else if (receiptDetail.OrderType == com.Sconit.CodeMaster.OrderType.SubContract)
            {
                if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Normal)
                {
                    //调整发货方库存,委外不作调整
                    if (receiptDetail.IpDetailType == CodeMaster.IpDetailType.Gap
                        && receiptDetail.IpGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        return null;
                    }
                    else
                    {
                        if (!receiptDetail.IsVoid)
                        {
                            return com.Sconit.CodeMaster.TransactionType.RCT_SWO;
                        }
                        else
                        {
                            return com.Sconit.CodeMaster.TransactionType.RCT_SWO_VOID;
                        }
                    }
                }
                else if (receiptDetail.OrderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
                {
                    return null;
                }
            }
            else
            {
                throw new TechnicalException("Wrong order type of receiptDetail:[" + receiptDetail.OrderType + "]");
            }

            return null;
        }
        public IDictionary<string, decimal> GetHuId(ReceiptDetail receiptDetail)
        {
            var HuIds = GetHuId(receiptDetail.LotNo, receiptDetail.Item, receiptDetail.ManufactureParty,
              receiptDetail.ReceivedQty, receiptDetail.UnitCount);

            return HuIds;
        }