Commit 85ce37a1 by kangxiaoshan

合同调整金

parent c14432c0
......@@ -117,6 +117,6 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select * from contract where ((start_date <= ?1 and end_date >= ?1) or (start_date <= ?2 and end_date >= ?2) or (start_date >= ?1 and end_date <= ?2) or (start_date <= ?1 and end_date >= ?2)) and platform=?3 and my_body_code in ?4 and status!='del' ", nativeQuery = true)
List<Contract> findShareContranctByDateFinace(String startDate, String endDate, String platform, List<String> financeBodies);
@Query(value = "select contract_code from contract where customer_body =? limit 3 ",nativeQuery = true)
List<String> findContractBodyNames(String customerBody);
@Query(value = "select contract_code from contract where customer_body =?1 and contract_code <> ?2 limit 3 ", nativeQuery = true)
List<String> findContractBodyNames(String customerBody, String contractCode);
}
......@@ -1586,6 +1586,7 @@ public class ContractServiceImpl implements ContractService {
Contract contract = contractRepository.findByCode(resource.getContractCode());
Map<Long, String> packageMap = getPackageMap(contract);
boolean showTip = false;
if (resource.getType().equals("price")) {
resource.setContent(packageMap.get(contract.getPriceLevel()) + "改为" + packageMap.get(resource.getLevel()));
......@@ -1614,10 +1615,12 @@ public class ContractServiceImpl implements ContractService {
//合同作废
resource.setContent(ContractStatusEnum.CANCEL.getValue());
contract.setStatus(ContractStatusEnum.CANCEL.getKey());
showTip = true;
} else if (ContractStatusEnum.SUSPEND.getKey().equals(resource.getStatus())) {
//合同中止
resource.setContent(ContractStatusEnum.SUSPEND.getValue());
contract.setStatus(ContractStatusEnum.SUSPEND.getKey());
showTip = true;
}
}
......@@ -1625,6 +1628,7 @@ public class ContractServiceImpl implements ContractService {
resource.setCreateAccount(loginUser.getId());
resource.setUser(loginUser.getId());
if (ContractStatusEnum.SUSPEND.getKey().equals(resource.getStatus())) {
resource.setCreateTime(new Date());
} else {
......@@ -1639,10 +1643,12 @@ public class ContractServiceImpl implements ContractService {
contractRepository.save(contract);
if (ContractStatusEnum.SUSPEND.getKey().equals(contract.getStatus())) {
if (showTip) {
//获取相关执行合同名称
List<String> codes = contractRepository.findContractBodyNames(contract.getCustomerBody());
List<String> codes = contractRepository.findContractBodyNames(contract.getCustomerBody(),contract.getContractCode());
contract.setCustomBodyNames(codes);
}else{
contract.setCustomBodyNames(new ArrayList<>());
}
return contract;
......
package common.service.impl;
import com.amazonaws.services.dynamodbv2.xspec.B;
import common.model.*;
import common.repository.AuthRepository;
import common.repository.ContractBodyRepository;
......@@ -11,10 +12,13 @@ import dic.RoleEnum;
import net.sf.json.JSONArray;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -22,6 +26,9 @@ import java.util.stream.Collectors;
@Service
public class ShareIncomeServiceImpl implements ShareIncomeService {
private final Logger logger = LoggerFactory.getLogger(ShareIncomeServiceImpl.class);
@Autowired
private ContractRepository contractRepository;
@Autowired
......@@ -84,6 +91,7 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
DateTime end = new DateTime(endDate);
for (Contract contract : contracts) {
this.caculateShareIncome(contract, start, end);
contract.setMyBodyName(bodiesNameMap.get(contract.getMyBodyCode()));
}
......@@ -113,6 +121,12 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
Long excludTax = contract.getMoney() * 94;//不含税收入*100 :contract.getMoney()*100 - contract.getMoney()*0.06*100 = contract.getMoney()*94
contract.setIncomeExcludingTax(excludTax);
//每天的分摊收入
//Long shareIncomDay = contract.getMoney() * 94 / allDay;
//处理精度
Long shareIncomDay = new BigDecimal(contract.getMoney() * 94 * 1.0 / allDay)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
DateTime creatMonth = create.dayOfMonth().withMinimumValue();//合同录入月1号
int aferDays = 9;
......@@ -120,41 +134,140 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
// 12月份的合同 次月30号(包含)
aferDays = 29;
}
DateTime nextMonth;
DateTime nextMonth = null;
Long adjustmentFund = 0L;
int betweenMonth = create.getMonthOfYear() - contractStart.getMonthOfYear();
if (ContractStatusEnum.CANCEL.getKey().equals(contract.getStatus()) || ContractStatusEnum.SUSPEND.getKey().equals(contract.getStatus())) {
//合同作废
String contentKey = ContractStatusEnum.CANCEL.getKey().equals(contract.getStatus()) ?
ContractStatusEnum.CANCEL.getValue() : ContractStatusEnum.SUSPEND.getValue();
boolean isCancel = ContractStatusEnum.CANCEL.getKey().equals(contract.getStatus()) ? true : false;
String contentKey = isCancel ? ContractStatusEnum.CANCEL.getValue() : ContractStatusEnum.SUSPEND.getValue();
ContractChange contractChange = contractChangeRepository.findByContentCode(contentKey, contract.getContractCode());
if (contractChange == null) {
contract.setAdjustmentFund(0L);
contract.setIntervaIncomeShare(0L);
contract.setIncomeShareAll(0L);
return;
}
// 合同终止日 或 作废日
DateTime cancelDate = new DateTime(contractChange.getDs());
//每天的分摊收入
Long shareIncomDay = contract.getMoney() * 94 / allDay;
usedEnd = cancelDate.compareTo(usedEnd) <= 0 ? cancelDate : usedEnd;
if (isCancel) {
int daysIncom = Days.daysBetween(contractStart, usedEnd).getDays() + 1;
adjustmentFund = new BigDecimal((Days.daysBetween(contractStart, cancelDate).getDays() + 1) * excludTax * 1.0 / allDay)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue() * -1;
usedEnd = usedEnd.compareTo(cancelDate) <= 0 ? usedEnd : cancelDate;
int daysIncom = Days.daysBetween(usedStart, usedEnd).getDays() + 1;
daysIncom = daysIncom < 0 ? 0 : daysIncom;
//区间分摊总收入
contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
//调整金
int daysCancle = Days.daysBetween(cancelDate, contractStart).getDays() + 1;
int reservType = ContractStatusEnum.CANCEL.getKey().equals(contract.getStatus()) ? -1 : 1;
Long adjustmentFund = daysCancle * excludTax / allDay * reservType;
if (checkTwoTime(start, cancelDate)) {
boolean fullRange = Days.daysBetween(start, end).getDays()
>= Days.daysBetween(contractStart, cancelDate).getDays() ? true : false;
if (fullRange) {
contract.setAdjustmentFund(-1 * contract.getIntervaIncomeShare());
} else if (checkTwoTime(start, cancelDate) && checkTwoTime(cancelDate, end)) {
contract.setAdjustmentFund(adjustmentFund);
//分摊加入调整金
contract.setIntervaIncomeShare(shareIncomDay * daysIncom + adjustmentFund);
} else {
contract.setAdjustmentFund(0L);
}
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
} else {
//中止操作入库时间
DateTime suspendDate = new DateTime(new DateTime(contractChange.getCreateTime()).toString("yyyy-MM-dd"));
if (checkTwoTime(suspendDate, cancelDate)) {
adjustmentFund = 0L;
} else {
adjustmentFund = new BigDecimal((Days.daysBetween(cancelDate, suspendDate).getDays() + 1) * excludTax * 1.0 / allDay)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue() * -1;
}
usedEnd = usedEnd.compareTo(cancelDate) <= 0 ? usedEnd : cancelDate;
int daysIncom = Days.daysBetween(usedStart, usedEnd).getDays() + 1;
daysIncom = daysIncom < 0 ? 0 : daysIncom;
//区间分摊总收入
contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
if (checkTwoTime(start, cancelDate) && checkTwoTime(cancelDate, end)) {
contract.setAdjustmentFund(adjustmentFund);
} else {
contract.setAdjustmentFund(0L);
}
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
}
// if (cancelDate.isBefore(start) && isCancel) {
// contract.setAdjustmentFund(0L);
// //分摊加入调整金
// contract.setIntervaIncomeShare(0L);
// return;
// }
//
// usedEnd = cancelDate.compareTo(usedEnd) <= 0 ? cancelDate : usedEnd;
//
// int daysIncom = Days.daysBetween(usedStart, usedEnd).getDays() + 1;
// daysIncom = daysIncom < 0 ? 0 : daysIncom;
// //区间分摊总收入
// contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
//
// //调整金
// int daysCancle = 0;
//
// if (isCancel) {
// //合同作废
// daysCancle = Days.daysBetween(contractStart, usedEnd).getDays() + 1;
//
// } else {
// //合同中止
// daysCancle = Days.daysBetween(usedStart, usedEnd).getDays() + 1;
// }
//
// adjustmentFund = new BigDecimal(daysCancle * excludTax * 1.0 / allDay)
// .setScale(0, BigDecimal.ROUND_HALF_UP).longValue() * -1;
//
// DateTime shareEnd = cancelDate.compareTo(contractEnd) <= 0 ? cancelDate : contractEnd;
//
// if (isCancel) {
// if (checkTwoTime(shareEnd, end)) {
// contract.setAdjustmentFund(adjustmentFund);
// } else {
// contract.setAdjustmentFund(0L);
// }
// } else {
//
// if (checkTwoTime(end, usedEnd)) {
// contract.setAdjustmentFund(0L);
// } else {
// contract.setAdjustmentFund(adjustmentFund);
// }
// }
//
// //分摊
// contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
// contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
//中止 取消 合同逻辑结束
return;
} else if (contractStart.dayOfMonth().withMaximumValue().plusDays(aferDays).isBefore(create)) {
int betweenMonth = create.getMonthOfYear() - contractStart.getMonthOfYear();
//录入时间在次月10以后
//录入时间在次月10以后 或次月30日以后
if (betweenMonth == 1) {
//相差一月
nextMonth = contractStart.dayOfMonth().withMaximumValue().plusDays(1);//合同开始次月1号 与调整金对应
......@@ -174,13 +287,12 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
//执行期内的分摊金额开始时间
nextMonth = usedStart;
}
//筛选结束时间包含合同开始次月1号 则计算分摊收入
//每天的分摊收入
Long shareIncomDay = contract.getMoney() * 94 / allDay;
//筛选结束时间包含合同开始次月1号 则计算分摊收入
//时间范围内用于计算分摊金额的天数
int daysIncom = Days.daysBetween(start, usedEnd).getDays() + 1;
//区间分摊总收入
DateTime shareStart = start.compareTo(nextMonth) <= 0 ? nextMonth : start;
int daysIncom = Days.daysBetween(shareStart, usedEnd).getDays() + 1;
//区间分摊收入
contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
} else {
contract.setIntervaIncomeShare(0L);
......@@ -188,31 +300,59 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
//调证金 筛选时间包含录入月1号 则计算调证金
//调证金:(合同开始月最后一日 - 合同开始日期 + 1)* (不含税收入 / 合同总天数)
Long adjustmentFund;
if (betweenMonth == 1) {
adjustmentFund = nextMonth == null ? 0 : (contractStart.dayOfMonth().withMaximumValue().dayOfMonth().get()
- contractStart.getDayOfMonth() + 1) * excludTax / allDay;
adjustmentFund = nextMonth == null ? 0 : new BigDecimal((contractStart.dayOfMonth().withMaximumValue().dayOfMonth().get()
- contractStart.getDayOfMonth() + 1) * excludTax * 1.0 / allDay)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
} else {
adjustmentFund = nextMonth == null ? 0 :
(nextMonth.plusDays(-1).dayOfMonth().withMaximumValue().dayOfMonth().get() - contractStart.getDayOfMonth() + 1)
* excludTax / allDay;
new BigDecimal((Days.daysBetween(contractStart, creatMonth.plusDays(-1)).getDays() + 1) * 1.0 * excludTax / allDay)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
}
if (nextMonth != null && checkTwoTime(start, creatMonth) && checkTwoTime(nextMonth, end)) {
if (nextMonth != null && checkTwoTime(start, nextMonth) && checkTwoTime(nextMonth, end)) {
contract.setAdjustmentFund(adjustmentFund);
//筛选开始时间包含次月1号,则分摊金需加上调证金
contract.setIntervaIncomeShare(contract.getIntervaIncomeShare() + adjustmentFund);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
} else {
contract.setAdjustmentFund(0L);
}
if (nextMonth != null && checkTwoTime(start, nextMonth) && checkTwoTime(nextMonth, end)) {
//筛选开始时间包含次月1号,则分摊金需加上调证金
contract.setIntervaIncomeShare(contract.getIntervaIncomeShare() + adjustmentFund);
} else {
//时间范围内用于计算分摊金额的天数
int daysIncom = Days.daysBetween(start, usedEnd).getDays() + 1;
//区间分摊总收入
contract.setIntervaIncomeShare(shareIncomDay * daysIncom);
contract.setAdjustmentFund(0L);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
adjustmentFund = 0L;
}
contract.setIncomeShareAll(contract.getIntervaIncomeShare() + contract.getAdjustmentFund());
DateTime dayShareStartDate;
dayShareStartDate = nextMonth == null ? contractStart : nextMonth;
//最后一日 包含最后一日 时 分摊金处理
// adjustmentFund = adjustmentFund < 0 ? 0 : adjustmentFund;
Long lastDay = excludTax - adjustmentFund - shareIncomDay * (Days.daysBetween(dayShareStartDate, contractEnd).getDays());
if (start.isEqual(end) && start.isEqual(contractEnd)) {
//最后一日分摊金处理
contract.setIntervaIncomeShare(lastDay);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
} else if (checkTwoTime(contractEnd, end)) {
//包含最后一日 时
contract.setIntervaIncomeShare(contract.getIntervaIncomeShare() - shareIncomDay + lastDay);
contract.setIncomeShareAll(contract.getIntervaIncomeShare());
}
}
......@@ -223,10 +363,15 @@ public class ShareIncomeServiceImpl implements ShareIncomeService {
public static void main(String[] args) {
DateTime contractStart = new DateTime("2020-05-15");
DateTime create = new DateTime("2020-06-15");
// System.out.println(contractStart.monthOfYear().getDateTime());
System.out.println(contractStart.monthOfYear().getDateTime());
System.out.println(contractStart.dayOfMonth().withMaximumValue().plusDays(1));
System.out.println(contractStart.dayOfMonth().withMaximumValue().plusDays(9).isBefore(create));
System.out.println(contractStart.compareTo(create));
long ss = new BigDecimal(94000 * 1.0 / 52)
.setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
System.out.println(ss);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment