package com.goafanti.order.bo;

import java.math.BigDecimal;
import java.util.Calendar;

import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.model.TChangeDun;
import com.goafanti.common.utils.DateUtils;
import com.goafanti.order.enums.NewOrderDunType;

public class TChangeDunOut extends TChangeDun{
	private String dunTypeName;
	private String commodityName;
	private String startDate;
	private BigDecimal setUpAmount;
	public String getDunTypeName() {
		if(super.getDunType()!=null&&super.getProjectType()!=null&&super.getDunType()!=0) {
			return NewOrderDunType.getValueByCode(Integer.valueOf(""+super.getProjectType()+super.getDunType()));
		}
		if(super.getDunType()!=null&&super.getProjectType()!=null&&super.getDunType()==0) {
			return NewOrderDunType.getValueByCode(Integer.valueOf(""+super.getProjectType()+super.getDunType()))+getCustomizeName();
		}
		return dunTypeName;
	}
	public String getCommodityName() {
		return commodityName;
	}
	public void setCommodityName(String commodityName) {
		this.commodityName = commodityName;
	}
	public String getStartDate() {
		//会员显示到期时间
		if(super.getCreateTime()!=null&&super.getEffectiveCount()!=null) {
			Calendar calendar=Calendar.getInstance();   
	  		calendar.setTime(super.getCreateTime());
	  		calendar.add(Calendar.DATE, super.getEffectiveCount()*180);
	  		return DateUtils.formatDate(calendar.getTime(), AFTConstants.YYYYMMDD);
		}
		//财税显示催款时间 大于9则年份+2，小于10年份+1
		if (super.getDunType()==2&&super.getProjectType()==5) {
			Calendar calendar=Calendar.getInstance();   
	  		calendar.setTime(super.getCreateTime());
	  		int year = calendar.get(Calendar.YEAR);  
		        //获取月份，0表示1月份
		        int month = calendar.get(Calendar.MONTH) + 1;
		        if(month<10)year=year+1;
		        if(month>9)year=year+2;
		        calendar.set(year, 5, 1);
		        return DateUtils.formatDate(calendar.getTime(), AFTConstants.YYYYMMDD);
		}
		return startDate;
	}
	public BigDecimal getMoney() {
		if(getDunType()!=null&&getProjectType()!=null){
			if(Integer.valueOf(""+getProjectType()+getDunType())==33&&
					super.getMoney()==null&&
					super.getAppropriationRatio()!=null&&getSetUpAmount()!=null) {
				return super.getAppropriationRatio().multiply(getSetUpAmount());
			}
		}
		return super.getMoney();
	}
	public BigDecimal getSetUpAmount() {
		return setUpAmount;
	}
	public void setSetUpAmount(BigDecimal setUpAmount) {
		this.setUpAmount = setUpAmount;
	}
}
