Exemple #1
0
        //报关审核生效	   流水操作:写入 流水类型:报关 流水状态:已生效    库存操作:更新 库存状态:预报关库存
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.customsclearanceDAL.Get(user, dataSource.RowId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.CustomsClearance customsClearance = result.ReturnValue as Model.CustomsClearance;
                    if (customsClearance == null || customsClearance.CustomsId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "报关不存在";
                        return result;
                    }

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

                    //审核通过
                    if (isPass)
                    {
                        //加载已生效明细
                        DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                        result = customsDetailDAL.Load(user, customsClearance.CustomsId, StatusEnum.已生效);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.CustomsDetail> details = result.ReturnValue as List<Model.CustomsDetail>;
                        if (details == null || !details.Any())
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取失败";
                            return result;
                        }

                        DAL.StockDAL stockDAL = new StockDAL();
                        DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                        DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                        Model.Stock stock = null;
                        Model.StockName stockName = null;
                        Model.StockLog stockLog = null;

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

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

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

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

                            //创建库存流水
                            stockLog = new StockLog()
                            {
                                StockId = stock.StockId,
                                StockNameId = stock.StockNameId,
                                RefNo = stockName.RefNo,
                                LogDirection = (int)LogDirectionEnum.Out,
                                LogType = (int)LogTypeEnum.报关,
                                //ContractId =
                                //SubContractId =
                                LogDate = DateTime.Now,
                                OpPerson = user.EmpId,
                                Bundles = stock.Bundles,
                                GrossAmount = stock.GrossAmount,
                                NetAmount = stock.NetAmount,
                                MUId = stock.UintId,
                                BrandId = stock.BrandId,
                                DeliverPlaceId = stock.DeliverPlaceId,
                                PaperNo = stock.PaperNo,
                                PaperHolder = stock.PaperHolder,
                                CardNo = stock.CardNo,
                                Memo = stock.Memo,
                                LogStatus = StatusEnum.已生效,
                                LogSourceBase = "NFMT",
                                LogSource = "dbo.St_CustomsClearance",
                                SourceId = customsClearance.CustomsId
                            };

                            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;
                            }

                            //将库存流水Id反向更新到明细表中
                            detail.StockLogId = stockLogId;
                            result = customsDetailDAL.Update(user, detail);
                            if (result.ResultStatus != 0)
                                return result;

                            //更新库存状态
                            result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预报关库存);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

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

            return result;
        }
