|
|
|
@@ -33,6 +33,7 @@ import com.iformall.domain.vo.RentContractFreePeriodVo; |
|
|
|
import com.iformall.domain.vo.WxBillSum;
|
|
|
|
import com.iformall.domain.vo.WxRentContractRevenueSetSalesVo;
|
|
|
|
import com.iformall.domain.vo.WxRentContractYearsSumVo;
|
|
|
|
import com.iformall.domain.vo.WxRentContractYearsVo;
|
|
|
|
import com.iformall.enums.EnumBillAllType;
|
|
|
|
import com.iformall.enums.EnumBillExtraCreateFrom;
|
|
|
|
import com.iformall.enums.EnumBillStatus;
|
|
|
|
@@ -55,6 +56,7 @@ import com.iformall.enums.EnumRentContractStatus; |
|
|
|
import com.iformall.enums.EnumRentContractType;
|
|
|
|
import com.iformall.enums.EnumRentDayPriceCalcute;
|
|
|
|
import com.iformall.enums.EnumRentShopType;
|
|
|
|
import com.iformall.enums.EnumRentStartType;
|
|
|
|
import com.iformall.enums.EnumTradeDailyDateType;
|
|
|
|
import com.iformall.enums.EnumYesOrNo;
|
|
|
|
import com.iformall.exception.MallinkException;
|
|
|
|
@@ -2298,9 +2300,20 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
|
|
|
|
@Override
|
|
|
|
public void saveFreePeriods(WxRentContract wxRentContract) {
|
|
|
|
WxRentContract rentContract = wxRentContractMapper.selectById(wxRentContract.getId());
|
|
|
|
List<WxRentContractYearsVo> yearsVo = getRentContractYears(rentContract);
|
|
|
|
if (null == yearsVo) {
|
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"无缴费年限");
|
|
|
|
}
|
|
|
|
Map<Integer,WxRentContractYearsVo> yearsMap = new HashMap<Integer,WxRentContractYearsVo>();
|
|
|
|
for (int i = 0 ; i < yearsVo.size() ; i++) {
|
|
|
|
WxRentContractYearsVo vo = yearsVo.get(i);
|
|
|
|
yearsMap.put(vo.getYearIndex(), vo);
|
|
|
|
}
|
|
|
|
|
|
|
|
WxRentContractFreePeriod del = new WxRentContractFreePeriod();
|
|
|
|
del.updateTenantInfo(wxRentContract);
|
|
|
|
del.setRentContractId(wxRentContract.getId());; |
|
|
|
del.setRentContractId(wxRentContract.getId()); |
|
|
|
wxRentContractFreePeriodMapper.deleteByContract(del);
|
|
|
|
List<RentContractFreePeriodVo> volist = wxRentContract.getFreePeriods();
|
|
|
|
if (null != volist && volist.size() > 0 ) {
|
|
|
|
@@ -2310,20 +2323,79 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
if (null != vo.getPeriods()) {
|
|
|
|
for (int j = 0 ; j < vo.getPeriods().size(); j++ ){
|
|
|
|
WxRentContractFreePeriod fp = vo.getPeriods().get(j);
|
|
|
|
final IdWorker idWorker = IdWorker.get();
|
|
|
|
fp.setId(idWorker.nextId());
|
|
|
|
fp.updateTenantInfo(wxRentContract);
|
|
|
|
fp.setYearIndex(vo.getYearIndex());
|
|
|
|
fp.setCreateTime(new Date());
|
|
|
|
fp.setUpdateTime(new Date());
|
|
|
|
fp.setRentContractId(wxRentContract.getId());
|
|
|
|
fpList.add(fp);
|
|
|
|
WxRentContractYearsVo yearVo = yearsMap.get(vo.getYearIndex());
|
|
|
|
if ((fp.getStartDate().after(yearVo.getStart()) || fp.getStartDate().equals(yearVo.getStart()) ) &&
|
|
|
|
(fp.getEndDate().before(yearVo.getEnd()) || fp.getEndDate().equals(yearVo.getEnd()))) {
|
|
|
|
final IdWorker idWorker = IdWorker.get();
|
|
|
|
fp.setId(idWorker.nextId());
|
|
|
|
fp.updateTenantInfo(wxRentContract);
|
|
|
|
fp.setYearIndex(vo.getYearIndex());
|
|
|
|
fp.setCreateTime(new Date());
|
|
|
|
fp.setUpdateTime(new Date());
|
|
|
|
fp.setRentContractId(rentContract.getId());
|
|
|
|
fpList.add(fp);
|
|
|
|
}else {
|
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"第"+vo.getYearIndex()+"年度有时间选择有误,不能超过该年度时间范围");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wxRentContractFreePeriodMapper.inertPeriods(wxRentContract.getTenantId(), fpList);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<WxRentContractYearsVo> getRentContractYears(WxRentContract rentContract) {
|
|
|
|
String adjustRatio = rentContract.getAdjustRatio();
|
|
|
|
List<Integer> integers = JSONArray.parseArray(adjustRatio, Integer.class);
|
|
|
|
integers.add(0, 0);
|
|
|
|
int years = integers.size();
|
|
|
|
//合同以什么日期来计算开始计租日期
|
|
|
|
if(rentContract.getRentStartType()!=null &&rentContract.getRentStartType().equals(EnumRentStartType.STARTTIME.getCode())){
|
|
|
|
rentContract.setRentalStartDate(rentContract.getStartDate());
|
|
|
|
}
|
|
|
|
//如果有撤铺日
|
|
|
|
Date endcontract = rentContract.getEndContractTime();
|
|
|
|
if (null != endcontract) {
|
|
|
|
endcontract = DateUtils.getDayEnd(endcontract);
|
|
|
|
}
|
|
|
|
List<Date> yearList = this.getYearList(years, 12, rentContract.getRentalStartDate(),endcontract);
|
|
|
|
List<WxRentContractYearsVo> retList = new ArrayList<WxRentContractYearsVo>();
|
|
|
|
if (null != yearList && yearList.size() > 0) {
|
|
|
|
if (yearList.size() == 1) {
|
|
|
|
WxRentContractYearsVo vo = new WxRentContractYearsVo();
|
|
|
|
vo.setStart(yearList.get(0));
|
|
|
|
vo.setEnd(rentContract.getRentalEndDate());
|
|
|
|
vo.setRemark("第1年度");
|
|
|
|
vo.setYearIndex(1);
|
|
|
|
retList.add(vo);
|
|
|
|
}else {
|
|
|
|
Date begin = null;
|
|
|
|
for (int i = 0 ; i < yearList.size()-1 ; i ++) {
|
|
|
|
int yearindex = i+1;
|
|
|
|
begin = yearList.get(i);
|
|
|
|
Date end = yearList.get(i+1);
|
|
|
|
Date realEnd = DateUtils.getDaySet(end, Calendar.SECOND, -1);
|
|
|
|
WxRentContractYearsVo vo = new WxRentContractYearsVo();
|
|
|
|
vo.setStart(begin);
|
|
|
|
vo.setEnd(realEnd);
|
|
|
|
vo.setRemark("第"+yearindex+"年度");
|
|
|
|
vo.setYearIndex(yearindex);
|
|
|
|
retList.add(vo);
|
|
|
|
begin = end;
|
|
|
|
}
|
|
|
|
WxRentContractYearsVo vo = new WxRentContractYearsVo();
|
|
|
|
vo.setStart(yearList.get(yearList.size()-1));
|
|
|
|
vo.setEnd(rentContract.getRentalEndDate());
|
|
|
|
vo.setRemark("第"+yearList.size()+"年度");
|
|
|
|
vo.setYearIndex(yearList.size());
|
|
|
|
retList.add(vo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (retList.size() > 0 ) {
|
|
|
|
return retList;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@@ -2353,30 +2425,40 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
//按照当前金额,当前时间区间,计算每一年的单价
|
|
|
|
//当前时间有多少个月
|
|
|
|
int months = diffs[0];
|
|
|
|
//计算当前区间算多少年
|
|
|
|
if (dayPriceCalcute.intValue() == EnumRentDayPriceCalcute.AVERAGE_DAYS.getCode()) {
|
|
|
|
int days = DateUtils.daysBetween(startDate, endDate)+1;
|
|
|
|
BigDecimal _months = new BigDecimal(days).divide(new BigDecimal(mothAverageDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).add(new BigDecimal(months));
|
|
|
|
unitPrice = salesDeciaml.multiply(new BigDecimal(12)).divide(_months,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
int lastdays = diffs[1];
|
|
|
|
if (lastdays > 0) {
|
|
|
|
//计算当前区间算多少年
|
|
|
|
if (dayPriceCalcute.intValue() == EnumRentDayPriceCalcute.AVERAGE_DAYS.getCode()) {
|
|
|
|
Date lastmonthStartDate = DateUtils.getTimeAfterMonths(diffs[0], startDate);
|
|
|
|
int days = DateUtils.daysBetween(lastmonthStartDate, endDate)+1;
|
|
|
|
BigDecimal _months = new BigDecimal(days).divide(new BigDecimal(mothAverageDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).add(new BigDecimal(months));
|
|
|
|
unitPrice = salesDeciaml.multiply(new BigDecimal(12)).divide(_months,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}else {
|
|
|
|
BigDecimal _months = getMonthsByRealDays(months,startDate,endDate,adjustPeriod,receivePeriodUnit);
|
|
|
|
unitPrice = salesDeciaml.multiply(new BigDecimal(12)).divide(_months,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
BigDecimal _months = getMonthsByRealDays(months,startDate,endDate,mothAverageDays,adjustPeriod,receivePeriodUnit);
|
|
|
|
unitPrice = salesDeciaml.multiply(new BigDecimal(12)).divide(_months,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}
|
|
|
|
unitPrice = salesDeciaml.multiply(new BigDecimal(12)).divide(new BigDecimal(months),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}
|
|
|
|
}else if(EnumPriceUnit.M.getCode().equals(priceUnit)) {
|
|
|
|
//每一月的单价
|
|
|
|
BigDecimal months = new BigDecimal(diffs[0]);
|
|
|
|
if (dayPriceCalcute.intValue() == EnumRentDayPriceCalcute.AVERAGE_DAYS.getCode()) {
|
|
|
|
int days = DateUtils.daysBetween(startDate, endDate)+1;
|
|
|
|
months = new BigDecimal(days).divide(new BigDecimal(mothAverageDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}else {
|
|
|
|
months = getMonthsByRealDays(diffs[0],startDate,endDate,mothAverageDays,adjustPeriod,receivePeriodUnit);
|
|
|
|
}
|
|
|
|
int lastdays = diffs[1];
|
|
|
|
if (lastdays > 0) {
|
|
|
|
if (dayPriceCalcute.intValue() == EnumRentDayPriceCalcute.AVERAGE_DAYS.getCode()) {
|
|
|
|
Date lastmonthStartDate = DateUtils.getTimeAfterMonths(diffs[0], startDate);
|
|
|
|
int days = DateUtils.daysBetween(lastmonthStartDate, endDate)+1;
|
|
|
|
months = months.add(new BigDecimal(days).divide(new BigDecimal(mothAverageDays),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP));
|
|
|
|
}else {
|
|
|
|
months = getMonthsByRealDays(diffs[0],startDate,endDate,adjustPeriod,receivePeriodUnit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unitPrice = salesDeciaml.divide(months,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP);
|
|
|
|
}
|
|
|
|
return unitPrice;
|
|
|
|
}
|
|
|
|
|
|
|
|
private BigDecimal getMonthsByRealDays(int months,Date startDate,Date endDate,Integer mothAverageDays,Integer adjustPeriod,Integer receivePeriodUnit) {
|
|
|
|
private BigDecimal getMonthsByRealDays(int months,Date startDate,Date endDate,Integer adjustPeriod,Integer receivePeriodUnit) {
|
|
|
|
BigDecimal _months = new BigDecimal(0);
|
|
|
|
//如果是自然月或者自然季度,则是到月底
|
|
|
|
if (adjustPeriod == EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode() ||
|
|
|
|
@@ -2625,9 +2707,11 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
List<Date> yearList = this.getYearList(rentPriceArrs.length, 12, rentcontract.getRentalStartDate(),null);
|
|
|
|
int yearIndex = 0;
|
|
|
|
for( int i = 0 ; i < yearList.size() ; i ++) {
|
|
|
|
Date yearEndDate = yearList.get(i);
|
|
|
|
if (rentBill.getEndtime().before(yearEndDate) || rentBill.getEndtime().equals(yearEndDate)) {
|
|
|
|
yearIndex = i-1;
|
|
|
|
Date yearStartDate = yearList.get(i);
|
|
|
|
Date yearEndDate = DateUtils.getTimeAfterMonths(12, yearStartDate);
|
|
|
|
if (rentBill.getStarttime().equals(yearStartDate) ||
|
|
|
|
(rentBill.getStarttime().after(yearStartDate) && (rentBill.getEndtime().before(yearEndDate) || rentBill.getEndtime().equals(yearEndDate)) )) {
|
|
|
|
yearIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -2643,6 +2727,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
if (null != operationManagerPriceArrs) {
|
|
|
|
rentTotal = rentTotal.add(new BigDecimal(operationManagerPriceArrs[yearIndex]));
|
|
|
|
}
|
|
|
|
//此处需要物业合同合租金合同的计费周期一致,严谨的需要用到上面计算的propertyPrice
|
|
|
|
if (null != propertyContractArrs) {
|
|
|
|
rentTotal = rentTotal.add(new BigDecimal(propertyContractArrs[yearIndex]));
|
|
|
|
}
|
|
|
|
@@ -3074,7 +3159,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
yearIndex = 0;
|
|
|
|
}
|
|
|
|
StringBuffer sb = new StringBuffer("");
|
|
|
|
return handleBills(sb,rentcontract,null,owe,null,rentcontract.getYearsEnd(),rentcontract.getYearsEnd(),EnumBillExtraCreateFrom.RNET_TIAODIAN_HUISUAN,null,rentPriceArrs,bussinessManagerPriceArrs,operationManagerPriceArrs,propertyContractArrs,yearIndex);
|
|
|
|
return handleBills(sb,rentcontract,null,owe,null,rentcontract.getYearsBegin(),rentcontract.getYearsEnd(),EnumBillExtraCreateFrom.RNET_TIAODIAN_HUISUAN,null,rentPriceArrs,bussinessManagerPriceArrs,operationManagerPriceArrs,propertyContractArrs,yearIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|