From 54bf2dd37045761d7e39a1658e447971a9bde1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Sun, 20 Nov 2022 01:23:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E9=87=87=E8=B4=AD=E5=92=8C=E9=94=80?= =?UTF-8?q?=E5=94=AE=E9=80=80=E8=B4=A7=E5=8D=95=E5=A2=9E=E5=8A=A0=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF=E6=8C=81=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E6=83=85=E5=86=B5=E7=9A=84=E6=AC=A0=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jsh/erp/constants/ExceptionConstants.java | 7 +- .../erp/datasource/vo/DepotHeadVo4List.java | 13 +++ .../service/depotHead/DepotHeadService.java | 82 +++++++++++++++++-- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java index 520806eb..34582d10 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java @@ -361,9 +361,9 @@ public class ExceptionConstants { //单据录入-请修改多账户的结算金额 public static final int DEPOT_HEAD_MANY_ACCOUNT_FAILED_CODE = 8500008; 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 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 String DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_MSG = "调入仓库与原仓库不能重复"; @@ -391,6 +391,9 @@ public class ExceptionConstants { //单据录入-商品条码XXX的单价低于最低售价 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 int DEPOT_HEAD_BACK_BILL_DEBT_OVER_CODE = 8500019; + public static final String DEPOT_HEAD_BACK_BILL_DEBT_OVER_MSG = "抱歉,本次欠款金额不能大于关联单据实际的欠款"; /** * 单据明细信息 * type = 90 diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4List.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4List.java index 986597bc..57227b4e 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4List.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4List.java @@ -52,6 +52,11 @@ public class DepotHeadVo4List extends DepotHead{ */ private Boolean hasBackFlag; + /** + * 实际欠款 + */ + private BigDecimal realNeedDebt; + public String getProjectName() { return projectName; } @@ -211,4 +216,12 @@ public class DepotHeadVo4List extends DepotHead{ public void setHasBackFlag(Boolean hasBackFlag) { this.hasBackFlag = hasBackFlag; } + + public BigDecimal getRealNeedDebt() { + return realNeedDebt; + } + + public void setRealNeedDebt(BigDecimal realNeedDebt) { + this.realNeedDebt = realNeedDebt; + } } \ No newline at end of file diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java index f10bbc01..be8ac767 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java @@ -780,6 +780,18 @@ public class DepotHeadService { return depotHeadMapper.selectByExample(example); } + /** + * 根据原单号查询关联的单据列表(排除当前的单据编号) + * @param linkNumber + * @return + * @throws Exception + */ + public List 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 @@ -802,9 +814,12 @@ public class DepotHeadService { } //欠款校验 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, - String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG)); + //退货单对应的原单实际欠款(这里面要除去收付款的金额) + BigDecimal originalRealDebt = getOriginalRealDebt(depotHead.getLinkNumber(), depotHead.getNumber()); + 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(depotHead.getChangeAmount().abs().compareTo(depotHead.getDiscountLastMoney().add(depotHead.getOtherMoney()))!=0) { - throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE, - String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG)); + //退货单对应的原单实际欠款(这里面要除去收付款的金额) + BigDecimal originalRealDebt = getOriginalRealDebt(depotHead.getLinkNumber(), depotHead.getNumber()); + 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())){ @@ -953,6 +971,38 @@ public class DepotHeadService { ((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 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 getBuyAndSaleStatistics(String today, String monthFirstDay, String yesterdayBegin, String yesterdayEnd, String yearBegin, String yearEnd, String roleType, HttpServletRequest request) throws Exception { String [] creatorArray = getCreatorArray(roleType); @@ -1076,15 +1126,29 @@ public class DepotHeadService { BigDecimal discountLastMoney = dh.getDiscountLastMoney()!=null?dh.getDiscountLastMoney():BigDecimal.ZERO; BigDecimal otherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():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))); + List 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()); finishDebt = finishDebt!=null?finishDebt:BigDecimal.ZERO; //已收欠款 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())); resList.add(dh); }