apzl_leasing/src_tenwa/com/tenwa/lease/util/MonthInterestEntity.java
2018-10-23 15:42:16 +08:00

376 lines
13 KiB
Java

package com.tenwa.lease.util;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import jbo.com.tenwa.lease.comm.CONTRACT_RENT_MONTH;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
public class MonthInterestEntity {
private String handling_charge_money;
private String sum_interest;
private String tax_rate;
private String contract_id;
private String payment_number;
private List<Map<String,String>> rent_plan_list;
private String start_date;
private String n_interest="0.00";//上半部分利息
private String p_interest="0.00";//下半部分利息
private String over_sum_interest="0.00";//已计算出来的利息
private String over_sum_handl="0.00";//已计算出来的手续费
private String date= new SimpleDateFormat("yyyy/MM/dd").format(new Date());
public List<BizObject> getBizObjList() throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
Calendar ca = Calendar.getInstance();
List<BizObject> bizoList=new ArrayList<BizObject>();
if(this.getRent_plan_list().size()>0){
BizObjectManager bm=JBOFactory.getBizObjectManager(CONTRACT_RENT_MONTH.CLASS_NAME);
for(int i=0;i<this.getRent_plan_list().size();i++){
if(i==0){
BizObject bo=bm.newObject();
bo.setAttributeValue("contract_id", contract_id);
bo.setAttributeValue("payment_number", payment_number);
bo.setAttributeValue("create_date", date);
ca.setTime(format.parse(start_date));
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String last = format.format(ca.getTime());
ca.add(Calendar.MONTH, 0);
ca.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
String first = format.format(ca.getTime());
bo.setAttributeValue("end_date", last);
bo.setAttributeValue("start_date", first);
String accurt_date=start_date.substring(0,7);
bo.setAttributeValue("accrued_date", accurt_date);
caculateN_interest(start_date,rent_plan_list.get(i).get("L_INTEREST"));
//caculateI_interest("0.00");
bo.setAttributeValue("interest", new BigDecimal(n_interest).toString());
bo.setAttributeValue("fee", caculateHandling_Money(n_interest,p_interest));
bo.setAttributeValue("rent_list", "0");
bizoList.add(bo);
}
BizObject bo=bm.newObject();
bo.setAttributeValue("contract_id", contract_id);
bo.setAttributeValue("payment_number", payment_number);
bo.setAttributeValue("create_date", date);
ca.setTime(format.parse(rent_plan_list.get(i).get("L_PLAN_DATE")));
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String last = format.format(ca.getTime());
ca.add(Calendar.MONTH, 0);
ca.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
String first = format.format(ca.getTime());
bo.setAttributeValue("end_date", last);
bo.setAttributeValue("start_date", first);
String accurt_date=rent_plan_list.get(i).get("L_PLAN_DATE").substring(0,7);
bo.setAttributeValue("accrued_date", accurt_date);
bo.setAttributeValue("rent_list", (i+1)+"");
if(i==rent_plan_list.size()-1){
//最后一个月
caculateI_interest(rent_plan_list.get(i).get("L_INTEREST"));
caculateN_interest(rent_plan_list.get(i).get("L_PLAN_DATE"),"0.00");
bo.setAttributeValue("interest", new BigDecimal(sum_interest).subtract(new BigDecimal(over_sum_interest)).toString());
bo.setAttributeValue("fee", new BigDecimal(handling_charge_money).subtract(new BigDecimal(over_sum_handl)).toString());
}else{
//不是起租月
caculateI_interest(rent_plan_list.get(i).get("L_INTEREST"));
caculateN_interest(rent_plan_list.get(i).get("L_PLAN_DATE"),rent_plan_list.get(i).get("N_INTERST"));
bo.setAttributeValue("interest", new BigDecimal(n_interest).add(new BigDecimal(p_interest)).toString());
bo.setAttributeValue("fee", caculateHandling_Money(n_interest,p_interest));
}
bizoList.add(bo);
}
}
return bizoList;
}
public List<BizObject> getBizObjListIn_three() throws Exception{
SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
Calendar ca = Calendar.getInstance();
List<BizObject> bizoList=new ArrayList<BizObject>();
if(this.getRent_plan_list().size()>0){
BizObjectManager bm=JBOFactory.getBizObjectManager(CONTRACT_RENT_MONTH.CLASS_NAME);
for(int i=0;i<this.getRent_plan_list().size();i++){
BizObject bo1=bm.newObject();
BizObject bo2=bm.newObject();
BizObject bo3=bm.newObject();
String al_handl="0.00";
bo1.setAttributeValue("contract_id", contract_id);
bo1.setAttributeValue("payment_number", payment_number);
bo1.setAttributeValue("create_date", date);
bo2.setAttributeValue("contract_id", contract_id);
bo2.setAttributeValue("payment_number", payment_number);
bo2.setAttributeValue("create_date", date);
bo3.setAttributeValue("contract_id", contract_id);
bo3.setAttributeValue("payment_number", payment_number);
bo3.setAttributeValue("create_date", date);
//三个月平均分
ca.setTime(format.parse(rent_plan_list.get(i).get("L_PLAN_DATE")));
ca.add(Calendar.MONTH, -2);
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
String last = format.format(ca.getTime());
ca.add(Calendar.MONTH, 0);
ca.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
String first = format.format(ca.getTime());
bo1.setAttributeValue("end_date", last);
bo1.setAttributeValue("start_date", first);
String accurt_date=start_date.substring(0,7);
bo1.setAttributeValue("accrued_date", accurt_date);
bo1.setAttributeValue("rent_list", i*3+1);
bo1.setAttributeValue("interest", new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).toString());
bo1.setAttributeValue("fee", caculateHandling_Money(new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).toString(),"0.00"));
ca.setTime(format.parse(rent_plan_list.get(i).get("L_PLAN_DATE")));
ca.add(Calendar.MONTH, -2);
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
last = format.format(ca.getTime());
ca.add(Calendar.MONTH, 0);
ca.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
first = format.format(ca.getTime());
bo2.setAttributeValue("end_date", last);
bo2.setAttributeValue("start_date", first);
accurt_date=start_date.substring(0,7);
bo2.setAttributeValue("accrued_date", accurt_date);
bo2.setAttributeValue("rent_list", i*3+2);
bo2.setAttributeValue("interest", new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).toString());
bo2.setAttributeValue("fee", caculateHandling_Money(new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).toString(),"0.00"));
ca.setTime(format.parse(rent_plan_list.get(i).get("L_PLAN_DATE")));
ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
last = format.format(ca.getTime());
ca.add(Calendar.MONTH, 0);
ca.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
first = format.format(ca.getTime());
bo3.setAttributeValue("end_date", last);
bo3.setAttributeValue("start_date", first);
accurt_date=start_date.substring(0,7);
bo3.setAttributeValue("accrued_date", accurt_date);
bo3.setAttributeValue("rent_list", i*3+3);
bo3.setAttributeValue("interest", new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).subtract(new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("2"))).toString());
if(i==rent_plan_list.size()-1){
bo3.setAttributeValue("fee", new BigDecimal(handling_charge_money).subtract(new BigDecimal(over_sum_handl)).toString());
}else{
bo3.setAttributeValue("fee", caculateHandling_Money(new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).subtract(new BigDecimal(rent_plan_list.get(i).
get("L_INTEREST")).divide(new BigDecimal("3"),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("2"))).toString(),"0.00"));
}
bizoList.add(bo1);
bizoList.add(bo2);
bizoList.add(bo3);
}
}
return bizoList;
}
public void caculateN_interest(String date,String interest) throws Exception{
BigDecimal inte=new BigDecimal(interest);
BigDecimal da30=new BigDecimal("30");
String day=date.substring(8);
n_interest=inte.divide(da30, 2, BigDecimal.ROUND_HALF_UP).multiply(da30.subtract(new BigDecimal(day))).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
over_sum_interest=new BigDecimal(over_sum_interest).add(new BigDecimal(n_interest)).toString();
}
public void caculateI_interest(String interest)throws Exception{
BigDecimal inte=new BigDecimal(interest);
p_interest=inte.subtract(new BigDecimal(n_interest)).toString();
over_sum_interest=new BigDecimal(over_sum_interest).add(new BigDecimal(p_interest)).toString();
}
public String caculateHandling_Money(String N_interest,String I_interest) throws Exception {
BigDecimal nInte=new BigDecimal(N_interest);
BigDecimal iInte=new BigDecimal(I_interest);
String handl_money=nInte.add(iInte).divide(new BigDecimal(sum_interest), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(handling_charge_money)).setScale(2,BigDecimal.ROUND_HALF_UP).toString();
over_sum_handl=new BigDecimal(over_sum_handl).add(new BigDecimal(handl_money)).toString();
return handl_money;
}
public String getContract_id() {
return contract_id;
}
public void setContract_id(String contract_id) {
this.contract_id = contract_id;
}
public String getPayment_number() {
return payment_number;
}
public void setPayment_number(String payment_number) {
this.payment_number = payment_number;
}
public String getN_interest() {
return n_interest;
}
public void setN_interest(String n_interest) {
this.n_interest = n_interest;
}
public String getP_interest() {
return p_interest;
}
public void setP_interest(String p_interest) {
this.p_interest = p_interest;
}
public String getOver_sum_interest() {
return over_sum_interest;
}
public void setOver_sum_interest(String over_sum_interest) {
this.over_sum_interest = over_sum_interest;
}
public String getOver_sum_handl() {
return over_sum_handl;
}
public String getHandling_charge_money() {
return handling_charge_money;
}
public void setHandling_charge_money(String handling_charge_money) {
this.handling_charge_money = handling_charge_money;
}
public String getSum_interest() {
return sum_interest;
}
public void setSum_interest(String sum_interest) {
this.sum_interest = sum_interest;
}
public String getTax_rate() {
return tax_rate;
}
public void setTax_rate(String tax_rate) {
this.tax_rate = tax_rate;
}
public List<Map<String, String>> getRent_plan_list() {
return rent_plan_list;
}
public void setRent_plan_list(List<Map<String, String>> rent_plan_list) {
this.rent_plan_list = rent_plan_list;
}
public String getStart_date() {
return start_date;
}
public void setStart_date(String start_date) {
this.start_date = start_date;
}
public void setOver_sum_handl(String over_sum_handl) {
this.over_sum_handl = over_sum_handl;
}
/*public void caculateExInterestOnHire(){
BigDecimal bpi=new BigDecimal(previousInterest);
BigDecimal bni=new BigDecimal(nextInterest);
BigDecimal bopi=new BigDecimal(previousOvInterest);
int a=Integer.parseInt(nextDate.substring(8));
if("trad_month".equals(exTpye)){
n_interest=bpi.subtract(bopi).add(bni.divide(new BigDecimal(30)).multiply(new BigDecimal(30).subtract(new BigDecimal(a)))).toString();
}
this.setExtractInterest(n_interest);
}
public void caculateN_Interest(String next,String plandate){
BigDecimal bni=new BigDecimal(next);
int a=Integer.parseInt(plandate);
if("trad_month".equals(exTpye)){
n_interest=bni.divide(new BigDecimal(30)).multiply(new BigDecimal(30).subtract(new BigDecimal(a))).setScale(2).toString();
}
}
public void caculatP_Interest(String last,String plandate){
BigDecimal bni=new BigDecimal(last);
int a=Integer.parseInt(plandate);
if("trad_month".equals(exTpye)){
p_interest=bni.subtract(bni.divide(new BigDecimal(30)).multiply(new BigDecimal(30).subtract(new BigDecimal(a)))).setScale(2).toString();
}
}*/
public static void main(String[] args) {
System.out.println(Integer.parseInt("2018/03/12".substring(0,7 )));
}
}