示例#1
0
        /// <summary>
        /// 记入成本逻辑,不同业务需要取不同成本,由子类实现{包括还货单、损益单、转换单}
        /// 需要从AdjustItemList中过滤出AdjustQuantity大于0的记录进行处理
        /// 最终将costin集合赋给ProductCostInList属性
        /// </summary>
        public virtual void UnitCostToCostIn()
        {
            ProductCostIn costIn;

            ProductCostInList = new List <ProductCostIn>();

            foreach (InventoryAdjustItemInfo item in this.AdjustContractInfo.AdjustItemList)
            {
                //特殊库存模式不处理库存成本 by feegod 2013.10.05
                int inventory = _productInventoryDA.GetProductInventroyType(item.ProductSysNo);
                if (inventory == (int)ProductInventoryType.Company ||
                    inventory == (int)ProductInventoryType.GetShopInventory ||
                    inventory == (int)ProductInventoryType.TwoDoor)
                {
                    continue;
                }
                if (item.AdjustQuantity > 0 && item.ProductSysNo == this.CurrentAdjustItemInfo.ProductSysNo)   //库存溢出表示为入库
                {
                    costIn                 = new ProductCostIn();
                    costIn.BillType        = (int)this.AdjustContractInfo.CostType;
                    costIn.BillSysNo       = int.Parse(this.AdjustContractInfo.ReferenceSysNo);
                    costIn.Quantity        = item.AdjustQuantity;
                    costIn.LeftQuantity    = item.AdjustQuantity;
                    costIn.LockQuantity    = 0;
                    costIn.ProductSysNo    = item.ProductSysNo;
                    costIn.Cost            = item.AdjustUnitCost;
                    costIn.WarehouseNumber = item.StockSysNo;
                    ProductCostInList.Add(costIn);
                }
            }

            _productInventoryDA.WriteProductCost(ProductCostInList);
        }
        /// <summary>
        /// 成本变价单更新库存成本
        /// </summary>
        /// <param name="costChangeInfo"></param>
        /// <returns></returns>
        public virtual void UpdateCostInWhenCostChange(CostChangeInfo costChangeInfo)
        {
            //预校验
            if (!PreCheck(costChangeInfo))
            {
                throw new BizException("存在有效库存成本数量不够变价数量的商品,无法审核通过!");
            }

            TransactionOptions option = new TransactionOptions();

            //option.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            option.Timeout = TransactionManager.DefaultTimeout;
            using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, option))
            {
                string msg = SerializationUtility.XmlSerialize(costChangeInfo);
                productInventoryDA.WriteCostLog((int)ECCentral.BizEntity.Inventory.InventoryAdjustContractInfo.CostBillType.CostAdjust, costChangeInfo.SysNo.Value, msg);

                List <ProductCostIn>  ProductCostInList  = new List <ProductCostIn>();
                List <ProductCostOut> ProductCostOutList = new List <ProductCostOut>();
                ProductCostIn         costIn;
                ProductCostOut        costout;
                foreach (CostChangeItemsInfo item in costChangeInfo.CostChangeItems)
                {
                    costout = new ProductCostOut
                    {
                        Quantity     = item.ChangeCount,
                        Cost         = item.OldPrice,
                        BillSysNo    = item.POSysNo,
                        BillType     = (int)ECCentral.BizEntity.Inventory.InventoryAdjustContractInfo.CostBillType.PO,
                        ProductSysNo = item.ProductSysNo
                    };
                    ProductCostOutList.Add(costout);
                    if (item.ChangeCount > 0)   //库存溢出表示为入库
                    {
                        costIn              = new ProductCostIn();
                        costIn.BillType     = (int)ECCentral.BizEntity.Inventory.InventoryAdjustContractInfo.CostBillType.CostAdjust;
                        costIn.BillSysNo    = costChangeInfo.SysNo.Value;
                        costIn.Quantity     = item.ChangeCount;
                        costIn.LeftQuantity = item.ChangeCount;
                        costIn.LockQuantity = 0;
                        costIn.ProductSysNo = item.ProductSysNo;
                        costIn.Cost         = item.NewPrice;
                        ProductCostInList.Add(costIn);
                    }
                }

                //先出
                productInventoryDA.UpdateProductCostForCostChange(ProductCostOutList);
                //后进
                productInventoryDA.WriteProductCost(ProductCostInList);

                tran.Complete();
            }
        }