private void RecordLocationTransaction(StockTakeMaster stockTakeMaster, StockTakeResult stockTakeResult, DateTime effectiveDate, IList<InventoryTransaction> inventoryTransactionList)
        {
            DateTime dateTimeNow = DateTime.Now;
            LocationTransaction locationTransaction = new LocationTransaction();

            locationTransaction.OrderNo = stockTakeResult.StNo;
            //locationTransaction.OrderType = ;
            //locationTransaction.OrderSubType = ;
            //locationTransaction.OrderDetailSequence =;
            //locationTransaction.OrderDetailId =;
            //locationTransaction.OrderBomDetId = 
            //locationTransaction.IpNo = 
            //locationTransaction.IpDetailId = 
            //locationTransaction.IpDetailSequence = 
            //locationTransaction.ReceiptNo = 
            //locationTransaction.ReceiptDetailId = 
            //locationTransaction.ReceiptDetailSequence = 
            //locationTransaction.SequenceNo = 
            //locationTransaction.TraceCode = ;
            locationTransaction.Item = stockTakeResult.Item;
            locationTransaction.Uom = stockTakeResult.Uom;
            locationTransaction.BaseUom = stockTakeResult.Uom;
            locationTransaction.Qty = stockTakeResult.DifferenceQty;
            locationTransaction.UnitQty = 1;
            locationTransaction.ActingBillQty = inventoryTransactionList.Sum(i => i.ActingBillQty);
            locationTransaction.QualityType = stockTakeResult.QualityType;
            locationTransaction.HuId = stockTakeResult.HuId;
            locationTransaction.LotNo = stockTakeResult.LotNo;
            locationTransaction.TransactionType = CodeMaster.TransactionType.CYC_CNT;
            locationTransaction.IOType = stockTakeResult.DifferenceQty < 0 ? CodeMaster.TransactionIOType.Out : CodeMaster.TransactionIOType.In;
            locationTransaction.PartyFrom = stockTakeMaster.Region;
            locationTransaction.PartyTo = stockTakeMaster.Region;
            locationTransaction.LocationFrom = stockTakeResult.Location;
            locationTransaction.LocationTo = stockTakeResult.Location;
            locationTransaction.LocationIOReason = stockTakeMaster.CostCenter;
            locationTransaction.EffectiveDate = effectiveDate;
            locationTransaction.CreateUserId = SecurityContextHolder.Get().Id;
            locationTransaction.CreateDate = dateTimeNow;

            this.genericMgr.Create(locationTransaction);
            RecordLocationTransactionDetail(locationTransaction, inventoryTransactionList);
        }
        private void RecordLocationTransaction(StockTakeMaster stockTakeMaster, StockTakeResult stockTakeResult, DateTime effectiveDate, 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 = stockTakeResult.StNo;
                //locationTransaction.OrderType = ;
                //locationTransaction.OrderSubType = ;
                //locationTransaction.OrderDetailSequence =;
                //locationTransaction.OrderDetailId =;
                //locationTransaction.OrderBomDetId = 
                //locationTransaction.IpNo = 
                //locationTransaction.IpDetailId = 
                //locationTransaction.IpDetailSequence = 
                //locationTransaction.ReceiptNo = 
                //locationTransaction.ReceiptDetailId = 
                //locationTransaction.ReceiptDetailSequence = 
                //locationTransaction.SequenceNo = 
                //locationTransaction.TraceCode = ;
                locationTransaction.Item = stockTakeResult.Item;
                locationTransaction.Uom = stockTakeResult.Uom;
                locationTransaction.BaseUom = stockTakeResult.Uom;
                locationTransaction.Qty = groupedInventoryTransaction.Qty;
                locationTransaction.UnitQty = 1;
                locationTransaction.IsConsignment = groupedInventoryTransaction.IsConsignment;
                if (groupedInventoryTransaction.IsConsignment && groupedInventoryTransaction.PlanBill.HasValue)
                {
                    locationTransaction.PlanBill = groupedInventoryTransaction.PlanBill.Value;
                }
                locationTransaction.PlanBillQty = groupedInventoryTransaction.PlanBillQty;
                if (groupedInventoryTransaction.ActingBill.HasValue)
                {
                    locationTransaction.ActingBill = groupedInventoryTransaction.ActingBill.Value;
                }
                locationTransaction.ActingBillQty = groupedInventoryTransaction.ActingBillQty; 
                locationTransaction.QualityType = stockTakeResult.QualityType;
                locationTransaction.HuId = stockTakeResult.HuId;
                locationTransaction.LotNo = stockTakeResult.LotNo;
                locationTransaction.TransactionType = CodeMaster.TransactionType.CYC_CNT;
                locationTransaction.IOType = stockTakeResult.DifferenceQty < 0 ? CodeMaster.TransactionIOType.Out : CodeMaster.TransactionIOType.In;
                locationTransaction.PartyFrom = stockTakeMaster.Region;
                locationTransaction.PartyTo = stockTakeMaster.Region;
                locationTransaction.LocationFrom = stockTakeResult.Location;
                locationTransaction.LocationTo = stockTakeResult.Location;
                locationTransaction.LocationIOReason = string.Empty;
                locationTransaction.EffectiveDate = effectiveDate;
                locationTransaction.CreateUserId = SecurityContextHolder.Get().Id;
                locationTransaction.CreateDate = dateTimeNow;

                this.genericMgr.Create(locationTransaction);
                RecordLocationTransactionDetail(locationTransaction, inventoryTransactionList);
            }
        }