|
|
|
@@ -9,7 +9,9 @@ import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker;
|
|
|
|
import com.iformall.common.Result;
|
|
|
|
import com.iformall.common.ResultData;
|
|
|
|
import com.iformall.common.SysConfigConstant;
|
|
|
|
import com.iformall.domain.po.MallUserInfo;
|
|
|
|
import com.iformall.domain.po.SysConfig;
|
|
|
|
import com.iformall.domain.po.WxAllBill;
|
|
|
|
import com.iformall.domain.po.WxEnergyFees;
|
|
|
|
import com.iformall.domain.po.WxFlowModel;
|
|
|
|
@@ -68,6 +70,7 @@ import com.iformall.mapper.WxRentContractMapper; |
|
|
|
import com.iformall.mapper.WxRentContractRevenueJumpMapper;
|
|
|
|
import com.iformall.mapper.WxRentContractRevenueSalesMapper;
|
|
|
|
import com.iformall.mapper.WxShopMapper;
|
|
|
|
import com.iformall.service.SysConfigService;
|
|
|
|
import com.iformall.service.WxEnergyService;
|
|
|
|
import com.iformall.service.WxFlowRecordService;
|
|
|
|
import com.iformall.service.WxFlowService;
|
|
|
|
@@ -204,6 +207,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
@Autowired
|
|
|
|
WxEnergyService wxEnergyService;
|
|
|
|
|
|
|
|
@Lazy
|
|
|
|
@Autowired
|
|
|
|
SysConfigService sysConfigService;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<WxRentContract> findList(WxRentContract record){
|
|
|
|
return wxRentContractMapper.findList(record);
|
|
|
|
@@ -2554,6 +2561,8 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
|
|
|
|
//加上物业
|
|
|
|
WxAllBill propertyBill = null;
|
|
|
|
BigDecimal propertyPrice = new BigDecimal(0);
|
|
|
|
WxPropertyContract propertyContract = null;
|
|
|
|
if (null != propertyContractId) {
|
|
|
|
WxAllBill propertyBillq = new WxAllBill();
|
|
|
|
propertyBillq.updateTenantInfo(rentcontract);
|
|
|
|
@@ -2569,7 +2578,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据销售额来计算价格均值
|
|
|
|
//根据销售额来计算平均每计费周期营业额,相当于设置联营扣点保底营业额
|
|
|
|
BigDecimal unitRevenuePrice = calcuteUnitPrice(rentBill.getStarttime(), rentBill.getEndtime(),salesDeciaml,
|
|
|
|
rentcontract.getPriceUnit(),rentcontract.getDayPriceCalcute(),rentcontract.getMonthAverageDays(),rentcontract.getAdjustPeriod(),rentcontract.getReceivePeriodUnit());
|
|
|
|
//设置保底营业额
|
|
|
|
@@ -2581,22 +2590,27 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
}else if (rentcontract.getType().intValue() == EnumRentContractType.RENT_BY_AREA_AND_JOINT.getCode()) {
|
|
|
|
//取高才能加上物业费
|
|
|
|
if (null != propertyContractId && null != propertyBill) {
|
|
|
|
WxPropertyContract propertyContract = wxPropertyContractMapper.selectById(propertyContractId);
|
|
|
|
BigDecimal rentPrice = new BigDecimal(rentcontract.getPrice());
|
|
|
|
propertyContract = wxPropertyContractMapper.selectById(propertyContractId);
|
|
|
|
//有可能物业的单价时间跟租金的不一致,需要根据物业的单价重新计算
|
|
|
|
BigDecimal propertyPrice = calcuteRentPropertyPrice(rentcontract, propertyContract, rentBill.getStarttime(), rentBill.getEndtime(),
|
|
|
|
propertyPrice = calcuteRentPropertyPrice(rentcontract, propertyContract, rentBill.getStarttime(), rentBill.getEndtime(),
|
|
|
|
new BigDecimal(propertyBill.getNeedPay()));
|
|
|
|
|
|
|
|
rentcontract.setPrice(rentPrice.add(propertyPrice).toPlainString());; |
|
|
|
}
|
|
|
|
}
|
|
|
|
//计算每一年的基数
|
|
|
|
String[] priceArrs = WxRentContractHelper.calcuteRentPrice(rentcontract);
|
|
|
|
List<String[]> priceArrs = WxRentContractHelper.calcuteRentAndRevenuePrice(rentcontract);
|
|
|
|
String[] rentPriceArrs = priceArrs.get(0);
|
|
|
|
String[] revenuePriceArrs = priceArrs.get(1);
|
|
|
|
//计算商业管理费
|
|
|
|
String[] bussinessManagerPriceArrs = WxRentContractHelper.calcuteBussinessManagementFee(rentcontract);
|
|
|
|
//计算运营管理费
|
|
|
|
String[] operationManagerPriceArrs = WxRentContractHelper.calcuteOperatingManagementFee(rentcontract);
|
|
|
|
List<Date> yearList = this.getYearList(priceArrs.length, 12, rentcontract.getRentalStartDate(),null);
|
|
|
|
|
|
|
|
//物业费单价
|
|
|
|
String[] propertyContractArrs = null;
|
|
|
|
if (null != propertyContract) {
|
|
|
|
propertyContractArrs = WxRentContractHelper.calcutePropertyPrice(propertyContract);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
@@ -2608,10 +2622,61 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
if (yearIndex <= 0 ) {
|
|
|
|
yearIndex = 0;
|
|
|
|
}
|
|
|
|
//免租期
|
|
|
|
|
|
|
|
//租金+营业管理费+商业管理费+物业 和扣点相比取高。
|
|
|
|
BigDecimal rentTotal = new BigDecimal(rentPriceArrs[yearIndex]);
|
|
|
|
if (null != bussinessManagerPriceArrs) {
|
|
|
|
rentTotal = rentTotal.add(new BigDecimal(bussinessManagerPriceArrs[yearIndex])); |
|
|
|
}
|
|
|
|
if (null != operationManagerPriceArrs) {
|
|
|
|
rentTotal = rentTotal.add(new BigDecimal(operationManagerPriceArrs[yearIndex]));
|
|
|
|
}
|
|
|
|
rentTotal = rentTotal.add(propertyPrice);
|
|
|
|
|
|
|
|
//跟扣点相比较
|
|
|
|
BigDecimal priceDecimal = rentTotal;
|
|
|
|
if (null != revenuePriceArrs) {
|
|
|
|
BigDecimal revenuePrice = new BigDecimal(revenuePriceArrs[yearIndex]);
|
|
|
|
if (revenuePrice.compareTo(rentTotal) > 0 ) {
|
|
|
|
priceDecimal = revenuePrice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//计算资金分摊的比例 租金,商业管理费,营业管理费,物业费。每个科目税点不一样,这样分摊能降低成本
|
|
|
|
String[] moneyShareRates = new String[4];
|
|
|
|
BigDecimal rentPriceDecimal = new BigDecimal(rentPriceArrs[yearIndex]);
|
|
|
|
BigDecimal bussinessPriceDecimal = new BigDecimal(bussinessManagerPriceArrs[yearIndex]);
|
|
|
|
BigDecimal operaterPriceDecimal = new BigDecimal(operationManagerPriceArrs[yearIndex]);
|
|
|
|
if (null != rentPriceArrs && null != bussinessManagerPriceArrs && null != operationManagerPriceArrs
|
|
|
|
&& rentPriceDecimal.compareTo(new BigDecimal(0)) > 0 && bussinessPriceDecimal.compareTo(new BigDecimal(0)) > 0 && operaterPriceDecimal.compareTo(new BigDecimal(0)) > 0) {
|
|
|
|
BigDecimal total = rentPriceDecimal.add(bussinessPriceDecimal).add(operaterPriceDecimal);
|
|
|
|
BigDecimal property = new BigDecimal(0);
|
|
|
|
if (null != propertyContractArrs) {
|
|
|
|
property = new BigDecimal(propertyContractArrs[yearIndex]);
|
|
|
|
}
|
|
|
|
total = total.add(property);
|
|
|
|
moneyShareRates[0] = rentPriceDecimal.divide(total,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
moneyShareRates[1] = bussinessPriceDecimal.divide(total,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
moneyShareRates[2] = operaterPriceDecimal.divide(total,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
moneyShareRates[3] = property.divide(total,Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
}else {
|
|
|
|
SysConfig shareConfig = sysConfigService.getByKey(SysConfigConstant.rent_share_bill_rate, rentcontract);
|
|
|
|
if (null == shareConfig || StringUtils.isBlank(shareConfig.getConfigItemValue())) {
|
|
|
|
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"系统配置"+SysConfigConstant.rent_share_bill_rate+"未配置。");
|
|
|
|
}
|
|
|
|
moneyShareRates = shareConfig.getConfigItemValue().split(",");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//免租期
|
|
|
|
List<Date> freePeriods = getFreeDays(rentcontract);
|
|
|
|
//根据租金和扣点来计算
|
|
|
|
String rentNeedpay = WxRentContractHelper.getNeedPayMoney(freePeriods,rentcontract, priceArrs[yearIndex],rentBill.getStarttime(),
|
|
|
|
|
|
|
|
//根据扣点规则和租赁相关费用取高来计算费用
|
|
|
|
String needpay = WxRentContractHelper.getNeedPayMoney(freePeriods,rentcontract, priceDecimal.toPlainString(),rentBill.getStarttime(),
|
|
|
|
rentBill.getEndtime(),0,0,false,rentcontract.getReceivePeriodUnit(),rentcontract.getReceivePeriod());
|
|
|
|
|
|
|
|
//根据租金来计算
|
|
|
|
String rentNeedpay = WxRentContractHelper.getNeedPayMoney(freePeriods,rentcontract, rentPriceArrs[yearIndex],rentBill.getStarttime(),
|
|
|
|
rentBill.getEndtime(),0,0,false,rentcontract.getReceivePeriodUnit(),rentcontract.getReceivePeriod());
|
|
|
|
|
|
|
|
String bussinessNeedPay = "0";
|
|
|
|
@@ -2625,8 +2690,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
rentBill.getEndtime(),0,0,false,rentcontract.getReceivePeriodUnit(),rentcontract.getReceivePeriod());
|
|
|
|
}
|
|
|
|
|
|
|
|
String needpay = new BigDecimal(rentNeedpay).add(new BigDecimal(bussinessNeedPay)).add(new BigDecimal(operationNeedPay)).toPlainString();
|
|
|
|
|
|
|
|
//计算跳点。
|
|
|
|
BigDecimal[] jumppays = calcuteReveneuJump(salesDeciaml, rentcontract,rentBill.getStarttime(), rentBill.getEndtime(),freePeriods);
|
|
|
|
BigDecimal jumpRevenuePay = jumppays[0];
|
|
|
|
@@ -2639,13 +2702,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
}
|
|
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
if (jumppay.compareTo(new BigDecimal(needpay)) > 0 ) {
|
|
|
|
sb.append("跳点规则计算金额:"+jumppay.toPlainString()+",合同租金扣点规则计算金额:"+needpay+".(其中包含租金:"+rentNeedpay+",商业管理费:"+bussinessNeedPay+",营运管理费:"+operationNeedPay+")");
|
|
|
|
sb.append("跳点规则计算金额:"+jumppay.toPlainString()+",合同租金扣点规则计算金额:"+needpay+".(其中包含租金:"+rentNeedpay+",商业管理费:"+bussinessNeedPay+",营运管理费:"+operationNeedPay+",物业费:"+propertyPrice.toPlainString()+")");
|
|
|
|
needpay = jumppay.toPlainString();
|
|
|
|
}else {
|
|
|
|
sb.append("跳点规则计算金额:"+jumppay.toPlainString()+",合同租金扣点规则计算金额:"+needpay+".(其中包含租金:"+rentNeedpay+",商业管理费:"+bussinessNeedPay+",营运管理费:"+operationNeedPay+")");
|
|
|
|
sb.append("跳点规则计算金额:"+jumppay.toPlainString()+",合同租金扣点规则计算金额:"+needpay+".(其中包含租金:"+rentNeedpay+",商业管理费:"+bussinessNeedPay+",营运管理费:"+operationNeedPay+",物业费:"+propertyPrice.toPlainString()+")");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//保存销售额
|
|
|
|
WxRentContractRevenueSales rs = new WxRentContractRevenueSales();
|
|
|
|
rs.updateTenantInfo(rentcontract);
|
|
|
|
@@ -2672,10 +2734,15 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
wxRentContractRevenueSalesMapper.insert(sale);
|
|
|
|
}
|
|
|
|
|
|
|
|
String rentRate = moneyShareRates[0];
|
|
|
|
String bussinessRate = moneyShareRates[1];
|
|
|
|
String operaterRate = moneyShareRates[2];
|
|
|
|
String propertyRate = moneyShareRates[3];
|
|
|
|
//更新账单费用
|
|
|
|
sb.append("原合同租金金额:"+rentBill.getNeedPay()+"元,计算之后为:"+needpay+"元。");
|
|
|
|
String rentneedpay = new BigDecimal(needpay).multiply(new BigDecimal(rentRate)).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
sb.append("原合同租金金额:"+rentBill.getNeedPay()+"元,计算之后为:"+rentneedpay+"元。");
|
|
|
|
rentBill.setMoneyChangeDetail(sb.toString());
|
|
|
|
rentBill.setReceivePay(needpay);
|
|
|
|
rentBill.setReceivePay(rentneedpay);
|
|
|
|
rentBill.setBillRemark("设置销售额,自动计算");
|
|
|
|
rentBill.setUpdatetime(new Date());
|
|
|
|
if (new BigDecimal(rentBill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) {
|
|
|
|
@@ -2686,9 +2753,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
wxAllBillMapper.updateById(rentBill);
|
|
|
|
//物业账单应收就改为0,因为金额已经合并了
|
|
|
|
if (null != propertyBill) {
|
|
|
|
propertyBill.setMoneyChangeDetail("原合同物业金额:"+propertyBill.getNeedPay()+"元,已合并到租金,调整为:0元。");
|
|
|
|
propertyBill.setReceivePay("0");
|
|
|
|
propertyBill.setBillRemark("设置销售额,已自动计算合并到租金");
|
|
|
|
String propertymoney = new BigDecimal(needpay).multiply(new BigDecimal(propertyRate)).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
propertyBill.setMoneyChangeDetail("原合同物业金额:"+propertyBill.getNeedPay()+"元,计算调整为:"+propertymoney+"元。");
|
|
|
|
propertyBill.setReceivePay(propertymoney);
|
|
|
|
propertyBill.setBillRemark("设置销售额,自动计算");
|
|
|
|
if (new BigDecimal(propertyBill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) {
|
|
|
|
propertyBill.setStatus(EnumBillStatus.STOP_TO_SETTLE.getCode());
|
|
|
|
}else {
|
|
|
|
@@ -2711,9 +2779,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
WxAllBill bmbill = null;
|
|
|
|
if (null != bmbillList && bmbillList.size() > 0 ) {
|
|
|
|
bmbill = bmbillList.get(0);
|
|
|
|
bmbill.setMoneyChangeDetail("原合同商业管理费金额:"+bmbill.getNeedPay()+"元,已合并到租金,调整为:0元。");
|
|
|
|
bmbill.setReceivePay("0");
|
|
|
|
bmbill.setBillRemark("设置销售额,已自动计算合并到租金");
|
|
|
|
String bussinessmoney = new BigDecimal(needpay).multiply(new BigDecimal(bussinessRate)).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
bmbill.setMoneyChangeDetail("原合同商业管理费金额:"+bmbill.getNeedPay()+"元,计算调整为:"+bussinessmoney+"元。");
|
|
|
|
bmbill.setReceivePay(bussinessmoney);
|
|
|
|
bmbill.setBillRemark("设置销售额,自动计算");
|
|
|
|
if (new BigDecimal(bmbill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) {
|
|
|
|
bmbill.setStatus(EnumBillStatus.STOP_TO_SETTLE.getCode());
|
|
|
|
}else {
|
|
|
|
@@ -2735,9 +2804,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { |
|
|
|
WxAllBill ombill = null;
|
|
|
|
if (null != ombillList && ombillList.size() > 0 ) {
|
|
|
|
ombill = ombillList.get(0);
|
|
|
|
ombill.setMoneyChangeDetail("原合同营业管理费金额:"+bmbill.getNeedPay()+"元,已合并到租金,调整为:0元。");
|
|
|
|
ombill.setReceivePay("0");
|
|
|
|
ombill.setBillRemark("设置销售额,已自动计算合并到租金");
|
|
|
|
String operatermoney = new BigDecimal(needpay).multiply(new BigDecimal(operaterRate)).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP).toPlainString();
|
|
|
|
ombill.setMoneyChangeDetail("原合同营业管理费金额:"+bmbill.getNeedPay()+"元,计算调整为:"+operatermoney+"元。");
|
|
|
|
ombill.setReceivePay(operatermoney);
|
|
|
|
ombill.setBillRemark("设置销售额,自动计算");
|
|
|
|
if (new BigDecimal(ombill.getOwe()).compareTo(new BigDecimal(0)) < 0 ) {
|
|
|
|
ombill.setStatus(EnumBillStatus.STOP_TO_SETTLE.getCode());
|
|
|
|
}else {
|
|
|
|
|