到账开票

This commit is contained in:
baozhipeng
2021-09-10 18:02:44 +08:00
parent be9c3cc0a8
commit 354d352bff
2 changed files with 80 additions and 19 deletions
@@ -119,9 +119,10 @@ public class PayMailBillServiceImpl extends ServiceImpl<PayMailBillMapper, PayMa
//校验不同项目是否属于同一个公司
private String checkCompanyProject(String[] projectIdArray,String[] projectTypeArray){
String standardCompanyId =null;//基准公司id
for (int i = 0; i < projectTypeArray.length; i++) {
String standardCompanyId =null;//基准公司id
switch (projectTypeArray[i]) {
// 普通项目
@@ -81,6 +81,8 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
BigDecimal receivableAmount;
Boolean isAdd;
BigDecimal newPaidAmount;
BigDecimal paidAmount;
Integer inAccount;
//累加主列表实收金额
switch (String.valueOf(payPaymentRecord.getProjectType())){
@@ -89,14 +91,16 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
PayCommonProject payCommonProject = payCommonProjectMapper.selectById(payPaymentRecord.getProjectId());
receivableAmount = payCommonProject.getReceivableAmount();//应收
paidAmount=payCommonProject.getPaidAmount();//实收
//是否还能再添加来款
isAdd = isAdd(receivableAmount, payPaymentRecord.getAmountReceived());
isAdd = isAdd(receivableAmount,paidAmount, payPaymentRecord.getAmountReceived());
if(isAdd){
//累加实收
newPaidAmount =addPaidAmount(payCommonProject.getPaidAmount(),payPaymentRecord.getAmountReceived());
newPaidAmount =addPaidAmount(paidAmount,payPaymentRecord.getAmountReceived());//累加实收
inAccount = getInAccount(receivableAmount, newPaidAmount);//到账状态
//更新主列表
payCommonProject.setPaidAmount(newPaidAmount);
payCommonProject.setInAccount(inAccount);
payCommonProjectMapper.updateById(payCommonProject);
}else{
return Result.error("到账金额大于当前欠款金额,不可提交!");
@@ -107,14 +111,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
PayWorkingGroupSubItem payWorking = payWorkingGroupSubItemMapper.selectById(payPaymentRecord.getProjectId());
receivableAmount = payWorking.getReceivableAmount();//应收
paidAmount=payWorking.getPaidAmount();//实收
//是否还能再添加来款
isAdd = isAdd(receivableAmount, payPaymentRecord.getAmountReceived());
isAdd = isAdd(receivableAmount,paidAmount, payPaymentRecord.getAmountReceived());
if(isAdd){
//累加实收
newPaidAmount =addPaidAmount(payWorking.getPaidAmount(),payPaymentRecord.getAmountReceived());
newPaidAmount =addPaidAmount(paidAmount,payPaymentRecord.getAmountReceived());//累加实收
inAccount = getInAccount(receivableAmount, newPaidAmount);//到账状态
//更新主列表
payWorking.setPaidAmount(newPaidAmount);
payWorking.setInAccount(inAccount);
payWorkingGroupSubItemMapper.updateById(payWorking);
}else{
return Result.error("到账金额大于当前欠款金额,不可提交!");
@@ -125,14 +132,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
PayMeetingSituation meeting = payMeetingSituationMapper.selectById(payPaymentRecord.getProjectId());
receivableAmount = meeting.getAmountReceivable();//应收
paidAmount=meeting.getPaidAmount();//实收
//是否还能再添加来款
isAdd = isAdd(receivableAmount, payPaymentRecord.getAmountReceived());
isAdd = isAdd(receivableAmount,paidAmount, payPaymentRecord.getAmountReceived());
if(isAdd){
//累加实收
newPaidAmount =addPaidAmount(meeting.getPaidAmount(),payPaymentRecord.getAmountReceived());
newPaidAmount =addPaidAmount(paidAmount,payPaymentRecord.getAmountReceived());//累加实收
inAccount = getInAccount(receivableAmount, newPaidAmount);//到账状态
//更新主列表
meeting.setPaidAmount(newPaidAmount);
meeting.setInAccount(inAccount);
payMeetingSituationMapper.updateById(meeting);
}else{
return Result.error("到账金额大于当前欠款金额,不可提交!");
@@ -143,14 +153,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
PayMemberProjectSubitem member = payMemberProjectSubitemMapper.selectById(payPaymentRecord.getProjectId());
receivableAmount = member.getAmountReceivable();//应收
paidAmount=member.getPaidAmount();//实收
//是否还能再添加来款
isAdd = isAdd(receivableAmount, payPaymentRecord.getAmountReceived());
isAdd = isAdd(receivableAmount, paidAmount,payPaymentRecord.getAmountReceived());
if(isAdd){
//累加实收
newPaidAmount =addPaidAmount(member.getPaidAmount(),payPaymentRecord.getAmountReceived());
newPaidAmount =addPaidAmount(paidAmount,payPaymentRecord.getAmountReceived());//累加实收
inAccount = getInAccount(receivableAmount, newPaidAmount);//到账状态
//更新主列表
member.setPaidAmount(newPaidAmount);
member.setInAccount(inAccount);
payMemberProjectSubitemMapper.updateById(member);
}else{
return Result.error("到账金额大于当前欠款金额,不可提交!");
@@ -161,14 +174,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
TbMemberProjectSubitem tbMember = tbMemberProjectSubitemMapper.selectById(payPaymentRecord.getProjectId());
receivableAmount = tbMember.getAmountReceivable();//应收
paidAmount=tbMember.getPaidAmount();//实收
//是否还能再添加来款
isAdd = isAdd(receivableAmount, payPaymentRecord.getAmountReceived());
isAdd = isAdd(receivableAmount,paidAmount, payPaymentRecord.getAmountReceived());
if(isAdd){
//累加实收
newPaidAmount =addPaidAmount(tbMember.getPaidAmount(),payPaymentRecord.getAmountReceived());
newPaidAmount =addPaidAmount(paidAmount,payPaymentRecord.getAmountReceived());//累加实收
inAccount = getInAccount(receivableAmount, newPaidAmount);//到账状态
//更新主列表
tbMember.setPaidAmount(newPaidAmount);
tbMember.setInAccount(inAccount);
tbMemberProjectSubitemMapper.updateById(tbMember);
}else{
return Result.error("到账金额大于当前欠款金额,不可提交!");
@@ -192,6 +208,17 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
if(type5List!=null && type5List.size()>0){
return "标协会员项目,只能来款一次。";
}
TbMemberProjectSubitem tbMemberInsert = tbMemberProjectSubitemMapper.selectById(payPaymentRecord.getProjectId());
BigDecimal rAInsert = tbMemberInsert.getAmountReceivable();//应收
BigDecimal pAInsert = tbMemberInsert.getPaidAmount();//实收
BigDecimal aRInsert =payPaymentRecord.getAmountReceived();//到账
//欠款
BigDecimal debtInsert = rAInsert.subtract(pAInsert);
if(aRInsert.compareTo(debtInsert) != 0){
return "标协会员项目,到账金额不等于欠款金额。";
}
}
payPaymentRecordMapper.insert(payPaymentRecord);
return "success";
@@ -200,15 +227,19 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
/**
* 是否还能再添加来款
* @param receivableAmount 应收
* @param paidAmount 实收
* @param amountReceived 到账
* @return
*/
private Boolean isAdd(BigDecimal receivableAmount, BigDecimal amountReceived){
private Boolean isAdd(BigDecimal receivableAmount,BigDecimal paidAmount,BigDecimal amountReceived){
if(receivableAmount == null){
receivableAmount = new BigDecimal("0");
}
if(paidAmount == null){
paidAmount = new BigDecimal("0");
}
//欠款
BigDecimal debt = receivableAmount.subtract(amountReceived);
BigDecimal debt = receivableAmount.subtract(paidAmount);
if(amountReceived.compareTo(debt) == 1){
//本次到账金额大于欠款
@@ -231,4 +262,33 @@ public class PayPaymentRecordServiceImpl extends ServiceImpl<PayPaymentRecordMap
}
return paidAmount.add(amountReceived).setScale(2,BigDecimal.ROUND_HALF_UP);
}
/**
* 得到到账状态
* @param receivableAmount 应收
* @param paidAmount 实收
* @return
*/
private Integer getInAccount(BigDecimal receivableAmount,BigDecimal paidAmount){
BigDecimal zero =new BigDecimal("0");
//应收=0
if(receivableAmount.compareTo(zero)==0){
return 3;
}
//应收>实收>0
if(receivableAmount.compareTo(paidAmount) == 1 && paidAmount!=null && paidAmount.compareTo(zero)==1){
return 2;
}
//应收=实收
if(receivableAmount.compareTo(paidAmount) == 0){
return 1;
}
//实收=0
if(paidAmount.compareTo(zero)==0){
return 0;
}else{
return 4;
}
}
}