优化对账单的查询接口

This commit is contained in:
季圣华
2023-03-20 23:45:20 +08:00
parent 5810cd953d
commit c03ca0274a
5 changed files with 34 additions and 22 deletions

View File

@@ -311,41 +311,50 @@ public class DepotHeadController {
String subType = ""; String subType = "";
String typeBack = ""; String typeBack = "";
String subTypeBack = ""; String subTypeBack = "";
String billType = "";
if (("供应商").equals(supplierType)) { if (("供应商").equals(supplierType)) {
type = "入库"; type = "入库";
subType = "采购"; subType = "采购";
typeBack = "出库"; typeBack = "出库";
subTypeBack = "采购退货"; subTypeBack = "采购退货";
billType = "付款";
} else if (("客户").equals(supplierType)) { } else if (("客户").equals(supplierType)) {
type = "出库"; type = "出库";
subType = "销售"; subType = "销售";
typeBack = "入库"; typeBack = "入库";
subTypeBack = "销售退货"; subTypeBack = "销售退货";
billType = "收款";
} }
String [] organArray = depotHeadService.getOrganArray(subType, ""); String [] organArray = depotHeadService.getOrganArray(subType, "");
beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME); beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME);
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME); endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
List<DepotHeadVo4StatementAccount> list = depotHeadService.getStatementAccount(beginTime, endTime, organId, organArray, List<DepotHeadVo4StatementAccount> list = depotHeadService.getStatementAccount(beginTime, endTime, organId, organArray,
supplierType, type, subType,typeBack, subTypeBack, (currentPage-1)*pageSize, pageSize); supplierType, type, subType,typeBack, subTypeBack, billType, (currentPage-1)*pageSize, pageSize);
int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, organArray, int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, organArray,
supplierType, type, subType,typeBack, subTypeBack); supplierType, type, subType,typeBack, subTypeBack, billType);
for(DepotHeadVo4StatementAccount item: list) { for(DepotHeadVo4StatementAccount item: list) {
//期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款
BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney()); BigDecimal preNeed = item.getBeginNeed().add(item.getPreDebtMoney()).subtract(item.getPreReturnDebtMoney()).subtract(item.getPreBackMoney());
item.setPreNeed(preNeed); item.setPreNeed(preNeed);
//实际欠款 = 本期欠款-本期退货的欠款金额
BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney()); BigDecimal realDebtMoney = item.getDebtMoney().subtract(item.getReturnDebtMoney());
item.setDebtMoney(realDebtMoney); item.setDebtMoney(realDebtMoney);
//期末 = 期初+实际欠款-本期收款
BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney()); BigDecimal allNeedGet = preNeed.add(realDebtMoney).subtract(item.getBackMoney());
item.setAllNeed(allNeedGet); item.setAllNeed(allNeedGet);
} }
map.put("rows", list); map.put("rows", list);
map.put("total", total); map.put("total", total);
List<DepotHeadVo4StatementAccount> totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType, typeBack, subTypeBack); List<DepotHeadVo4StatementAccount> totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, organArray,
supplierType, type, subType, typeBack, subTypeBack, billType);
if(totalPayList.size()>0) { if(totalPayList.size()>0) {
DepotHeadVo4StatementAccount totalPayItem = totalPayList.get(0); DepotHeadVo4StatementAccount totalPayItem = totalPayList.get(0);
BigDecimal firstMoney = BigDecimal.ZERO; BigDecimal firstMoney = BigDecimal.ZERO;
BigDecimal lastMoney = BigDecimal.ZERO; BigDecimal lastMoney = BigDecimal.ZERO;
if(totalPayItem!=null) { if(totalPayItem!=null) {
//期初 = 起始期初金额+上期欠款金额-上期退货的欠款金额-上期收付款
firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreReturnDebtMoney()).subtract(totalPayItem.getPreBackMoney()); firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreReturnDebtMoney()).subtract(totalPayItem.getPreBackMoney());
//期末 = 期初+本期欠款-本期退货的欠款金额-本期收款
lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getReturnDebtMoney()).subtract(totalPayItem.getBackMoney()); lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getReturnDebtMoney()).subtract(totalPayItem.getBackMoney());
} }
map.put("firstMoney", firstMoney); //期初 map.put("firstMoney", firstMoney); //期初

View File