Exemple #2
0
        public ResultModel Complete(UserModel user, int stockInId)
        {
            //总体业务描述
            //1:验证入库登记
            //2:完成入库登记
            //3:完成入库登记与合约关联
            //4:完成库存流水与入库登记合约关联
            //5:更新库存流水状态为已完成
            //6:更新库存状态为在库正常

            ResultModel result = new ResultModel();

            try
            {
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = stockinDAL.Get(user, stockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockIn stockIn = result.ReturnValue as Model.StockIn;
                    if (stockIn == null || stockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "数据不存在,无法完成";
                        return result;
                    }

                    //入库登记完成
                    result = stockinDAL.Complete(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn == null || contractStockIn.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记未关联合约,不允许确认完成";
                        return result;
                    }

                    //完成合约关联
                    result = contractStockInDAL.Complete(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取入库登记库存关联
                    result = stockInStockDAL.GetByStockIn(NFMT.Common.DefaultValue.SysUser, stockIn.StockInId);

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

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取入库登记与库存关联失败";
                        return result;
                    }

                    //完成入库登记库存关联
                    result = stockInStockDAL.Complete(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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;
                    }

                    //判断库存流水是否关联合约
                    if (stockLog.ContractId <= 0)
                    {
                        stockLog.ContractId = contractStockIn.ContractId;
                        stockLog.SubContractId = contractStockIn.ContractSubId;

                        result = stockLogDAL.Update(user, stockLog);
                        if (result.ResultStatus != 0)
                            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;
                    }

                    //更新库存表
                    result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.在库正常);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
Exemple #3
0
        public ResultModel CompleteCancel(UserModel user, int stockInId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取入库登记
                    result = this.stockinDAL.Get(user, stockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockIn stockIn = result.ReturnValue as Model.StockIn;
                    if (stockIn == null || stockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记不存在";
                        return result;
                    }

                    //入库登记撤销完成
                    result = this.stockinDAL.CompleteCancel(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn == null || contractStockIn.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记未关联合约,不允许确认完成";
                        return result;
                    }

                    //完成撤销合约关联
                    result = contractStockInDAL.CompleteCancel(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取入库登记与库存流水关联
                    result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "关联获取失败";
                        return result;
                    }

                    //撤销关联
                    result = stockInStockDAL.CompleteCancel(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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;
                    }

                    //更新库存状态为预入库存
                    result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预入库存);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
Exemple #4
0
        public ResultModel Close(UserModel user, int stockInId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                DAL.StockExclusiveDAL stockExclusiveDAL = new StockExclusiveDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取入库登记
                    result = this.stockinDAL.Get(user, stockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockIn stockIn = result.ReturnValue as Model.StockIn;
                    if (stockIn == null || stockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记不存在";
                        return result;
                    }

                    //入库登记关闭
                    result = this.stockinDAL.Close(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联
                    result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                    if (contractStockIn != null && contractStockIn.RefId > 0)
                    {
                        //关闭合约关联
                        result = contractStockInDAL.Close(user, contractStockIn);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取入库登记与库存流水关联
                    result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockInStock stockInStock = result.ReturnValue as Model.StockInStock;
                    if (stockInStock == null || stockInStock.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "关联获取失败";
                        return result;
                    }

                    //关闭关联
                    result = stockInStockDAL.Close(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存流水
                    result = stockLogDAL.Get(user, stockInStock.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.ResultStatus = -1;
                        result.Message = "库存已由业务关联,不允许关闭";
                        return result;
                    }

                    //库存流水校验是否配货
                    result = stockExclusiveDAL.CheckStockIsInExclusive(user, stock.StockId);
                    if (result.ResultStatus != 0)
                        return result;

                    //更新库存状态为作废库存
                    result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.作废库存);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }

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

            return result;
        }
Exemple #5
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;
        }
Exemple #6
0
        //移库完成撤销	   流水操作:更新 流水状态:已生效		     库存操作:更新 库存状态:预移库存
        public ResultModel CompleteCancel(UserModel user, int stockMoveId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    result = this.stockmoveDAL.Get(user, stockMoveId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockMove stockmove = result.ReturnValue as StockMove;
                    if (stockmove == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = stockmoveDAL.CompleteCancel(user, stockmove);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.StockMoveDetailDAL stockMoveDetailDAL = new StockMoveDetailDAL();
                    result = stockMoveDetailDAL.Load(user, stockMoveId, StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockMoveDetail> details = result.ReturnValue as List<Model.StockMoveDetail>;
                    if (details == null || !details.Any())
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取失败";
                        return result;
                    }

                    DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.StockMoveDetail detail in details)
                    {
                        //明细完成
                        result = stockMoveDetailDAL.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, detail.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 = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预移库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Exemple #7
0
        public ResultModel ContractInCompleteStockOperate(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();
            StockInDAL stockInDAL = new StockInDAL();
            StockLogDAL stockLogDAL = new StockLogDAL();
            StockDAL stockDAL = new StockDAL();
            ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
            StockInStockDAL stockInStockDAL = new StockInStockDAL();

            result = contractStockInDAL.Load(user, contractId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.WareHouse.Model.ContractStockIn> contractStockIns = result.ReturnValue as List<NFMT.WareHouse.Model.ContractStockIn>;
            if (contractStockIns == null)
            {
                result.Message = "合约入库分配获取失败";
                result.ResultStatus = -1;
                return result;
            }

            foreach (NFMT.WareHouse.Model.ContractStockIn contractStcokIn in contractStockIns)
            {
                //获取入库登记
                result = stockInDAL.Get(user, contractStcokIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockIn stockIn = result.ReturnValue as NFMT.WareHouse.Model.StockIn;
                if (stockIn == null || stockIn.StockInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "数据不存在,无法完成";
                    return result;
                }

                //入库登记完成
                if (stockIn.StockInStatus == StatusEnum.已生效)
                {
                    result = stockInDAL.Complete(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取合约关联
                result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.ContractStockIn contractStockIn = result.ReturnValue as NFMT.WareHouse.Model.ContractStockIn;
                if (contractStockIn == null || contractStockIn.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "入库登记未关联合约,不允许确认完成";
                    return result;
                }

                //完成合约关联
                if (contractStockIn.RefStatus == StatusEnum.已生效)
                {
                    result = contractStockInDAL.Complete(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取入库登记库存关联
                result = stockInStockDAL.GetByStockIn(NFMT.Common.DefaultValue.SysUser, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockInStock stockInStock = result.ReturnValue as NFMT.WareHouse.Model.StockInStock;
                if (stockInStock == null || stockInStock.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取入库登记与库存关联失败";
                    return result;
                }

                //完成入库登记库存关联
                if (stockInStock.RefStatus == StatusEnum.已生效)
                {
                    result = stockInStockDAL.Complete(user, stockInStock);
                    if (result.ResultStatus != 0)
                        return result;
                }

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

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

                //判断库存流水是否关联合约
                if (stockLog.ContractId <= 0)
                {
                    stockLog.ContractId = contractStockIn.ContractId;
                    stockLog.SubContractId = contractStockIn.ContractSubId;

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

                if (stockLog.LogStatus == StatusEnum.已生效)
                {
                    result = stockLogDAL.Complete(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取库存
                result = stockDAL.Get(user, stockLog.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.StockStatus == NFMT.WareHouse.StockStatusEnum.预入库存)
                {
                    result = stockDAL.UpdateStockStatus(stock, NFMT.WareHouse.StockStatusEnum.在库正常);
                    if (result.ResultStatus != 0)
                        return result;
                }
            }

            return result;
        }
Exemple #8
0
        public ResultModel ContractInCompleteCancelStockOperate(UserModel user, int contractId)
        {
            ResultModel result = new ResultModel();
            StockDAL stockDAL = new StockDAL();
            StockLogDAL stockLogDAL = new StockLogDAL();
            StockInStockDAL stockInStockDAL = new StockInStockDAL();
            ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
            StockInDAL stockInDAL = new StockInDAL();

            result = contractStockInDAL.Load(user, contractId);
            if (result.ResultStatus != 0)
                return result;

            List<NFMT.WareHouse.Model.ContractStockIn> contractStockIns = result.ReturnValue as List<NFMT.WareHouse.Model.ContractStockIn>;
            if (contractStockIns == null)
            {
                result.Message = "合约入库分配获取失败";
                result.ResultStatus = -1;
                return result;
            }

            foreach (NFMT.WareHouse.Model.ContractStockIn contractStcokIn in contractStockIns)
            {
                //获取入库登记
                result = stockInDAL.Get(user, contractStcokIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockIn stockIn = result.ReturnValue as NFMT.WareHouse.Model.StockIn;
                if (stockIn == null || stockIn.StockInId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "入库登记不存在";
                    return result;
                }

                //入库登记撤销完成
                result = stockInDAL.CompleteCancel(user, stockIn);
                if (result.ResultStatus != 0)
                    return result;

                //获取合约关联
                result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.ContractStockIn contractStockIn = result.ReturnValue as NFMT.WareHouse.Model.ContractStockIn;
                if (contractStockIn == null || contractStockIn.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "入库登记未关联合约,不允许确认完成";
                    return result;
                }

                //完成撤销合约关联
                result = contractStockInDAL.CompleteCancel(user, contractStockIn);
                if (result.ResultStatus != 0)
                    return result;

                //获取入库登记与库存流水关联
                result = stockInStockDAL.GetByStockIn(user, stockIn.StockInId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockInStock stockInStock = result.ReturnValue as NFMT.WareHouse.Model.StockInStock;
                if (stockInStock == null || stockInStock.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "关联获取失败";
                    return result;
                }

                //撤销关联
                result = stockInStockDAL.CompleteCancel(user, stockInStock);
                if (result.ResultStatus != 0)
                    return result;

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

                NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.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;

                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 = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预入库存);
                if (result.ResultStatus != 0)
                    return result;
            }

            return result;
        }