diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java index 3b90e17c4..f93bb22a5 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/contract/WxRentContractController.java @@ -874,7 +874,10 @@ public class WxRentContractController extends WxContractBaseController { bq.setOperationType(EnumContractOperationType.WHOLE.getCode()); bq.setStatus(EnumRentContractStatus.PAING.getCode()); List propertyList = wxPropertyContractService.findList(bq); - return new ResultData(propertyList); + if (null != propertyList && propertyList.size() > 0 ) { + return new ResultData(propertyList.get(0)); + } + return new ResultData(); } /** @@ -905,19 +908,20 @@ public class WxRentContractController extends WxContractBaseController { List retList = new ArrayList(); Date begin = rentContract.getRentalStartDate(); for (int i = 0 ; i < yearList.size() ; i ++) { + Date end = yearList.get(i); + Date realEnd = DateUtils.getDaySet(end, Calendar.SECOND, -1); WxRentContractYearsVo vo = new WxRentContractYearsVo(); vo.setStart(begin); - vo.setEnd(yearList.get(i)); + vo.setEnd(realEnd); vo.setRemark("第"+i+1+"年度"); retList.add(vo); - begin = DateUtils.getDaySet(begin, Calendar.DATE, 1); + begin = end; } return new ResultData(retList); } return new ResultData(); } - /** * 取高年度汇算计算 * @param wxRentContract diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxRentContract.java b/mallinkService/src/main/java/com/iformall/domain/po/WxRentContract.java index 9ec70c2d1..99480c779 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxRentContract.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxRentContract.java @@ -621,6 +621,6 @@ public class WxRentContract extends TenantEntity { @TableField(exist = false) private Date yearsBegin; @TableField(exist = false) - private Long yearsEnd; + private Date yearsEnd; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxRentContractYearsSumVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxRentContractYearsSumVo.java index 8e9cdef26..be1ca34d7 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxRentContractYearsSumVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxRentContractYearsSumVo.java @@ -2,9 +2,11 @@ package com.iformall.domain.vo; import lombok.Data; import java.io.Serializable; +import java.math.BigDecimal; import java.util.Date; import java.util.List; +import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.iformall.domain.po.WxAllBill; import com.iformall.utils.DateUtils; @@ -15,12 +17,20 @@ public class WxRentContractYearsSumVo implements Serializable { //总计销售额 private String totalSales; - //总应收 - private String receivePay; - //总冲抵 - private String setoff; - //总实收 - private String pay; - //总退回 - private String returnPay; + //总计应扣点 + private String totalRevenue; + //账单总应收 + private String billReceivePay; + //差额 + private String owe; + public String getOwe() { + if (StringUtils.isBlank(totalRevenue)) { + totalRevenue = "0"; + } + if (StringUtils.isBlank(billReceivePay)) { + billReceivePay = "0"; + } + owe = new BigDecimal(totalRevenue).subtract(new BigDecimal(billReceivePay)).toPlainString(); + return owe; + } } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxRentContractRevenueSalesMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxRentContractRevenueSalesMapper.java index 4be9e0878..3ae7f05dd 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxRentContractRevenueSalesMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxRentContractRevenueSalesMapper.java @@ -4,6 +4,8 @@ import com.iformall.common.CommonMapper; import com.iformall.domain.po.WxRentContractRevenueSales; import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; import java.util.List; /** @@ -13,5 +15,7 @@ public interface WxRentContractRevenueSalesMapper extends CommonMapper findList(WxRentContractRevenueSales wxBillRent); WxRentContractRevenueSales selectById(@Param("id")Long id,@Param("tenantId")String tenantId); + + BigDecimal findSumSalesMoney(WxRentContractRevenueSales wxBillRent); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index f76aef36c..421e93769 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -28,6 +28,7 @@ import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.BillTimeVo; import com.iformall.domain.vo.RatioVo; 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.enums.EnumBillAllType; @@ -1045,7 +1046,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { } return yearList; } - + public List buildRentMonth(MallUserInfo user, WxRentContract wxRentContract, int receivePeriod, Integer lease, Date rentalStartDate,Integer isPreview, boolean saveDb) { int years = 0; //计算租金每年的计费基数 @@ -2438,8 +2439,45 @@ public class WxRentContractServiceImpl implements WxRentContractService { } - private BigDecimal calcuteReveneuJump(BigDecimal sales,WxRentContract rentcontract) { - return null; + private BigDecimal[] calcuteReveneuJump(BigDecimal sales,WxRentContract rentcontract,Date startDate,Date endDate,List freePeriods) { + WxRentContractRevenueJump jq = new WxRentContractRevenueJump(); + jq.updateTenantInfo(rentcontract); + jq.setRentContractId(rentcontract.getId()); + jq.setSortColumn(" minMoney asc"); + BigDecimal revenueDecimal = new BigDecimal(0); + BigDecimal rentDecimal = new BigDecimal(0); + List jumpList = wxRentContractRevenueJumpMapper.findList(jq); + if (null != jumpList && jumpList.size() > 0 ) { + for (int i = 0 ; i< jumpList.size() ; i ++) { + WxRentContractRevenueJump rj = jumpList.get(i); + String minMoney = rj.getMinMoney(); + String maxMoney = rj.getMaxMoney(); + if (StringUtils.isNotBlank(maxMoney)) { + if (sales.compareTo(new BigDecimal(maxMoney)) <= 0 ) { + revenueDecimal = sales.multiply(new BigDecimal(rj.getRate())); + if (StringUtils.isNotBlank(rj.getRentMoney())) { + rentDecimal = new BigDecimal(rj.getRentMoney()); + } + break; + } + }else { + if (sales.compareTo(new BigDecimal(minMoney)) > 0 ) { + revenueDecimal = sales.multiply(new BigDecimal(rj.getRate())); + if (StringUtils.isNotBlank(rj.getRentMoney())) { + rentDecimal = new BigDecimal(rj.getRentMoney()); + } + break; + } + } + } + } + //根据时间区间计算 + //固定租金需要再计算,因为跳点设置的租金是单价 + String rentNeedpay = WxRentContractHelper.getNeedPayMoney(freePeriods,rentcontract, rentDecimal.toPlainString(),startDate, + endDate,0,0,false,rentcontract.getReceivePeriodUnit(),rentcontract.getReceivePeriod()); + rentDecimal = new BigDecimal(rentNeedpay); + BigDecimal[] bs = new BigDecimal[] {revenueDecimal,rentDecimal}; + return bs; } @@ -2504,7 +2542,15 @@ public class WxRentContractServiceImpl implements WxRentContractService { rentBill.getEndtime(),0,0,false,rentcontract.getReceivePeriodUnit(),rentcontract.getReceivePeriod()); //计算跳点。 - BigDecimal jumppay = calcuteReveneuJump(salesDeciaml, rentcontract); + BigDecimal[] jumppays = calcuteReveneuJump(salesDeciaml, rentcontract,rentBill.getStarttime(), rentBill.getEndtime(),freePeriods); + BigDecimal jumpRevenuePay = jumppays[0]; + BigDecimal jumpRentPay = jumppays[1]; + BigDecimal jumppay = new BigDecimal(0); + if (jumpRevenuePay.compareTo(jumpRentPay) > 0 ) { + jumppay = jumppay.add(jumpRevenuePay); + }else { + jumppay = jumppay.add(jumpRentPay); + } if (jumppay.compareTo(new BigDecimal(needpay)) > 0 ) { needpay = jumppay.toPlainString(); @@ -2542,7 +2588,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (new BigDecimal(rentBill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) { rentBill.setStatus(EnumBillStatus.STOP_TO_SETTLE.getCode()); }else { - rentBill.setStatus(EnumBillStatus.PAID.getCode()); + //rentBill.setStatus(EnumBillStatus.PAID.getCode()); } wxAllBillMapper.updateById(rentBill); //物业账单应收就改为0,因为金额已经合并了 @@ -2553,7 +2599,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (new BigDecimal(propertyBill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) { propertyBill.setStatus(EnumBillStatus.STOP_TO_SETTLE.getCode()); }else { - propertyBill.setStatus(EnumBillStatus.PAID.getCode()); + //propertyBill.setStatus(EnumBillStatus.PAID.getCode()); } propertyBill.setUpdatetime(new Date()); wxAllBillMapper.updateById(propertyBill); @@ -2572,7 +2618,84 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Override public WxRentContractYearsSumVo calcuteYearsRevenueRentUp(WxRentContract rentcontract) { - //通过销售额汇总,查询跳点,计算扣点总应收 - return null; + //查询销售总数 + WxRentContractRevenueSales rsq = new WxRentContractRevenueSales(); + rsq.updateTenantInfo(rentcontract); + rsq.setRentContractId(rentcontract.getId()); + BigDecimal sum = wxRentContractRevenueSalesMapper.findSumSalesMoney(rsq); + //计算跳点。 + BigDecimal[] jumppays = calcuteReveneuJump(sum, rentcontract,rentcontract.getYearsBegin(), rentcontract.getYearsEnd(),null); + BigDecimal jumpRevenuePay = jumppays[0]; + //BigDecimal jumpRentPay = jumppays[1]; + + BigDecimal receivepay = new BigDecimal(0); + //查询所有租金和物业账单的信息 + WxAllBill rentBillq = new WxAllBill(); + rentBillq.updateTenantInfo(rentcontract); + rentBillq.setRentContractId(rentcontract.getId()); + rentBillq.setBillType(EnumBillAllType.RENT.getCode()); + rentBillq.setEnergyFeesId(EnumBillAllType.RENT.getEnergyFeesId()); + rentBillq.setIsPreview(EnumYesOrNo.NO.getCode()); + rentBillq.setStarttimeEqual(rentcontract.getYearsBegin()); + rentBillq.setEndtimeEqual(rentcontract.getYearsEnd()); + WxBillSum rentBillSum = wxAllBillMapper.getBillMonthSum(rentBillq); + if (null != rentBillSum) { + receivepay = receivepay.add(rentBillSum.getNeedPayNumber()); + } + + WxPropertyContract bq = new WxPropertyContract(); + bq.updateTenantInfo(rentcontract); + bq.setMerchantId(rentcontract.getMerchantId()); + bq.setRentContractId(rentcontract.getId()); + bq.setOperationType(EnumContractOperationType.WHOLE.getCode()); + bq.setStatus(EnumRentContractStatus.PAING.getCode()); + List propertyList = wxPropertyContractService.findList(bq); + if (null != propertyList && propertyList.size() > 0 ) { + WxPropertyContract pc = propertyList.get(0); + WxAllBill propertyBillq = new WxAllBill(); + propertyBillq.updateTenantInfo(rentcontract); + propertyBillq.setPropertyContractId(pc.getId()); + propertyBillq.setBillType(EnumBillAllType.PROPERTY.getCode()); + propertyBillq.setEnergyFeesId(EnumBillAllType.PROPERTY.getEnergyFeesId()); + propertyBillq.setIsPreview(EnumYesOrNo.NO.getCode()); + propertyBillq.setStarttimeEqual(rentcontract.getYearsBegin()); + propertyBillq.setEndtimeEqual(rentcontract.getYearsEnd()); + WxBillSum propertyBillSum = wxAllBillMapper.getBillMonthSum(rentBillq); + if (null != propertyBillSum) { + receivepay = receivepay.add(propertyBillSum.getNeedPayNumber()); + } + } + + WxRentContractYearsSumVo vo = new WxRentContractYearsSumVo(); + vo.setTotalSales(sum.toPlainString()); + vo.setTotalRevenue(jumpRevenuePay.toPlainString()); + vo.setBillReceivePay(receivepay.toPlainString()); + + if ( new BigDecimal(vo.getOwe()).compareTo(new BigDecimal(0)) > 0) { + //增加一个账单 + WxAllBill createBillq = new WxAllBill(); + createBillq.updateTenantInfo(rentcontract); + final IdWorker idWorker = IdWorker.get(); + createBillq.setId(idWorker.nextId()); + createBillq.setMerchantId(rentcontract.getMerchantId()); + createBillq.setRentShopType(rentcontract.getRentShopType()); + createBillq.setCreatetime(new Date()); + createBillq.setUpdatetime(new Date()); + createBillq.setPriceDetail("年度汇算销售额:"+sum.toPlainString()+",应扣点金额:"+jumpRevenuePay.toPlainString()+",账单总金额:"+receivepay.toPlainString()+".差额:"+vo.getOwe()); + createBillq.setNeedPay(vo.getOwe()); + createBillq.setReceivePay(vo.getOwe()); + createBillq.setPay("0"); + createBillq.setBillType(EnumBillAllType.RENT.getCode()); + createBillq.setStarttime(rentcontract.getYearsBegin()); + createBillq.setEndtime(rentcontract.getYearsEnd()); + createBillq.setStatus(EnumBillStatus.WAIT_PAY.getCode()); + createBillq.setEnergyFeesId(EnumBillAllType.RENT.getEnergyFeesId()); + createBillq.setBillRemark("扣点年度汇算自动生成"); + createBillq.setIsPreview(EnumYesOrNo.NO.getCode()); + createBillq.setRentContractId(rentcontract.getId()); + wxAllBillMapper.insert(createBillq); + } + + return vo; } } diff --git a/mallinkService/src/main/resources/mapper/WxRentContractRevenueSalesMapper.xml b/mallinkService/src/main/resources/mapper/WxRentContractRevenueSalesMapper.xml index 7591717d9..ef01dc466 100644 --- a/mallinkService/src/main/resources/mapper/WxRentContractRevenueSalesMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxRentContractRevenueSalesMapper.xml @@ -55,5 +55,11 @@ from wx_rent_contract_revenue_sales where id = #{id} and `tenant_id` = #{tenantId} + +