@@ -151,6 +151,7 @@ public interface DepotHeadMapperEx {
@Param("subType") String subType, @Param("subType") String subType,
@Param("typeBack") String typeBack, @Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack, @Param("subTypeBack") String subTypeBack,
@Param("billType") String billType,
@Param("offset") Integer offset, @Param("offset") Integer offset,
@Param("rows") Integer rows); @Param("rows") Integer rows);
@@ -163,7 +164,8 @@ public interface DepotHeadMapperEx {
@Param("type") String type, @Param("type") String type,
@Param("subType") String subType, @Param("subType") String subType,
@Param("typeBack") String typeBack, @Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack); @Param("subTypeBack") String subTypeBack,
@Param("billType") String billType);
List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay( List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(
@Param("beginTime") String beginTime, @Param("beginTime") String beginTime,
@@ -174,7 +176,8 @@ public interface DepotHeadMapperEx {
@Param("type") String type, @Param("type") String type,
@Param("subType") String subType, @Param("subType") String subType,
@Param("typeBack") String typeBack, @Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack); @Param("subTypeBack") String subTypeBack,
@Param("billType") String billType);
BigDecimal findAllMoney( BigDecimal findAllMoney(
@Param("supplierId") Integer supplierId, @Param("supplierId") Integer supplierId,

View File

@@ -675,10 +675,10 @@ public class DepotHeadService {
} }
public List<DepotHeadVo4StatementAccount> getStatementAccount(String beginTime, String endTime, Integer organId, String [] organArray, public List<DepotHeadVo4StatementAccount> getStatementAccount(String beginTime, String endTime, Integer organId, String [] organArray,
String supplierType, String type, String subType, String typeBack, String subTypeBack, Integer offset, Integer rows) { String supplierType, String type, String subType, String typeBack, String subTypeBack, String billType, Integer offset, Integer rows) {
List<DepotHeadVo4StatementAccount> list = null; List<DepotHeadVo4StatementAccount> list = null;
try{ try{
list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack, offset, rows); list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack, billType, offset, rows);
} catch(Exception e){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
@@ -686,10 +686,10 @@ public class DepotHeadService {
} }
public int getStatementAccountCount(String beginTime, String endTime, Integer organId, public int getStatementAccountCount(String beginTime, String endTime, Integer organId,
String [] organArray, String supplierType, String type, String subType, String typeBack, String subTypeBack) { String [] organArray, String supplierType, String type, String subType, String typeBack, String subTypeBack, String billType) {
int result = 0; int result = 0;
try{ try{
result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack); result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack, billType);
} catch(Exception e){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
@@ -698,10 +698,10 @@ public class DepotHeadService {
public List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(String beginTime, String endTime, Integer organId, public List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(String beginTime, String endTime, Integer organId,
String [] organArray, String supplierType, String [] organArray, String supplierType,
String type, String subType, String typeBack, String subTypeBack) { String type, String subType, String typeBack, String subTypeBack, String billType) {
List<DepotHeadVo4StatementAccount> list = null; List<DepotHeadVo4StatementAccount> list = null;
try{ try{
list = depotHeadMapperEx.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack); list = depotHeadMapperEx.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType,typeBack, subTypeBack, billType);
} catch(Exception e){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }

View File

@@ -411,9 +411,9 @@ public class SupplierService {
} else if("客户".equals(supplier.getType())) { } else if("客户".equals(supplier.getType())) {
needDebt = supplier.getBeginNeedGet(); needDebt = supplier.getBeginNeedGet();
} }
BigDecimal finishDebt = accountItemMapperEx.getFinishDebtByOrganId(organId); BigDecimal finishDebt = accountItemMapperEx.getFinishDebtByOrganId(organId).abs();
BigDecimal eachAmount = BigDecimal.ZERO; BigDecimal eachAmount = BigDecimal.ZERO;
if(needDebt != null && finishDebt != null) { if(needDebt != null) {
eachAmount = needDebt.subtract(finishDebt); eachAmount = needDebt.subtract(finishDebt);
} }
//应收欠款 //应收欠款

View File

@@ -654,9 +654,9 @@
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney, and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
(select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai (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' left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
where dh.organ_id=s.id where ah.organ_id=s.id and ah.type=#{billType}
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s from jsh_supplier s
where s.enabled=1 where s.enabled=1
@@ -717,9 +717,9 @@
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney, and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
(select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai (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' left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
where dh.organ_id=s.id where ah.organ_id=s.id and ah.type=#{billType}
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s from jsh_supplier s
where s.enabled=1 where s.enabled=1
@@ -777,9 +777,9 @@
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime}
and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney, and ifnull(dh.delete_flag,'0') !='1') returnDebtMoney,
(select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai (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' left join jsh_account_head ah on ai.header_id=ah.id and ifnull(ah.delete_flag,'0') !='1'
where dh.organ_id=s.id where ah.organ_id=s.id and ah.type=#{billType}
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{endTime} and ah.bill_time>#{beginTime} and ah.bill_time &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s from jsh_supplier s
where s.enabled=1 where s.enabled=1