Пример #1
0
        public ResultModel CreateStockOut(NFMT.Common.UserModel user, int stockOutApplyId, List<int> detailIds, string memo)
        {
            ResultModel result = new ResultModel();

            try
            {
                //dal init
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL();
                DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new StockOutApplyDetailDAL();
                DAL.StockOutDAL stockOutDAL = new StockOutDAL();
                DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //获取出库申请
                    result = stockOutApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply;
                    if (stockOutApply == null || stockOutApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //获取出库申请明细
                    result = stockOutApplyDetailDAL.Load(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutApplyDetail> stockOutApplyDetails = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    if (stockOutApplyDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请明细获取失败";
                        return result;
                    }

                    //判断detailIds 是否都在出库申请明细中
                    List<int> applyDetails = new List<int>();
                    foreach (Model.StockOutApplyDetail detail in stockOutApplyDetails)
                    {
                        applyDetails.Add(detail.DetailId);
                    }

                    foreach (int id in detailIds)
                    {
                        if (!applyDetails.Contains(id))
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }
                    }

                    decimal sumGrossAmount = 0;
                    decimal sumNetAmount = 0;
                    int sumBundles = 0;

                    //验证库存及申请明细
                    foreach (int id in detailIds)
                    {
                        Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id);

                        if (applyDetail == null || applyDetail.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }
                        if (applyDetail.DetailStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "选中库存存在已作废状态库存";
                            return result;
                        }

                        //获取库存
                        result = stockDAL.Get(user, applyDetail.StockId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存不存在";
                            return result;
                        }

                        //库存状态校验
                        if (stock.StockStatus != StockStatusEnum.在库正常 && stock.StockStatus != StockStatusEnum.新拆库存 && stock.StockStatus != StockStatusEnum.质押库存)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存不允许出库,出库失败";
                            return result;
                        }

                        sumGrossAmount += applyDetail.GrossAmount;
                        sumNetAmount += applyDetail.NetAmount;
                        sumBundles += applyDetail.Bundles;
                    }

                    //新增出库表
                    Model.StockOut stockOut = new StockOut();
                    stockOut.Executor = user.EmpId;
                    stockOut.Memo = memo;
                    stockOut.StockOutApplyId = stockOutApply.StockOutApplyId;
                    stockOut.StockOutStatus = StatusEnum.已录入;
                    stockOut.StockOutTime = DateTime.Now;
                    stockOut.Unit = stockOutApply.UnitId;
                    stockOut.GrosstAmount = sumGrossAmount;
                    stockOut.NetAmount = sumNetAmount;
                    stockOut.Bundles = sumBundles;

                    result = stockoutDAL.Insert(user, stockOut);
                    if (result.ResultStatus != 0)
                        return result;

                    int stockOutId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockOutId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库新增失败";
                        return result;
                    }

                    stockOut.StockOutId = stockOutId;

                    //新增出库明细表
                    foreach (int id in detailIds)
                    {
                        Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id);

                        Model.StockOutDetail stockOutDetail = new StockOutDetail();
                        stockOutDetail.DetailStatus = StatusEnum.已生效;
                        stockOutDetail.GrossAmount = applyDetail.GrossAmount;
                        stockOutDetail.NetAmount = applyDetail.NetAmount;
                        stockOutDetail.Bundles = applyDetail.Bundles;
                        stockOutDetail.StockId = applyDetail.StockId;
                        stockOutDetail.StockOutApplyDetailId = applyDetail.DetailId;
                        stockOutDetail.StockOutId = stockOutId;

                        result = stockOutDetailDAL.Insert(user, stockOutDetail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    if (result.ResultStatus == 0)
                        result.ReturnValue = stockOut;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Пример #2
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockOutDetailDAL detailDAL = new StockOutDetailDAL();
                DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockoutDAL.Get(NFMT.Common.DefaultValue.SysUser, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOut stockOut = result.ReturnValue as Model.StockOut;
                    if (stockOut == null || stockOut.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库不存在";
                        return result;
                    }

                    //审核,修改数据状态
                    result = this.stockoutDAL.Audit(user, stockOut, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //流水操作:写入 流水类型:出库 流水状态:已生效    库存操作:更新 库存状态:预售库存

                        //获取出库申请
                        result = stockOutApplyDAL.Get(user,stockOut.StockOutApplyId);
                        if(result.ResultStatus!=0)
                            return result;

                        Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply;
                        if(stockOutApply == null || stockOutApply.StockOutApplyId<=0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请获取失败";
                            return result;
                        }

                        //获取出库明细
                        result = detailDAL.Load(user, stockOut.StockOutId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.StockOutDetail> outDetails = result.ReturnValue as List<Model.StockOutDetail>;
                        if (outDetails == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库明细获取失败";
                            return result;
                        }

                        foreach (Model.StockOutDetail outDetail in outDetails)
                        {
                            //获取库存
                            result = stockDAL.Get(user, outDetail.StockId);
                            if (result.ResultStatus != 0)
                                return result;

                            Model.Stock stock = result.ReturnValue as Model.Stock;
                            if (stock == null || stock.StockId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "出库库存不存在";
                                return result;
                            }

                            //获取业务单
                            result = stockNameDAL.Get(user,stock.StockNameId);
                            if(result.ResultStatus!=0)
                                return result;

                            Model.StockName stockName = result.ReturnValue as Model.StockName;
                            if(stockName == null || stockName.StockNameId <=0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "业务单号获取失败";
                                return result;
                            }

                            //出库净重==当前净重时 库存状态更新至 预售库存
                            if (outDetail.NetAmount == stock.CurNetAmount)
                            {
                                result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预售库存);
                                if (result.ResultStatus != 0)
                                    return result;
                            }

                            //写出库流水,流水状态为已生效
                            Model.StockLog stockLog = new StockLog()
                            {
                                AssetId = stock.AssetId,
                                BrandId = stock.BrandId,
                                CardNo = stock.CardNo,
                                DeliverPlaceId = stock.DeliverPlaceId,
                                GrossAmount = outDetail.GrossAmount,
                                LogDate = DateTime.Now,
                                LogDirection = (int)LogDirectionEnum.Out,
                                LogSource = "dbo.St_StockOutDetail",
                                LogSourceBase = "NFMT",
                                LogStatus = StatusEnum.已生效,
                                LogType = (int)LogTypeEnum.出库,
                                NetAmount = outDetail.NetAmount,
                                MUId = stock.UintId,
                                OpPerson = user.EmpId,
                                PaperHolder = stock.PaperHolder,
                                PaperNo = stock.PaperNo,
                                RefNo = stockName.RefNo,
                                SourceId = outDetail.DetailId,
                                StockId = stock.StockId,
                                StockNameId = stock.StockNameId,
                                SubContractId = stockOutApply.SubContractId,
                                ContractId = stockOutApply.ContractId,
                                Memo = stockOut.Memo,
                                Bundles = outDetail.Bundles
                            };

                            result = stockLogDAL.Insert(user, stockLog);
                            if (result.ResultStatus != 0)
                                return result;

                            int stockLogId = 0;
                            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockLogId) || stockLogId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "出库流水写入失败";
                                return result;
                            }

                            //更新出库明细的出库流水
                            outDetail.StockLogId = stockLogId;
                            result = detailDAL.Update(user, outDetail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Пример #3
0
        public ResultModel Complete(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockDAL stockDAL = new StockDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                StockNameDAL stockNameDAL = new StockNameDAL();
                StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                StockOutApplyDAL applyDAL = new StockOutApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;
                    StockOut resultObj = result.ReturnValue as StockOut;
                    if (resultObj == null || resultObj.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //执行完成
                    result = stockoutDAL.Complete(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //加载明细
                    result = stockOutDetailDAL.Load(user, resultObj.StockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库明细失败";
                        return result;
                    }

                    //加载对应出库申请
                    result = applyDAL.Get(user, resultObj.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOutApply apply = result.ReturnValue as StockOutApply;
                    if (apply == null || apply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应出库申请加载失败";
                        return result;
                    }

                    //明细执行完成
                    foreach(Model.StockOutDetail detail in details)
                    {
                        //出库明细完成
                        result = stockOutDetailDAL.Complete(user,detail);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取出库流水
                        result = stockLogDAL.Get(user, detail.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库流水获取失败";
                            return result;
                        }

                        //完成出库流水
                        result = stockLogDAL.Complete(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        result = stockDAL.Get(user, stockLog.StockId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存获取失败";
                            return result;
                        }

                        //库存重量捆数减少
                        stock.CurGrossAmount -= detail.GrossAmount;
                        stock.CurNetAmount -= detail.NetAmount;
                        stock.Bundles -= detail.Bundles;

                        //库存状态修改
                        if (stock.StockStatus == StockStatusEnum.预售库存)
                            stock.StockStatus = StockStatusEnum.已售库存;

                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;

                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #4
0
        public ResultModel CompleteCancel(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                DAL.StockOutDAL stockOutDAL = new StockOutDAL();
                DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;
                    StockOut stockOut = result.ReturnValue as StockOut;
                    if (stockOut == null || stockOut.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //撤销出库
                    result = this.stockoutDAL.CompleteCancel(user, stockOut);
                    if (result.ResultStatus != 0)
                        return result;

                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOut.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //判断主申请状态是否为已生效,
                    if (apply.ApplyStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请状态只有在已生效下才能进行执行完成撤销";
                        return result;
                    }

                    //获取已完成出库明细
                    result = stockOutDetailDAL.Load(user, stockOut.StockOutId, Common.StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库明细错误";
                        return result;
                    }

                    //将所有已完成出库明细更新至已生效
                    foreach (Model.StockOutDetail detail in details)
                    {
                        result = stockOutDetailDAL.CompleteCancel(user, detail);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取出库流水
                        result = stockLogDAL.Get(user, detail.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取出库流水失败";
                            return result;
                        }

                        //更新出库流水状态为已生效
                        result = stockLogDAL.CompleteCancel(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        result = stockDAL.Get(user,stockLog.StockId);
                        if(result.ResultStatus!=0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取库存错误";
                            return result;
                        }

                        //库存重量添加
                        stock.CurGrossAmount += detail.GrossAmount;
                        stock.CurNetAmount += detail.NetAmount;
                        stock.Bundles += detail.Bundles;

                        //明细关联库存状态更新至前一状态
                        if (stock.StockStatus == StockStatusEnum.已售库存)
                            stock.StockStatus = StockStatusEnum.预售库存;

                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;

                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #5
0
        public ResultModel Confirm(UserModel user, int stockOutApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockExclusiveDAL exclusiveDAL = new StockExclusiveDAL();
                DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
                DAL.StockOutApplyDetailDAL detailDAL = new StockOutApplyDetailDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //验证是否执行完成
                    result = stockoutapplyDAL.CheckStockOutCanConfirm(user, outApply.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Common.StatusEnum status = (Common.StatusEnum)result.ReturnValue;

                    //获取已生效出库申请明细
                    result = detailDAL.Load(user, outApply.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockOutApplyDetail> details = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库申请明细失败";
                        return result;
                    }

                    //获取已生效排他明细
                    result = exclusiveDAL.Load(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockExclusive> exclusives = result.ReturnValue as List<Model.StockExclusive>;
                    if (exclusives == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取排他明细失败";
                        return result;
                    }

                    //主申请更新状态至已完成
                    if (status == StatusEnum.已完成)
                        result = applyDAL.Confirm(user, apply);
                    else if (status == StatusEnum.部分完成)
                        result = applyDAL.PartiallyConfirm(user, apply);
                    else
                    {
                        result.ResultStatus = -1;
                        result.Message = "更新主申请状态失败";
                        return result;
                    }
                    if (result.ResultStatus != 0)
                        return result;

                    //出库申请明细更新状态至已完成
                    foreach (Model.StockOutApplyDetail detail in details)
                    {
                        //出库申请明细更新状态至已完成
                        result = detailDAL.Confirm(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //排他明细更新状态至已完成
                    foreach (Model.StockExclusive exc in exclusives)
                    {
                        result = exclusiveDAL.Confirm(user, exc);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #6
0
        public ResultModel Close(UserModel user, int stockOutId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL();
                StockOutApplyDAL applyDAL = new StockOutApplyDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                StockDAL stockDAL = new StockDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库
                    result = stockoutDAL.Get(user, stockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOut resultObj = result.ReturnValue as StockOut;
                    if (resultObj == null || resultObj.StockOutId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能进行执行完成操作";
                        return result;
                    }

                    //关闭出库
                    result = stockoutDAL.Close(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //加载对应出库申请
                    result = applyDAL.Get(user, resultObj.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOutApply apply = result.ReturnValue as StockOutApply;
                    if (apply == null || apply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应出库申请加载失败";
                        return result;
                    }

                    //加载明细
                    result = stockOutDetailDAL.Load(user, resultObj.StockOutId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockOutDetail> details = result.ReturnValue as List<StockOutDetail>;
                    if(details ==null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取明细失败";
                        return result;
                    }

                    foreach (StockOutDetail detail in details)
                    {
                        //关闭明细
                        result = stockOutDetailDAL.Close(user,detail);
                        if(result.ResultStatus !=0)
                            return result;

                        //获取出库流水
                        result = stockLogDAL.Get(user, detail.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.StockLog stockLog = result.ReturnValue as Model.StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取出库流水失败";
                            return result;
                        }

                        //关闭出库流水
                        result = stockLogDAL.Close(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取库存
                        result = stockDAL.Get(user, stockLog.StockId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取库存失败";
                            return result;
                        }

                        if (stock.StockStatus == StockStatusEnum.预售库存)
                        {
                            result = stockDAL.UpdateStockStatusToPrevious(user, stock);
                            if (result.ResultStatus != 0)
                                return result;
                        }

                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Пример #7
0
        public ResultModel ContractOutCreateStockOperate(UserModel user, NFMT.Contract.Model.Contract contract, int subId, int outCorpId, List<NFMT.WareHouse.Model.StockOutApplyDetail> details)
        {
            ResultModel result = new ResultModel();

            NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL();
            NFMT.WareHouse.DAL.StockOutApplyDAL outApplyDAL = new NFMT.WareHouse.DAL.StockOutApplyDAL();
            NFMT.WareHouse.DAL.StockOutApplyDetailDAL detailDAL = new NFMT.WareHouse.DAL.StockOutApplyDetailDAL();
            NFMT.WareHouse.DAL.StockExclusiveDAL exclusiveDAL = new NFMT.WareHouse.DAL.StockExclusiveDAL();
            NFMT.WareHouse.DAL.StockDAL stockDAL = new NFMT.WareHouse.DAL.StockDAL();

            try
            {
                //验证分配库存
                if (details == null || details.Count == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "未分配任务库存";
                    return result;
                }

                //添加主申请表
                NFMT.Operate.Model.Apply apply = new NFMT.Operate.Model.Apply();
                apply.ApplyDept = user.DeptId;
                apply.ApplyCorp = user.CorpId;
                apply.ApplyTime = DateTime.Now;
                apply.ApplyDesc = string.Empty;
                apply.ApplyType = NFMT.Operate.ApplyType.出库申请;
                apply.EmpId = user.EmpId;
                apply.ApplyStatus = NFMT.Common.StatusEnum.绑定合约;

                result = applyDAL.Insert(user, apply);
                if (result.ResultStatus != 0)
                    return result;

                int applyId = 0;
                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out applyId) || applyId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "申请主表添加失败";
                    return result;
                }

                decimal sumNetAmount = details.Sum(temp => temp.NetAmount);
                int sumBundles = details.Sum(temp => temp.Bundles);

                //添加出库申请主表
                NFMT.WareHouse.Model.StockOutApply outApply = new NFMT.WareHouse.Model.StockOutApply();
                outApply.ApplyId = applyId;
                outApply.ContractId = contract.ContractId;
                outApply.SubContractId = subId;
                outApply.NetAmount = sumNetAmount;
                outApply.Bundles = sumBundles;
                outApply.UnitId = contract.UnitId;
                outApply.BuyCorpId = outCorpId;

                foreach (NFMT.WareHouse.Model.StockOutApplyDetail applyDetail in details)
                {
                    //验证库存
                    result = stockDAL.Get(user, applyDetail.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                    if (stock == null || stock.StockId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存不存在";
                        return result;
                    }

                    //判断库存品种是否与合约品种相同
                    if (stock.AssetId != contract.AssetId)
                    {
                        result.ResultStatus = -1;
                        result.Message = "分配库存的品种与合约品种不一致";
                        return result;
                    }

                    //验证关境
                    if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.外贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关外)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存关境与合约不一致";
                        return result;
                    }
                    else if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.内贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关内)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存关境与合约不一致";
                        return result;
                    }

                    //不允许配货库存
                    int planStockInStatus = (int)NFMT.WareHouse.StockStatusEnum.预入库存;
                    int planCustomsStatus = (int)NFMT.WareHouse.StockStatusEnum.预报关库存;
                    int stockStatus = (int)stock.StockStatus;
                    if (stockStatus > planCustomsStatus || stockStatus < planStockInStatus)
                    {
                        result.ResultStatus = -1;
                        result.Message = "访笔库存不能进行出库申请分配";
                        return result;
                    }

                    applyDetail.ContractId = contract.ContractId;
                    applyDetail.DetailStatus = StatusEnum.已生效;
                    applyDetail.SubContractId = subId;

                    if (contract.ContractId == (int)NFMT.Contract.TradeBorderEnum.ForeignTrade)
                        applyDetail.GrossAmount = stock.GrossAmount;
                    else
                        applyDetail.GrossAmount = applyDetail.NetAmount;
                }

                decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount);
                outApply.GrossAmount = sumGrossAmount;
                outApply.CreateFrom = (int)NFMT.Common.CreateFromEnum.销售合约库存创建;
                result = outApplyDAL.Insert(user, outApply);

                if (result.ResultStatus != 0)
                    return result;

                int outApplyId = 0;
                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out outApplyId) || outApplyId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "出库申请添加失败";
                    return result;
                }

                foreach (NFMT.WareHouse.Model.StockOutApplyDetail applyDetail in details)
                {
                    NFMT.WareHouse.Model.StockOutApplyDetail appDetail = new NFMT.WareHouse.Model.StockOutApplyDetail();
                    appDetail.StockOutApplyId = outApplyId;
                    appDetail.Bundles = applyDetail.Bundles;
                    appDetail.ContractId = applyDetail.ContractId;
                    appDetail.DetailStatus = StatusEnum.已生效;
                    appDetail.GrossAmount = applyDetail.GrossAmount;
                    appDetail.NetAmount = applyDetail.NetAmount;
                    appDetail.StockId = applyDetail.StockId;
                    appDetail.SubContractId = applyDetail.SubContractId;

                    result = detailDAL.Insert(user, appDetail);
                    if (result.ResultStatus != 0)
                        return result;

                    int detailApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailApplyId) || detailApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存明细添加失败";
                        return result;
                    }

                    //验证库存
                    result = stockDAL.Get(user, applyDetail.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                    if (stock == null || stock.StockId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存不存在";
                        return result;
                    }

                    //排他表校验
                    result = exclusiveDAL.LoadByStockId(user, stock.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<NFMT.WareHouse.Model.StockExclusive> excs = result.ReturnValue as List<NFMT.WareHouse.Model.StockExclusive>;
                    if (excs == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取排他库存信息失败";
                        return result;
                    }

                    decimal excAmount = excs.Sum(temp => temp.ExclusiveAmount);
                    if (excAmount + applyDetail.NetAmount > stock.CurNetAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该笔库存剩余净重不足,配货失败";
                        return result;
                    }

                    //排他表新增
                    NFMT.WareHouse.Model.StockExclusive exculsive = new NFMT.WareHouse.Model.StockExclusive();
                    exculsive.ApplyId = applyId;
                    exculsive.DetailApplyId = detailApplyId;
                    exculsive.ExclusiveStatus = StatusEnum.已生效;
                    exculsive.StockApplyId = outApplyId;
                    exculsive.StockId = stock.StockId;
                    exculsive.ExclusiveAmount = applyDetail.NetAmount;

                    result = exclusiveDAL.Insert(user, exculsive);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #8
0
        public ResultModel ContractOutInvalidStockOperate(UserModel user, int subId)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.WareHouse.DAL.StockOutApplyDAL stockOutApplyDAL = new NFMT.WareHouse.DAL.StockOutApplyDAL();
                NFMT.WareHouse.DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new NFMT.WareHouse.DAL.StockOutApplyDetailDAL();
                NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL();
                NFMT.WareHouse.DAL.StockExclusiveDAL stockExclusiveDAL = new NFMT.WareHouse.DAL.StockExclusiveDAL();

                //获取子合约出库申请
                result = stockOutApplyDAL.LoadBySubId(user, subId);
                if (result.ResultStatus != 0)
                    return result;

                List<NFMT.WareHouse.Model.StockOutApply> outApplies = result.ReturnValue as List<NFMT.WareHouse.Model.StockOutApply>;
                if (outApplies == null || outApplies.Count == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取出库申请失败";
                    return result;
                }

                foreach (NFMT.WareHouse.Model.StockOutApply outApply in outApplies)
                {
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取主申请失败";
                        return result;
                    }

                    //申请作废
                    result = applyDAL.Invalid(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取出库申请明细
                    result = stockOutApplyDetailDAL.Load(user, outApply.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<NFMT.WareHouse.Model.StockOutApplyDetail> details = result.ReturnValue as List<NFMT.WareHouse.Model.StockOutApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取出库申请明细失败";
                        return result;
                    }

                    foreach (NFMT.WareHouse.Model.StockOutApplyDetail detail in details)
                    {
                        detail.DetailStatus = StatusEnum.已录入;
                        result = stockOutApplyDetailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;

                        //获取排他明细
                        result = stockExclusiveDAL.Get(user, apply.ApplyId, outApply.StockOutApplyId, detail.DetailId);
                        if (result.ResultStatus != 0)
                            return result;

                        NFMT.WareHouse.Model.StockExclusive stockExclusive = result.ReturnValue as NFMT.WareHouse.Model.StockExclusive;
                        if (stockExclusive == null || stockExclusive.ExclusiveId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取排他明细失败";
                            return result;
                        }

                        //作废排他明细
                        stockExclusive.ExclusiveStatus = StatusEnum.已录入;
                        result = stockExclusiveDAL.Invalid(user, stockExclusive);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #9
0
        public ResultModel ContractOutAuditStockOperate(UserModel user, int subId, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.WareHouse.DAL.StockOutApplyDAL stockOutApplyDAL = new NFMT.WareHouse.DAL.StockOutApplyDAL();
                NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL();

                //获取子合约出库申请
                result = stockOutApplyDAL.LoadBySubId(user, subId);
                if (result.ResultStatus != 0)
                    return result;

                List<NFMT.WareHouse.Model.StockOutApply> outApplies = result.ReturnValue as List<NFMT.WareHouse.Model.StockOutApply>;
                if (outApplies == null || outApplies.Count == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取出库申请失败";
                    return result;
                }

                foreach (NFMT.WareHouse.Model.StockOutApply outApply in outApplies)
                {
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取主申请失败";
                        return result;
                    }

                    //审核出库申请
                    result = applyDAL.Audit(user, apply, isPass);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #10
0
        public ResultModel ConfirmCancel(UserModel user, int stockOutApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
                DAL.StockOutApplyDetailDAL detailDAL = new StockOutApplyDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //主申请状态更新至已生效
                    result = applyDAL.ConfirmCancel(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //出库申请明细,在已关闭状态下的更新至已生效
                    //获取已关闭的明细
                    result = detailDAL.Load(user, outApply.StockOutApplyId, Common.StatusEnum.已关闭);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutApplyDetail> details = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取申请明细失败";
                        return result;
                    }

                    foreach (Model.StockOutApplyDetail detail in details)
                    {
                        result = detailDAL.ConfirmCancel(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #11
0
        public ResultModel StockOutApplyDetailClose(UserModel user, int stockOutApplyId, List<int> detailIds, string memo)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //加载对应出库申请
                    StockOutApplyDAL applyDAL = new StockOutApplyDAL();
                    result = applyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    StockOutApply stockOutApply = result.ReturnValue as StockOutApply;
                    if (stockOutApply == null || stockOutApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应出库申请加载失败";
                        return result;
                    }

                    //获取出库申请明细
                    DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new StockOutApplyDetailDAL();
                    result = stockOutApplyDetailDAL.Load(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.StockOutApplyDetail> stockOutApplyDetails = result.ReturnValue as List<Model.StockOutApplyDetail>;
                    if (stockOutApplyDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请明细获取失败";
                        return result;
                    }

                    //判断detailIds 是否都在出库申请明细中
                    List<int> applyDetails = new List<int>();
                    foreach (Model.StockOutApplyDetail detail in stockOutApplyDetails)
                    {
                        applyDetails.Add(detail.DetailId);
                    }

                    foreach (int id in detailIds)
                    {
                        if (!applyDetails.Contains(id))
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }
                    }

                    //关闭申请明细
                    StockExclusiveDAL excDAL = new StockExclusiveDAL();
                    foreach (int id in detailIds)
                    {
                        Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id);
                        if (applyDetail == null || applyDetail.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "出库申请不包含选中库存";
                            return result;
                        }

                        if (applyDetail.DetailStatus != StatusEnum.已生效)
                        {
                            result.ResultStatus = -1;
                            result.Message = "选中库存状态不匹配,不能进行关闭";
                            return result;
                        }

                        result = stockOutApplyDetailDAL.Close(user, applyDetail);
                        if (result.ResultStatus != 0)
                            return result;

                        //加载对应排他明细
                        result = excDAL.Get(user, stockOutApply.ApplyId, stockOutApply.StockOutApplyId, applyDetail.DetailId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.StockExclusive excl = result.ReturnValue as Model.StockExclusive;
                        if (excl == null || excl.ExclusiveId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取排他明细失败";
                            return result;
                        }

                        //关闭排他明细
                        result = excDAL.Close(user, excl);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #12
0
        public ResultModel Invalid(UserModel user, int stockOutApplyId)
        {
            ResultModel result = new ResultModel();

            DAL.StockDAL stockDAL = new StockDAL();
            DAL.StockExclusiveDAL exclusiveDAL = new StockExclusiveDAL();
            DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
            Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.StockOutApplyDetailDAL detailDAL = new StockOutApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //获取主申请实体
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //获取申请明细
                    result = detailDAL.Load(user, outApply.StockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockOutApplyDetail> details = result.ReturnValue as List<StockOutApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请明细获取失败";
                        return result;
                    }

                    //获取排他表数据
                    result = exclusiveDAL.Load(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockExclusive> exclusives = result.ReturnValue as List<StockExclusive>;
                    if (exclusives == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "排他明细获取失败";
                        return result;
                    }

                    //作废主申请
                    result = applyDAL.Invalid(user, apply);
                    if (result.ResultStatus != 0)
                        return result;
                    //作废申请明细
                    foreach (Model.StockOutApplyDetail detail in details)
                    {
                        detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                    //作废排他表
                    foreach (Model.StockExclusive exclusive in exclusives)
                    {
                        exclusive.ExclusiveStatus = StatusEnum.已录入;
                        result = exclusiveDAL.Invalid(user, exclusive);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Пример #13
0
        /// <summary>
        /// 撤返出库申请
        /// 待审核状态下出库申请允许撤返 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="stockOutApplyId"></param>
        /// <returns></returns>
        public ResultModel Goback(UserModel user, int stockOutApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库申请
                    result = outApplyDAL.Get(user, stockOutApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply;
                    if (outApply == null || outApply.StockOutApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "出库申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, outApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //主申请状态修改至已撤返
                    result = applyDAL.Goback(user, apply);

                    if (result.ResultStatus != 0)
                        return result;

                    //工作流任务关闭
                    WorkFlow.DAL.DataSourceDAL sourceDAL = new WorkFlow.DAL.DataSourceDAL();
                    result = sourceDAL.SynchronousStatus(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }