diff --git a/jshERP-boot/src/main/java/com/jsh/erp/constants/BusinessConstants.java b/jshERP-boot/src/main/java/com/jsh/erp/constants/BusinessConstants.java index 5fa4ad64..b3b0bf96 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/constants/BusinessConstants.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/constants/BusinessConstants.java @@ -96,6 +96,12 @@ public class BusinessConstants { public static final String SUB_TYPE_REPLAY = "盘点复盘"; public static final String SUB_TYPE_ASSEMBLE = "组装单"; public static final String SUB_TYPE_DISASSEMBLE = "拆卸单"; + /** + * 财务单据分类 + * 收款、付款 + * */ + public static final String TYPE_MONEY_IN = "收款"; + public static final String TYPE_MONEY_OUT = "付款"; /** * 批量插入sql时最大的数据条数 * */ 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 05c32c59..04f75525 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,6 @@ 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 int DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_CODE = 8500010; public static final String DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_MSG = "调入仓库与原仓库不能重复"; @@ -391,9 +388,6 @@ 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 = "抱歉,本次欠款金额不能大于关联单据实际的欠款"; //单据录入-单据明细中必须要有组合件和普通子件 public static final int DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_CODE = 8000020; public static final String DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_MSG = "抱歉,单据明细中必须要有组合件和普通子件"; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/AccountItemController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/AccountItemController.java index a96086b3..80367716 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/AccountItemController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/AccountItemController.java @@ -2,7 +2,9 @@ package com.jsh.erp.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.datasource.vo.AccountItemVo4List; +import com.jsh.erp.service.accountHead.AccountHeadService; import com.jsh.erp.service.accountItem.AccountItemService; import com.jsh.erp.utils.BaseResponseInfo; import com.jsh.erp.utils.StringUtil; @@ -35,15 +37,20 @@ public class AccountItemController { @Resource private AccountItemService accountItemService; + @Resource + private AccountHeadService accountHeadService; + @GetMapping(value = "/getDetailList") @ApiOperation(value = "明细列表") public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId, HttpServletRequest request)throws Exception { BaseResponseInfo res = new BaseResponseInfo(); try { + String type = null; List dataList = new ArrayList<>(); if(headerId != 0) { dataList = accountItemService.getDetailList(headerId); + type = accountHeadService.getAccountHead(headerId).getType(); } JSONObject outer = new JSONObject(); outer.put("total", dataList.size()); @@ -64,7 +71,13 @@ public class AccountItemController { item.put("needDebt", ai.getNeedDebt()); item.put("finishDebt", ai.getFinishDebt()); BigDecimal eachAmount = ai.getEachAmount(); - item.put("eachAmount", (eachAmount.compareTo(BigDecimal.ZERO))==-1 ? BigDecimal.ZERO.subtract(eachAmount): eachAmount); + if(BusinessConstants.TYPE_MONEY_IN.equals(type)) { + item.put("eachAmount", eachAmount); + } else if(BusinessConstants.TYPE_MONEY_OUT.equals(type)) { + item.put("eachAmount", BigDecimal.ZERO.subtract(eachAmount)); + } else { + item.put("eachAmount", (eachAmount.compareTo(BigDecimal.ZERO))==-1 ? BigDecimal.ZERO.subtract(eachAmount): eachAmount); + } item.put("remark", ai.getRemark()); dataArray.add(item); } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java index d8afcd69..4f6cffd6 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/DepotHeadController.java @@ -531,14 +531,11 @@ public class DepotHeadController { String number = StringUtil.getInfo(search, "number"); String beginTime = StringUtil.getInfo(search, "beginTime"); String endTime = StringUtil.getInfo(search, "endTime"); - String type = StringUtil.getInfo(search, "type"); - String subType = StringUtil.getInfo(search, "subType"); String roleType = StringUtil.getInfo(search, "roleType"); String status = StringUtil.getInfo(search, "status"); - List list = depotHeadService.debtList(organId, materialParam, number, beginTime, endTime, type, - subType, roleType, status, (currentPage-1)*pageSize, pageSize); - int total = depotHeadService.debtListCount(organId, materialParam, number, beginTime, endTime, type, - subType, roleType, status); + List list = depotHeadService.debtList(organId, materialParam, number, beginTime, endTime, roleType, + status, (currentPage-1)*pageSize, pageSize); + int total = depotHeadService.debtListCount(organId, materialParam, number, beginTime, endTime, roleType, status); if (list != null) { objectMap.put("rows", list); objectMap.put("total", total); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java index 2067d946..93294a00 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java @@ -42,12 +42,6 @@ public interface AccountHeadMapperEx { @Param("remark") String remark, @Param("number") String number); - BigDecimal findAllMoney( - @Param("supplierId") Integer supplierId, - @Param("type") String type, - @Param("modeName") String modeName, - @Param("endTime") String endTime); - List getDetailByNumber( @Param("billNo") String billNo); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java index a6b19149..4a5c20b4 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java @@ -179,25 +179,6 @@ public interface DepotHeadMapperEx { @Param("subTypeBack") String subTypeBack, @Param("billType") String billType); - BigDecimal findAllMoney( - @Param("supplierId") Integer supplierId, - @Param("type") String type, - @Param("subType") String subType, - @Param("modeName") String modeName, - @Param("endTime") String endTime); - - BigDecimal findAllOtherMoney( - @Param("supplierId") Integer supplierId, - @Param("type") String type, - @Param("subType") String subType, - @Param("endTime") String endTime); - - BigDecimal findDepositMoney( - @Param("supplierId") Integer supplierId, - @Param("type") String type, - @Param("subType") String subType, - @Param("endTime") String endTime); - List getDetailByNumber( @Param("number") String number); @@ -228,8 +209,6 @@ public interface DepotHeadMapperEx { List debtList( @Param("organId") Long organId, - @Param("type") String type, - @Param("subType") String subType, @Param("creatorArray") String[] creatorArray, @Param("status") String status, @Param("number") String number, @@ -242,8 +221,6 @@ public interface DepotHeadMapperEx { int debtListCount( @Param("organId") Long organId, - @Param("type") String type, - @Param("subType") String subType, @Param("creatorArray") String[] creatorArray, @Param("status") String status, @Param("number") String number, diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4StatementAccount.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4StatementAccount.java index 9ecbb457..6eebed81 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4StatementAccount.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/DepotHeadVo4StatementAccount.java @@ -54,7 +54,7 @@ public class DepotHeadVo4StatementAccount { private BigDecimal returnDebtMoney; /** - * 本期收款 + * 本期收付款 */ private BigDecimal backMoney; diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java index 104bc247..64c79b9b 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java @@ -102,10 +102,22 @@ public class AccountHeadService { if (null != list) { for (AccountHeadVo4ListEx ah : list) { if(ah.getChangeAmount() != null) { - ah.setChangeAmount(ah.getChangeAmount().abs()); + if(BusinessConstants.TYPE_MONEY_IN.equals(ah.getType())) { + ah.setChangeAmount(ah.getChangeAmount()); + } else if(BusinessConstants.TYPE_MONEY_OUT.equals(ah.getType())) { + ah.setChangeAmount(BigDecimal.ZERO.subtract(ah.getChangeAmount())); + } else { + ah.setChangeAmount(ah.getChangeAmount().abs()); + } } if(ah.getTotalPrice() != null) { - ah.setTotalPrice(ah.getTotalPrice().abs()); + if(BusinessConstants.TYPE_MONEY_IN.equals(ah.getType())) { + ah.setTotalPrice(ah.getTotalPrice()); + } else if(BusinessConstants.TYPE_MONEY_OUT.equals(ah.getType())) { + ah.setTotalPrice(BigDecimal.ZERO.subtract(ah.getTotalPrice())); + } else { + ah.setTotalPrice(ah.getTotalPrice().abs()); + } } if(ah.getBillTime() !=null) { ah.setBillTimeStr(getCenternTime(ah.getBillTime())); @@ -340,66 +352,6 @@ public class AccountHeadService { new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(accountHead.getBillNo()).toString(), request); } - public BigDecimal findAllMoney(Integer supplierId, String type, String mode, String endTime) { - String modeName = ""; - if (mode.equals("实际")) { - modeName = "change_amount"; - } else if (mode.equals("合计")) { - modeName = "total_price"; - } - BigDecimal result = null; - try{ - result = accountHeadMapperEx.findAllMoney(supplierId, type, modeName, endTime); - }catch(Exception e){ - JshException.readFail(logger, e); - } - return result; - } - - /** - * 统计总金额 - * @param getS - * @param type - * @param mode 合计或者金额 - * @param endTime - * @return - */ - public BigDecimal allMoney(String getS, String type, String mode, String endTime) { - BigDecimal allMoney = BigDecimal.ZERO; - try { - Integer supplierId = Integer.valueOf(getS); - BigDecimal sum = findAllMoney(supplierId, type, mode, endTime); - if(sum != null) { - allMoney = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - //返回正数,如果负数也转为正数 - if ((allMoney.compareTo(BigDecimal.ZERO))==-1) { - allMoney = allMoney.abs(); - } - return allMoney; - } - - /** - * 查询往来单位的累计应收和累计应付,只计入收款或付款 - * @param supplierId - * @param endTime - * @param supType - * @return - */ - public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) { - BigDecimal sum = BigDecimal.ZERO; - String getS = supplierId.toString(); - if (("客户").equals(supType)) { //客户 - sum = allMoney(getS, "收款", "合计",endTime); - } else if (("供应商").equals(supType)) { //供应商 - sum = allMoney(getS, "付款", "合计",endTime); - } - return sum; - } - public List getDetailByNumber(String billNo)throws Exception { List resList = new ArrayList(); List list = null; @@ -411,10 +363,22 @@ public class AccountHeadService { if (null != list) { for (AccountHeadVo4ListEx ah : list) { if(ah.getChangeAmount() != null) { - ah.setChangeAmount(ah.getChangeAmount().abs()); + if(BusinessConstants.TYPE_MONEY_IN.equals(ah.getType())) { + ah.setChangeAmount(ah.getChangeAmount()); + } else if(BusinessConstants.TYPE_MONEY_OUT.equals(ah.getType())) { + ah.setChangeAmount(BigDecimal.ZERO.subtract(ah.getChangeAmount())); + } else { + ah.setChangeAmount(ah.getChangeAmount().abs()); + } } if(ah.getTotalPrice() != null) { - ah.setTotalPrice(ah.getTotalPrice().abs()); + if(BusinessConstants.TYPE_MONEY_IN.equals(ah.getType())) { + ah.setTotalPrice(ah.getTotalPrice()); + } else if(BusinessConstants.TYPE_MONEY_OUT.equals(ah.getType())) { + ah.setTotalPrice(BigDecimal.ZERO.subtract(ah.getTotalPrice())); + } else { + ah.setTotalPrice(ah.getTotalPrice().abs()); + } } if(ah.getBillTime() !=null) { ah.setBillTimeStr(getCenternTime(ah.getBillTime())); 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 b0b173da..479961e2 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 @@ -712,76 +712,6 @@ public class DepotHeadService { return list; } - public BigDecimal findAllMoney(Integer supplierId, String type, String subType, String mode, String endTime)throws Exception { - String modeName = ""; - BigDecimal allOtherMoney = BigDecimal.ZERO; - BigDecimal allDepositMoney = BigDecimal.ZERO; - if (mode.equals("实际")) { - modeName = "change_amount"; - } else if (mode.equals("合计")) { - modeName = "discount_last_money"; - allOtherMoney = depotHeadMapperEx.findAllOtherMoney(supplierId, type, subType, endTime); - allDepositMoney = depotHeadMapperEx.findDepositMoney(supplierId, type, subType, endTime); - } - BigDecimal result = BigDecimal.ZERO; - try{ - result =depotHeadMapperEx.findAllMoney(supplierId, type, subType, modeName, endTime); - }catch(Exception e){ - JshException.readFail(logger, e); - } - if(allOtherMoney!=null) { - result = result.add(allOtherMoney); - } - if(allDepositMoney!=null) { - result = result.subtract(allDepositMoney); - } - return result; - } - - /** - * 统计总金额 - * @param getS - * @param type - * @param subType - * @param mode 合计或者金额 - * @return - */ - public BigDecimal allMoney(String getS, String type, String subType, String mode, String endTime) { - BigDecimal allMoney = BigDecimal.ZERO; - try { - Integer supplierId = Integer.valueOf(getS); - BigDecimal sum = findAllMoney(supplierId, type, subType, mode, endTime); - if(sum != null) { - allMoney = sum; - } - } catch (Exception e) { - e.printStackTrace(); - } - //返回正数,如果负数也转为正数 - if ((allMoney.compareTo(BigDecimal.ZERO))==-1) { - allMoney = allMoney.abs(); - } - return allMoney; - } - - /** - * 查询单位的累计应收和累计应付,零售不能计入 - * @param supplierId - * @param endTime - * @param supType - * @return - */ - public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) { - BigDecimal sum = BigDecimal.ZERO; - String getS = supplierId.toString(); - if (("客户").equals(supType)) { //客户 - sum = allMoney(getS, "出库", "销售", "合计",endTime).subtract(allMoney(getS, "出库", "销售", "实际",endTime)); - } else if (("供应商").equals(supType)) { //供应商 - sum = allMoney(getS, "入库", "采购", "合计",endTime).subtract(allMoney(getS, "入库", "采购", "实际",endTime)); - } - return sum; - } - public List getDetailByNumber(String number)throws Exception { List resList = new ArrayList(); try{ @@ -927,10 +857,6 @@ public class DepotHeadService { String.format(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_MSG)); } } - //欠款校验 - if("采购退货".equals(subType) || "销售退货".equals(subType)) { - checkDebtByParam(beanJson, depotHead); - } //判断用户是否已经登录过,登录过不再处理 User userInfo=userService.getCurrentUser(); depotHead.setCreator(userInfo==null?null:userInfo.getId()); @@ -1029,10 +955,6 @@ public class DepotHeadService { String.format(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_MSG)); } } - //欠款校验 - if("采购退货".equals(subType) || "销售退货".equals(subType)) { - checkDebtByParam(beanJson, depotHead); - } if(StringUtil.isNotEmpty(depotHead.getAccountIdList())){ depotHead.setAccountIdList(depotHead.getAccountIdList().replace("[", "").replace("]", "").replaceAll("\"", "")); } @@ -1084,29 +1006,6 @@ public class DepotHeadService { ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); } - /** - * 针对退货单,校验欠款 - * @param beanJson - * @param depotHead - * @throws Exception - */ - public void checkDebtByParam(String beanJson, DepotHead depotHead) throws Exception { - JSONObject billObj = JSONObject.parseObject(beanJson); - if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) { - //退货单对应的原单实际欠款(这里面要除去收付款的金额) - BigDecimal originalRealDebt = getOriginalRealDebt(depotHead.getLinkNumber(), depotHead.getNumber()); - 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)); - } - } else { - if(billObj!=null && billObj.get("debt")!=null && BigDecimal.ZERO.compareTo(billObj.getBigDecimal("debt"))!=0) { - throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_CODE, - String.format(ExceptionConstants.DEPOT_HEAD_BACK_BILL_DEBT_FAILED_MSG)); - } - } - } - /** * 退货单对应的原单实际欠款(这里面要除去收付款的金额) * @param linkNumber 原单单号 @@ -1238,7 +1137,7 @@ public class DepotHeadService { } public List debtList(Long organId, String materialParam, String number, String beginTime, String endTime, - String type, String subType, String roleType, String status, Integer offset, Integer rows) { + String roleType, String status, Integer offset, Integer rows) { List resList = new ArrayList<>(); try{ String depotIds = depotService.findDepotStrByCurrentUser(); @@ -1246,7 +1145,7 @@ public class DepotHeadService { String [] creatorArray = getCreatorArray(roleType); beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME); endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME); - List list=depotHeadMapperEx.debtList(organId, type, subType, creatorArray, status, number, + List list=depotHeadMapperEx.debtList(organId, creatorArray, status, number, beginTime, endTime, materialParam, depotArray, offset, rows); if (null != list) { List idList = new ArrayList<>(); @@ -1272,28 +1171,18 @@ public class DepotHeadService { 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().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); + if(BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(dh.getSubType()) || BusinessConstants.SUB_TYPE_SALES_RETURN.equals(dh.getSubType())) { + dh.setNeedDebt(BigDecimal.ZERO.subtract(dh.getNeedDebt())); } 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(needDebt.subtract(allBillDebt).subtract(finishDebt)); + dh.setDebt(needDebt.subtract(finishDebt)); //商品信息简述 if(materialsListMap!=null) { dh.setMaterialsList(materialsListMap.get(dh.getId())); @@ -1308,7 +1197,7 @@ public class DepotHeadService { } public int debtListCount(Long organId, String materialParam, String number, String beginTime, String endTime, - String type, String subType, String roleType, String status) { + String roleType, String status) { int total = 0; try { String depotIds = depotService.findDepotStrByCurrentUser(); @@ -1316,7 +1205,7 @@ public class DepotHeadService { String[] creatorArray = getCreatorArray(roleType); beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME); endTime = Tools.parseDayToTime(endTime, BusinessConstants.DAY_LAST_TIME); - total = depotHeadMapperEx.debtListCount(organId, type, subType, creatorArray, status, number, + total = depotHeadMapperEx.debtListCount(organId, creatorArray, status, number, beginTime, endTime, materialParam, depotArray); } catch(Exception e){ JshException.readFail(logger, e); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java index ede6a0a0..b1a226af 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java @@ -1,11 +1,11 @@ package com.jsh.erp.service.supplier; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.ExceptionConstants; import com.jsh.erp.datasource.entities.*; import com.jsh.erp.datasource.mappers.*; +import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount; import com.jsh.erp.exception.BusinessRunTimeException; import com.jsh.erp.exception.JshException; import com.jsh.erp.service.accountHead.AccountHeadService; @@ -17,6 +17,7 @@ import com.jsh.erp.service.userBusiness.UserBusinessService; import com.jsh.erp.utils.BaseResponseInfo; import com.jsh.erp.utils.ExcelUtils; import com.jsh.erp.utils.StringUtil; +import com.jsh.erp.utils.Tools; import jxl.Sheet; import jxl.Workbook; import org.slf4j.Logger; @@ -33,7 +34,6 @@ import java.io.File; import java.math.BigDecimal; import java.util.*; -import static com.jsh.erp.utils.Tools.getNow3; @Service public class SupplierService { @@ -104,24 +104,45 @@ public class SupplierService { List list = supplierMapperEx.selectByConditionSupplier(supplier, type, phonenum, telephone, offset, rows); for(Supplier s : list) { Integer supplierId = s.getId().intValue(); - String endTime = getNow3(); - String supType = s.getType(); + String beginTime = Tools.getYearBegin(); + String endTime = Tools.getCenternTime(new Date()); BigDecimal sum = BigDecimal.ZERO; - BigDecimal beginNeedGet = s.getBeginNeedGet(); - if(beginNeedGet==null) { - beginNeedGet = BigDecimal.ZERO; + String supplierType = type; + String inOutType = ""; + String subType = ""; + String typeBack = ""; + String subTypeBack = ""; + String billType = ""; + if (("供应商").equals(supplierType)) { + inOutType = "入库"; + subType = "采购"; + typeBack = "出库"; + subTypeBack = "采购退货"; + billType = "付款"; + } else if (("客户").equals(supplierType)) { + inOutType = "出库"; + subType = "销售"; + typeBack = "入库"; + subTypeBack = "销售退货"; + billType = "收款"; } - BigDecimal beginNeedPay = s.getBeginNeedPay(); - if(beginNeedPay==null) { - beginNeedPay = BigDecimal.ZERO; + List saList = depotHeadService.getStatementAccount(beginTime, endTime, supplierId, null, + supplierType, inOutType, subType, typeBack, subTypeBack, billType, null, null); + if(saList.size()>0) { + DepotHeadVo4StatementAccount item = saList.get(0); + //期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款 + BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney()); + item.setPreNeed(preNeed); + //实际欠款 = 本期欠款-本期退货的欠款金额 + BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney()); + item.setDebtMoney(realDebtMoney); + //期末 = 期初+实际欠款-本期收款 + BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney()); + sum = sum.add(allNeedGet); } - sum = sum.add(depotHeadService.findTotalPay(supplierId, endTime, supType)) - .subtract(accountHeadService.findTotalPay(supplierId, endTime, supType)); if(("客户").equals(s.getType())) { - sum = sum.add(beginNeedGet); s.setAllNeedGet(sum); } else if(("供应商").equals(s.getType())) { - sum = sum.add(beginNeedPay); s.setAllNeedPay(sum); } resList.add(s); @@ -602,24 +623,46 @@ public class SupplierService { if (null != dataList) { for (Supplier s : dataList) { Integer supplierId = s.getId().intValue(); - String endTime = getNow3(); - String supType = s.getType(); + + String beginTime = Tools.getYearBegin(); + String endTime = Tools.getCenternTime(new Date()); BigDecimal sum = BigDecimal.ZERO; - BigDecimal beginNeedGet = s.getBeginNeedGet(); - if(beginNeedGet==null) { - beginNeedGet = BigDecimal.ZERO; + String supplierType = type; + String inOutType = ""; + String subType = ""; + String typeBack = ""; + String subTypeBack = ""; + String billType = ""; + if (("供应商").equals(supplierType)) { + inOutType = "入库"; + subType = "采购"; + typeBack = "出库"; + subTypeBack = "采购退货"; + billType = "付款"; + } else if (("客户").equals(supplierType)) { + inOutType = "出库"; + subType = "销售"; + typeBack = "入库"; + subTypeBack = "销售退货"; + billType = "收款"; } - BigDecimal beginNeedPay = s.getBeginNeedPay(); - if(beginNeedPay==null) { - beginNeedPay = BigDecimal.ZERO; + List saList = depotHeadService.getStatementAccount(beginTime, endTime, supplierId, null, + supplierType, inOutType, subType, typeBack, subTypeBack, billType, null, null); + if(saList.size()>0) { + DepotHeadVo4StatementAccount item = saList.get(0); + //期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款 + BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney()); + item.setPreNeed(preNeed); + //实际欠款 = 本期欠款-本期退货的欠款金额 + BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney()); + item.setDebtMoney(realDebtMoney); + //期末 = 期初+实际欠款-本期收款 + BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney()); + sum = sum.add(allNeedGet); } - sum = sum.add(depotHeadService.findTotalPay(supplierId, endTime, supType)) - .subtract(accountHeadService.findTotalPay(supplierId, endTime, supType)); if(("客户").equals(s.getType())) { - sum = sum.add(beginNeedGet); s.setAllNeedGet(sum); } else if(("供应商").equals(s.getType())) { - sum = sum.add(beginNeedPay); s.setAllNeedPay(sum); } String[] objs = new String[20]; diff --git a/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml index 54b5464d..95df5b36 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml @@ -133,13 +133,6 @@ and ifnull(ah.delete_flag,'0') !='1') tb - - select * from (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email, + -- 起始期初金额 (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need, + -- 上期欠款金额 (select ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0)) from jsh_depot_head dh @@ -627,6 +629,7 @@ and dh.type=#{type} and dh.sub_type=#{subType} and dh.oper_time <= #{beginTime} and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, + -- 上期退货的欠款金额 (select ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0)) from jsh_depot_head dh @@ -634,11 +637,13 @@ and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack} and dh.oper_time <= #{beginTime} and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney, - (select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai - left join jsh_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1' - where dh.organ_id=s.id - and dh.oper_time <= #{beginTime} + -- 上期收付款 + (select (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) from jsh_account_item ai + left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1' + where ah.organ_id=s.id and ah.type=#{billType} + and ah.bill_time <= #{beginTime} and ifnull(ai.delete_flag,'0') !='1') preBackMoney, + -- 本期欠款 (select ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0)) from jsh_depot_head dh @@ -646,6 +651,7 @@ and dh.type=#{type} and dh.sub_type=#{subType} and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime} and ifnull(dh.delete_flag,'0') !='1') debtMoney, + -- 本期退货的欠款金额 (select ifnull(sum(dh.discount_last_money),0)+ifnull(sum(dh.other_money),0)-ifnull(sum(dh.deposit),0)-abs(ifnull(sum(dh.change_amount),0)) from jsh_depot_head dh @@ -653,7 +659,8 @@ and dh.type=#{typeBack} and dh.sub_type=#{subTypeBack} and dh.oper_time>#{beginTime} and dh.oper_time <= #{endTime} and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney, - (select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai + -- 本期收付款 + (select (case when ah.type='收款' then ifnull(sum(ai.each_amount),0) else 0-ifnull(sum(ai.each_amount),0) end) from jsh_account_item ai left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1' where ah.organ_id=s.id and ah.type=#{billType} and ah.bill_time>#{beginTime} and ah.bill_time <= #{endTime} @@ -672,7 +679,7 @@ ) and ifnull(s.delete_flag,'0') !='1') tb - where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0 + where begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney!=0 order by begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney desc limit #{offset},#{rows} @@ -682,45 +689,52 @@ - - - - - -