From 1015eb9046ef56ca43c2e69e0a0d1860aee9d0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E5=9C=A3=E5=8D=8E?= <752718920@qq.com> Date: Fri, 3 Jun 2022 18:34:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7=E5=AF=B9?= =?UTF-8?q?=E8=B4=A6=E5=92=8C=E4=BE=9B=E5=BA=94=E5=95=86=E5=AF=B9=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/controller/DepotHeadController.java | 62 ++++--- .../datasource/mappers/DepotHeadMapperEx.java | 20 ++- .../vo/DepotHeadVo4StatementAccount.java | 130 +++++++++------ .../service/depotHead/DepotHeadService.java | 69 +++----- .../mapper_xml/DepotHeadMapperEx.xml | 151 +++++++++++++----- 5 files changed, 261 insertions(+), 171 deletions(-) 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 0beb2ec6f..9bc0e16c7 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 @@ -280,44 +280,54 @@ public class DepotHeadController { * @param beginTime * @param endTime * @param organId - * @param supType + * @param supplierType * @param request * @return */ - @GetMapping(value = "/findStatementAccount") + @GetMapping(value = "/getStatementAccount") @ApiOperation(value = "对账单接口") - public BaseResponseInfo findStatementAccount(@RequestParam("currentPage") Integer currentPage, - @RequestParam("pageSize") Integer pageSize, - @RequestParam("beginTime") String beginTime, - @RequestParam("endTime") String endTime, - @RequestParam(value = "organId", required = false) Integer organId, - @RequestParam("supType") String supType, - HttpServletRequest request) throws Exception{ + public BaseResponseInfo getStatementAccount(@RequestParam("currentPage") Integer currentPage, + @RequestParam("pageSize") Integer pageSize, + @RequestParam("beginTime") String beginTime, + @RequestParam("endTime") String endTime, + @RequestParam(value = "organId", required = false) Integer organId, + @RequestParam("supplierType") String supplierType, + HttpServletRequest request) throws Exception{ BaseResponseInfo res = new BaseResponseInfo(); Map map = new HashMap(); try { + String type = ""; + String subType = ""; + if (("供应商").equals(supplierType)) { + type = "入库"; + subType = "采购"; + } else if (("客户").equals(supplierType)) { + type = "出库"; + subType = "销售"; + } beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME); endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME); - List list = depotHeadService.findStatementAccount(beginTime, endTime, organId, supType, (currentPage-1)*pageSize, pageSize); - int total = depotHeadService.findStatementAccountCount(beginTime, endTime, organId, supType); + List list = depotHeadService.getStatementAccount(beginTime, endTime, organId, + supplierType, type, subType, (currentPage-1)*pageSize, pageSize); + int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, + supplierType, type, subType); + for(DepotHeadVo4StatementAccount item: list) { + BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreBackMoney()); + item.setPreNeed(preNeed); + BigDecimal allNeedGet = preNeed.add(item.getDebtMoney()).subtract(item.getBackMoney()); + item.setAllNeed(allNeedGet); + } map.put("rows", list); map.put("total", total); - if(null!=organId) { - Supplier supplier = supplierService.getSupplier(organId); - BigDecimal beginNeed = BigDecimal.ZERO; - if (("客户").equals(supType)) { - if(supplier.getBeginNeedGet()!=null) { - beginNeed = supplier.getBeginNeedGet(); - } - } else if (("供应商").equals(supType)) { - if(supplier.getBeginNeedPay()!=null) { - beginNeed = supplier.getBeginNeedPay(); - } + List totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, supplierType, type, subType); + 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()); } - BigDecimal firstMoney = depotHeadService.findTotalPay(organId, beginTime, supType) - .subtract(accountHeadService.findTotalPay(organId, beginTime, supType)).add(beginNeed); - BigDecimal lastMoney = depotHeadService.findTotalPay(organId, endTime, supType) - .subtract(accountHeadService.findTotalPay(organId, endTime, supType)).add(beginNeed); 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 895db0a79..909de6501 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 @@ -121,19 +121,31 @@ public interface DepotHeadMapperEx { @Param("depotFList") List depotFList, @Param("remark") String remark); - List findStatementAccount( + List getStatementAccount( @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("organId") Integer organId, - @Param("supType") String supType, + @Param("supplierType") String supplierType, + @Param("type") String type, + @Param("subType") String subType, @Param("offset") Integer offset, @Param("rows") Integer rows); - int findStatementAccountCount( + int getStatementAccountCount( @Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("organId") Integer organId, - @Param("supType") String supType); + @Param("supplierType") String supplierType, + @Param("type") String type, + @Param("subType") String subType); + + List getStatementAccountTotalPay( + @Param("beginTime") String beginTime, + @Param("endTime") String endTime, + @Param("organId") Integer organId, + @Param("supplierType") String supplierType, + @Param("type") String type, + @Param("subType") String subType); 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 9a529d26a..b420453df 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 @@ -5,103 +5,133 @@ import java.math.BigDecimal; public class DepotHeadVo4StatementAccount { - private String number; + private Long id; - private String type; + private String supplier; - private BigDecimal discountLastMoney; + private String contacts; - private BigDecimal otherMoney; + private String telephone; - private BigDecimal billMoney; + private String phoneNum; - private BigDecimal changeAmount; + private String email; - private BigDecimal allPrice; + private BigDecimal beginNeed; - private String supplierName; + private BigDecimal preDebtMoney; - private String oTime; + private BigDecimal preBackMoney; - private Long tenantId; + private BigDecimal preNeed; - public String getNumber() { - return number; + private BigDecimal debtMoney; + + private BigDecimal backMoney; + + private BigDecimal allNeed; + + public Long getId() { + return id; } - public void setNumber(String number) { - this.number = number; + public void setId(Long id) { + this.id = id; } - public String getType() { - return type; + public String getSupplier() { + return supplier; } - public void setType(String type) { - this.type = type; + public void setSupplier(String supplier) { + this.supplier = supplier; } - public BigDecimal getDiscountLastMoney() { - return discountLastMoney; + public String getContacts() { + return contacts; } - public void setDiscountLastMoney(BigDecimal discountLastMoney) { - this.discountLastMoney = discountLastMoney; + public void setContacts(String contacts) { + this.contacts = contacts; } - public BigDecimal getOtherMoney() { - return otherMoney; + public String getTelephone() { + return telephone; } - public void setOtherMoney(BigDecimal otherMoney) { - this.otherMoney = otherMoney; + public void setTelephone(String telephone) { + this.telephone = telephone; } - public BigDecimal getBillMoney() { - return billMoney; + public String getPhoneNum() { + return phoneNum; } - public void setBillMoney(BigDecimal billMoney) { - this.billMoney = billMoney; + public void setPhoneNum(String phoneNum) { + this.phoneNum = phoneNum; } - public BigDecimal getChangeAmount() { - return changeAmount; + public String getEmail() { + return email; } - public void setChangeAmount(BigDecimal changeAmount) { - this.changeAmount = changeAmount; + public void setEmail(String email) { + this.email = email; } - public BigDecimal getAllPrice() { - return allPrice; + public BigDecimal getBeginNeed() { + return beginNeed; } - public void setAllPrice(BigDecimal allPrice) { - this.allPrice = allPrice; + public void setBeginNeed(BigDecimal beginNeed) { + this.beginNeed = beginNeed; } - public String getSupplierName() { - return supplierName; + public BigDecimal getPreDebtMoney() { + return preDebtMoney; } - public void setSupplierName(String supplierName) { - this.supplierName = supplierName; + public void setPreDebtMoney(BigDecimal preDebtMoney) { + this.preDebtMoney = preDebtMoney; } - public String getoTime() { - return oTime; + public BigDecimal getPreBackMoney() { + return preBackMoney; } - public void setoTime(String oTime) { - this.oTime = oTime; + public void setPreBackMoney(BigDecimal preBackMoney) { + this.preBackMoney = preBackMoney; } - public Long getTenantId() { - return tenantId; + public BigDecimal getPreNeed() { + return preNeed; } - public void setTenantId(Long tenantId) { - this.tenantId = tenantId; + public void setPreNeed(BigDecimal preNeed) { + this.preNeed = preNeed; + } + + public BigDecimal getDebtMoney() { + return debtMoney; + } + + public void setDebtMoney(BigDecimal debtMoney) { + this.debtMoney = debtMoney; + } + + public BigDecimal getBackMoney() { + return backMoney; + } + + public void setBackMoney(BigDecimal backMoney) { + this.backMoney = backMoney; + } + + public BigDecimal getAllNeed() { + return allNeed; + } + + public void setAllNeed(BigDecimal allNeed) { + this.allNeed = allNeed; } } \ 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 b3ac60791..411433921 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 @@ -511,72 +511,39 @@ public class DepotHeadService { return result; } - public List findStatementAccount(String beginTime, String endTime, Integer organId, String supType, Integer offset, Integer rows)throws Exception { + public List getStatementAccount(String beginTime, String endTime, Integer organId, String supplierType, + String type, String subType, Integer offset, Integer rows) { List list = null; try{ - int j = 1; - if (supType.equals("客户")) { //客户 - j = 1; - } else if (supType.equals("供应商")) { //供应商 - j = -1; - } - list =depotHeadMapperEx.findStatementAccount(beginTime, endTime, organId, supType, offset, rows); - if (null != list) { - for (DepotHeadVo4StatementAccount dha : list) { - dha.setNumber(dha.getNumber()); //单据编号 - dha.setType(dha.getType()); //类型 - String type = dha.getType(); - BigDecimal p1 = BigDecimal.ZERO ; - BigDecimal p2 = BigDecimal.ZERO; - if (dha.getDiscountLastMoney() != null) { - p1 = dha.getDiscountLastMoney(); - } - if (dha.getChangeAmount() != null) { - p2 = dha.getChangeAmount(); - } - BigDecimal allPrice = BigDecimal.ZERO; - if ((p1.compareTo(BigDecimal.ZERO))==-1) { - p1 = p1.abs(); - } - if(dha.getOtherMoney()!=null) { - p1 = p1.add(dha.getOtherMoney()); //与其它费用相加 - } - if ((p2 .compareTo(BigDecimal.ZERO))==-1) { - p2 = p2.abs(); - } - if (type.equals("采购入库")) { - allPrice = p2.subtract(p1); - } else if (type.equals("销售出库")) { - allPrice = p1.subtract(p2); - } else if (type.equals("收款")) { - allPrice = BigDecimal.ZERO.subtract(p1); - } else if (type.equals("付款")) { - allPrice = p1; - } - dha.setBillMoney(p1); //单据金额 - dha.setChangeAmount(p2); //实际支付 - DecimalFormat df = new DecimalFormat(".##"); - dha.setAllPrice(new BigDecimal(df.format(allPrice.multiply(new BigDecimal(j))))); //本期变化 - dha.setSupplierName(dha.getSupplierName()); //单位名称 - dha.setoTime(dha.getoTime()); //单据日期 - } - } + list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, supplierType, type, subType, offset, rows); } catch(Exception e){ JshException.readFail(logger, e); } return list; } - public int findStatementAccountCount(String beginTime, String endTime, Integer organId, String supType) throws Exception{ + public int getStatementAccountCount(String beginTime, String endTime, Integer organId, String supplierType, + String type, String subType) { int result = 0; try{ - result =depotHeadMapperEx.findStatementAccountCount(beginTime, endTime, organId, supType); - }catch(Exception e){ + result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, supplierType, type, subType); + } catch(Exception e){ JshException.readFail(logger, e); } return result; } + public List getStatementAccountTotalPay(String beginTime, String endTime, Integer organId, String supplierType, + String type, String subType) { + List list = null; + try{ + list = depotHeadMapperEx.getStatementAccountTotalPay(beginTime, endTime, organId, supplierType, type, subType); + } catch(Exception e){ + JshException.readFail(logger, e); + } + return list; + } + public BigDecimal findAllMoney(Integer supplierId, String type, String subType, String mode, String endTime)throws Exception { String modeName = ""; BigDecimal allOtherMoney = BigDecimal.ZERO; diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml index 65c43ed62..d637ad1ab 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml @@ -473,53 +473,123 @@ ORDER BY oper_time DESC,number desc - + 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 + where dh.organ_id=s.id + and dh.type=#{type} and dh.sub_type=#{subType} + and dh.oper_time <= #{beginTime} + and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, + (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} + 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 + where dh.organ_id=s.id + 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 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} and dh.oper_time <= #{endTime} + and ifnull(ai.delete_flag,'0') !='1') backMoney + from jsh_supplier s + where s.enabled=1 + and s.type=#{supplierType} - and dh.organ_id=#{organId} + and s.id = #{organId} - and ifnull(dh.delete_flag,'0') !='1' - UNION ALL - select ah.bill_no number,ah.type as newType,ah.total_price discount_last_money, 0 other_money,ah.change_amount,s.supplier supplierName, - date_format(ah.bill_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_account_head ah - left join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1' - where s.type=#{supType} and (ah.type='收款' or ah.type='付款') - and ah.bill_time >=#{beginTime} and ah.bill_time <=#{endTime} - - and ah.organ_id=#{organId} - - and ifnull(ah.delete_flag,'0') !='1' - ORDER BY oTime desc + 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 limit #{offset},#{rows} - + select count(1) 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 + where dh.organ_id=s.id + and dh.type=#{type} and dh.sub_type=#{subType} + and dh.oper_time <= #{beginTime} + and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, + (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} + 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 + where dh.organ_id=s.id + 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 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} and dh.oper_time <= #{endTime} + and ifnull(ai.delete_flag,'0') !='1') backMoney + from jsh_supplier s + where s.enabled=1 + and s.type=#{supplierType} + + and s.id = #{organId} + + and ifnull(s.delete_flag,'0') !='1') tb + where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0 + + + + \ No newline at end of file