예제 #1
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="sellReturn"></param>
        /// <returns></returns>
        public ResultData <string> ApproveSellReturn(WSellReturn sellReturn)
        {
            ResultData <string> rData = new ResultData <string>();

            if (sellReturn.Lines.Count < 1)
            {
                sellReturn.Lines = srlRepository.GetLinesByParentId(sellReturn.ID);
            }

            DatabaseContext dbContext = srRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(sellReturn.Lines.Count);

                //添加其他入库
                int result = srRepository.ApproveSellReturn(sellReturn);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in sellReturn.Lines)
                {
                    stockIns.Add(CloneSellReturn(line, sellReturn));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.AddStocks(stockIns);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
예제 #2
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="purchase"></param>
        /// <returns></returns>
        public ResultData <string> ApprovePurchase(WPurchase purchase)
        {
            if (purchase.Lines.Count < 1)
            {
                purchase.Lines = plRepository.GetLinesByParentId(purchase.ID);
            }

            ResultData <string> rData = CheckValid(purchase);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = pRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(purchase.Lines.Count);

                //更新主表状态
                int result = pRepository.ApprovePurchase(purchase);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in purchase.Lines)
                {
                    stockIns.Add(ClonePurchase(line, purchase));
                    //添加完成数量
                    if (line.SourceLineID > 0)
                    {
                        pnlRepository.AddCompleteCount(line.SourceLineID, line.InCount);
                    }
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.AddStocks(stockIns);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }

                //更新通知单状态
                if (purchase.SourceID > 0)
                {
                    bool isAll = pnlRepository.IsAllComplete(purchase.SourceID);
                    if (isAll)
                    {
                        pnRepository.UpdateNoticeStatus(NoticeStatusEnum.Complete, purchase.SourceID);
                    }
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }