public int GetProductAvailableSaleQty(int productSysNo)
        {
            var result = InventoryDA.GetProductTotalInventoryInfo(productSysNo);

            if (result != null)
            {
                return(result.AvailableQty + result.ConsignQty + result.VirtualQty - result.InvalidQty);
            }
            else
            {
                return(0);
            }
        }
Exemple #2
0
        /// <summary>
        /// 采购单确认入库(接口调用)
        /// </summary>
        /// <param name="poSysNo"></param>
        public static PurchaseOrderInfo WaitingInstockPO(PurchaseOrderInfo poInfo, List <KeyValuePair <string, int> > productList)
        {
            if (null == poInfo || !poInfo.SysNo.HasValue)
            {
                throw new BusinessException("找不到相关的采购单信息!");
            }
            if (poInfo.PurchaseOrderBasicInfo.PurchaseOrderStatus != PurchaseOrderStatus.Reporting)
            {
                throw new BusinessException("该采购单状态不是'申报中'状态,不能进行入库确认操作!");
            }
            if (productList == null || productList.Count <= 0)
            {
                throw new BusinessException("该采购单商品明细传入为空!");
            }
            //poInfo.PurchaseOrderBasicInfo.ETATimeInfo.ETATime = localEntity.PurchaseOrderBasicInfo.ETATimeInfo.ETATime;
            //poInfo.PurchaseOrderBasicInfo.ETATimeInfo.HalfDay = localEntity.PurchaseOrderBasicInfo.ETATimeInfo.HalfDay;
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = System.Transactions.TransactionManager.DefaultTimeout;
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                #region 更新PO单Item的PurchaseQty:
                if (null != productList && productList.Count > 0)
                {
                    foreach (var item in productList)
                    {
                        var poItem = poInfo.POItems.SingleOrDefault(x => x.ProductID.Trim().ToLower() == item.Key.Trim().ToLower());
                        if (null != poItem)
                        {
                            if (poItem.PrePurchaseQty < item.Value)
                            {
                                throw new BusinessException(string.Format("采购单编号:{0},商品ID为{1}的实际采购数量(ItemNum)大于计划采购数量!", poInfo.SysNo.Value, item.Key));
                            }

                            poItem.PurchaseQty = item.Value;
                            ProductPurchaseDA.UpdatePOItemPurchaseQty(poItem.ItemSysNo.Value, item.Value);
                        }
                        else
                        {
                            throw new BusinessException(string.Format("采购单编号:{0},找不到商品ID为{1}的采购单商品信息!", poInfo.SysNo.Value, item.Key));
                        }
                    }
                }
                #endregion

                #region 更新采购单状态:
                poInfo.PurchaseOrderBasicInfo.PurchaseOrderStatus = PurchaseOrderStatus.WaitingInStock;
                poInfo.PurchaseOrderBasicInfo.MemoInfo.RefuseMemo = string.Empty;

                ProductPurchaseDA.WaitingInStockPO(poInfo);
                #endregion

                #region 更新POItem信息:
                List <KeyValuePair <int, int> > kv = new List <KeyValuePair <int, int> >();
                foreach (PurchaseOrderItemInfo item in poInfo.POItems)
                {
                    kv.Add(new KeyValuePair <int, int>(item.ProductSysNo.Value, item.PurchaseQty.Value));

                    //总仓有效库存 上月销售总量
                    PurchaseOrderItemInfo tempPoItem = ProductPurchaseDA.LoadExtendPOItem(item.ProductSysNo.Value);
                    item.M1                  = tempPoItem.M1;
                    item.AvailableQty        = tempPoItem.AvailableQty;
                    item.UnitCostWithoutTax  = item.UnitCostWithoutTax ?? 0;
                    item.CurrentUnitCost     = tempPoItem.CurrentUnitCost;
                    item.CurrentPrice        = tempPoItem.CurrentPrice;
                    item.LastInTime          = tempPoItem.LastInTime;
                    item.LastAdjustPriceDate = tempPoItem.LastAdjustPriceDate;
                    item.LastOrderPrice      = tempPoItem.LastOrderPrice;
                    ProductPurchaseDA.UpdatePOItem(item);
                }
                #endregion

                #region 设置采购在途数量,(代销PO该业务逻辑不变)

                ProductPurchaseInstockAdjustInventoryInfo inventoryAdjustInfo = new ProductPurchaseInstockAdjustInventoryInfo()
                {
                    ReferenceSysNo   = poInfo.SysNo.Value,
                    SourceActionName = "Audit",
                    AdjustItemList   = new List <Entity.Inventory.InventoryAdjustItemInfo>()
                };
                kv.ForEach(x =>
                {
                    inventoryAdjustInfo.AdjustItemList.Add(new InventoryAdjustItemInfo()
                    {
                        ProductSysNo   = x.Key,
                        StockSysNo     = poInfo.PurchaseOrderBasicInfo.StockInfo.SysNo.Value,
                        AdjustQuantity = x.Value
                    });
                });

                foreach (InventoryAdjustItemInfo adjustItem in inventoryAdjustInfo.AdjustItemList)
                {
                    //this.CurrentAdjustItemInfo = adjustItem;
                    //this.AdjustQuantity = adjustItem.AdjustQuantity;
                    //ProcessAdjustItemInfo();
                    CostLockType     costLockAction = CostLockType.NoUse;
                    ProductQueryInfo productInfo    = ProductService.GetProductBySysNo(adjustItem.ProductSysNo);
                    if (productInfo == null || productInfo.SysNo <= 0)
                    {
                        throw new BusinessException(string.Format("欲调库存的商品不存在,商品编号:{0}", adjustItem.ProductSysNo));
                    }
                    InventoryDA.InitProductInventoryInfo(adjustItem.ProductSysNo, adjustItem.StockSysNo);
                    var inventoryType = InventoryDA.GetProductInventroyType(adjustItem.ProductSysNo);
                    ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryCurrentInfo = InventoryDA.GetProductInventoryInfoByStock(adjustItem.ProductSysNo, adjustItem.StockSysNo);
                    ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryCurrentInfo = InventoryDA.GetProductTotalInventoryInfo(adjustItem.ProductSysNo);

                    ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryAdjustInfo = new Entity.Inventory.ProductInventoryInfo()
                    {
                        ProductSysNo = adjustItem.ProductSysNo,
                        StockSysNo   = adjustItem.StockSysNo
                    };

                    ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryAdjustInfo = new ECommerce.Entity.Inventory.ProductInventoryInfo()
                    {
                        ProductSysNo = adjustItem.ProductSysNo
                    };
                    //获取负po的成本库存
                    List <ProductCostIn> productCostInList = InventoryDA.GetProductCostIn(adjustItem.ProductSysNo, Convert.ToInt32(inventoryAdjustInfo.ReferenceSysNo), adjustItem.StockSysNo);


                    List <ProductCostIn> adjustProductCostInList = new List <ProductCostIn>();
                    int CanUseQuantity = 0;
                    //区分正负PO单
                    if (adjustItem.AdjustQuantity < 0)
                    {
                        //负PO单审核, AdjustQty<0, 减少可用库存, 增加已分配库存
                        stockInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity;
                        totalInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity;

                        if (adjustItem.AdjustQuantity < 0)
                        {
                            //AllocatedQty(-,->0),小于0则自动调为0。
                            if (stockInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                            {
                                stockInventoryAdjustInfo.AllocatedQty = -stockInventoryCurrentInfo.AllocatedQty;
                            }
                            else
                            {
                                stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                            }

                            if (totalInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                            {
                                totalInventoryAdjustInfo.AllocatedQty = -totalInventoryCurrentInfo.AllocatedQty;
                            }
                            else
                            {
                                totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                            }
                        }
                        else
                        {
                            stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                            totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                        }

                        //标识要锁定成本库存
                        costLockAction = CostLockType.Lock;
                        int temp = Math.Abs(adjustItem.AdjustQuantity);
                        //锁定库存
                        foreach (var item in productCostInList)
                        {
                            CanUseQuantity = item.LeftQuantity - item.LockQuantity;
                            //可用数量大于要锁定数量,直接累加加到锁定数量
                            if (CanUseQuantity >= temp)
                            {
                                item.LockQuantity += temp;
                                adjustProductCostInList.Add(item);
                                break;
                            }
                            else if (CanUseQuantity > 0) //可用数量不足且大于0,
                            {
                                //调整数量减少相应值,进行一次锁定分配
                                temp = temp - CanUseQuantity;
                                //将可用加到锁定数量上
                                item.LockQuantity += CanUseQuantity;
                                adjustProductCostInList.Add(item);
                            }
                        }
                    }
                    else
                    {
                        //正PO单审核, AdjustQty>0, 增加采购库存
                        stockInventoryAdjustInfo.PurchaseQty = adjustItem.AdjustQuantity;
                        totalInventoryAdjustInfo.PurchaseQty = adjustItem.AdjustQuantity;
                    }

                    //预检调整后的商品库存是否合法
                    Entity.Inventory.ProductInventoryInfo stockInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(stockInventoryCurrentInfo, stockInventoryAdjustInfo);
                    Entity.Inventory.ProductInventoryInfo totalInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(totalInventoryCurrentInfo, totalInventoryAdjustInfo);

                    bool isNeedCompareAvailableQtyAndAccountQty = true;
                    InventoryService.PreCheckGeneralRules(stockInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty);
                    InventoryService.PreCheckGeneralRules(totalInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty);

                    //调整商品库存:

                    InventoryDA.AdjustProductStockInventoryInfo(stockInventoryAdjustInfo);
                    InventoryDA.AdjustProductTotalInventoryInfo(totalInventoryAdjustInfo);
                    //如果需要调整锁定库存
                    if (costLockAction != CostLockType.NoUse && adjustProductCostInList != null)
                    {
                        InventoryDA.LockProductCostInList(adjustProductCostInList);
                    }
                }
                #endregion

                #region 如果是负采购单,调整批次库存:
                if (poInfo.PurchaseOrderBasicInfo.PurchaseOrderType == PurchaseOrderType.Negative)
                {
                    SetInventoryInfo(poInfo, "");
                }

                #endregion

                scope.Complete();
            }
            return(poInfo);
        }
Exemple #3
0
        /// <summary>
        /// 损益单出库 (确认成功):
        /// </summary>
        /// <param name="adjustRequestSysNo">原始损益单编号</param>
        /// <param name="productSysNo">损益商品编号</param>
        /// <param name="realAdjustQty">该商品的实际损益数量</param>
        /// <returns></returns>
        public static AdjustRequestInfo AdjustOutStock(int adjustRequestSysNo, int?productSysNo, int?realAdjustQty, int sellerSysNo)
        {
            var adjustRequestInfo = GetAdjustRequestInfoBySysNo(adjustRequestSysNo);


            #region Check操作 :
            if (null == adjustRequestInfo || adjustRequestInfo.SysNo <= 0)
            {
                throw new BusinessException(string.Format("找不到编号为{0}的损益单据信息!", adjustRequestSysNo));
            }

            if (productSysNo.HasValue && realAdjustQty.HasValue)
            {
                var productItemInfo = adjustRequestInfo.AdjustItemInfoList.FirstOrDefault(x => x.ProductSysNo == productSysNo);
                if (productItemInfo == null)
                {
                    throw new BusinessException(string.Format("编号为{0}的商品不存在于该损益单中!损益单编号 :{1}", productSysNo, adjustRequestSysNo));
                }
                if (realAdjustQty >= 0)
                {
                    if (realAdjustQty > productItemInfo.AdjustQuantity)
                    {
                        throw new BusinessException(string.Format("编号为{0}的商品实际损益的数量大于预损益的数量!损益单编号 :{1}", productSysNo, adjustRequestSysNo));
                    }
                }
                else
                {
                    if (realAdjustQty < productItemInfo.AdjustQuantity)
                    {
                        throw new BusinessException(string.Format("编号为{0}的商品实际损益的数量大于预损益的数量!损益单编号 :{1}", productSysNo, adjustRequestSysNo));
                    }
                }
            }

            var stockInfo = StockService.LoadStock(adjustRequestInfo.Stock.SysNo);
            if (null == stockInfo)
            {
                throw new BusinessException("损益单据关联的仓库编号无效!");
            }
            if (stockInfo.MerchantSysNo != sellerSysNo)
            {
                throw new BusinessException("此商家无权操作此单据!");
            }

            //增加损益单状态Check (已申报状态):
            if (adjustRequestInfo.RequestStatus != AdjustRequestStatus.Reported)
            {
                throw new BusinessException(string.Format("损益单编号 :{1},当前单据的状态不是'已申报'状态,不能进行损益单确认操作", productSysNo, adjustRequestSysNo));
            }

            #endregion

            bool isConsign = false;
            adjustRequestInfo.OutStockDate  = DateTime.Now;
            adjustRequestInfo.RequestStatus = Enums.AdjustRequestStatus.OutStock;
            isConsign = (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay);
            var inventoryAdjustContract = new InventoryAdjustContractInfo
            {
                SourceBizFunctionName = InventoryAdjustSourceBizFunction.Inventory_AdjustRequest,
                SourceActionName      = InventoryAdjustSourceAction.OutStock,
                ReferenceSysNo        = adjustRequestInfo.SysNo.ToString(),
                AdjustItemList        = new List <InventoryAdjustItemInfo>()
            };

            using (TransactionScope scope = new TransactionScope())
            {
                if (adjustRequestInfo.AdjustItemInfoList != null && adjustRequestInfo.AdjustItemInfoList.Count > 0)
                {
                    adjustRequestInfo.AdjustItemInfoList.ForEach(adjustItem =>
                    {
                        //if (adjustItem.AdjustProduct.ProductPriceInfo == null)
                        //{
                        //    BizExceptionHelper.Throw("Common_CannotFindPriceInformation");
                        //    throw new BusinessException("损益数量只能为非0的整数!");
                        //}
                        if (adjustItem.AdjustQuantity == 0)
                        {
                            throw new BusinessException("损益数量只能为非0的整数!");
                        }

                        var cost = InventoryDA.GetItemCost(adjustItem.ProductSysNo.Value);
                        inventoryAdjustContract.AdjustItemList.Add(new InventoryAdjustItemInfo
                        {
                            AdjustQuantity = adjustItem.AdjustQuantity.Value,
                            ProductSysNo   = adjustItem.ProductSysNo.Value,
                            StockSysNo     = (int)adjustRequestInfo.Stock.SysNo,
                            AdjustUnitCost = cost,
                        });

                        //update flash item unit cost
                        if (adjustItem.AdjustCost != cost)
                        {
                            adjustItem.AdjustCost = cost;
                            InventoryDA.UpdateAdjustItemCost(adjustItem);
                        }
                    });
                }
                InventoryDA.UpdateAdjustRequestStatus(adjustRequestInfo);

                if (inventoryAdjustContract.AdjustItemList.Count > 0)
                {
                    //string adjustResult = ObjectFactory<InventoryAdjustContractProcessor>.Instance.ProcessAdjustContract(inventoryAdjustContract);
                    //if (!string.IsNullOrEmpty(adjustResult))
                    //{
                    //    throw new BizException("库存调整失败: " + adjustResult);
                    //}


                    #region 调整库存:

                    foreach (InventoryAdjustItemInfo adjustItem in inventoryAdjustContract.AdjustItemList)
                    {
                        ProductQueryInfo productInfo = ProductService.GetProductBySysNo(adjustItem.ProductSysNo);
                        if (productInfo == null || productInfo.SysNo <= 0)
                        {
                            throw new BusinessException(string.Format("欲调库存的商品不存在,商品编号:{0}", adjustItem.ProductSysNo));
                        }
                        InventoryDA.InitProductInventoryInfo(adjustItem.ProductSysNo, adjustItem.StockSysNo);
                        var inventoryType = InventoryDA.GetProductInventroyType(adjustItem.ProductSysNo);
                        ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryCurrentInfo = InventoryDA.GetProductInventoryInfoByStock(adjustItem.ProductSysNo, adjustItem.StockSysNo);
                        ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryCurrentInfo = InventoryDA.GetProductTotalInventoryInfo(adjustItem.ProductSysNo);

                        ECommerce.Entity.Inventory.ProductInventoryInfo stockInventoryAdjustInfo = new Entity.Inventory.ProductInventoryInfo()
                        {
                            ProductSysNo = adjustItem.ProductSysNo,
                            StockSysNo   = adjustItem.StockSysNo
                        };

                        ECommerce.Entity.Inventory.ProductInventoryInfo totalInventoryAdjustInfo = new ECommerce.Entity.Inventory.ProductInventoryInfo()
                        {
                            ProductSysNo = adjustItem.ProductSysNo
                        };


                        if (adjustItem.AdjustQuantity < 0)
                        {
                            //损单出库
                            if (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay)
                            {
                                //代销商品, 恢复可用库存, 减少已分配库存/代销库存
                                stockInventoryAdjustInfo.AvailableQty = -adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.AvailableQty = -adjustItem.AdjustQuantity;

                                if (adjustItem.AdjustQuantity < 0)
                                {
                                    //AllocatedQty(-,->0),小于0则自动调为0。
                                    if (stockInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                                    {
                                        stockInventoryAdjustInfo.AllocatedQty = -stockInventoryCurrentInfo.AllocatedQty;
                                    }
                                    else
                                    {
                                        stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    }

                                    if (totalInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                                    {
                                        totalInventoryAdjustInfo.AllocatedQty = -totalInventoryCurrentInfo.AllocatedQty;
                                    }
                                    else
                                    {
                                        totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    }
                                }
                                else
                                {
                                    stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                }

                                stockInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity;
                            }
                            else
                            {
                                //非代销商品, 减少财务库存/已分配库存
                                stockInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.AccountQty = adjustItem.AdjustQuantity;

                                if (adjustItem.AdjustQuantity < 0)
                                {
                                    //AllocatedQty(-,->0),小于0则自动调为0。
                                    if (stockInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                                    {
                                        stockInventoryAdjustInfo.AllocatedQty = -stockInventoryCurrentInfo.AllocatedQty;
                                    }
                                    else
                                    {
                                        stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    }

                                    if (totalInventoryCurrentInfo.AllocatedQty + adjustItem.AdjustQuantity < 0)
                                    {
                                        totalInventoryAdjustInfo.AllocatedQty = -totalInventoryCurrentInfo.AllocatedQty;
                                    }
                                    else
                                    {
                                        totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    }
                                }
                                else
                                {
                                    stockInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                    totalInventoryAdjustInfo.AllocatedQty = adjustItem.AdjustQuantity;
                                }
                            }
                        }
                        else
                        {
                            //溢单出库
                            if (adjustRequestInfo.ConsignFlag == RequestConsignFlag.Consign || adjustRequestInfo.ConsignFlag == RequestConsignFlag.GatherPay)
                            {
                                //代销商品, 增加代销库存 (损/溢单都增加代销库存?)
                                stockInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.ConsignQty = adjustItem.AdjustQuantity;
                            }
                            else
                            {
                                //非代销商品, 增加财务库存/可用库存
                                stockInventoryAdjustInfo.AccountQty   = adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.AccountQty   = adjustItem.AdjustQuantity;
                                stockInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity;
                                totalInventoryAdjustInfo.AvailableQty = adjustItem.AdjustQuantity;
                            }
                        }

                        //预检调整后的商品库存是否合法
                        Entity.Inventory.ProductInventoryInfo stockInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(stockInventoryCurrentInfo, stockInventoryAdjustInfo);
                        Entity.Inventory.ProductInventoryInfo totalInventoryAdjustAfterAdjust = InventoryService.PreCalculateInventoryAfterAdjust(totalInventoryCurrentInfo, totalInventoryAdjustInfo);

                        bool isNeedCompareAvailableQtyAndAccountQty = true;
                        InventoryService.PreCheckGeneralRules(stockInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty);
                        InventoryService.PreCheckGeneralRules(totalInventoryAdjustAfterAdjust, ref isNeedCompareAvailableQtyAndAccountQty);

                        //调整商品库存:
                        InventoryDA.AdjustProductStockInventoryInfo(stockInventoryAdjustInfo);
                        InventoryDA.AdjustProductTotalInventoryInfo(totalInventoryAdjustInfo);
                    }
                    #endregion

                    #region 损益单为代销类型,出库时需要写入代销转财务日志
                    if (isConsign)
                    {
                        List <ConsignToAcctLogInfo> acctLogInfoList = new List <ConsignToAcctLogInfo>();
                        adjustRequestInfo.AdjustItemInfoList.ForEach(x =>
                        {
                            ConsignToAcctLogInfo acctLog = new ConsignToAcctLogInfo();
                            acctLog.ProductSysNo         = x.ProductSysNo;
                            acctLog.StockSysNo           = adjustRequestInfo.Stock.SysNo;
                            acctLog.VendorSysNo          = InventoryDA.GetProductBelongVendorSysNo(x.ProductSysNo.Value);
                            acctLog.ProductQuantity      = -x.AdjustQuantity;
                            acctLog.OutStockTime         = adjustRequestInfo.OutStockDate;
                            acctLog.CreateCost           = x.AdjustCost;
                            acctLog.OrderSysNo           = adjustRequestInfo.SysNo;
                            acctLog.CompanyCode          = adjustRequestInfo.CompanyCode;
                            acctLog.StoreCompanyCode     = adjustRequestInfo.CompanyCode;
                            acctLog.IsConsign            = (int)adjustRequestInfo.ConsignFlag;
                            acctLogInfoList.Add(acctLog);
                        });

                        if (acctLogInfoList.Count > 0)
                        {
                            foreach (var item in acctLogInfoList)
                            {
                                InventoryDA.CreatePOConsignToAccLogForInventory(item);
                            }
                        }
                    }
                    #endregion

                    #region
                    string InUser = "******";
                    List <InventoryBatchDetailsInfo> batchDetailsInfoEntitylist = InventoryDA.GetBatchDetailsInfoEntityListByNumber(adjustRequestInfo.SysNo.Value);
                    if (batchDetailsInfoEntitylist != null && batchDetailsInfoEntitylist.Count > 0)
                    {
                        #region 构建损益单 出库调整批次库存表的SSB消息 调整库存
                        List <ItemBatchInfo> itemBatchInfoList = new List <ItemBatchInfo>();
                        foreach (var item in batchDetailsInfoEntitylist)
                        {
                            ItemBatchInfo itemBatchInfo = new ItemBatchInfo();
                            itemBatchInfo.BatchNumber   = item.BatchNumber;
                            itemBatchInfo.ProductNumber = item.ProductSysNo.ToString();
                            Stock stock = new Stock();
                            AdjustRequestItemInfo aEntity = new AdjustRequestItemInfo();
                            aEntity = adjustRequestInfo.AdjustItemInfoList.Find(x => { return(x.ProductSysNo == item.ProductSysNo); });
                            if (aEntity != null && aEntity.AdjustQuantity > 0)
                            {
                                stock.Quantity     = item.Quantity.ToString(); //单据出库两个数量都要调整
                                stock.AllocatedQty = string.Empty;             //益单不调 占用库存 作废 取消作废 单据 只调整 占用库存
                            }
                            else
                            {
                                stock.Quantity     = item.Quantity.ToString(); //单据出库两个数量都要调整
                                stock.AllocatedQty = item.Quantity.ToString(); //损单 需要调整 占用库存 作废 取消作废 单据 只调整 占用库存
                            }
                            stock.WarehouseNumber = item.StockSysNo.ToString();
                            List <Stock> StockList = new List <Stock>();
                            StockList.Add(stock);

                            Stocks stocks = new Stocks();
                            stocks.Stock = StockList;

                            itemBatchInfo.Stocks = stocks;
                            itemBatchInfoList.Add(itemBatchInfo);
                        }
                        BatchXMLMessage batchXMLMessage = new BatchXMLMessage()
                        {
                            Header = new InventoryHeader
                            {
                                NameSpace          = "http://soa.ECommerce.com/InventoryProfile",
                                Action             = "OutStock",
                                Version            = "V10",
                                Type               = "Adjust",
                                CompanyCode        = "8601",
                                Tag                = "AdjustOutStock",
                                Language           = "zh-CN",
                                From               = "IPP",
                                GlobalBusinessType = "Listing",
                                StoreCompanyCode   = "8601",
                                TransactionCode    = adjustRequestInfo.SysNo.ToString()
                            },
                            Body = new InventoryBody
                            {
                                InUser        = InUser,
                                Number        = adjustRequestInfo.SysNo.ToString(),
                                ItemBatchInfo = itemBatchInfoList
                            }
                        };
                        string      paramXml = SerializationUtility.XmlSerialize(batchXMLMessage);
                        XmlDocument xmlD     = new XmlDocument();
                        xmlD.LoadXml(paramXml);
                        paramXml = "<" + xmlD.DocumentElement.Name + ">" + xmlD.DocumentElement.InnerXml + "</" + xmlD.DocumentElement.Name + ">";

                        InventoryDA.AdjustBatchNumberInventory(paramXml);//调整批次库存表 占用数量
                        #endregion
                    }
                    List <InventoryAdjustItemInfo> adjustCaseEntityList = new List <InventoryAdjustItemInfo>();
                    foreach (var item in inventoryAdjustContract.AdjustItemList)
                    {
                        if (!InventoryDA.CheckISBatchNumberProduct(item.ProductSysNo))
                        {
                            item.AdjustQuantity = item.AdjustQuantity;

                            adjustCaseEntityList.Add(item);
                        }
                    }
                    AdjustSendSSBToWMS(adjustRequestInfo.SysNo.Value, adjustRequestInfo.Stock.SysNo.ToString(), batchDetailsInfoEntitylist, adjustCaseEntityList);//损益单出库向仓库发送SSB消息

                    #endregion
                }

                scope.Complete();
            }

            return(adjustRequestInfo);
        }