148 lines
6.6 KiB
Java
148 lines
6.6 KiB
Java
package com.tenwa.reckon.help;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import jbo.app.tenwa.calc.LC_CALC_CONDITION_TEMP;
|
|
import jbo.app.tenwa.calc.LC_RENT_PLAN_TEMP;
|
|
import jbo.com.tenwa.lease.comm.LC_HANDLING_APPORTION;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
import com.amarsoft.are.jbo.BizObjectManager;
|
|
import com.amarsoft.are.jbo.JBOException;
|
|
import com.amarsoft.are.jbo.JBOFactory;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.amarsoft.awe.util.Transaction;
|
|
import com.tenwa.lease.app.quartzmession.SplitInts;
|
|
import com.tenwa.reckon.constant.Scale;
|
|
import com.tenwa.reckon.util.DateTools;
|
|
|
|
public class HandlingApportionManager {
|
|
|
|
public static void setHandlingApportion(String flowunid,String contractid,String paymentNumber,JBOTransaction tx) throws JBOException{
|
|
BizObject boLCCT = JBOFactory.getBizObjectManager(LC_CALC_CONDITION_TEMP.CLASS_NAME,tx)
|
|
.createQuery("flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"'").getSingleResult(false);
|
|
//手续费
|
|
BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString());
|
|
|
|
BizObject boLRPT = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx)
|
|
.createQuery("select v.sum(interest) v.Interest from O where flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"'").getSingleResult(false);
|
|
|
|
//总利息
|
|
BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("Interest").getString());
|
|
|
|
List<BizObject> boLRPTs = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx)
|
|
.createQuery("flowunid='"+flowunid+"' and payment_number='"+paymentNumber+"' order by plan_list").getResultList(false);
|
|
|
|
List<String> dateList = getDateList(boLRPTs);
|
|
//按日计算手续费分摊
|
|
List<Map<String,BigDecimal>> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+"");
|
|
|
|
BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx);
|
|
bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate();
|
|
//入库
|
|
int n = 0;
|
|
for(BizObject bo:boLRPTs){
|
|
BizObject boLHA = bomLHA.newObject();
|
|
boLHA.setAttributeValue("CONTRACT_ID",contractid);
|
|
boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString());
|
|
boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber);
|
|
boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money"));
|
|
boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio"));
|
|
bomLHA.saveObject(boLHA);
|
|
n++;
|
|
}
|
|
}
|
|
|
|
public static void setSingleHandlingApportion(String flowunid,String paymentNumber,String contractid,JBOTransaction tx) throws JBOException{
|
|
BizObject boLCCT = JBOFactory.getBizObjectManager(LC_CALC_CONDITION_TEMP.CLASS_NAME,tx)
|
|
.createQuery("flowunid='"+flowunid+"'").getSingleResult(false);
|
|
//手续费
|
|
BigDecimal handMoney = new BigDecimal(boLCCT.getAttribute("HANDLING_CHARGE_MONEY").getString());
|
|
|
|
BizObject boLRPT = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx)
|
|
.createQuery("select v.sum(interest) v.allInterest from O where flowunid='"+flowunid+"'").getSingleResult(false);
|
|
|
|
//总利息
|
|
BigDecimal allInterest = new BigDecimal(boLRPT.getAttribute("allInterest").getString());
|
|
|
|
List<BizObject> boLRPTs = JBOFactory.getBizObjectManager(LC_RENT_PLAN_TEMP.CLASS_NAME,tx)
|
|
.createQuery("flowunid='"+flowunid+"' order by plan_list").getResultList(false);
|
|
|
|
List<String> dateList = getDateList(boLRPTs);
|
|
//按日计算手续费分摊
|
|
List<Map<String,BigDecimal>> handMoneyList = gethandMoneyList(handMoney.toString(), dateList, boLCCT.getAttribute("START_DATE").getString(), boLCCT.getAttribute("PERIOD_TYPE").getString(), boLCCT.getAttribute("INCOME_INTERVAL_MONTH").getInt()+"");
|
|
|
|
BizObjectManager bomLHA = JBOFactory.getBizObjectManager(LC_HANDLING_APPORTION.CLASS_NAME,tx);
|
|
bomLHA.createQuery("delete from O where payment_number='"+paymentNumber+"'").executeUpdate();
|
|
//入库
|
|
int n = 0;
|
|
for(BizObject bo:boLRPTs){
|
|
BizObject boLHA = bomLHA.newObject();
|
|
boLHA.setAttributeValue("CONTRACT_ID",contractid);
|
|
boLHA.setAttributeValue("PLAN_LIST",bo.getAttribute("PLAN_LIST").getString());
|
|
boLHA.setAttributeValue("PAYMENT_NUMBER",paymentNumber);
|
|
boLHA.setAttributeValue("HANDLING_APPORTION_MONEY",handMoneyList.get(n).get("money"));
|
|
boLHA.setAttributeValue("HANDLING_APPORTION_RATIO",handMoneyList.get(n).get("ratio"));
|
|
bomLHA.saveObject(boLHA);
|
|
n++;
|
|
}
|
|
}
|
|
|
|
public static List<String> getDateList(List<BizObject> bos) throws JBOException{
|
|
List<String> dateList = new ArrayList<String>();
|
|
for(BizObject bo:bos){
|
|
dateList.add(bo.getAttribute("PLAN_DATE").getString());
|
|
}
|
|
return dateList;
|
|
}
|
|
|
|
public static List<Map<String,BigDecimal>> gethandMoneyList(String handMoney,List<String> dateList,String startDate,String period_type,String incomeNumberyear){
|
|
List<Map<String,BigDecimal>> handMoneyList=new ArrayList<Map<String,BigDecimal>>();
|
|
try {
|
|
BigDecimal hmoney=new BigDecimal(handMoney);
|
|
int number=Integer.parseInt(incomeNumberyear);
|
|
if("period_type_1".equals(period_type)){
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
|
|
dateList.remove(0);
|
|
Calendar enddate=Calendar.getInstance();
|
|
enddate.setTime(sdf.parse(dateList.get(dateList.size()-1)));
|
|
enddate.add(Calendar.MONTH, number);
|
|
dateList.add(sdf.format(enddate.getTime()));
|
|
}
|
|
BigDecimal money=BigDecimal.ZERO;
|
|
BigDecimal all=BigDecimal.ZERO;
|
|
all=new BigDecimal(DateTools.getDateDiff(dateList.get(dateList.size()-1), startDate));
|
|
for(int i=0;i<dateList.size();i++){
|
|
Map<String,BigDecimal> hand = new HashMap<String,BigDecimal>();
|
|
BigDecimal mon=BigDecimal.ZERO;
|
|
BigDecimal ratio=BigDecimal.ZERO;
|
|
long dateDiff=DateTools.getDateDiff(dateList.get(i), startDate);
|
|
if(i<dateList.size()-1){
|
|
BigDecimal cur=new BigDecimal(dateDiff);
|
|
ratio=cur.divide(all,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
|
|
mon=hmoney.multiply(cur).divide(all,Scale.CORPUS_SCALE,BigDecimal.ROUND_HALF_UP);
|
|
money=money.add(mon);
|
|
}else{
|
|
mon=hmoney.subtract(money);
|
|
if(hmoney.compareTo(BigDecimal.ZERO) != 0){
|
|
ratio=mon.divide(hmoney,Scale.GENERAL_RATE,BigDecimal.ROUND_HALF_UP);
|
|
}
|
|
}
|
|
hand.put("ratio", ratio);
|
|
hand.put("money", mon);
|
|
handMoneyList.add(hand);
|
|
startDate=dateList.get(i);
|
|
}
|
|
}catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return handMoneyList;
|
|
}
|
|
}
|