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 ab4e2ca2..c8f8b88a 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 @@ -302,36 +302,44 @@ public class DepotHeadController { try { String type = ""; String subType = ""; + String typeBack = ""; + String subTypeBack = ""; if (("供应商").equals(supplierType)) { type = "入库"; subType = "采购"; + typeBack = "出库"; + subTypeBack = "采购退货"; } else if (("客户").equals(supplierType)) { type = "出库"; subType = "销售"; + typeBack = "入库"; + subTypeBack = "销售退货"; } String [] organArray = depotHeadService.getOrganArray(subType, ""); beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME); endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME); List list = depotHeadService.getStatementAccount(beginTime, endTime, organId, organArray, - supplierType, type, subType, (currentPage-1)*pageSize, pageSize); + supplierType, type, subType,typeBack, subTypeBack, (currentPage-1)*pageSize, pageSize); int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, organArray, - supplierType, type, subType); + supplierType, type, subType,typeBack, subTypeBack); for(DepotHeadVo4StatementAccount item: list) { - BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreBackMoney()); + BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney()); item.setPreNeed(preNeed); - BigDecimal allNeedGet = preNeed.add(item.getDebtMoney()).subtract(item.getBackMoney()); + BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney()); + item.setDebtMoney(realDebtMoney); + BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney()); item.setAllNeed(allNeedGet); } map.put("rows", list); map.put("total", total); - List totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType); + List totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType, typeBack, subTypeBack); if(totalPayList.size()>0) { DepotHeadVo4StatementAccount totalPayItem = totalPayList.get(0); BigDecimal firstMoney = BigDecimal.ZERO; BigDecimal lastMoney = BigDecimal.ZERO; if(totalPayItem!=null) { - firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreBackMoney()); - lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getBackMoney()); + firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreReturnDebtMoney()).subtract(totalPayItem.getPreBackMoney()); + lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getReturnDebtMoney()).subtract(totalPayItem.getBackMoney()); } map.put("firstMoney", firstMoney); //期初 map.put("lastMoney", lastMoney); //期末 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 3be3f4c1..288c1f42 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 @@ -146,6 +146,8 @@ public interface DepotHeadMapperEx { @Param("supplierType") String supplierType, @Param("type") String type, @Param("subType") String subType, + @Param("typeBack") String typeBack, + @Param("subTypeBack") String subTypeBack, @Param("offset") Integer offset, @Param("rows") Integer rows); @@ -156,7 +158,9 @@ public interface DepotHeadMapperEx { @Param("organArray") String[] organArray, @Param("supplierType") String supplierType, @Param("type") String type, - @Param("subType") String subType); + @Param("subType") String subType, + @Param("typeBack") String typeBack, + @Param("subTypeBack") String subTypeBack); List getStatementAccountTotalPay( @Param("beginTime") String beginTime, @@ -165,7 +169,9 @@ public interface DepotHeadMapperEx { @Param("organArray") String[] organArray, @Param("supplierType") String supplierType, @Param("type") String type, - @Param("subType") String subType); + @Param("subType") String subType, + @Param("typeBack") String typeBack, + @Param("subTypeBack") String subTypeBack); BigDecimal findAllMoney( @Param("supplierId") Integer supplierId, 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 b420453d..9ecbb457 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 @@ -17,18 +17,50 @@ public class DepotHeadVo4StatementAccount { private String email; + /** + * 起始期初金额 + */ private BigDecimal beginNeed; + /** + * 上期欠款金额 + */ private BigDecimal preDebtMoney; + /** + * 上期退货的欠款金额 + */ + private BigDecimal preReturnDebtMoney; + + + /** + * 上期收付款 + */ private BigDecimal preBackMoney; + /** + * 期初应收 + */ private BigDecimal preNeed; + /** + * 本期欠款 + */ private BigDecimal debtMoney; + /** + * 本期退货的欠款金额 + */ + private BigDecimal returnDebtMoney; + + /** + * 本期收款 + */ private BigDecimal backMoney; + /** + * 期末应收 + */ private BigDecimal allNeed; public Long getId() { @@ -95,6 +127,14 @@ public class DepotHeadVo4StatementAccount { this.preDebtMoney = preDebtMoney; } + public BigDecimal getPreReturnDebtMoney() { + return preReturnDebtMoney; + } + + public void setPreReturnDebtMoney(BigDecimal preReturnDebtMoney) { + this.preReturnDebtMoney = preReturnDebtMoney; + } + public BigDecimal getPreBackMoney() { return preBackMoney; } @@ -119,6 +159,14 @@ public class DepotHeadVo4StatementAccount { this.debtMoney = debtMoney; } + public BigDecimal getReturnDebtMoney() { + return returnDebtMoney; + } + + public void setReturnDebtMoney(BigDecimal returnDebtMoney) { + this.returnDebtMoney = returnDebtMoney; + } + public BigDecimal getBackMoney() { return backMoney; } 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 be8ac767..66255d51 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 @@ -603,10 +603,10 @@ public class DepotHeadService { } public List getStatementAccount(String beginTime, String endTime, Integer organId, String [] organArray, - String supplierType, String type, String subType, Integer offset, Integer rows) { + String supplierType, String type, String subType, String typeBack, String subTypeBack, Integer offset, Integer rows) { List list = null; try{ - list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, organArray, supplierType, type, subType, offset, rows); + list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack, offset, rows); } catch(Exception e){ JshException.readFail(logger, e); } @@ -614,10 +614,10 @@ public class DepotHeadService { } public int getStatementAccountCount(String beginTime, String endTime, Integer organId, - String [] organArray, String supplierType, String type, String subType) { + String [] organArray, String supplierType, String type, String subType, String typeBack, String subTypeBack) { int result = 0; try{ - result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, organArray, supplierType, type, subType); + result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack); } catch(Exception e){ JshException.readFail(logger, e); } @@ -626,10 +626,10 @@ public class DepotHeadService { public List getStatementAccountTotalPay(String beginTime, String endTime, Integer organId, String [] organArray, String supplierType, - String type, String subType) { + String type, String subType, String typeBack, String subTypeBack) { List list = null; try{ - list = depotHeadMapperEx.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType); + list = depotHeadMapperEx.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack); } catch(Exception e){ JshException.readFail(logger, e); } diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml index c51185f4..831ef3cf 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml @@ -591,6 +591,13 @@ 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 + where dh.organ_id=s.id + 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 @@ -603,6 +610,13 @@ 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 + where dh.organ_id=s.id + 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 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 @@ -623,7 +637,7 @@ and ifnull(s.delete_flag,'0') !='1') tb where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0 - order by begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney desc + order by begin_need+preDebtMoney-preReturnDebtMoney-preBackMoney+debtMoney-returnDebtMoney-backMoney desc limit #{offset},#{rows} @@ -640,6 +654,13 @@ 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 + where dh.organ_id=s.id + 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 @@ -652,6 +673,13 @@ 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 + where dh.organ_id=s.id + 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 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 @@ -671,12 +699,12 @@ ) 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