177 lines
8.2 KiB
Java
177 lines
8.2 KiB
Java
package com.tenwa.reckon.executor;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.tenwa.reckon.bean.ConditionBean;
|
|
import com.tenwa.reckon.bean.FundRentPlanBean;
|
|
import com.tenwa.reckon.bean.TabCalBean;
|
|
import com.tenwa.reckon.help.PlanDateServiceImpl;
|
|
import com.tenwa.reckon.help.RentPlanContrCalDAOImpl;
|
|
import com.tenwa.reckon.util.NumberUtils;
|
|
|
|
public abstract class FundRentPlanExecutor {
|
|
public JBOTransaction tx;
|
|
public FundRentPlanExecutor(JBOTransaction tx){
|
|
this.tx=tx;
|
|
}
|
|
//租金含税算法
|
|
public void addRentRate(ConditionBean cb,FundRentPlanBean fpb){
|
|
// 0.17 税 0.13 附加税
|
|
//租金=(测算租金*0.17*0.13/(1-0.17*0.13)+测算租金)*1.17 利息=租金-本金
|
|
List<String> rentList=fpb.getRentList();//租金
|
|
List<String> corpusList=fpb.getCorpusBusinessList();//本金
|
|
List<String> c1=fpb.getColumn_1();
|
|
List<String> rentListNew=new ArrayList<String>();//新的租金
|
|
List<String> interestListNew=new ArrayList<String>();//新的利息
|
|
List<String> c2New=new ArrayList<String>();
|
|
|
|
BigDecimal rate=new BigDecimal(NumberUtils.nullToZero( cb.getRate()));
|
|
BigDecimal additionalRate=new BigDecimal(NumberUtils.nullToZero(cb.getAdditionalRate()));
|
|
for(int i=0;i<rentList.size();i++){
|
|
BigDecimal rentNew=new BigDecimal(rentList.get(i)).multiply(rate).multiply(additionalRate).divide(BigDecimal.ONE.subtract(rate.multiply(additionalRate)),20,BigDecimal.ROUND_HALF_UP).add(new BigDecimal(rentList.get(i))).multiply(BigDecimal.ONE.add(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
BigDecimal interestNew=rentNew.subtract(new BigDecimal(corpusList.get(i)));
|
|
rentListNew.add(rentNew.toString());
|
|
interestListNew.add(interestNew.toString());
|
|
if(cb.getSettleMethod().equals("even_interest")){
|
|
c2New.add(rentNew.subtract(new BigDecimal(c1.get(i))).toString());
|
|
}
|
|
}
|
|
fpb.setRentList(rentListNew);
|
|
fpb.setInterestBusinessList(interestListNew);
|
|
fpb.setColumn_2(c2New);
|
|
}
|
|
|
|
public void addRentPlan(FundRentPlanBean fpb, TabCalBean tcb, int startList) throws Exception{
|
|
if (fpb != null && fpb.getRentList() != null && fpb.getRentList().size() > 0) {
|
|
List<String> rent_list = fpb.getRentList();// 租金列表
|
|
|
|
List<String> planDate_list = fpb.getPlanDateList();// 日期列表
|
|
List<String> interestDateList=fpb.getInterestDateList();//计息日期列表
|
|
List<String> corpus_list = fpb.getCorpusBusinessList();// 本金列表
|
|
List<String> corpusOverage_list = fpb.getCorpusOverageBusinessList();// 本金余额列表
|
|
List<String> interest_list = fpb.getInterestBusinessList();// 利息列表
|
|
List<String> year_rate_list = new ArrayList<String>();
|
|
List<String> rent_adjust = fpb.getRentAdjustList();// 租金调整列
|
|
if(interestDateList.size()==0){
|
|
interestDateList=planDate_list;
|
|
}
|
|
int flag = 1;// 是否添加租金调整列
|
|
if (null == rent_adjust || (null != rent_adjust && rent_adjust.size() == 0) || rent_adjust.get(0) == null) {
|
|
flag = 0;
|
|
}
|
|
if (fpb.getYearRateList() == null || (null != fpb.getYearRateList() && fpb.getYearRateList().size() == 0)) {
|
|
for (int i = 0; i < fpb.getRentList().size(); i++) {
|
|
year_rate_list.add(fpb.getYearRate());
|
|
}
|
|
} else {
|
|
if (fpb.getYearRateList().size() != fpb.getRentList().size()) {
|
|
for (int i = fpb.getYearRateList().size() - 1; i >= startList - 1; i--) {
|
|
year_rate_list.add(0, fpb.getYearRateList().get(i));
|
|
}
|
|
} else {
|
|
year_rate_list = fpb.getYearRateList();
|
|
}
|
|
|
|
}
|
|
// Column_1和Column_2 是均息法下的均息法本息,暂时只有在均息法的测算中会处理,
|
|
// 所以其他的地方直接赋值本息
|
|
if (fpb.getColumn_1() == null || fpb.getColumn_1().size() == 0) {
|
|
fpb.setColumn_1(fpb.getCorpusBusinessList());
|
|
fpb.setColumn_2(fpb.getInterestBusinessList());
|
|
}
|
|
BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRentPlan_tb(), tx);
|
|
for (int i = 0; i < rent_list.size(); i++) {
|
|
BizObject rent=bm.newObject();
|
|
rent.setAttributeValue("flowunid",tcb.getDocId());
|
|
rent.setAttributeValue(tcb.getPlanCName(), tcb.getPlanCValue());
|
|
rent.setAttributeValue("plan_list",startList);
|
|
rent.setAttributeValue("plan_date",planDate_list.get(i));
|
|
rent.setAttributeValue("INTEREST_DATE", interestDateList.get(i));
|
|
rent.setAttributeValue("plan_status","未回笼");
|
|
rent.setAttributeValue("rent",NumberUtils.nullToZero( rent_list.get(i) ));
|
|
rent.setAttributeValue("corpus",NumberUtils.nullToZero( corpus_list.get(i) ));
|
|
rent.setAttributeValue("year_rate",NumberUtils.nullToZero( year_rate_list.get(i) ));
|
|
rent.setAttributeValue("interest",NumberUtils.nullToZero( interest_list.get(i) ));
|
|
rent.setAttributeValue("all_remain_corpus",NumberUtils.nullToZero( corpusOverage_list.get(i) ));
|
|
rent.setAttributeValue("CORPUS_BUSINESS",fpb.getColumn_1().get(i));
|
|
rent.setAttributeValue("INTEREST_BUSINESS",fpb.getColumn_2().get(i));
|
|
|
|
if(flag >0){
|
|
rent.setAttributeValue("rent_adjust",rent_adjust.get(i).equals("") ? "null" : rent_adjust.get(i));
|
|
}
|
|
startList++;
|
|
bm.saveObject(rent);
|
|
}
|
|
}
|
|
|
|
}
|
|
public void deleteRentPlan(String tbName, TabCalBean tcb, int startList) throws Exception{
|
|
BizObjectManager bm=JBOFactory.getBizObjectManager(tcb.getRentPlan_tb(), tx);
|
|
|
|
String sql = " delete from O where flowunid='" + tcb.getDocId() + "' and "+tcb.getPlanCName()+"='"+tcb.getPlanCValue()+"' and plan_list>=" + startList;
|
|
|
|
bm.createQuery(sql).executeUpdate();
|
|
}
|
|
public abstract FundRentPlanBean create(TabCalBean tcb,Integer startList) throws Exception ;
|
|
|
|
public FundRentPlanBean createOnhire(TabCalBean tcb ) throws Exception {
|
|
ConditionBean cb = tcb.getCb();
|
|
// 查询他的租金计划
|
|
RentPlanContrCalDAOImpl rpccdi = new RentPlanContrCalDAOImpl();
|
|
FundRentPlanBean frpb = rpccdi.getRentAndDateByTcb(tcb, 1,tx);
|
|
frpb.setRentAdjustList(new ArrayList<String>());// 租金调整值
|
|
// 根据交易结构重新算出的租金计划日期
|
|
// 日期类返回租金列表
|
|
PlanDateServiceImpl pdsi = new PlanDateServiceImpl(tx);
|
|
frpb.setPlanDateList(pdsi.getPlanDateList(cb, String.valueOf(frpb.getRentList().size())));
|
|
// 更新租金计划 的时间
|
|
pdsi.updateRentPlanDate(tcb.getRentPlan_tb(), tcb, 1, frpb.getPlanDateList());
|
|
return frpb;
|
|
}
|
|
/**
|
|
* 车辆均息:分摊本金=车辆款*产品配置一年内本金比例+参与融资并选择分摊费用项
|
|
* 尾款 = 车辆款-首付款-(车辆款*产品配置一年内本金比例)+参与融资并选择尾款费用项
|
|
*/
|
|
public void initShareAndRetainage(TabCalBean tcb, ConditionBean cb) throws Exception{
|
|
//获取车辆款
|
|
BigDecimal equipAmt = new BigDecimal(cb.getEquipAmt());
|
|
//获取首付款
|
|
BigDecimal firstPayment = new BigDecimal(cb.getFirstPayment());
|
|
//或者产品配置一年内本金比例(在设备款的限定比例)
|
|
//String corpusRatio = ProductParamUtil.getProductParameterValue(tcb.getProductId(), "PRD0315", "EQUIP_AMT", "CostType09");
|
|
//获得分摊本金
|
|
//BigDecimal share = equipAmt.multiply(new BigDecimal(corpusRatio).divide(new BigDecimal("100"),20,BigDecimal.ROUND_HALF_UP)).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
BigDecimal share = new BigDecimal(cb.getCorpus());
|
|
//获得尾款本金
|
|
BigDecimal retainage = equipAmt.subtract(firstPayment).subtract(share);
|
|
//计算参与融资费用
|
|
if("finatype02".equals(cb.getPurchaseTaxFina())){//购置税
|
|
share = share.add(new BigDecimal(cb.getPurchaseTax()));
|
|
}else if("finatype03".equals(cb.getPurchaseTaxFina())){
|
|
retainage = retainage.add(new BigDecimal(cb.getPurchaseTax()));
|
|
}
|
|
if("finatype02".equals(cb.getInsurancePremiumFina())){//保险费
|
|
share = share.add(new BigDecimal(cb.getInsurancePremium()));
|
|
}else if("finatype03".equals(cb.getInsurancePremiumFina())){
|
|
retainage = retainage.add(new BigDecimal(cb.getInsurancePremium()));
|
|
}
|
|
if("finatype02".equals(cb.getIncidentalFina())){//杂费
|
|
share = share.add(new BigDecimal(cb.getIncidental()));
|
|
}else if("finatype03".equals(cb.getIncidentalFina())){
|
|
retainage = retainage.add(new BigDecimal(cb.getIncidental()));
|
|
}
|
|
if("finatype02".equals(cb.getFactoryAccessoriesFina())){//原厂配置费
|
|
share = share.add(new BigDecimal(cb.getFactoryAccessories()));
|
|
}else if("finatype03".equals(cb.getFactoryAccessoriesFina())){
|
|
retainage = retainage.add(new BigDecimal(cb.getFactoryAccessories()));
|
|
}
|
|
cb.setShare(share);
|
|
cb.setRetainage(retainage);
|
|
}
|
|
}
|