コード例 #1
0
ファイル: PaymentVirtualBLL.cs プロジェクト: weiliji/NFMT
        public ResultModel PaymentVirtualConfirm(UserModel user, Model.PaymentVirtual paymentVirtual)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.PaymentDAL paymentDAL = new PaymentDAL();
                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证虚拟付款
                    result = paymentvirtualDAL.Get(user, paymentVirtual.VirtualId);

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

                    Model.PaymentVirtual resultObj = result.ReturnValue as Model.PaymentVirtual;
                    if (resultObj == null || resultObj.VirtualId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "虚拟付款不存在";
                        return result;
                    }

                    if (resultObj.DetailStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "虚拟付款状态不能进行确认";
                        return result;
                    }

                    //获取财务付款
                    result = paymentDAL.Get(user, resultObj.PaymentId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Payment payment = result.ReturnValue as Model.Payment;
                    if (payment == null || payment.PaymentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款不存在";
                        return result;
                    }

                    //更新虚拟付款
                    resultObj.ConfirmMemo = paymentVirtual.ConfirmMemo;
                    resultObj.DetailStatus = StatusEnum.已完成;

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

                    //获取对应的付款申请
                    DAL.PayApplyDAL payApplyDAL = new PayApplyDAL();
                    result = payApplyDAL.Get(user, resultObj.PayApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.PayApply payApply = result.ReturnValue as Model.PayApply;
                    if (payApply == null || payApply.PayApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款申请不存在";
                        return result;
                    }

                    NFMT.Data.DAL.BankDAL outBankDAL = new Data.DAL.BankDAL();
                    NFMT.User.DAL.BlocDAL blocDAL = new User.DAL.BlocDAL();
                    DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();

                    //写付款资金流水,状态为已完成
                    Model.FundsLog fundsLog = new FundsLog();
                    fundsLog.CurrencyId = payment.CurrencyId;
                    fundsLog.FundsBala = payment.FundsBala;
                    fundsLog.FundsDesc = payment.Memo;
                    fundsLog.InAccountId = payment.PayBankAccountId;
                    fundsLog.InBankId = payment.PayBankId;
                    fundsLog.InBlocId = user.BlocId;
                    fundsLog.InCorpId = payment.PayCorp;
                    fundsLog.IsVirtualPay = false;
                    fundsLog.LogDate = DateTime.Now;
                    fundsLog.LogDirection = (int)NFMT.WareHouse.LogDirectionEnum.Out;
                    fundsLog.LogSource = "dbo.Fun_PaymentVirtual";
                    fundsLog.LogSourceBase = "NFMT";
                    fundsLog.LogStatus = StatusEnum.已完成;
                    fundsLog.LogType = (int)NFMT.WareHouse.LogTypeEnum.付款;
                    fundsLog.OpPerson = user.EmpId;
                    fundsLog.OutAccount = payment.ReceBankAccount;
                    fundsLog.OutAccountId = payment.ReceBankAccountId;
                    result = outBankDAL.Get(user, payment.ReceBankId);
                    if (result.ResultStatus != 0)
                        return result;
                    NFMT.Data.Model.Bank outBank = result.ReturnValue as NFMT.Data.Model.Bank;
                    if (outBank == null || outBank.BankId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "收款银行不存在";
                        return result;
                    }
                    fundsLog.OutBank = outBank.BankName;
                    fundsLog.OutBankId = payment.ReceBankId;

                    result = blocDAL.GetBlocByCorpId(user, payment.RecevableCorp);
                    if (result.ResultStatus == 0)
                    {
                        NFMT.User.Model.Bloc bloc = result.ReturnValue as NFMT.User.Model.Bloc;
                        if (bloc != null && bloc.BlocId > 0)
                            fundsLog.OutBlocId = bloc.BlocId;
                    }
                    fundsLog.OutCorpId = payment.RecevableCorp;
                    fundsLog.PayMode = payment.PayStyle;
                    fundsLog.SourceId = payment.PaymentId;

                    if (payApply.PayApplySource == (int)FundsStyleEnum.库存付款申请 || payApply.PayApplySource == (int)FundsStyleEnum.合约付款申请)
                    {
                        //加载合约明细
                        DAL.PaymentContractDetailDAL paymentContractDetailDAL = new PaymentContractDetailDAL();
                        result = paymentContractDetailDAL.GetByPaymentId(user, payment.PaymentId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.PaymentContractDetail paymentContractDetail = result.ReturnValue as Model.PaymentContractDetail;
                        if (paymentContractDetail == null || paymentContractDetail.DetailId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "付款合约明细加载失败";
                            return result;
                        }

                        fundsLog.ContractId = paymentContractDetail.ContractId;
                        fundsLog.SubId = paymentContractDetail.ContractSubId;
                    }

                    result = fundsLogDAL.Insert(user, fundsLog);
                    if (result.ResultStatus != 0)
                        return result;

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

                    //更新虚拟付款表的资金流水序号
                    resultObj.FundsLogId = fundsLogId;
                    resultObj.DetailStatus = StatusEnum.已完成;
                    result = this.paymentvirtualDAL.Update(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

                    //反向分配一收款至对应公司

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

            return result;
        }
コード例 #2
0
ファイル: PaymentBLL.cs プロジェクト: weiliji/NFMT
        public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.PayApplyDAL payApplyDAL = new PayApplyDAL();
                NFMT.User.DAL.BlocDAL blocDAL = new User.DAL.BlocDAL();
                DAL.FundsLogDAL fundsLogDAL = new FundsLogDAL();
                NFMT.Data.DAL.BankDAL outBankDAL = new Data.DAL.BankDAL();
                DAL.PaymentVirtualDAL paymentVirtualDAL = new PaymentVirtualDAL();

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

                    Model.Payment payment = result.ReturnValue as Model.Payment;
                    if (payment == null || payment.PaymentId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "付款不存在";
                        return result;
                    }

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

                    //获取虚拟付款
                    result = paymentVirtualDAL.GetByPaymentId(user, payment.PaymentId, StatusEnum.已录入);
                    if (result.ResultStatus == 0)
                    {
                        Model.PaymentVirtual paymentVirtual = result.ReturnValue as Model.PaymentVirtual;
                        if (paymentVirtual != null && paymentVirtual.VirtualId > 0)
                        {
                            //审核虚拟付款
                            result = paymentVirtualDAL.Audit(user, paymentVirtual, isPass);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }

                    //审核通过
                    if (isPass)
                    {
                        //获取对方的付款申请
                        result = payApplyDAL.Get(user, payment.PayApplyId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.PayApply payApply = result.ReturnValue as Model.PayApply;
                        if (payApply == null || payApply.PayApplyId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "付款申请不存在";
                            return result;
                        }

                        // 流水操作:写入 流水类型:付款 流水状态:已生效 【仅写入实际付款】
                        Model.FundsLog fundsLog = new FundsLog();
                        fundsLog.CurrencyId = payment.CurrencyId;
                        fundsLog.FundsBala = payment.FundsBala;
                        fundsLog.FundsDesc = payment.Memo;
                        fundsLog.InAccountId = payment.PayBankAccountId;
                        fundsLog.InBankId = payment.PayBankId;
                        fundsLog.InBlocId = user.BlocId;
                        fundsLog.InCorpId = payment.PayCorp;
                        fundsLog.IsVirtualPay = false;
                        fundsLog.LogDate = DateTime.Now;
                        fundsLog.LogDirection = (int)NFMT.WareHouse.LogDirectionEnum.Out;
                        fundsLog.LogSource = "dbo.Fun_Payment";
                        fundsLog.LogSourceBase = "NFMT";
                        fundsLog.LogStatus = StatusEnum.已生效;
                        fundsLog.LogType = (int)NFMT.WareHouse.LogTypeEnum.付款;
                        fundsLog.OpPerson = user.EmpId;
                        fundsLog.OutAccount = payment.ReceBankAccount;
                        fundsLog.OutAccountId = payment.ReceBankAccountId;
                        result = outBankDAL.Get(user, payment.ReceBankId);
                        if (result.ResultStatus != 0)
                            return result;
                        NFMT.Data.Model.Bank outBank = result.ReturnValue as NFMT.Data.Model.Bank;
                        if (outBank == null || outBank.BankId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "收款银行不存在";
                            return result;
                        }
                        fundsLog.OutBank = outBank.BankName;
                        fundsLog.OutBankId = payment.ReceBankId;

                        result = blocDAL.GetBlocByCorpId(user, payment.RecevableCorp);
                        if (result.ResultStatus == 0)
                        {
                            NFMT.User.Model.Bloc bloc = result.ReturnValue as NFMT.User.Model.Bloc;
                            if (bloc != null && bloc.BlocId > 0)
                                fundsLog.OutBlocId = bloc.BlocId;
                        }
                        fundsLog.OutCorpId = payment.RecevableCorp;
                        fundsLog.PayMode = payment.PayStyle;
                        fundsLog.SourceId = payment.PaymentId;

                        if (payApply.PayApplySource == (int)FundsStyleEnum.库存付款申请 || payApply.PayApplySource == (int)FundsStyleEnum.合约付款申请)
                        {
                            //加载合约明细
                            DAL.PaymentContractDetailDAL paymentContractDetailDAL = new PaymentContractDetailDAL();
                            result = paymentContractDetailDAL.GetByPaymentId(user, payment.PaymentId);
                            if (result.ResultStatus != 0)
                                return result;

                            Model.PaymentContractDetail paymentContractDetail = result.ReturnValue as Model.PaymentContractDetail;
                            if (paymentContractDetail == null || paymentContractDetail.DetailId <= 0)
                            {
                                result.ResultStatus = -1;
                                result.Message = "付款合约明细加载失败";
                                return result;
                            }

                            fundsLog.ContractId = paymentContractDetail.ContractId;
                            fundsLog.SubId = paymentContractDetail.ContractSubId;
                        }

                        result = fundsLogDAL.Insert(user, fundsLog);
                        if (result.ResultStatus != 0)
                            return result;

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

                        //更新付款表的资金流水序号
                        payment.FundsLogId = fundsLogId;
                        payment.PaymentStatus = StatusEnum.已生效;
                        result = this.paymentDAL.Update(user, payment);
                        if (result.ResultStatus != 0)
                            return result;
                    }

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

            return result;
        }