Beispiel #1
0
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.stockinDAL.Get(user, dataSource.RowId);
                    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.Audit(user, stockIn, isPass);
                    if (result.ResultStatus != 0)
                        return result;

                    //审核通过
                    if (isPass)
                    {
                        //写入St_StockName表
                        result = stockNameDAL.Insert(user, new Model.StockName() { RefNo = stockIn.RefNo });
                        if (result.ResultStatus != 0)
                            return result;

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

                        //写入St_Stock库存表
                        result = stockDAL.Insert(user, new Model.Stock()
                        {
                            StockNameId = stockNameId,
                            StockDate = stockIn.StockInDate,
                            AssetId = stockIn.AssetId,
                            Bundles = stockIn.Bundles,
                            GrossAmount = stockIn.GrossAmount,
                            NetAmount = stockIn.NetAmount,
                            ReceiptInGap = 0,
                            ReceiptOutGap = 0,
                            CurGrossAmount = stockIn.GrossAmount,
                            CurNetAmount = stockIn.NetAmount,
                            UintId = stockIn.UintId,
                            DeliverPlaceId = stockIn.DeliverPlaceId,
                            BrandId = stockIn.BrandId,
                            CustomsType = stockIn.CustomType,
                            GroupId = stockIn.GroupId,
                            CorpId = stockIn.CorpId,
                            DeptId = stockIn.DeptId,
                            ProducerId = stockIn.ProducerId,
                            PaperNo = stockIn.PaperNo,
                            PaperHolder = stockIn.PaperHolder,
                            PreStatus = StockStatusEnum.预入库存,
                            StockStatus = StockStatusEnum.预入库存,
                            CardNo = stockIn.CardNo,
                            Memo = string.Empty,
                            StockType = stockIn.StockType,
                            OriginPlaceId = stockIn.OriginPlaceId,
                            OriginPlace = stockIn.OriginPlace,
                            Format = stockIn.Format
                        });
                        if (result.ResultStatus != 0)
                            return result;

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

                        int contractId = 0, subId = 0;

                        //获取合约关联
                        result = contractStockInDAL.GetByStockInId(user, stockIn.StockInId);
                        if (result.ResultStatus == 0)
                        {
                            Model.ContractStockIn contractStockIn = result.ReturnValue as Model.ContractStockIn;
                            if (contractStockIn != null && contractStockIn.RefId > 0)
                            {
                                contractId = contractStockIn.ContractId;
                                subId = contractStockIn.ContractSubId;
                            }
                        }

                        //创建stockLog对象
                        NFMT.WareHouse.Model.StockLog stockLog = new StockLog()
                        {
                            StockId = stockId,
                            StockNameId = stockNameId,
                            RefNo = stockIn.RefNo,
                            LogDirection = (int)LogDirectionEnum.In,
                            LogType = (int)LogTypeEnum.入库,
                            ContractId = contractId,
                            SubContractId = subId,
                            LogDate = DateTime.Now,
                            OpPerson = user.EmpId,
                            Bundles = stockIn.Bundles,
                            GrossAmount = stockIn.GrossAmount,
                            NetAmount = stockIn.NetAmount,
                            MUId = stockIn.UintId,
                            BrandId = stockIn.BrandId,
                            DeliverPlaceId = stockIn.DeliverPlaceId,
                            PaperNo = stockIn.PaperNo,
                            PaperHolder = stockIn.PaperHolder,
                            CardNo = stockIn.CardNo,
                            Memo = string.Empty,
                            LogStatus = StatusEnum.已生效,
                            LogSourceBase = "NFMT",
                            LogSource = "dbo.St_StockIn",
                            SourceId = stockIn.StockInId,

                            AssetId = stockIn.AssetId,
                            CorpId = stockIn.CorpId,
                            CustomsType = stockIn.CustomType,
                            DeptId = stockIn.DeptId,
                            ProducerId = stockIn.ProducerId,
                            StockType = stockIn.StockType,
                            OriginPlaceId = stockIn.OriginPlaceId,
                            OriginPlace = stockIn.OriginPlace,
                            Format = stockIn.Format
                        };

                        DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                        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;
                        }

                        //写入库登记库存关联表
                        DAL.StockInStockDAL stockInStockDAL = new StockInStockDAL();
                        result = stockInStockDAL.Insert(user, new Model.StockInStock()
                        {
                            StockInId = stockIn.StockInId,
                            StockId = stockId,
                            StockLogId = stockLogId,
                            RefStatus = StatusEnum.已生效
                        });

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

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

            return result;
        }