public ResultModel PaymentStockCreate(UserModel user, Model.Payment payment, List<Model.PaymentStockDetail> paymentStockDetails, int payApplyId) { ResultModel result = new ResultModel(); try { DAL.PayApplyDAL payApplyDAL = new PayApplyDAL(); NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); DAL.StockPayApplyDAL stockPayApplyDAL = new StockPayApplyDAL(); DAL.PaymentStockDetailDAL paymentStockDetailDAL = new PaymentStockDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //设置库存明细付款总额 foreach (Model.PaymentStockDetail d in paymentStockDetails) { d.PayBala = d.FundsBala + d.VirtualBala; } //验证付款总额是否等于财务付款金额+虚拟付款金额 if (payment.PayBala != payment.FundsBala + payment.VirtualBala) { result.ResultStatus = -1; result.Message = "付款总额必须等于财务付款金额+虚拟付款金额"; return result; } //验证付款申请 result = payApplyDAL.Get(user, 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 = stockPayApplyDAL.Load(user, payApply.PayApplyId); if (result.ResultStatus != 0) return result; List<Model.StockPayApply> stockPayApplies = result.ReturnValue as List<Model.StockPayApply>; if (stockPayApplies == null) { result.ResultStatus = -1; result.Message = "付款申请关联合约获取失败"; return result; } foreach (PaymentStockDetail d in paymentStockDetails) { if (d.PayBala > 0) { //获取当前库存付款明细列表 result = paymentStockDetailDAL.LoadByStockPayApplyId(user, d.PayApplyDetailId); if (result.ResultStatus != 0) return result; List<Model.PaymentStockDetail> details = result.ReturnValue as List<Model.PaymentStockDetail>; decimal detailPayedBala = details.Sum(temp => temp.PayBala); var ls = paymentStockDetails.Where(temp => temp.PayApplyDetailId == d.PayApplyDetailId); decimal detailPayingBala = ls.Sum(temp => temp.PayBala); //获取对应的申请明细 result = stockPayApplyDAL.Get(user, d.PayApplyDetailId); if (result.ResultStatus != 0) return result; StockPayApply stockPayApply = result.ReturnValue as StockPayApply; if (stockPayApply == null || stockPayApply.RefId <= 0) { result.ResultStatus = -1; result.Message = string.Format("库存明细获取失败"); return result; } if (stockPayApply.ApplyBala - detailPayedBala - detailPayingBala < 0) { result.ResultStatus = -1; result.Message = string.Format("库存明细付款超额"); return result; } } } decimal sumFundsBala = paymentStockDetails.Sum(temp => temp.FundsBala); decimal sumVirtualBala = paymentStockDetails.Sum(temp => temp.VirtualBala); decimal sumPayBala = sumFundsBala + sumVirtualBala; //添加付款表 payment.PayEmpId = user.EmpId; payment.PayDept = apply.ApplyDept; payment.PayApplyId = payApply.PayApplyId; payment.PayBala = sumPayBala; payment.FundsBala = sumFundsBala; payment.VirtualBala = sumVirtualBala; 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.StockPayApply payApplyStock = stockPayApplies[0]; Model.PaymentContractDetail paymentContractDetail = new PaymentContractDetail(); paymentContractDetail.ContractId = payApplyStock.ContractId; paymentContractDetail.ContractSubId = payApplyStock.SubId; paymentContractDetail.PayApplyDetailId = payApplyStock.ContractRefId; paymentContractDetail.PayApplyId = payApplyStock.PayApplyId; paymentContractDetail.PayBala = sumPayBala; paymentContractDetail.FundsBala = sumFundsBala; paymentContractDetail.VirtualBala = sumVirtualBala; paymentContractDetail.PaymentId = paymentId; DAL.PaymentContractDetailDAL paymentContractDetailDAL = new PaymentContractDetailDAL(); result = paymentContractDetailDAL.Insert(user, paymentContractDetail); 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; } //添加付款库存明细表 foreach (PaymentStockDetail d in paymentStockDetails) { if (d.PayBala > 0) { //获取库存付款申请 result = stockPayApplyDAL.Get(user, d.PayApplyDetailId); if (result.ResultStatus != 0) return result; Model.StockPayApply dp = result.ReturnValue as Model.StockPayApply; if (dp == null || dp.RefId <= 0) { result.ResultStatus = -1; result.Message = "对应付款申请获取失败"; return result; } d.DetailStatus = Common.StatusEnum.已生效; d.PayApplyId = payApply.PayApplyId; d.PaymentId = paymentId; d.ContractDetailId = contractRefId; d.ContractId = paymentContractDetail.ContractId; d.SubId = paymentContractDetail.ContractSubId; d.StockId = dp.StockId; d.StockLogId = dp.StockLogId; d.PayBala = d.FundsBala + d.VirtualBala; result = paymentStockDetailDAL.Insert(user, d); 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; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public override IModel CreateModel(SqlDataReader dr) { PaymentVirtual paymentvirtual = new PaymentVirtual(); int indexVirtualId = dr.GetOrdinal("VirtualId"); paymentvirtual.VirtualId = Convert.ToInt32(dr[indexVirtualId]); int indexPaymentId = dr.GetOrdinal("PaymentId"); paymentvirtual.PaymentId = Convert.ToInt32(dr[indexPaymentId]); int indexPayApplyId = dr.GetOrdinal("PayApplyId"); if(dr["PayApplyId"] != DBNull.Value) { paymentvirtual.PayApplyId = Convert.ToInt32(dr[indexPayApplyId]); } int indexPayBala = dr.GetOrdinal("PayBala"); if(dr["PayBala"] != DBNull.Value) { paymentvirtual.PayBala = Convert.ToDecimal(dr[indexPayBala]); } int indexDetailStatus = dr.GetOrdinal("DetailStatus"); if(dr["DetailStatus"] != DBNull.Value) { paymentvirtual.DetailStatus = (StatusEnum)Convert.ToInt32(dr[indexDetailStatus]); } int indexIsConfirm = dr.GetOrdinal("IsConfirm"); if(dr["IsConfirm"] != DBNull.Value) { paymentvirtual.IsConfirm = Convert.ToBoolean(dr[indexIsConfirm]); } int indexMemo = dr.GetOrdinal("Memo"); if(dr["Memo"] != DBNull.Value) { paymentvirtual.Memo = Convert.ToString(dr[indexMemo]); } int indexConfirmMemo = dr.GetOrdinal("ConfirmMemo"); if(dr["ConfirmMemo"] != DBNull.Value) { paymentvirtual.ConfirmMemo = Convert.ToString(dr[indexConfirmMemo]); } int indexFundsLogId = dr.GetOrdinal("FundsLogId"); if(dr["FundsLogId"] != DBNull.Value) { paymentvirtual.FundsLogId = Convert.ToInt32(dr[indexFundsLogId]); } return paymentvirtual; }
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; }