Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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;
        }