/// <summary> /// 获取可足科填充科目(自动填帐规则) /// </summary> /// <param name="amount"></param> /// <returns></returns> public override List <BillItem> GetFillItems(decimal amount) { List <Bill> bills = BillDAL.GetArrearsBills(Business.Bills).OrderBy(o => o.CreateTime).ToList(); List <BillItem> items = new List <BillItem>(); foreach (Bill bill in bills) { foreach (var subject in Subjects) { var item = bill.BillItems.Where(p => subject.Contains(p.Subject.ValueToEnum <EnumCostSubject>()) && !p.IsShelve); var amt = item.Sum(p => p.DueAmt - p.ReceivedAmt); if (amt <= 0) { continue; } if (amount >= amt) { amount -= amt; items.AddRange(item); } if (amount == 0) { break; } } if (amount == 0) { break; } } return(items); }
/// <summary> /// 为提前清贷订单进行自动填帐收款 /// </summary> /// <param name="business"></param> /// <param name="payid"></param> /// <param name="filter"></param> /// <param name="lstUpdateItem"></param> /// <param name="lstReceived"></param> protected void AutoReceivedByCLoan(Business business, int payid, PayAccountFilter filter , List <UpdateItem> lstUpdateItem, List <Received> lstReceived) { var bills = BillDAL.GetArrearsBills(business.Bills); CloanApply apply = null; var lstApply = Singleton <CloanApplyDetailDAL <CloanApply> > .Instance.SearchData(filter); if (lstApply == null || lstApply.Count == 0) { return; } apply = lstApply[0]; IEnumerable <CloanApplyItem> items = new List <CloanApplyItem>(); if (apply != null) { filter.CloanApplyID = apply.CloanApplyID; apply.CloanApplyItems = Singleton <CloanApplyItemDetailDAL <CloanApplyItem> > .Instance.SearchData(filter); items = apply.CloanApplyItems.Where(p => p.IsAnnul); } if (bills.Count > 0) { if (items.Count() > 0)//有减免项,先做减免 { //提前清贷服务费重置为不包括减免金额 Bill advbill = bills.FirstOrDefault(p => p.BillType == (byte)EnumBillKind.Advance); BillItem billitem = advbill.BillItems.FirstOrDefault(p => p.Subject == (byte)EnumCostSubject.AdvServiceFee); billitem.DueAmt = billitem.DueAmt + items.Sum(p => p.Amount); lstUpdateItem.Add(new UpdateItem { Id = billitem.BillItemID, Amount = billitem.DueAmt, Type = 2 }); //billItemDAL.Update(billitem); foreach (var item in items) { AnnulBillItemBySubAndAmount(bills, item.Subject, item.Amount, payid, DateTime.Now, lstReceived, lstUpdateItem); } } foreach (var bill in bills) { FtpAdvRecevied(bill.BillItems.Where(p => p.DueAmt - p.ReceivedAmt > 0).ToList(), payid, DateTime.Now , filter.UserId, filter.Explain, lstReceived, lstUpdateItem, EnumAdjustKind.Transfer); } //apply.CloanApplyStatus = (byte)EnumCloanApplyStatus.Success; //cLoanApplyDAL.Update(apply); } else { m_Logger.Error("提前清贷出错,未找到相应账单:" + business.BusinessID);; } }
/// <summary> /// 创建罚息科目 /// </summary> public override BillItem CreatePunitiveInterest(DateTime limitTime, List <PenaltyInt> penaltyInts) { // 获取当期帐单,为NULL或已在第三次扣失日前全额付清则继续循环 var nbills = BillDAL.GetNormalBills(Business.Bills); var prevBill = nbills.FirstOrDefault(p => p.BillMonth == _PrevMonth); var curBill = nbills.FirstOrDefault(p => p.BillMonth == _CurMonth); // 判断是否存在原因帐单或当期帐单,不存在则返回NULL if (prevBill == null || curBill == null || Business.Bills.Count == 1 || (limitTime >= prevBill.FullPaidTime && prevBill.FullPaidTime != null)) { return(null); } // 获取本金、利息或租金等参与科目,计算上期所欠本息或租金 var subjects = new List <byte> { (byte)EnumCostSubject.Capital, (byte)EnumCostSubject.Interest, (byte)EnumCostSubject.Rent }; // 是否为渤海订单, 渤海订单一次性生成一个月的罚息, 其他合同都按日罚息千分之一计算 bool isBoHai = Business.LendingSideKey.EndsWith(EnumCompanyKey.BHXT_LENDING.ToEnumName()); decimal debtsPrincipal = 0; if (isBoHai) { // 获取普通帐单的所欠本息 var bills = BillDAL.GetArrearsBills(Business.Bills, true); foreach (var bill in bills) { debtsPrincipal += bill.BillItems.Where(p => subjects.Contains(p.Subject) && !p.IsCurrent) .Sum(p => p.DueAmt - p.ReceivedAmt); } // 判断欠费帐单是否存在未归还所欠本息或租金,无则不生成罚息 if (debtsPrincipal <= 0) { return(null); } debtsPrincipal = SubjectFormula.CalculatPunitiveInterest(debtsPrincipal, 0.03m); } else { // 获取上期帐单的本息欠费 debtsPrincipal = prevBill.BillItems.Where(p => subjects.Contains(p.Subject)) .Sum(s => s.DueAmt - s.ReceivedAmt); // 判断上期帐单是否存在未归还所欠本息或租金,无则不生成罚息 if (debtsPrincipal <= 0) { return(null); } var beginDay = DateTime.Now.AddMonths(-1).SetDay(21); // 在罚息表中计算罚息金额 CalculatPenaltyInt(penaltyInts, debtsPrincipal, prevBill.BillID, curBill.BillID, beginDay); // 当所欠本息大于零时,计算从上月21日至今天数的罚息 var totalDays = DateTime.Now - beginDay; debtsPrincipal = SubjectFormula.CalculatPunitiveInterest(debtsPrincipal, Business.PenaltyRate, totalDays.Days); } // 创建罚息科目(科目名称、金额) return(CreateBillItem(EnumCostSubject.PunitiveInterest, debtsPrincipal, false, curBill.BillID)); }
/// <summary> /// 检索数据 /// </summary> /// <param name="filter"></param> /// <param name="responseEntity"></param> public void PayAccount(PayAccountFilter filter, ResponseEntity responseEntity) { if (filter == null) { ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.RequestCommandError); return; } string message = ""; string guid = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(filter.JsonString)) { if (!BusinessHelper.JsonToReceivedItem(filter, guid)) { message = "错误,实收金额不允许大于应收金额!"; ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.Others, message); m_Logger.Info(message); return; } } if (filter.Amout > 0) { // 获取订单信息 Business business = BusinessHelper.GetBusinessInfo(filter); List <UpdateItem> lstUpdateItem = new List <UpdateItem>(); List <Received> lstReceived = new List <Received>(); // 根据不同订单清贷状态分别处理 if (business.CLoanStatus == (byte)EnumCLoanStatus.AdvanceProcess) { #region 提前清贷自动填帐 var bills = BillDAL.GetArrearsBills(business.Bills); var countAmout = bills.Sum(b => b.BillItems.Sum(i => i.DueAmt - i.ReceivedAmt)); // 提前清贷订单自定义付款金额必须大于等于提前清贷总额 if (filter.Amout < countAmout) { message = "抱歉,您的输入金额不足,提前清贷订单【欠费:" + countAmout + "】必须足额支付!"; ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.Others, message); m_Logger.Info(message); return; } AutoReceivedByCLoan(business, 0, filter, lstUpdateItem, lstReceived); // 插入临时表数据 BusinessHelper.SaveUpdateItemTempDataBase(guid, lstUpdateItem); BusinessHelper.SaveReceivedTempDataBase(guid, lstReceived); // 更新订单、帐单信息 filter.UpdateCloanApplyStatus = 1; filter.Guid = guid; Singleton <BusinessPayAccountDAL> .Instance.Update(filter); // 更新订单、帐单信息 //UpdateBusinessInfo(filter, responseEntity); //decimal losAmt = filter.Amout - countAmout; var result = new PayAccountResultViewData(); result.LostAmt = filter.Amout - countAmout; var responseResult = new ResponseListResult <PayAccountResultViewData>(); responseResult.TotalCount = 1; responseResult.LstResult = new List <PayAccountResultViewData>(); responseResult.LstResult.Add(result); responseEntity.Results = responseResult; responseEntity.ResponseStatus = (int)EnumResponseState.Success; return; #endregion } else if (business.CLoanStatus == (byte)EnumCLoanStatus.Refunding) { #region 普通账单自动填帐 VcreditProduct s = null; if (business.ProductType == 8) { s = new JingAnMortgageLoan(business); } else if (business.ProductType == 9) { s = new JingAnUnMortgageLoan(business); } else { s = new UnsecuredLoan(business); } //成都填充项判断 List <BillItem> list = s.GetFillItems(filter.Amout); if (list == null || list.Count < 1) { message = "金额不足,无法填充款项!"; ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.Others, message); m_Logger.Info(message); return; } decimal couAcmou = 0; //余额 foreach (var item in list) { decimal ssrmt = item.DueAmt - item.ReceivedAmt; couAcmou += ssrmt; item.ReceivedAmt = item.DueAmt; item.FullPaidTime = filter.Dectime; lstUpdateItem.Add(new UpdateItem { Id = item.BillItemID, Amount = item.DueAmt, FullPaidTime = filter.Dectime, Type = 3 }); //_FinanceFactory.CreateBillItemDAL().Update(item); //_FinanceContext.SaveChanges(); lstReceived.Add(new Received { BillID = item.BillID, BillItemID = item.BillItemID, Amount = ssrmt, CreateTime = DateTime.Now, OperatorID = filter.UserId, PayID = 0, ReceivedTime = filter.Dectime, ReceivedType = (byte)EnumAdjustKind.Transfer, DeductionID = 0, Explain = "" }); } // 插入临时表数据 BusinessHelper.SaveUpdateItemTempDataBase(guid, lstUpdateItem); BusinessHelper.SaveReceivedTempDataBase(guid, lstReceived); // 更新订单、帐单信息 filter.UpdateCloanApplyStatus = 0; filter.Guid = guid; Singleton <BusinessPayAccountDAL> .Instance.Update(filter); // 更新订单、帐单信息 //UpdateBusinessInfo(filter, responseEntity); //decimal losAmt = filter.Amout - couAcmou; var result = new PayAccountResultViewData(); result.LostAmt = filter.Amout - couAcmou; var responseResult = new ResponseListResult <PayAccountResultViewData>(); responseResult.TotalCount = 1; responseResult.LstResult = new List <PayAccountResultViewData>(); responseResult.LstResult.Add(result); responseEntity.Results = responseResult; responseEntity.ResponseStatus = (int)EnumResponseState.Success; //ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.Success); #endregion } else { message = "抱歉,当前的订单状态不允许手工扣款!"; ServiceUtility.SetResponseStatus(responseEntity, EnumResponseState.Others, message); m_Logger.Info(message); return; } } }