优化对账单接口,扣除退货单的欠款金额

This commit is contained in:
季圣华
2022-11-20 12:24:08 +08:00
parent 966942741b
commit 6e49ae8404
5 changed files with 124 additions and 20 deletions

View File

@@ -302,36 +302,44 @@ public class DepotHeadController {
try { try {
String type = ""; String type = "";
String subType = ""; String subType = "";
String typeBack = "";
String subTypeBack = "";
if (("供应商").equals(supplierType)) { if (("供应商").equals(supplierType)) {
type = "入库"; type = "入库";
subType = "采购"; subType = "采购";
typeBack = "出库";
subTypeBack = "采购退货";
} else if (("客户").equals(supplierType)) { } else if (("客户").equals(supplierType)) {
type = "出库"; type = "出库";
subType = "销售"; subType = "销售";
typeBack = "入库";
subTypeBack = "销售退货";
} }
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, (currentPage-1)*pageSize, pageSize); supplierType, type, subType,typeBack, subTypeBack, (currentPage-1)*pageSize, pageSize);
int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, organArray, int total = depotHeadService.getStatementAccountCount(beginTime, endTime, organId, organArray,
supplierType, type, subType); supplierType, type, subType,typeBack, subTypeBack);
for(DepotHeadVo4StatementAccount item: list) { 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); 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); 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); List<DepotHeadVo4StatementAccount> totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, organArray, supplierType, type, subType, typeBack, subTypeBack);
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.getPreBackMoney()); firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreReturnDebtMoney()).subtract(totalPayItem.getPreBackMoney());
lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getBackMoney()); lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getReturnDebtMoney()).subtract(totalPayItem.getBackMoney());
} }
map.put("firstMoney", firstMoney); //期初 map.put("firstMoney", firstMoney); //期初
map.put("lastMoney", lastMoney); //期末 map.put("lastMoney", lastMoney); //期末

View File

