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; }
public ResultModel Close(UserModel user, int virtualId) { ResultModel result = new ResultModel(); try { DAL.PayApplyDAL payApplyDAL = new PayApplyDAL(); DAL.PaymentDAL paymentDAL = new PaymentDAL(); DAL.PaymentInvioceDetailDAL invoiceDetailDAL = new PaymentInvioceDetailDAL(); DAL.PaymentStockDetailDAL stockDetailDAL = new PaymentStockDetailDAL(); DAL.PaymentContractDetailDAL contractDetailDAL = new PaymentContractDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope()) { //获取虚拟付款 result = this.paymentvirtualDAL.Get(user, virtualId); if (result.ResultStatus != 0) return result; Model.PaymentVirtual paymentVirtual = result.ReturnValue as Model.PaymentVirtual; if (paymentVirtual == null || paymentVirtual.VirtualId <= 0) { result.ResultStatus = -1; result.Message = "虚拟付款不存在"; return result; } //关闭虚拟付款 result = this.paymentvirtualDAL.Close(user, paymentVirtual); if (result.ResultStatus != 0) return result; //获取主付款 result = paymentDAL.Get(user, paymentVirtual.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; } //当前主付款虚拟金额更新为0 payment.VirtualBala = 0; payment.PayBala = payment.FundsBala; result = paymentDAL.Update(user, payment); if (result.ResultStatus != 0) return result; //获取对应付款申请 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; } if (payApply.PayApplySource == (int)FundsStyleEnum.InvoicePayApply) { //获取所有发票明细 result = invoiceDetailDAL.Load(user, payment.PaymentId); if (result.ResultStatus != 0) return result; List<Model.PaymentInvioceDetail> invoiceDetails = result.ReturnValue as List<Model.PaymentInvioceDetail>; if (invoiceDetails == null) { result.ResultStatus = -1; result.Message = "发票明细获取失败"; return result; } //当前主付款发票明细虚拟金额更新为0 foreach (Model.PaymentInvioceDetail invoiceDetail in invoiceDetails) { invoiceDetail.VirtualBala =0; invoiceDetail.PayBala = invoiceDetail.FundsBala; result = invoiceDetailDAL.Update(user, invoiceDetail); if (result.ResultStatus != 0) return result; } } else if (payApply.PayApplySource == (int)FundsStyleEnum.ContractPayApply) { //获取合约明细 result = contractDetailDAL.GetByPaymentId(user, payment.PaymentId); if(result.ResultStatus!=0) return result; Model.PaymentContractDetail contractDetail = result.ReturnValue as Model.PaymentContractDetail; if (contractDetail == null || contractDetail.DetailId <= 0) { result.ResultStatus = -1; result.Message = "合约明细获取失败"; return result; } //当前主付款合约明细虚拟金额更新为0 contractDetail.VirtualBala = 0; contractDetail.PayBala = contractDetail.FundsBala; result = contractDetailDAL.Update(user, contractDetail); if (result.ResultStatus != 0) return result; } else if (payApply.PayApplySource == (int)FundsStyleEnum.StockPayApply) { //获取合约明细 result = contractDetailDAL.GetByPaymentId(user, payment.PaymentId); if(result.ResultStatus!=0) return result; Model.PaymentContractDetail contractDetail = result.ReturnValue as Model.PaymentContractDetail; if (contractDetail == null || contractDetail.DetailId <= 0) { result.ResultStatus = -1; result.Message = "合约明细获取失败"; return result; } //当前主付款合约明细虚拟金额更新为0 contractDetail.VirtualBala = 0; contractDetail.PayBala = contractDetail.FundsBala; result = contractDetailDAL.Update(user, contractDetail); if (result.ResultStatus != 0) return result; //获取库存明细 result = stockDetailDAL.LoadByPaymentId(user, payment.PaymentId); if (result.ResultStatus != 0) return result; List<Model.PaymentStockDetail> stockDetails = result.ReturnValue as List<Model.PaymentStockDetail>; if (stockDetails == null) { result.ResultStatus = -1; result.Message = "库存明细获取失败"; return result; } //当前主付款库存明细虚拟金额更新为0 foreach (Model.PaymentStockDetail stockDetail in stockDetails) { stockDetail.VirtualBala = 0; stockDetail.PayBala = stockDetail.FundsBala; result = stockDetailDAL.Update(user, stockDetail); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Confirm(UserModel user, int payApplyId) { ResultModel result = new ResultModel(); try { PayApplyDAL payApplyDAL = new PayApplyDAL(); ApplyDAL applyDAL = new ApplyDAL(); PaymentDAL paymentDAL = new PaymentDAL(); StockPayApplyDAL payApplyStockDAL = new StockPayApplyDAL(); ContractPayApplyDAL payApplyContractDAL = new ContractPayApplyDAL(); PaymentStockDetailDAL paymentStockDetailDAL = new PaymentStockDetailDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证付款申请 result = payApplyDAL.Get(user, payApplyId); if (result.ResultStatus != 0) return result; PayApply payApply = result.ReturnValue as PayApply; if (payApply == null || payApply.PayApplyId <= 0) { result.ResultStatus = -1; result.Message = "付款申请不存在"; return result; } //验证主申请 result = applyDAL.Get(user, payApply.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 = paymentDAL.GetCountByPayApplyId(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; if (result == null || result.AffectCount > 0) { result.ResultStatus = -1; result.Message = "付款申请存在未完成的关联付款,不能进行执行完成确认"; return result; } //验证当前付款申请的申请金额与已执行完成的关联付款的付款金额是否相等 //如果不相等则不能进行执行完成确认 result = paymentDAL.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<Payment> payments = result.ReturnValue as List<Payment>; if (payments == null) { result.ResultStatus = -1; result.Message = "获取关联付款失败"; return result; } decimal sumPayBala = payments.Sum(temp => temp.PayBala); if (sumPayBala != payApply.ApplyBala) { result.ResultStatus = -1; result.Message = "付款申请金额与付款执行金额不相等,不能进行付款申请执行完成确认"; return result; } //验证库存付款申请明细的申请金额与付款执行的付款金额是否相等 //如果不相等则不能进行执行完成确认 if (payApply.PayApplySource == (int)FundsStyleEnum.ContractPayApply) { //获取付款申请下合约申请明细 result = payApplyContractDAL.GetByPayApplyId(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; ContractPayApply payApplyContract = result.ReturnValue as ContractPayApply; if (payApplyContract == null || payApplyContract.RefId <= 0) { result.ResultStatus = -1; result.Message = "获取明细失败"; return result; } //完成明细 //result = payApplyContractDAL.Confirm(user, payApplyContract); //if (result.ResultStatus != 0) // return result; } else if (payApply.PayApplySource == (int)FundsStyleEnum.StockPayApply) { //获取付款申请下库存申请明细 result = payApplyStockDAL.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<StockPayApply> payApplyStocks = result.ReturnValue as List<StockPayApply>; if (payApplyStocks == null) { result.ResultStatus = -1; result.Message = "获取付款申请库存明细失败"; return result; } foreach (StockPayApply payApplyStock in payApplyStocks) { //获取付款申请库存明细关联的付款库存明细 result = paymentStockDetailDAL.LoadByStockPayApplyId(user, payApplyStock.RefId); if (result.ResultStatus != 0) return result; List<PaymentStockDetail> details = result.ReturnValue as List<PaymentStockDetail>; decimal sumStockPayBala = details.Sum(temp => temp.PayBala); if (sumStockPayBala != payApplyStock.ApplyBala) { result.ResultStatus = -1; result.Message = "付款申请存在未付完的金额,不能进行执行确认完成"; return result; } //明细完成 result = payApplyStockDAL.Confirm(user, payApplyStock); if (result.ResultStatus != 0) return result; } } //付款申请完成确认 //因付款执行不进行部分关闭,因此不存在部分完成状态 result = applyDAL.Confirm(user, apply); if (result.ResultStatus != 0) return result; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }