public ResultModel PaymentContractUpdate(UserModel user, Model.Payment payment) { ResultModel result = new ResultModel(); try { DAL.PayApplyDAL payApplyDAL = new PayApplyDAL(); NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); DAL.ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL(); DAL.PaymentContractDetailDAL paymentContractDetailDAL = new PaymentContractDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证付款总额是否等于财务付款金额+虚拟付款金额 if (payment.PayBala != payment.FundsBala + payment.VirtualBala) { result.ResultStatus = -1; result.Message = "付款总额必须等于财务付款金额+虚拟付款金额"; return result; } //验证财务付款 result = paymentDAL.Get(user, payment.PaymentId); if (result.ResultStatus != 0) return result; Model.Payment resultObj = result.ReturnValue as Model.Payment; if (resultObj == null || resultObj.PaymentId <= 0) { result.ResultStatus = -1; result.Message = "财务付款不存在,不能进行修改"; return result; } //验证付款申请 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; } //获取主申请 result = applyDAL.Get(user, payApply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "付款主申请不存在"; return result; } //判断申请状态是否已生效 if (apply.ApplyStatus != NFMT.Common.StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "付款申请非已生效状态,不能进行付款"; return result; } //获取当前付款申请中的所有付款 result = paymentDAL.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<Model.Payment> payments = result.ReturnValue as List<Model.Payment>; if (payments == null) { result.ResultStatus = -1; result.Message = "获取当前付款申请的付款执行失败"; return result; } //判断付款申请可付余额 decimal payedBala = payments.Sum(temp => temp.PayBala); if (payApply.ApplyBala - payedBala - payment.PayBala + resultObj.PayBala < 0) { result.ResultStatus = -1; result.Message = "当前付款金额大于可付余额"; return result; } //获取付款申请对应合约明细表 result = contractPayApplyDAL.GetByPayApplyId(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; Model.ContractPayApply contractPayApply = result.ReturnValue as Model.ContractPayApply; if (contractPayApply == null || contractPayApply.RefId <= 0) { result.ResultStatus = -1; result.Message = "付款申请关联合约获取失败"; return result; } //修改付款表 resultObj.PayBala = payment.PayBala; resultObj.FundsBala = payment.FundsBala; resultObj.VirtualBala = payment.VirtualBala; resultObj.PayStyle = payment.PayStyle; resultObj.PayBankId = payment.PayBankId; resultObj.PayBankAccountId = payment.PayBankAccountId; resultObj.PayCorp = payment.PayCorp; resultObj.PayDatetime = payment.PayDatetime; resultObj.RecevableCorp = payment.RecevableCorp; resultObj.ReceBankId = payment.ReceBankId; resultObj.ReceBankAccountId = payment.ReceBankAccountId; resultObj.ReceBankAccount = payment.ReceBankAccount; resultObj.FlowName = payment.FlowName; resultObj.Memo = payment.Memo; result = paymentDAL.Update(user, resultObj); if (result.ResultStatus != 0) return result; //获取付款合约明细 result = paymentContractDetailDAL.GetByPaymentId(user, payment.PaymentId); if (result.ResultStatus != 0) return result; Model.PaymentContractDetail resultDetail = result.ReturnValue as PaymentContractDetail; if (resultDetail == null || resultDetail.DetailId <= 0) { result.ResultStatus = -1; result.Message = "财务付款合约明细信息获取失败"; return result; } //修改付款合约明细 resultDetail.PaymentId = payment.PaymentId; resultDetail.PayBala = payment.PayBala; resultDetail.VirtualBala = payment.VirtualBala; resultDetail.FundsBala = payment.FundsBala; result = paymentContractDetailDAL.Update(user, resultDetail); if (result.ResultStatus != 0) return result; //虚拟收付款 //获取虚拟收付款明细 DAL.PaymentVirtualDAL paymentVirtualDAL = new PaymentVirtualDAL(); result = paymentVirtualDAL.GetByPaymentId(user, payment.PaymentId); if (result.ResultStatus != 0) return result; Model.PaymentVirtual paymentVirtual = result.ReturnValue as Model.PaymentVirtual; if (paymentVirtual == null) { result.ResultStatus = -1; result.Message = "获取虚拟收付款信息失败"; return result; } if (payment.VirtualBala == 0) { if (paymentVirtual.VirtualId > 0) { //作废原有虚拟收付款 result = paymentVirtualDAL.Invalid(user, paymentVirtual); if (result.ResultStatus != 0) return result; } } else { if (payment.VirtualBala > payment.PayBala) { result.ResultStatus = -1; result.Message = "虚拟付款金额不能大于付款总额"; return result; } if (paymentVirtual.VirtualId > 0) { //更新虚拟收付款 paymentVirtual.PayBala = payment.VirtualBala; result = paymentVirtualDAL.Update(user, paymentVirtual); if (result.ResultStatus != 0) return result; } else { //新增虚拟收付款 paymentVirtual.PayApplyId = resultObj.PayApplyId; paymentVirtual.PayBala = payment.VirtualBala; paymentVirtual.PaymentId = resultObj.PaymentId; paymentVirtual.DetailStatus = StatusEnum.已录入; result = paymentVirtualDAL.Insert(user, paymentVirtual); 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 payApplyId) { ResultModel result = new ResultModel(); try { PayApplyDAL payApplyDAL = new PayApplyDAL(); ApplyDAL applyDAL = new ApplyDAL(); 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 = applyDAL.Close(user, apply); if (result.ResultStatus != 0) return result; //关闭明细申请 if (payApply.PayApplySource == (int)FundsStyleEnum.ContractPayApply) { //获取付款申请下合约申请明细 ContractPayApplyDAL payApplyContractDAL = new ContractPayApplyDAL(); 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.Close(user, payApplyContract); if (result.ResultStatus != 0) return result; } else if (payApply.PayApplySource == (int)FundsStyleEnum.StockPayApply) { //获取付款申请下库存申请明细 StockPayApplyDAL payApplyStockDAL = new StockPayApplyDAL(); 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 = payApplyStockDAL.Close(user, payApplyStock); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel PaymentContractCreate(UserModel user, Model.Payment payment) { ResultModel result = new ResultModel(); try { DAL.PayApplyDAL payApplyDAL = new PayApplyDAL(); NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); DAL.ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL(); DAL.PaymentContractDetailDAL paymentContractDetailDAL = new PaymentContractDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证付款总额是否等于财务付款金额+虚拟付款金额 if (payment.PayBala != payment.FundsBala + payment.VirtualBala) { result.ResultStatus = -1; result.Message = "付款总额必须等于财务付款金额+虚拟付款金额"; 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; } //获取主申请 result = applyDAL.Get(user, payApply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "付款主申请不存在"; return result; } //判断申请状态是否已生效 if (apply.ApplyStatus != NFMT.Common.StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "付款申请非已生效状态,不能进行付款"; return result; } //获取当前付款申请中的所有付款 result = paymentDAL.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<Model.Payment> payments = result.ReturnValue as List<Model.Payment>; if (payments == null) { result.ResultStatus = -1; result.Message = "获取当前付款申请的付款执行失败"; return result; } //判断付款申请可付余额 decimal payedBala = payments.Sum(temp => temp.PayBala); if (payApply.ApplyBala - payedBala < 0) { result.ResultStatus = -1; result.Message = "当前付款申请已无余款可付"; return result; } if (payApply.ApplyBala - payedBala - payment.PayBala < 0) { result.ResultStatus = -1; result.Message = "当前付款金额大于可付余额"; return result; } //获取付款申请对应合约明细表 result = contractPayApplyDAL.GetByPayApplyId(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; Model.ContractPayApply contractPayApply = result.ReturnValue as Model.ContractPayApply; if (contractPayApply == null || contractPayApply.RefId <= 0) { result.ResultStatus = -1; result.Message = "付款申请关联合约获取失败"; return result; } //添加付款表 payment.PayEmpId = user.EmpId; payment.PayDept = apply.ApplyDept; payment.PayApplyId = payApply.PayApplyId; payment.PaymentStatus = StatusEnum.已录入; result = paymentDAL.Insert(user, payment); if (result.ResultStatus != 0) return result; int paymentId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out paymentId)) { result.ResultStatus = -1; result.Message = "付款新增失败"; return result; } payment.PaymentId = paymentId; //添加付款合约明细表 Model.PaymentContractDetail paymentContractDetail = new PaymentContractDetail(); paymentContractDetail.ContractId = contractPayApply.ContractId; paymentContractDetail.ContractSubId = contractPayApply.ContractSubId; paymentContractDetail.PayApplyDetailId = contractPayApply.RefId; paymentContractDetail.PaymentId = paymentId; paymentContractDetail.PayApplyId = payApply.PayApplyId; paymentContractDetail.PayBala = payment.PayBala; paymentContractDetail.FundsBala = payment.FundsBala; paymentContractDetail.VirtualBala = payment.VirtualBala; result = paymentContractDetailDAL.Insert(user, paymentContractDetail); if (result.ResultStatus != 0) return result; //添加虚拟收付款 if (payment.VirtualBala > 0) { if (payment.VirtualBala > payment.PayBala) { result.ResultStatus = -1; result.Message = "虚拟付款金额不能大于付款总额"; return result; } DAL.PaymentVirtualDAL virtualDAL = new PaymentVirtualDAL(); Model.PaymentVirtual paymentVirtual = new PaymentVirtual(); paymentVirtual.PayApplyId = payApply.PayApplyId; paymentVirtual.PayBala = payment.VirtualBala; paymentVirtual.PaymentId = paymentId; paymentVirtual.DetailStatus = StatusEnum.已录入; result = virtualDAL.Insert(user, paymentVirtual); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = paymentId; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
/// <summary> /// 获取付款申请审核内容 /// </summary> /// <param name="user"></param> /// <param name="applyId"></param> /// <param name="fundsStyleEnum"></param> /// <returns></returns> public ResultModel GetAuditInfo(UserModel user, int applyId, FundsStyleEnum fundsStyleEnum) { ResultModel result = new ResultModel(); ApplyDAL applyDAL = new ApplyDAL(); string customBala = string.Empty; int customCorpId = 0; try { //获取付款申请 result = this.payapplyDAL.GetByApplyId(user, applyId); if (result.ResultStatus != 0) return result; PayApply payApply = result.ReturnValue as PayApply; if (payApply == null) { result.ResultStatus = -1; result.Message = "获取失败"; return result; } customCorpId = payApply.RecCorpId; int subContractId; switch (fundsStyleEnum) { case FundsStyleEnum.合约付款申请: ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL(); result = contractPayApplyDAL.GetByPayApplyId(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; ContractPayApply contractPayApply = result.ReturnValue as ContractPayApply; if (contractPayApply == null) { result.ResultStatus = -1; result.Message = "获取失败"; return result; } subContractId = contractPayApply.ContractSubId; break; case FundsStyleEnum.库存付款申请: StockPayApplyDAL stockPayApplyDAl = new StockPayApplyDAL(); result = stockPayApplyDAl.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<StockPayApply> stockPayApplys = result.ReturnValue as List<StockPayApply>; if (stockPayApplys == null || !stockPayApplys.Any()) { result.ResultStatus = -1; result.Message = "获取失败"; return result; } subContractId = stockPayApplys.First().SubId; break; case FundsStyleEnum.发票付款申请://价外付款 subContractId = 0; break; default: subContractId = 0; break; } //获取客户余额 result = applyDAL.GetCustomerBala(user, customCorpId, subContractId, applyId, payApply.ApplyBala, 0); if (result.ResultStatus != 0) return result; customBala = result.ReturnValue.ToString(); if (!string.IsNullOrEmpty(customBala) && customBala.IndexOf('_') > -1) { string corpName = string.Empty; Corporation corp = UserProvider.Corporations.SingleOrDefault(a => a.CorpId == customCorpId); if (corp != null) corpName = corp.CorpName; decimal customBalaValue = 0; if (!decimal.TryParse(customBala.Split('_')[0], out customBalaValue)) { result.ResultStatus = -1; result.Message = "转换失败"; return result; } string currencyName = customBala.Split('_')[1].ToString(); string returnValue = string.Format("本次申请后,按照合同结算,{0} {1}(合{2}){3}", corpName, customBalaValue > 0 ? "余款" : "欠款", currencyName, string.Format("{0:N}", customBalaValue)); if (customBalaValue < 0) { returnValue = string.Format("<font color='#660000'>{0}</font>", returnValue); } result.ResultStatus = 0; result.ReturnValue = returnValue; } else { result.Message = "获取客户余额失败"; result.ResultStatus = -1; return result; } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
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; }
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; }
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; }
public ResultModel PayApplyContractUpdate(UserModel user, PayApply payApply, string memo, int deptId, int corpId) { ResultModel result = new ResultModel(); try { ContractSubDAL subDAL = new ContractSubDAL(); ApplyDAL applyDAL = new ApplyDAL(); PayApplyDAL payApplyDAL = new PayApplyDAL(); ContractPayApplyDAL contractPayApplyDAL = new ContractPayApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证付款申请 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 = contractPayApplyDAL.GetByPayApplyId(user, resultObj.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; } //验证子合约信息 result = subDAL.Get(user, contractPayApply.ContractSubId); if (result.ResultStatus != 0) return result; ContractSub sub = result.ReturnValue as ContractSub; if (sub == null || sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } //验证可申请金额 //NFMT.Data.Model.FuturesPrice futuresPrice = NFMT.Data.BasicDataProvider.FuturesPrices[0]; //更新申请主表 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.PayApplySource = (int)FundsStyleEnum.ContractPayApply; 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; //更新Fun_ContractPayApply_Ref合约付款申请 contractPayApply.ApplyBala = payApply.ApplyBala; result = contractPayApplyDAL.Update(user, contractPayApply); if (result.ResultStatus != 0) return result; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }