@@ -619,6 +619,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
bill.setCreatetime(date);
bill.updateTenantInfo(record);
bill.setNeedPay(bill.getNeedPay());
bill.setBussinessManageFeeNeedPay(bill.getBussinessManageFeeNeedPay());
bill.setOperatingManageFeeNeedPay(bill.getOperatingManageFeeNeedPay());
bill.setUpdatetime(date);
bill.setRentShopType(record.getRentShopType());
bill.setPeriod(count);
@@ -1328,12 +1330,12 @@ public class WxRentContractServiceImpl implements WxRentContractService {
BillTimeVo billTimeVo = billTimeVoList.get(i);
//计算金额
long needpay = 0;
//商业管理费
long bussinessManageFeeNeedpay = 0;
//营业管理费
long operatingManageFeeNeedpay = 0;
boolean flag = false;
long bmpricePre = 0;
long bmPrce = 0;
long ompricePre = 0;
long omPrce = 0;
//此处逻辑处理这一年和下一年交接那一期账单。
if(yearList.size() > 1) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) {
@@ -1342,41 +1344,80 @@ public class WxRentContractServiceImpl implements WxRentContractService {
//logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate));
index++;
if (null != bussinessManagerPriceArrs && null != operationManagerPriceArrs) {
bmpricePre = bussinessManagerPriceArrs[index-1];
bmPrce = bussinessManagerPriceArrs[index];
ompricePre = operationManagerPriceArrs[index-1];
omPrce = operationManagerPriceArrs[index];
}
//如果是计算账单金额&cross 拆分日期进行计算
if(billTimeVo.getEndDate().after(endDate)) {
long needpayFront = 0;
long needpayAfter = 0;
//商业管理费
long bussinessManageFeeNeedpayFront = 0;
long bussinessManageFeeNeedpayAfter = 0;
//营业管理费
long operatingManageFeeNeedpayFront = 0;
long operatingManageFeeNeedpayAfter = 0;
//同一天,算一天
if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){
needpayFront = getNeedPayMoney(wxRentContract,priceArrs[index-1],bmpricePre,ompricePre,billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) {
bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,bussinessManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
}
if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) {
operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract,operationManagerPriceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
}
}else{
if(billTimeVo.getStartDate().before(endDate)){
if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType()) && EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) {
//设置跳点率为年周期 price不变
needpayFront = priceArrs[index - 1];
if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) {
bussinessManageFeeNeedpayFront = bussinessManagerPriceArrs[index - 1];
}
if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) {
operatingManageFeeNeedpayFront = operationManagerPriceArrs[index - 1];
}
}else {
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1],bmpricePre,ompricePre, billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index],bmPrce,omPrce, endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) {
bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
}
if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) {
operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,false);
}
}
}else{
//如果是按自然月,则这一年和下一年交叉部分需要重新计算
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
Date currentYearRentDate = getCurrentYearRentDate(endDate,wxRentContract.getRentalStartDate());
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index - 1],bmpricePre,ompricePre, endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
needpayAfter = getNeedPayMoney(wxRentContract, priceArrs[index],bmPrce,omPrce, currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
needpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) {
bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
bussinessManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
}
if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) {
operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index - 1],endDate, DateUtils.getDaySet(currentYearRentDate, Calendar.DATE, -1), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
operatingManageFeeNeedpayAfter = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index],currentYearRentDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb, dayType, receivePeriod,true,true);
}
}else {
//按账单日
needpayFront = getNeedPayMoney(wxRentContract, priceArrs[index],bmPrce,omPrce, billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false);
needpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false);
if (null != bussinessManagerPriceArrs && bussinessManagerPriceArrs.length > 0) {
bussinessManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, bussinessManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false);
}
if (null != operationManagerPriceArrs && operationManagerPriceArrs.length > 0) {
operatingManageFeeNeedpayFront = WxRentContractHelper.getNeedPayMoney(wxRentContract, operationManagerPriceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod,false,false);
}
}
}
}
needpay = needpayFront+needpayAfter;
bussinessManageFeeNeedpay = bussinessManageFeeNeedpayFront + bussinessManageFeeNeedpayAfter;
operatingManageFeeNeedpay = operatingManageFeeNeedpayFront + operatingManageFeeNeedpayAfter;
flag = true;
}
if(index >= yearList.size()-1){
@@ -1392,7 +1433,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
//计算金额
if(!flag){
needpay = getNeedPayMoney(wxRentContract, priceArrs[index],bmPrce,omPrce, billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
needpay = WxRentContractHelper. getNeedPayMoney(wxRentContract, priceArrs[index],billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod,false,false);
}
WxBillRent wxBillRent = new WxBillRent();
@@ -1408,8 +1449,11 @@ public class WxRentContractServiceImpl implements WxRentContractService {
wxBillRent.setRentPriceInfo(getRentPriceInfo(wxRentContract,needpay));
wxBillRent.setNeedPay(needpay);
wxBillRent.setOwe(needpay);
wxBillRent.setReceivePay(needpay);
wxBillRent.setReceivePay(bussinessManageFeeNeedpay+operatingManageFeeNeedpay+needpay);
//商业管理费
wxBillRent.setBussinessManageFeeNeedPay(bussinessManageFeeNeedpay);
//运营管理费
wxBillRent.setOperatingManageFeeNeedPay(operatingManageFeeNeedpay);
//截止收租日在当前时间之前
Date date = new Date();
setExpiredDay(wxBillRent,dayType,receivePeriod);
@@ -1445,97 +1489,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return resultMap;
}
public long getNeedPayMoney(WxRentContract wxRentContract,long price,long bussinessManageFee,long operatingManageFee,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod,boolean part,boolean monthCalDay){
long needpay;
//按日
if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){
Double priceD = new Double(price);
double needpayD = WxRentContractHelper.getNeedPay(0,priceD,startDate,endDate);
//取整
//needpay = new Double(needpayD).longValue();
//四舍五入
needpay = new BigDecimal(needpayD).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}else{
Double priceD = new Double(price);
if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(wxRentContract.getType())) {
//设置跳点率为年周期 price不变
if (EnumMissTimeType.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())) {
return priceD.longValue();
}
//年或者设置跳点率为年周期 除12
if (EnumMissTimeType.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())) {
priceD = new Double(price) / 12;
}
}else{
//年 除12
if(EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())){
priceD = new Double(price)/12;
}
}
//生成金额直接计算
if(!saveDb){
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).longValue();
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,part)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
return needpay;
}
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
if(i == billTimeVoListSize - 1){//最后
//判断是否满足整月
Calendar instance = Calendar.getInstance();
instance.setTime(startDate);
instance.add(dayType, receivePeriod);
instance.add(Calendar.DATE, -1);
if(sd.format(instance.getTime()).equals(sd.format(endDate))){
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(DateUtils.getDaySet(endDate,Calendar.DATE,1))+"-01");
needpay = new Double(months * priceD).longValue();
}else{
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}else if(i == 0){//第一期
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
if(isFirstDay(startDate)){
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01");
months++;
needpay = new Double(months * priceD).longValue();
}else{
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}else{
if(isFirstDay(startDate)){
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01");
if(isFirstDay(startDate)){
months++;
}
needpay = new Double(months * priceD).longValue();
}else{
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
}
}else{//中间
int months = WxRentContractHelper.getMonths(sdM.format(startDate)+"-01",sdM.format(endDate)+"-01");
if(isFirstDay(startDate)){
months++;
}
//如果当月费用需要按天计算
if (monthCalDay) {
//needpay = new Double(getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).longValue();
needpay = new BigDecimal(WxRentContractHelper.getMonthNeedPay(priceD, startDate, endDate,dayType,receivePeriod,false)).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}else {
needpay = new Double(months * priceD).longValue();
}
}
}
return needpay;
}
public void setExpiredDay(WxBillRent wxBillRent,int dayType, int receivePeriod){
//截止收租日在当前时间之前
Date date = new Date();
@@ -1559,15 +1512,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
}
public boolean isFirstDay(Date date){
int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date));
if(dateInt == 1){
return true;
}
return false;
}
@Transactional(rollbackFor = {Exception.class})
@Override
public ResultData deleteById(String id) {