Пример #1
0
        public ResultModel PayApplyStockUpdate(UserModel user, PayApply payApply, List<StockPayApply> stockPayApplies, string memo, int deptId, int corpId)
        {
            ResultModel result = new ResultModel();
            try
            {
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证可申请金额
                    //NFMT.Data.Model.FuturesPrice futuresPrice = NFMT.Data.BasicDataProvider.FuturesPrices[0];

                    //获取付款申请
                    result = payapplyDAL.Get(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    PayApply resultObj = result.ReturnValue as PayApply;
                    if (resultObj == null || resultObj.PayApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请不存在";
                        return result;
                    }

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

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

                    //获取库存明细列表
                    result = stockPayApplyDAL.Load(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //更新申请主表
                    Department dept = UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == deptId);
                    if (dept == null || dept.DeptId < 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    apply.ApplyDept = dept.DeptId;
                    apply.ApplyCorp = corpId;
                    apply.ApplyDesc = memo;
                    apply.ApplyType = ApplyType.付款申请;
                    apply.EmpId = user.EmpId;

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

                    //更新付款申请表
                    resultObj.RecCorpId = payApply.RecCorpId;
                    resultObj.RecBankId = payApply.RecBankId;
                    resultObj.RecBankAccountId = payApply.RecBankAccountId;
                    resultObj.RecBankAccount = payApply.RecBankAccount;
                    resultObj.ApplyBala = payApply.ApplyBala;
                    resultObj.CurrencyId = payApply.CurrencyId;
                    resultObj.PayMode = payApply.PayMode;
                    resultObj.PayDeadline = payApply.PayDeadline;
                    resultObj.PayMatter = payApply.PayMatter;
                    resultObj.SpecialDesc = payApply.SpecialDesc;

                    result = payapplyDAL.Update(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废现有已生效库存分配明细
                    foreach (StockPayApply stockPayApply in readyStockPayApplies)
                    {
                        stockPayApply.RefStatus = StatusEnum.已录入;
                        result = stockPayApplyDAL.Invalid(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取合约付款申请
                    result = contractPayApplyDAL.GetByPayApplyId(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply;
                    if (contractPayApply == null || contractPayApply.RefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取对应合约付款失败";
                        return result;
                    }

                    //验证库存流水是否在同一子合约中
                    int subId = 0;
                    int contractId = 0;
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        result = stockLogDAL.Get(user, stockPayApply.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        StockLog stockLog = result.ReturnValue as StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存流水不存在";
                            return result;
                        }

                        if (subId == 0)
                        {
                            subId = stockLog.SubContractId;
                            contractId = stockLog.ContractId;
                        }

                        if (stockLog.SubContractId != subId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "不能同时申请不同子合约中的库存付款";
                            return result;
                        }
                    }

                    //更新合约付款
                    contractPayApply.ApplyBala = stockPayApplies.Sum(temp => temp.ApplyBala);
                    contractPayApply.ContractId = contractId;
                    contractPayApply.ContractSubId = subId;

                    result = contractPayApplyDAL.Update(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //新增dbo.Fun_StockPayApply_Ref库存付款申请
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        stockPayApply.ContractId = contractPayApply.ContractId;
                        stockPayApply.ContractRefId = contractPayApply.RefId;
                        stockPayApply.SubId = contractPayApply.ContractSubId;
                        stockPayApply.PayApplyId = contractPayApply.PayApplyId;
                        stockPayApply.RefStatus = StatusEnum.已生效;
                        result = stockPayApplyDAL.Insert(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

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

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取报关
                    result = this.customsclearanceDAL.Get(user, customId);
                    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.Close(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已完成的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, 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.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细关闭
                        result = customsDetailDAL.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, 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.UpdateStockStatusDirect(stock, StockStatusEnum.在库正常);
                        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 CompleteCancel(UserModel user, int customId)
        {
            ResultModel result = new ResultModel();

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

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

                    result = customsclearanceDAL.CompleteCancel(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, 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.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细完成
                        result = customsDetailDAL.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;
                        }

                        stock.StockStatus = StockStatusEnum.预报关库存;
                        stock.CustomsType = NFMT.Data.DetailProvider.Details(Data.StyleEnum.CustomType)["OutsideCustom"].StyleDetailId;//关外
                        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;
            }

            return result;
        }
Пример #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;
        }
Пример #5
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;
        }
Пример #6
0
        public ResultModel Close(UserModel user, int receiptId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取回执
                    result = this.stockreceiptDAL.Get(user, receiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceipt stockReceipt = result.ReturnValue as Model.StockReceipt;
                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存回执不存在";
                        return result;
                    }

                    //关闭回执
                    result = this.stockreceiptDAL.Close(user, stockReceipt);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取回执明细
                    result = stockReceiptDetailDAL.Load(user, stockReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockReceiptDetail> details = result.ReturnValue as List<Model.StockReceiptDetail>;
                    if (details == null || details.Count == 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回执明细获取失败";
                        return result;
                    }

                    foreach (Model.StockReceiptDetail detail in details)
                    {
                        //关闭回执明细
                        result = stockReceiptDetailDAL.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;
                        }

                        //更新库存流水磅差
                        stockLog.GapAmount -= detail.QtyMiss;
                        result = stockLogDAL.Update(user, stockLog);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #7
0
        public ResultModel CreateStockReceipt(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details, List<NFMT.WareHouse.Model.StockReceiptDetail> saleDetails, bool isAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL();
                DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证合约
                    result = subDAL.Get(user, stockReceipt.ContractSubId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    result = contractDAL.Get(user, sub.ContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                    if (contract == null || contract.ContractId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    decimal sumNetAmount = 0;
                    decimal sumReceiptAmount = 0;
                    decimal sumMissAmount = 0;
                    decimal missRate = 0;

                    //明细验证
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        if (detail.ReceiptAmount > 0)
                        {
                            //验证库存
                            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 = 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;
                            }

                            if (stockLog.StockId != stock.StockId)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存与库存流水不匹配";
                                return result;
                            }

                            if (stockLog.SubContractId != stockReceipt.ContractSubId)
                            {
                                result.ResultStatus = -1;
                                result.Message = "库存流水与合约不匹配";
                                return result;
                            }

                            detail.ContractId = sub.ContractId;
                            detail.ContractSubId = sub.SubId;
                            detail.DetailStatus = StatusEnum.已生效;
                            detail.PreNetAmount = stock.NetAmount;
                            detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                            detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                            sumNetAmount += stock.NetAmount;
                            sumReceiptAmount += detail.ReceiptAmount;
                        }
                    }

                    sumMissAmount = sumReceiptAmount - sumNetAmount;
                    missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                    //赋值StockReceipt
                    stockReceipt.ContractId = sub.ContractId;
                    stockReceipt.ContractSubId = sub.SubId;
                    stockReceipt.PreNetAmount = sumNetAmount;
                    stockReceipt.QtyMiss = sumMissAmount;
                    stockReceipt.QtyRate = missRate;
                    stockReceipt.ReceiptAmount = sumReceiptAmount;
                    stockReceipt.Receipter = user.EmpId;
                    stockReceipt.ReceiptDate = DateTime.Now;

                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                    else
                        stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;

                    stockReceipt.UnitId = sub.UnitId;

                    //新增StockReceipt
                    result = stockreceiptDAL.Insert(user, stockReceipt);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //新增明细
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        detail.ReceiptId = receiptId;
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    stockReceipt.ReceiptId = receiptId;
                    string resultStr = Newtonsoft.Json.JsonConvert.SerializeObject(stockReceipt);

                    //if(isAudit)
                    //{
                    //    stockReceipt.ReceiptId = receiptId;
                    //    NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit();
                    //    result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核);
                    //    if (result.ResultStatus != 0)
                    //        return result;
                    //}

                    #region 销售合约库存回执

                    if (saleDetails != null && saleDetails.Any())
                    {
                        foreach (int subId in saleDetails.Select(a => a.ContractSubId).Distinct())
                        {
                            //验证合约
                            result = subDAL.Get(user, subId);
                            if (result.ResultStatus != 0)
                                return result;

                            NFMT.Contract.Model.ContractSub saleSub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                            if (saleSub.SubId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "子合约不存在";
                                return result;
                            }

                            sumNetAmount = 0;
                            sumReceiptAmount = 0;
                            sumMissAmount = 0;
                            missRate = 0;

                            //明细验证
                            foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId))
                            {
                                if (detail.ReceiptAmount > 0)
                                {
                                    //验证库存
                                    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 = 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;
                                    }

                                    if (stockLog.StockId != stock.StockId)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存与库存流水不匹配";
                                        return result;
                                    }

                                    if (stockLog.SubContractId != subId)
                                    {
                                        result.ResultStatus = -1;
                                        result.Message = "库存流水与合约不匹配";
                                        return result;
                                    }

                                    detail.ContractId = saleSub.ContractId;
                                    detail.ContractSubId = saleSub.SubId;
                                    detail.DetailStatus = StatusEnum.已生效;
                                    detail.PreNetAmount = stock.NetAmount;
                                    detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                                    detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                                    sumNetAmount += stock.NetAmount;
                                    sumReceiptAmount += detail.ReceiptAmount;
                                }
                            }

                            sumMissAmount = sumReceiptAmount - sumNetAmount;
                            missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                            //赋值StockReceipt
                            stockReceipt.ContractId = saleSub.ContractId;
                            stockReceipt.ContractSubId = saleSub.SubId;
                            stockReceipt.PreNetAmount = sumNetAmount;
                            stockReceipt.ReceiptAmount = sumReceiptAmount;
                            stockReceipt.UnitId = saleSub.UnitId;
                            stockReceipt.QtyMiss = sumMissAmount;
                            stockReceipt.QtyRate = missRate;
                            stockReceipt.Receipter = user.EmpId;
                            stockReceipt.ReceiptDate = DateTime.Now;

                            if (saleSub.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                                stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                            else
                                stockReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;

                            //新增StockReceipt
                            result = stockreceiptDAL.Insert(user, stockReceipt);
                            if (result.ResultStatus != 0)
                                return result;

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

                            //新增明细
                            foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in saleDetails.Where(a => a.ContractSubId == subId))
                            {
                                detail.ReceiptId = receiptId;
                                result = detailDAL.Insert(user, detail);
                                if (result.ResultStatus != 0)
                                    return result;
                            }
                        }

                        //if (isAudit)
                        //{
                        //    stockReceipt.ReceiptId = receiptId;
                        //    NFMT.WorkFlow.AutoSubmit submit = new NFMT.WorkFlow.AutoSubmit();
                        //    result = submit.Submit(user, stockReceipt, new TaskProvider.StockReceiptTaskProvider(), NFMT.WorkFlow.MasterEnum.库存净重回执审核);
                        //    if (result.ResultStatus != 0)
                        //        return result;
                        //}
                    }

                    #endregion

                    stockReceipt.ReceiptId = receiptId;
                    if (result.ResultStatus == 0)
                    {
                        if (saleDetails != null && saleDetails.Any())
                            result.ReturnValue = stockReceipt;
                        else
                            result.ReturnValue = null;

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

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

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取质押
                    result = this.pledgeDAL.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Pledge pledge = result.ReturnValue as Model.Pledge;
                    if (pledge == null || pledge.PledgeId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押不存在";
                        return result;
                    }

                    //质押关闭
                    result = this.pledgeDAL.Close(user, pledge);
                    if (result.ResultStatus != 0)
                        return result;

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

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

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

                    foreach (Model.PledgeDetial detail in details)
                    {
                        //明细关闭
                        result = pledgeDetialDAL.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, 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;
                        }

                        if (stock.PreStatus == StockStatusEnum.质押库存)
                            stock.PreStatus = 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;
        }
Пример #9
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;
        }
Пример #10
0
        public ResultModel Complete(UserModel user, int pledgeId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证质押
                    result = pledgeDAL.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

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

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

                    //加载明细
                    PledgeDetialDAL pledgeDetialDAL = new PledgeDetialDAL();
                    result = pledgeDetialDAL.Load(user, pledge.PledgeId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //加载对应质押申请
                    PledgeApplyDAL pledgeApplyDAL = new PledgeApplyDAL();
                    result = pledgeApplyDAL.Get(user, pledge.PledgeApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    PledgeApply pledgeApply = result.ReturnValue as PledgeApply;
                    if (pledgeApply == null || pledgeApply.PledgeApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "对应质押申请加载失败";
                        return result;
                    }

                    //明细执行完成
                    //更新库存状态至质押库存
                    StockDAL stockDAL = new StockDAL();
                    StockLogDAL stockLogDAL = new StockLogDAL();
                    StockNameDAL stockNameDAL = new StockNameDAL();

                    foreach (Model.PledgeDetial detail in details)
                    {
                        //明细完成
                        result = pledgeDetialDAL.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, 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.UpdateStockStatusDirect(stock, StockStatusEnum.质押库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #11
0
        /// <summary>
        /// 数据撤返
        /// </summary>
        /// <param name="user">当前操作用户</param>
        /// <param name="pledge">Pledge对象</param>
        /// <returns></returns>
        public ResultModel GoBack(UserModel user, int pledgeId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = this.Get(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;
                    Model.Pledge pledge = result.ReturnValue as Pledge;

                    if (pledge == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能撤返";
                        return result;
                    }

                    if (pledge.Status != StatusEnum.待审核 && pledge.Status != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "非待审核或已生效状态的数据不允许撤返";
                        return result;
                    }

                    //获取质押申请实体
                    DAL.PledgeApplyDAL pledgeApplyDAL = new PledgeApplyDAL();
                    result = pledgeApplyDAL.Get(user, pledge.PledgeApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.PledgeApply pledgeApply = result.ReturnValue as Model.PledgeApply;

                    //获取申请实体
                    NFMT.Operate.DAL.ApplyDAL applyDAl = new Operate.DAL.ApplyDAL();
                    result = applyDAl.Get(user, pledgeApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply.Status == Common.StatusEnum.已关闭 || apply.Status == Common.StatusEnum.已完成)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押对应的申请已完成或已关闭,不能进行撤返操作";
                        return result;
                    }

                    result = pledgeDAL.Goback(user, pledge);
                    if (result.ResultStatus != 0)
                        return result;

                    if (pledge.Status == StatusEnum.待审核)
                    {
                        //同步工作流状态
                        NFMT.WorkFlow.BLL.DataSourceBLL dataSourceBLL = new WorkFlow.BLL.DataSourceBLL();
                        result = dataSourceBLL.SynchronousStatus(user, pledge);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    NFMT.WareHouse.DAL.PledgeDetialDAL pledgeDetialDAL = new DAL.PledgeDetialDAL();
                    result = pledgeDetialDAL.GetStockId(user, pledgeId);
                    if (result.ResultStatus != 0)
                        return result;

                    if (!string.IsNullOrEmpty(result.ReturnValue.ToString()))
                    {
                        NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                        NFMT.WareHouse.DAL.StockNameDAL stockNameDAL = new StockNameDAL();
                        NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();

                        NFMT.WareHouse.Model.StockName stockName = new StockName();
                        NFMT.WareHouse.Model.Stock stock = new Stock();
                        NFMT.WareHouse.Model.StockLog stockLog = new StockLog();

                        foreach (string s in result.ReturnValue.ToString().Split(','))
                        {
                            result = stockDAL.Get(user, Convert.ToInt32(s));
                            if (result.ResultStatus != 0)
                                return result;
                            stock = result.ReturnValue as Model.Stock;

                            result = stockNameDAL.Get(user, stock.StockNameId);
                            if (result.ResultStatus != 0)
                                return result;
                            stockName = result.ReturnValue as Model.StockName;

                            ////创建stockLog对象
                            //stockLog = new StockLog()
                            //{
                            //    StockId = stock.StockId,
                            //    StockNameId = stock.StockNameId,
                            //    RefNo = stockName.RefNo,
                            //    //LogDirection =
                            //    LogType = LogEnum.质押冲销,
                            //    //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_Pledge",
                            //    SourceId = pledgeId
                            //};

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

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

                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #12
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;
        }
Пример #13
0
        public ResultModel Complete(UserModel user, int stockMoveId)
        {
            ResultModel result = new ResultModel();

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

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

                    result = stockmoveDAL.Complete(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.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, 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.UpdateStockStatusToPrevious(user, stock, StockStatusEnum.在库正常);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #14
0
        public ResultModel PayApplyUpdate(UserModel user, Apply apply, PayApply payApply, List<StockPayApply> stockDetails)
        {
            ResultModel result = new ResultModel();

            try
            {
                ApplyDAL applyDAL = new ApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                StockDAL stockDAL = new StockDAL();
                StockLogDAL stockLogDAL = new StockLogDAL();
                ContractSubDAL subDAL = new ContractSubDAL();

                using (TransactionScope scope = new TransactionScope())
                {
                    //获取主申请
                    result = applyDAL.Get(user, apply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

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

                    resultApply.EmpId = user.EmpId;
                    resultApply.ApplyDept = apply.ApplyDept;
                    resultApply.ApplyCorp = apply.ApplyCorp;
                    resultApply.ApplyDesc = apply.ApplyDesc;
                    resultApply.ApplyTime = apply.ApplyTime;

                    result = applyDAL.Update(user, resultApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取付款申请
                    result = this.payapplyDAL.Get(user, payApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    PayApply resultPayApply = result.ReturnValue as PayApply;
                    if (resultPayApply == null || resultPayApply.PayApplyId <= 0)
                    {
                        result.Message = "付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }
                    if (resultPayApply.ApplyId != resultApply.ApplyId)
                    {
                        result.Message = "付款申请与主申请不一致,更新失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    resultPayApply.RecCorpId = payApply.RecCorpId;
                    resultPayApply.RecBankId = payApply.RecBankId;
                    resultPayApply.RecBankAccountId = payApply.RecBankAccountId;
                    resultPayApply.RecBankAccount = payApply.RecBankAccount;
                    resultPayApply.ApplyBala = payApply.ApplyBala;
                    resultPayApply.CurrencyId = payApply.CurrencyId;
                    resultPayApply.PayMode = payApply.PayMode;
                    resultPayApply.PayDeadline = payApply.PayDeadline;
                    resultPayApply.PayMatter = payApply.PayMatter;
                    resultPayApply.SpecialDesc = payApply.SpecialDesc;

                    if (stockDetails.Count > 0)
                        resultPayApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;
                    else
                        resultPayApply.PayApplySource = (int)FundsStyleEnum.ContractPayApply;

                    result = this.payapplyDAL.Update(user, resultPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取合约关联付款申请
                    result = contractPayApplyDAL.GetByPayApplyId(user, resultPayApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply;
                    if (contractPayApply == null || contractPayApply.RefId <= 0)
                    {
                        result.Message = "合约关联付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    contractPayApply.ApplyBala = resultPayApply.ApplyBala;
                    result = contractPayApplyDAL.Update(user, contractPayApply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取现有库存明细
                    result = stockPayApplyDAL.Load(user, resultPayApply.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<StockPayApply> resultDetails = result.ReturnValue as List<StockPayApply>;
                    if (resultDetails == null)
                    {
                        result.Message = "库存付款申请获取失败";
                        result.ResultStatus = -1;
                        return result;
                    }

                    //作废现有库存明细
                    foreach (StockPayApply stockPayApply in resultDetails)
                    {
                        stockPayApply.RefStatus = StatusEnum.已录入;
                        result = stockPayApplyDAL.Invalid(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增库存付款申请
                    if (stockDetails != null && stockDetails.Count > 0)
                    {
                        foreach (StockPayApply detail in stockDetails)
                        {
                            detail.ContractId = contractPayApply.ContractId;
                            detail.ContractRefId = contractPayApply.RefId;
                            detail.PayApplyId = contractPayApply.PayApplyId;
                            detail.RefStatus = StatusEnum.已生效;
                            detail.SubId = contractPayApply.ContractSubId;
                            result = stockPayApplyDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    if (result.ResultStatus == 0)
                        result.ReturnValue = payApply.PayApplyId;

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

            return result;
        }
Пример #15
0
        public ResultModel StockReceiptUpdate(UserModel user, int detailId, int stockId, int stockLogId, decimal receiptAmount)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();

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

                    Model.StockReceiptDetail stockReceiptDetail = result.ReturnValue as Model.StockReceiptDetail;
                    if (stockReceiptDetail == null || stockReceiptDetail.DetailId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取库存回执错误";
                        return result;
                    }
                    stockReceiptDetail.ReceiptAmount = receiptAmount;
                    stockReceiptDetail.QtyMiss = receiptAmount - stockReceiptDetail.PreNetAmount;
                    stockReceiptDetail.QtyRate = (receiptAmount / stockReceiptDetail.PreNetAmount - 1) / 100;

                    //修改库存回执明细
                    result = stockReceiptDetailDAL.Update(user, stockReceiptDetail);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存回执
                    result = stockreceiptDAL.Get(user, stockReceiptDetail.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceipt stockReceipt = result.ReturnValue as Model.StockReceipt;
                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取库存回执出错";
                        return result;
                    }

                    result = stockLogDAL.Get(user, 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;
                    }

                    stockLog.GapAmount = receiptAmount - stockReceiptDetail.PreNetAmount;

                    //更新库存流水
                    result = stockLogDAL.Update(user, stockLog);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取库存
                    result = stockDAL.Get(user, 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 (stockReceipt.ReceiptType == (int)NFMT.WareHouse.ReceiptTypeEnum.入库回执)
                    {
                        stock.ReceiptInGap = receiptAmount - stockReceiptDetail.PreNetAmount;
                    }
                    else if (stockReceipt.ReceiptType == (int)NFMT.WareHouse.ReceiptTypeEnum.出库回执)
                    {
                        stock.ReceiptOutGap = receiptAmount - stockReceiptDetail.PreNetAmount;
                    }
                    stock.CurNetAmount = receiptAmount;

                    //更新库存
                    result = stockDAL.Update(user, stock);
                    if (result.ResultStatus != 0)
                        return result;

                    //若此库存已开业务票,则修改业务票中的净重
                    result = stockreceiptDAL.UpdateBussinessInvDetail(user, stockLogId, receiptAmount);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #16
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;
        }
Пример #17
0
        public ResultModel Update(UserModel user, NFMT.WareHouse.Model.StockReceipt stockReceipt, List<NFMT.WareHouse.Model.StockReceiptDetail> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL();
                NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
                DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                DAL.StockReceiptDAL receiptDAL = new StockReceiptDAL();
                DAL.StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证仓库回执
                    result = receiptDAL.Get(user, stockReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockReceipt resultReceipt = result.ReturnValue as Model.StockReceipt;
                    if (resultReceipt == null || resultReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "仓库回执不存在";
                        return result;
                    }

                    //获取仓库回执明细
                    result = detailDAL.Load(user, resultReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockReceiptDetail> resultDetails = result.ReturnValue as List<Model.StockReceiptDetail>;
                    if (resultDetails == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "仓库回执明细获取失败";
                        return result;
                    }

                    //作废现有仓库回执明细
                    foreach (Model.StockReceiptDetail d in resultDetails)
                    {
                        if (d.DetailStatus == StatusEnum.已生效)
                            d.DetailStatus = StatusEnum.已录入;

                        result = detailDAL.Invalid(user, d);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //验证合约
                    result = subDAL.Get(user, resultReceipt.ContractSubId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                    if (sub.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    result = contractDAL.Get(user, sub.ContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                    if (contract == null || contract.ContractId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "合约不存在";
                        return result;
                    }

                    decimal sumNetAmount = 0;
                    decimal sumReceiptAmount = 0;
                    decimal sumMissAmount = 0;
                    decimal missRate = 0;

                    //明细验证
                    foreach (NFMT.WareHouse.Model.StockReceiptDetail detail in details)
                    {
                        //验证库存
                        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 = 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;
                        }

                        if (stockLog.StockId != stock.StockId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存与库存流水不匹配";
                            return result;
                        }

                        if (stockLog.SubContractId != stockReceipt.ContractSubId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存流水与合约不匹配";
                            return result;
                        }

                        detail.ReceiptId = resultReceipt.ReceiptId;
                        detail.ContractId = sub.ContractId;
                        detail.ContractSubId = sub.SubId;
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.PreNetAmount = stock.NetAmount;
                        detail.QtyMiss = detail.ReceiptAmount - stock.NetAmount;
                        detail.QtyRate = (detail.ReceiptAmount / stock.NetAmount - 1) / 100;

                        sumNetAmount += stock.NetAmount;
                        sumReceiptAmount += detail.ReceiptAmount;

                        //新增仓库回执明细
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    sumMissAmount = sumReceiptAmount - sumNetAmount;
                    missRate = (sumReceiptAmount / sumNetAmount - 1) / 100;

                    //赋值StockReceipt
                    resultReceipt.PreNetAmount = sumReceiptAmount;
                    resultReceipt.QtyMiss = sumMissAmount;
                    resultReceipt.QtyRate = missRate;
                    resultReceipt.ReceiptAmount = sumReceiptAmount;
                    resultReceipt.Receipter = user.EmpId;
                    resultReceipt.Memo = stockReceipt.Memo;
                    resultReceipt.ReceiptDate = stockReceipt.ReceiptDate;
                    if (contract.TradeDirection == (int)NFMT.Contract.TradeDirectionEnum.Buy)
                        resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockInReceipt;
                    else
                        resultReceipt.ReceiptType = (int)WareHouse.ReceiptTypeEnum.StockOutReceipt;
                    resultReceipt.UnitId = sub.UnitId;

                    //修改StockReceipt
                    result = stockreceiptDAL.Update(user, resultReceipt);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }
Пример #18
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;
        }
Пример #19
0
        public ResultModel Complete(UserModel user, int receiptId)
        {
            ResultModel result = new ResultModel();

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

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

                    StockReceipt stockReceipt = result.ReturnValue as StockReceipt;

                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "该数据不存在,不能作废";
                        return result;
                    }

                    result = this.stockreceiptDAL.Complete(user, stockReceipt);
                    if (result.ResultStatus != 0)
                        return result;

                    StockReceiptDetailDAL detailDAL = new StockReceiptDetailDAL();
                    result = detailDAL.Load(user, stockReceipt.ReceiptId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockReceiptDetail> details = result.ReturnValue as List<Model.StockReceiptDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取回执明细失败";
                        return result;
                    }
                    foreach (Model.StockReceiptDetail detail in details)
                    {
                        result = detailDAL.Complete(user, detail);
                        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;
                        //}

                        ////更新库存净重
                        //if (stockReceipt.ReceiptType == (int)ReceiptTypeEnum.入库回执)
                        //{
                        //    stock.ReceiptInGap += detail.QtyMiss;
                        //    //stock.NetAmount += detail.QtyMiss;
                        //}
                        //else
                        //    stock.ReceiptOutGap += detail.QtyMiss;
                        //stock.CurNetAmount += detail.QtyMiss;

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

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #20
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;
        }
Пример #21
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.StockLogDAL stockLogDAL = new StockLogDAL();
                NFMT.WareHouse.DAL.StockReceiptDetailDAL stockReceiptDetailDAL = new StockReceiptDetailDAL();

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

                    Model.StockReceipt stockReceipt = result.ReturnValue as Model.StockReceipt;
                    if (stockReceipt == null || stockReceipt.ReceiptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "库存回执不存在";
                        return result;
                    }

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

                    //审核通过
                    if (isPass)
                    {
                        //获取回执明细
                        result = stockReceiptDetailDAL.Load(user, stockReceipt.ReceiptId);
                        if (result.ResultStatus != 0)
                            return result;

                        List<Model.StockReceiptDetail> stockReceiptDetails = result.ReturnValue as List<Model.StockReceiptDetail>;
                        if (stockReceiptDetails == null || stockReceiptDetails.Count == 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取回执明细失败";
                            return result;
                        }

                        foreach (Model.StockReceiptDetail detail in stockReceiptDetails)
                        {
                            //获取库存流水
                            result = stockLogDAL.Get(NFMT.Common.DefaultValue.SysUser, 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;
                            }

                            //更新库存流水回执重量
                            stockLog.GapAmount += detail.QtyMiss;
                            result = stockLogDAL.Update(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;
                            }

                            //更新库存净重
                            if (stockReceipt.ReceiptType == (int)ReceiptTypeEnum.入库回执)
                            {
                                stock.ReceiptInGap += detail.QtyMiss;
                                //stock.NetAmount += detail.QtyMiss;
                            }
                            else
                                stock.ReceiptOutGap += detail.QtyMiss;
                            stock.CurNetAmount = detail.ReceiptAmount;

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

            return result;
        }
Пример #22
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;
        }
Пример #23
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;
        }
Пример #24
0
        /// <summary>
        /// 库存处理(此方法不包含事务,必须在事务下执行)
        /// </summary>
        /// <param name="stockLog">库存流水</param>
        /// <param name="stockLogAttach">库存流水附件</param>
        /// <param name="user">当前用户</param>
        /// <param name="bdStyleDetail">库存操作类型</param>
        /// <returns></returns>
        public NFMT.Common.ResultModel StockHandle(NFMT.Common.UserModel user, NFMT.WareHouse.Model.StockLog stockLog, List<NFMT.WareHouse.Model.StockLogAttach> stockLogAttachs, StockOperateEnum stockOperate)
        {
            NFMT.Common.ResultModel result = new NFMT.Common.ResultModel();

            //result = CheckUser(user);
            //if (result.ResultStatus != 0)
            //    return result;

            try
            {
                //获取stock
                NFMT.WareHouse.BLL.StockBLL stockBLL = new NFMT.WareHouse.BLL.StockBLL();
                result = stockBLL.Get(user, stockLog.StockId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;

                //根据库存处理类型修改库存状态
                result = stockBLL.UpdateStockStatus(user, stock, stockOperate);
                if (result.ResultStatus != 0)
                    return result;

                //写库存流水
                NFMT.WareHouse.DAL.StockLogDAL stockLogDAL = new StockLogDAL();
                result = stockLogDAL.Insert(user, stockLog);
                if (result.ResultStatus != 0)
                    return result;

                int stockLogId = (int)result.ReturnValue;

                //写库存流水附件
                if (stockLogAttachs != null)
                {
                    NFMT.WareHouse.DAL.StockLogAttachDAL stockLogAttachDAL = new StockLogAttachDAL();
                    foreach (NFMT.WareHouse.Model.StockLogAttach stockLogAttach in stockLogAttachs)
                    {
                        stockLogAttach.StockLogId = stockLogId;
                        result = stockLogAttachDAL.Insert(user, stockLogAttach);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.ResultStatus = -1;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Пример #25
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;
        }
Пример #26
0
        public ResultModel Close(UserModel user, int repoId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //获取回购
                    result = this.repoDAL.Get(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Repo repo = result.ReturnValue as Model.Repo;
                    if (repo == null || repo.RepoId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回购不存在";
                        return result;
                    }

                    //回购关闭
                    result = this.repoDAL.Close(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

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

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

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

                    foreach (Model.RepoDetail detail in details)
                    {
                        //明细关闭
                        result = repoDetailDAL.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, 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.UpdateStockStatusToPrevious(user, stock, StockStatusEnum.质押库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }

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

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

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

                    Model.CustomsClearance customsClearance = result.ReturnValue as CustomsClearance;
                    if (customsClearance == null)
                    {
                        result.Message = "该数据不存在,不能完成";
                        return result;
                    }

                    result = customsclearanceDAL.Complete(user, customsClearance);
                    if (result.ResultStatus != 0)
                        return result;

                    //获取所有已生效的明细
                    DAL.CustomsDetailDAL customsDetailDAL = new CustomsDetailDAL();
                    result = customsDetailDAL.Load(user, customId, 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.StockLogDAL stockLogDAL = new StockLogDAL();
                    DAL.StockDAL stockDAL = new StockDAL();

                    foreach (Model.CustomsDetail detail in details)
                    {
                        //明细完成
                        result = customsDetailDAL.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, 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;
                        }

                        stock.StockStatus = (int)stock.PreStatus == 0 ? StockStatusEnum.在库正常 : stock.PreStatus;
                        stock.CustomsType = NFMT.Data.DetailProvider.Details(Data.StyleEnum.CustomType)["InsideCustom"].StyleDetailId;//关内
                        result = stockDAL.Update(user, stock);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

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

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

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

                    result = repoDAL.CompleteCancel(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

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

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

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

                    foreach (Model.RepoDetail detail in details)
                    {
                        //明细完成
                        result = repoDetailDAL.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.UpdateStockStatusDirect(stock, StockStatusEnum.预回购库存);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }
Пример #29
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;
        }
Пример #30
0
        public ResultModel PayApplyStockCreate(UserModel user, PayApply payApply, List<StockPayApply> stockPayApplies, string memo, int deptId, int corpId)
        {
            ResultModel result = new ResultModel();

            try
            {
                StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL();
                ApplyDAL applyDAL = new ApplyDAL();
                PayApplyDAL payApplyDAL = new PayApplyDAL();
                ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL();

                StockLogDAL stockLogDAL = new StockLogDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证可申请金额
                    //NFMT.Data.Model.FuturesPrice futuresPrice = NFMT.Data.BasicDataProvider.FuturesPrices[0];

                    //验证库存流水是否在同一子合约中
                    int subId = 0;
                    int contractId = 0;
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        result = stockLogDAL.Get(user, stockPayApply.StockLogId);
                        if (result.ResultStatus != 0)
                            return result;

                        StockLog stockLog = result.ReturnValue as StockLog;
                        if (stockLog == null || stockLog.StockLogId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存流水不存在";
                            return result;
                        }

                        if (subId == 0)
                        {
                            subId = stockLog.SubContractId;
                            contractId = stockLog.ContractId;
                        }

                        if (stockLog.SubContractId != subId)
                        {
                            result.ResultStatus = -1;
                            result.Message = "不能同时申请不同子合约中的库存付款";
                            return result;
                        }
                    }

                    //新增申请主表
                    Department dept = UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == deptId);
                    if (dept == null || dept.DeptId < 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    int applyId = 0;
                    Apply apply = new Apply();

                    apply.ApplyDept = dept.DeptId;
                    apply.ApplyCorp = corpId;
                    apply.ApplyDesc = memo;
                    apply.ApplyTime = DateTime.Now;
                    apply.ApplyType = ApplyType.付款申请;
                    apply.EmpId = user.EmpId;

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

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

                    decimal sumApplyBala = stockPayApplies.Sum(temp => temp.ApplyBala);
                    //新增付款申请表
                    payApply.ApplyId = applyId;
                    payApply.PayApplySource = (int)FundsStyleEnum.StockPayApply;
                    payApply.ApplyBala = sumApplyBala;
                    result = payapplyDAL.Insert(user, payApply);
                    if (result.ResultStatus != 0)
                        return result;
                    int payApplyId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out payApplyId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请新增失败";
                        return result;
                    }

                    //新增合约付款申请关联表
                    ContractPayApply payApplyContract = new ContractPayApply();
                    payApplyContract.ApplyBala = sumApplyBala;
                    payApplyContract.ContractId = contractId;
                    payApplyContract.ContractSubId = subId;
                    payApplyContract.PayApplyId = payApplyId;

                    result = contractPayApplyDAL.Insert(user, payApplyContract);
                    if (result.ResultStatus != 0)
                        return result;

                    int contractRefId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out contractRefId) || contractRefId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "新增付款申请失败";
                        return result;
                    }

                    //新增dbo.Fun_StockPayApply_Ref库存付款申请
                    foreach (StockPayApply stockPayApply in stockPayApplies)
                    {
                        stockPayApply.ContractId = contractId;
                        stockPayApply.ContractRefId = contractRefId;
                        stockPayApply.SubId = subId;
                        stockPayApply.PayApplyId = payApplyId;
                        stockPayApply.RefStatus = StatusEnum.已生效;
                        result = stockPayApplyDAL.Insert(user, stockPayApply);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }