给采购和销售退货单增加校验逻辑,支持特殊情况的欠款

This commit is contained in:
季圣华
2022-11-20 01:23:25 +08:00
parent f006b4c80f
commit 54bf2dd370
3 changed files with 91 additions and 11 deletions

View File

@@ -361,9 +361,9 @@ public class ExceptionConstants {
//单据录入-请修改多账户的结算金额 //单据录入-请修改多账户的结算金额
public static final int DEPOT_HEAD_MANY_ACCOUNT_FAILED_CODE = 8500008; public static final int DEPOT_HEAD_MANY_ACCOUNT_FAILED_CODE = 8500008;
public static final String DEPOT_HEAD_MANY_ACCOUNT_FAILED_MSG = "请修改多账户的结算金额"; public static final String DEPOT_HEAD_MANY_ACCOUNT_FAILED_MSG = "请修改多账户的结算金额";
//单据录入-退货单不能欠款 //单据录入-关联单据实际不存在欠款
public static final int DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE = 8500009; public static final int DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE = 8500009;
public static final String DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG = "退货单不能欠款"; public static final String DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG = "抱歉,关联单据实际不存在欠款";
//单据录入-调入仓库与原仓库不能重复 //单据录入-调入仓库与原仓库不能重复
public static final int DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_CODE = 8500010; public static final int DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_CODE = 8500010;
public static final String DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_MSG = "调入仓库与原仓库不能重复"; public static final String DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_MSG = "调入仓库与原仓库不能重复";
@@ -391,6 +391,9 @@ public class ExceptionConstants {
//单据录入-商品条码XXX的单价低于最低售价 //单据录入-商品条码XXX的单价低于最低售价
public static final int DEPOT_HEAD_UNIT_PRICE_LOW_CODE = 8000018; public static final int DEPOT_HEAD_UNIT_PRICE_LOW_CODE = 8000018;
public static final String DEPOT_HEAD_UNIT_PRICE_LOW_MSG = "商品条码%s的单价低于最低售价"; public static final String DEPOT_HEAD_UNIT_PRICE_LOW_MSG = "商品条码%s的单价低于最低售价";
//单据录入-本次欠款金额不能大于关联单据实际的欠款
public static final int DEPOT_HEAD_BACK_BILL_DEBT_OVER_CODE = 8500019;
public static final String DEPOT_HEAD_BACK_BILL_DEBT_OVER_MSG = "抱歉,本次欠款金额不能大于关联单据实际的欠款";
/** /**
* 单据明细信息 * 单据明细信息
* type = 90 * type = 90

View File

@@ -52,6 +52,11 @@ public class DepotHeadVo4List extends DepotHead{
*/ */
private Boolean hasBackFlag; private Boolean hasBackFlag;
/**
* 实际欠款
*/
private BigDecimal realNeedDebt;
public String getProjectName() { public String getProjectName() {
return projectName; return projectName;
} }
@@ -211,4 +216,12 @@ public class DepotHeadVo4List extends DepotHead{
public void setHasBackFlag(Boolean hasBackFlag) { public void setHasBackFlag(Boolean hasBackFlag) {
this.hasBackFlag = hasBackFlag; this.hasBackFlag = hasBackFlag;
} }
public BigDecimal getRealNeedDebt() {
return realNeedDebt;
}
public void setRealNeedDebt(BigDecimal realNeedDebt) {
this.realNeedDebt = realNeedDebt;
}
} }

View File

@@ -780,6 +780,18 @@ public class DepotHeadService {
return depotHeadMapper.selectByExample(example); return depotHeadMapper.selectByExample(example);
} }
/**
* 根据原单号查询关联的单据列表(排除当前的单据编号)
* @param linkNumber
* @return
* @throws Exception
*/
public List<DepotHead> getBillListByLinkNumberExceptNumber(String linkNumber, String number)throws Exception {
DepotHeadExample example = new DepotHeadExample();
example.createCriteria().andLinkNumberEqualTo(linkNumber).andNumberNotEqualTo(number).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
return depotHeadMapper.selectByExample(example);
}
/** /**
* 新增单据主表及单据子表信息 * 新增单据主表及单据子表信息
* @param beanJson * @param beanJson
@@ -802,9 +814,12 @@ public class DepotHeadService {
} }
//欠款校验 //欠款校验
if("采购退货".equals(subType) || "销售退货".equals(subType)) { if("采购退货".equals(subType) || "销售退货".equals(subType)) {
if(depotHead.getChangeAmount().abs().compareTo(depotHead.getDiscountLastMoney().add(depotHead.getOtherMoney()))!=0) { //退货单对应的原单实际欠款(这里面要除去收付款的金额)
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE, BigDecimal originalRealDebt = getOriginalRealDebt(depotHead.getLinkNumber(), depotHead.getNumber());
String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG)); JSONObject billObj = JSONObject.parseObject(beanJson);
if(billObj!=null && billObj.get("debt")!=null && originalRealDebt.compareTo(billObj.getBigDecimal("debt"))<0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_OVER_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_OVER_MSG));
} }
} }
//判断用户是否已经登录过,登录过不再处理 //判断用户是否已经登录过,登录过不再处理
@@ -897,9 +912,12 @@ public class DepotHeadService {
} }
//欠款校验 //欠款校验
if("采购退货".equals(subType) || "销售退货".equals(subType)) { if("采购退货".equals(subType) || "销售退货".equals(subType)) {
if(depotHead.getChangeAmount().abs().compareTo(depotHead.getDiscountLastMoney().add(depotHead.getOtherMoney()))!=0) { //退货单对应的原单实际欠款(这里面要除去收付款的金额)
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE, BigDecimal originalRealDebt = getOriginalRealDebt(depotHead.getLinkNumber(), depotHead.getNumber());
String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG)); JSONObject billObj = JSONObject.parseObject(beanJson);
if(billObj!=null && billObj.get("debt")!=null && originalRealDebt.compareTo(billObj.getBigDecimal("debt"))<0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_OVER_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_OVER_MSG));
} }
} }
if(StringUtil.isNotEmpty(depotHead.getAccountIdList())){ if(StringUtil.isNotEmpty(depotHead.getAccountIdList())){
@@ -953,6 +971,38 @@ public class DepotHeadService {
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
} }
/**
* 退货单对应的原单实际欠款(这里面要除去收付款的金额)
* @param linkNumber 原单单号
* @param number 当前单号
* @return
*/
public BigDecimal getOriginalRealDebt(String linkNumber, String number) throws Exception {
DepotHead depotHead = getDepotHead(linkNumber);
BigDecimal discountLastMoney = depotHead.getDiscountLastMoney()!=null?depotHead.getDiscountLastMoney():BigDecimal.ZERO;
BigDecimal otherMoney = depotHead.getOtherMoney()!=null?depotHead.getOtherMoney():BigDecimal.ZERO;
BigDecimal deposit = depotHead.getDeposit()!=null?depotHead.getDeposit():BigDecimal.ZERO;
BigDecimal changeAmount = depotHead.getChangeAmount()!=null?depotHead.getChangeAmount().abs():BigDecimal.ZERO;
//原单欠款
BigDecimal debt = discountLastMoney.add(otherMoney).subtract((deposit.add(changeAmount)));
//完成欠款
BigDecimal finishDebt = accountItemService.getEachAmountByBillId(depotHead.getId());
finishDebt = finishDebt!=null?finishDebt:BigDecimal.ZERO;
//原单对应的退货单欠款(总数)
List<DepotHead> billList = getBillListByLinkNumberExceptNumber(linkNumber, number);
BigDecimal allBillDebt = BigDecimal.ZERO;
for(DepotHead dh: billList) {
BigDecimal billDiscountLastMoney = dh.getDiscountLastMoney()!=null?dh.getDiscountLastMoney():BigDecimal.ZERO;
BigDecimal billOtherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():BigDecimal.ZERO;
BigDecimal billDeposit = dh.getDeposit()!=null?dh.getDeposit():BigDecimal.ZERO;
BigDecimal billChangeAmount = dh.getChangeAmount()!=null?dh.getChangeAmount().abs():BigDecimal.ZERO;
BigDecimal billDebt = billDiscountLastMoney.add(billOtherMoney).subtract((billDeposit.add(billChangeAmount)));
allBillDebt = allBillDebt.add(billDebt);
}
//原单实际欠款
return debt.subtract(finishDebt).subtract(allBillDebt);
}
public Map<String, Object> getBuyAndSaleStatistics(String today, String monthFirstDay, String yesterdayBegin, String yesterdayEnd, public Map<String, Object> getBuyAndSaleStatistics(String today, String monthFirstDay, String yesterdayBegin, String yesterdayEnd,
String yearBegin, String yearEnd, String roleType, HttpServletRequest request) throws Exception { String yearBegin, String yearEnd, String roleType, HttpServletRequest request) throws Exception {
String [] creatorArray = getCreatorArray(roleType); String [] creatorArray = getCreatorArray(roleType);
@@ -1076,15 +1126,29 @@ public class DepotHeadService {
BigDecimal discountLastMoney = dh.getDiscountLastMoney()!=null?dh.getDiscountLastMoney():BigDecimal.ZERO; BigDecimal discountLastMoney = dh.getDiscountLastMoney()!=null?dh.getDiscountLastMoney():BigDecimal.ZERO;
BigDecimal otherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():BigDecimal.ZERO; BigDecimal otherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():BigDecimal.ZERO;
BigDecimal deposit = dh.getDeposit()!=null?dh.getDeposit():BigDecimal.ZERO; BigDecimal deposit = dh.getDeposit()!=null?dh.getDeposit():BigDecimal.ZERO;
BigDecimal changeAmount = dh.getChangeAmount()!=null?dh.getChangeAmount():BigDecimal.ZERO; BigDecimal changeAmount = dh.getChangeAmount()!=null?dh.getChangeAmount().abs():BigDecimal.ZERO;
//欠款 //本单欠款
dh.setNeedDebt(discountLastMoney.add(otherMoney).subtract(deposit.add(changeAmount))); dh.setNeedDebt(discountLastMoney.add(otherMoney).subtract(deposit.add(changeAmount)));
List<DepotHead> billList = getBillListByLinkNumber(dh.getNumber());
//退货单欠款(总数)
BigDecimal allBillDebt = BigDecimal.ZERO;
for(DepotHead depotHead: billList) {
BigDecimal billDiscountLastMoney = depotHead.getDiscountLastMoney()!=null?depotHead.getDiscountLastMoney():BigDecimal.ZERO;
BigDecimal billOtherMoney = depotHead.getOtherMoney()!=null?depotHead.getOtherMoney():BigDecimal.ZERO;
BigDecimal billDeposit = depotHead.getDeposit()!=null?depotHead.getDeposit():BigDecimal.ZERO;
BigDecimal billChangeAmount = depotHead.getChangeAmount()!=null?depotHead.getChangeAmount().abs():BigDecimal.ZERO;
BigDecimal billDebt = billDiscountLastMoney.add(billOtherMoney).subtract((billDeposit.add(billChangeAmount)));
allBillDebt = allBillDebt.add(billDebt);
}
BigDecimal needDebt = dh.getNeedDebt()!=null?dh.getNeedDebt():BigDecimal.ZERO;
//实际欠款 实际欠款=本单欠款-退货单欠款(主要针对存在退货的情况)
dh.setRealNeedDebt(needDebt.subtract(allBillDebt));
BigDecimal finishDebt = accountItemService.getEachAmountByBillId(dh.getId()); BigDecimal finishDebt = accountItemService.getEachAmountByBillId(dh.getId());
finishDebt = finishDebt!=null?finishDebt:BigDecimal.ZERO; finishDebt = finishDebt!=null?finishDebt:BigDecimal.ZERO;
//已收欠款 //已收欠款
dh.setFinishDebt(finishDebt); dh.setFinishDebt(finishDebt);
//待收欠款 //待收欠款
dh.setDebt(discountLastMoney.add(otherMoney).subtract(deposit.add(changeAmount).add(finishDebt))); dh.setDebt(needDebt.subtract(allBillDebt).subtract(finishDebt));
dh.setMaterialsList(findMaterialsListByHeaderId(dh.getId())); dh.setMaterialsList(findMaterialsListByHeaderId(dh.getId()));
resList.add(dh); resList.add(dh);
} }