@@ -146,6 +146,8 @@ public interface DepotHeadMapperEx {
@Param("supplierType") String supplierType, @Param("supplierType") String supplierType,
@Param("type") String type, @Param("type") String type,
@Param("subType") String subType, @Param("subType") String subType,
@Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack,
@Param("offset") Integer offset, @Param("offset") Integer offset,
@Param("rows") Integer rows); @Param("rows") Integer rows);
@@ -156,7 +158,9 @@ public interface DepotHeadMapperEx {
@Param("organArray") String[] organArray, @Param("organArray") String[] organArray,
@Param("supplierType") String supplierType, @Param("supplierType") String supplierType,
@Param("type") String type, @Param("type") String type,
@Param("subType") String subType); @Param("subType") String subType,
@Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack);
List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay( List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(
@Param("beginTime") String beginTime, @Param("beginTime") String beginTime,
@@ -165,7 +169,9 @@ public interface DepotHeadMapperEx {
@Param("organArray") String[] organArray, @Param("organArray") String[] organArray,
@Param("supplierType") String supplierType, @Param("supplierType") String supplierType,
@Param("type") String type, @Param("type") String type,
@Param("subType") String subType); @Param("subType") String subType,
@Param("typeBack") String typeBack,
@Param("subTypeBack") String subTypeBack);
BigDecimal findAllMoney( BigDecimal findAllMoney(
@Param("supplierId") Integer supplierId, @Param("supplierId") Integer supplierId,

View File

@@ -17,18 +17,50 @@ public class DepotHeadVo4StatementAccount {
private String email; private String email;
/**
* 起始期初金额
*/
private BigDecimal beginNeed; private BigDecimal beginNeed;
/**
* 上期欠款金额
*/
private BigDecimal preDebtMoney; private BigDecimal preDebtMoney;
/**
* 上期退货的欠款金额
*/
private BigDecimal preReturnDebtMoney;
/**
* 上期收付款
*/
private BigDecimal preBackMoney; private BigDecimal preBackMoney;
/**
* 期初应收
*/
private BigDecimal preNeed; private BigDecimal preNeed;
/**
* 本期欠款
*/
private BigDecimal debtMoney; private BigDecimal debtMoney;
/**
* 本期退货的欠款金额
*/
private BigDecimal returnDebtMoney;
/**
* 本期收款
*/
private BigDecimal backMoney; private BigDecimal backMoney;
/**
* 期末应收
*/
private BigDecimal allNeed; private BigDecimal allNeed;
public Long getId() { public Long getId() {
@@ -95,6 +127,14 @@ public class DepotHeadVo4StatementAccount {
this.preDebtMoney = preDebtMoney; this.preDebtMoney = preDebtMoney;
} }
public BigDecimal getPreReturnDebtMoney() {
return preReturnDebtMoney;
}
public void setPreReturnDebtMoney(BigDecimal preReturnDebtMoney) {
this.preReturnDebtMoney = preReturnDebtMoney;
}
public BigDecimal getPreBackMoney() { public BigDecimal getPreBackMoney() {
return preBackMoney; return preBackMoney;
} }
@@ -119,6 +159,14 @@ public class DepotHeadVo4StatementAccount {
this.debtMoney = debtMoney; this.debtMoney = debtMoney;
} }
public BigDecimal getReturnDebtMoney() {
return returnDebtMoney;
}
public void setReturnDebtMoney(BigDecimal returnDebtMoney) {
this.returnDebtMoney = returnDebtMoney;
}
public BigDecimal getBackMoney() { public BigDecimal getBackMoney() {
return backMoney; return backMoney;
} }

View File

@@ -603,10 +603,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, Integer offset, Integer rows) { String supplierType, String type, String subType, String typeBack, String subTypeBack, Integer offset, Integer rows) {
List<DepotHeadVo4StatementAccount> list = null; List<DepotHeadVo4StatementAccount> list = null;
try{ 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){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
@@ -614,10 +614,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 [] organArray, String supplierType, String type, String subType, String typeBack, String subTypeBack) {
int result = 0; int result = 0;
try{ 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){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
@@ -626,10 +626,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 type, String subType, String typeBack, String subTypeBack) {
List<DepotHeadVo4StatementAccount> list = null; List<DepotHeadVo4StatementAccount> list = null;
try{ 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){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }

View File

@@ -591,6 +591,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
and dh.oper_time &lt;= #{beginTime} and dh.oper_time &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, 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 &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
(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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -603,6 +610,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
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') debtMoney, 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 &lt;= #{endTime}
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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -623,7 +637,7 @@
</if> </if>
and ifnull(s.delete_flag,'0') !='1') tb and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0 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
<if test="offset != null and rows != null"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
@@ -640,6 +654,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
and dh.oper_time &lt;= #{beginTime} and dh.oper_time &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, 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 &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
(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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -652,6 +673,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
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') debtMoney, 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 &lt;= #{endTime}
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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -671,12 +699,12 @@
) )
</if> </if>
and ifnull(s.delete_flag,'0') !='1') tb 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
</select> </select>
<select id="getStatementAccountTotalPay" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount"> <select id="getStatementAccountTotalPay" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preBackMoney) preBackMoney, select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preReturnDebtMoney) preReturnDebtMoney, sum(preBackMoney) preBackMoney,
sum(debtMoney) debtMoney, sum(backMoney) backMoney from sum(debtMoney) debtMoney, sum(returnDebtMoney) returnDebtMoney, sum(backMoney) backMoney from
(select s.id, (select s.id,
(case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need, (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
(select (select
@@ -686,6 +714,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
and dh.oper_time &lt;= #{beginTime} and dh.oper_time &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preDebtMoney, 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 &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1') preReturnDebtMoney,
(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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -698,6 +733,13 @@
and dh.type=#{type} and dh.sub_type=#{subType} and dh.type=#{type} and dh.sub_type=#{subType}
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') debtMoney, 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 &lt;= #{endTime}
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_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
where dh.organ_id=s.id where dh.organ_id=s.id
@@ -717,7 +759,7 @@
) )
</if> </if>
and ifnull(s.delete_flag,'0') !='1') tb 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
</select> </select>
<select id="findAllMoney" resultType="java.math.BigDecimal"> <select id="findAllMoney" resultType="java.math.BigDecimal">