优化客户对账和供应商对账

This commit is contained in:
季圣华
2022-06-03 18:34:09 +08:00
parent 9ff1d99abf
commit 1015eb9046
5 changed files with 261 additions and 171 deletions

View File

@@ -280,44 +280,54 @@ public class DepotHeadController {
* @param beginTime * @param beginTime
* @param endTime * @param endTime
* @param organId * @param organId
* @param supType * @param supplierType
* @param request * @param request
* @return * @return
*/ */
@GetMapping(value = "/findStatementAccount") @GetMapping(value = "/getStatementAccount")
@ApiOperation(value = "对账单接口") @ApiOperation(value = "对账单接口")
public BaseResponseInfo findStatementAccount(@RequestParam("currentPage") Integer currentPage, public BaseResponseInfo getStatementAccount(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize, @RequestParam("pageSize") Integer pageSize,
@RequestParam("beginTime") String beginTime, @RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime, @RequestParam("endTime") String endTime,
@RequestParam(value = "organId", required = false) Integer organId, @RequestParam(value = "organId", required = false) Integer organId,
@RequestParam("supType") String supType, @RequestParam("supplierType") String supplierType,
HttpServletRequest request) throws Exception{ HttpServletRequest request) throws Exception{
BaseResponseInfo res = new BaseResponseInfo(); BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
try { try {
String type = "";
String subType = "";
if (("供应商").equals(supplierType)) {
type = "入库";
subType = "采购";
} else if (("客户").equals(supplierType)) {
type = "出库";
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.findStatementAccount(beginTime, endTime, organId, supType, (currentPage-1)*pageSize, pageSize); List<DepotHeadVo4StatementAccount> list = depotHeadService.getStatementAccount(beginTime, endTime, organId,
int total = depotHeadService.findStatementAccountCount(beginTime, endTime, organId, supType); 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("rows", list);
map.put("total", total); map.put("total", total);
if(null!=organId) { List<DepotHeadVo4StatementAccount> totalPayList = depotHeadService.getStatementAccountTotalPay(beginTime, endTime, organId, supplierType, type, subType);
Supplier supplier = supplierService.getSupplier(organId); if(totalPayList.size()>0) {
BigDecimal beginNeed = BigDecimal.ZERO; DepotHeadVo4StatementAccount totalPayItem = totalPayList.get(0);
if (("客户").equals(supType)) { BigDecimal firstMoney = BigDecimal.ZERO;
if(supplier.getBeginNeedGet()!=null) { BigDecimal lastMoney = BigDecimal.ZERO;
beginNeed = supplier.getBeginNeedGet(); if(totalPayItem!=null) {
} firstMoney = totalPayItem.getBeginNeed().add(totalPayItem.getPreDebtMoney()).subtract(totalPayItem.getPreBackMoney());
} else if (("供应商").equals(supType)) { lastMoney = firstMoney.add(totalPayItem.getDebtMoney()).subtract(totalPayItem.getBackMoney());
if(supplier.getBeginNeedPay()!=null) {
beginNeed = supplier.getBeginNeedPay();
}
} }
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("firstMoney", firstMoney); //期初
map.put("lastMoney", lastMoney); //期末 map.put("lastMoney", lastMoney); //期末
} }

View File

@@ -121,19 +121,31 @@ public interface DepotHeadMapperEx {
@Param("depotFList") List<Long> depotFList, @Param("depotFList") List<Long> depotFList,
@Param("remark") String remark); @Param("remark") String remark);
List<DepotHeadVo4StatementAccount> findStatementAccount( List<DepotHeadVo4StatementAccount> getStatementAccount(
@Param("beginTime") String beginTime, @Param("beginTime") String beginTime,
@Param("endTime") String endTime, @Param("endTime") String endTime,
@Param("organId") Integer organId, @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("offset") Integer offset,
@Param("rows") Integer rows); @Param("rows") Integer rows);
int findStatementAccountCount( int getStatementAccountCount(
@Param("beginTime") String beginTime, @Param("beginTime") String beginTime,
@Param("endTime") String endTime, @Param("endTime") String endTime,
@Param("organId") Integer organId, @Param("organId") Integer organId,
@Param("supType") String supType); @Param("supplierType") String supplierType,
@Param("type") String type,
@Param("subType") String subType);
List<DepotHeadVo4StatementAccount> 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( BigDecimal findAllMoney(
@Param("supplierId") Integer supplierId, @Param("supplierId") Integer supplierId,

View File

@@ -5,103 +5,133 @@ import java.math.BigDecimal;
public class DepotHeadVo4StatementAccount { 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() { private BigDecimal debtMoney;
return number;
private BigDecimal backMoney;
private BigDecimal allNeed;
public Long getId() {
return id;
} }
public void setNumber(String number) { public void setId(Long id) {
this.number = number; this.id = id;
} }
public String getType() { public String getSupplier() {
return type; return supplier;
} }
public void setType(String type) { public void setSupplier(String supplier) {
this.type = type; this.supplier = supplier;
} }
public BigDecimal getDiscountLastMoney() { public String getContacts() {
return discountLastMoney; return contacts;
} }
public void setDiscountLastMoney(BigDecimal discountLastMoney) { public void setContacts(String contacts) {
this.discountLastMoney = discountLastMoney; this.contacts = contacts;
} }
public BigDecimal getOtherMoney() { public String getTelephone() {
return otherMoney; return telephone;
} }
public void setOtherMoney(BigDecimal otherMoney) { public void setTelephone(String telephone) {
this.otherMoney = otherMoney; this.telephone = telephone;
} }
public BigDecimal getBillMoney() { public String getPhoneNum() {
return billMoney; return phoneNum;
} }
public void setBillMoney(BigDecimal billMoney) { public void setPhoneNum(String phoneNum) {
this.billMoney = billMoney; this.phoneNum = phoneNum;
} }
public BigDecimal getChangeAmount() { public String getEmail() {
return changeAmount; return email;
} }
public void setChangeAmount(BigDecimal changeAmount) { public void setEmail(String email) {
this.changeAmount = changeAmount; this.email = email;
} }
public BigDecimal getAllPrice() { public BigDecimal getBeginNeed() {
return allPrice; return beginNeed;
} }
public void setAllPrice(BigDecimal allPrice) { public void setBeginNeed(BigDecimal beginNeed) {
this.allPrice = allPrice; this.beginNeed = beginNeed;
} }
public String getSupplierName() { public BigDecimal getPreDebtMoney() {
return supplierName; return preDebtMoney;
} }
public void setSupplierName(String supplierName) { public void setPreDebtMoney(BigDecimal preDebtMoney) {
this.supplierName = supplierName; this.preDebtMoney = preDebtMoney;
} }
public String getoTime() { public BigDecimal getPreBackMoney() {
return oTime; return preBackMoney;
} }
public void setoTime(String oTime) { public void setPreBackMoney(BigDecimal preBackMoney) {
this.oTime = oTime; this.preBackMoney = preBackMoney;
} }
public Long getTenantId() { public BigDecimal getPreNeed() {
return tenantId; return preNeed;
} }
public void setTenantId(Long tenantId) { public void setPreNeed(BigDecimal preNeed) {
this.tenantId = tenantId; 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;
} }
} }

View File

@@ -511,72 +511,39 @@ public class DepotHeadService {
return result; return result;
} }
public List<DepotHeadVo4StatementAccount> findStatementAccount(String beginTime, String endTime, Integer organId, String supType, Integer offset, Integer rows)throws Exception { public List<DepotHeadVo4StatementAccount> getStatementAccount(String beginTime, String endTime, Integer organId, String supplierType,
String type, String subType, Integer offset, Integer rows) {
List<DepotHeadVo4StatementAccount> list = null; List<DepotHeadVo4StatementAccount> list = null;
try{ try{
int j = 1; list = depotHeadMapperEx.getStatementAccount(beginTime, endTime, organId, supplierType, type, subType, offset, rows);
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()); //单据日期
}
}
} catch(Exception e){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
return list; 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; int result = 0;
try{ try{
result =depotHeadMapperEx.findStatementAccountCount(beginTime, endTime, organId, supType); result = depotHeadMapperEx.getStatementAccountCount(beginTime, endTime, organId, supplierType, type, subType);
}catch(Exception e){ } catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
return result; return result;
} }
public List<DepotHeadVo4StatementAccount> getStatementAccountTotalPay(String beginTime, String endTime, Integer organId, String supplierType,
String type, String subType) {
List<DepotHeadVo4StatementAccount> 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 { public BigDecimal findAllMoney(Integer supplierId, String type, String subType, String mode, String endTime)throws Exception {
String modeName = ""; String modeName = "";
BigDecimal allOtherMoney = BigDecimal.ZERO; BigDecimal allOtherMoney = BigDecimal.ZERO;

View File

@@ -473,53 +473,123 @@
ORDER BY oper_time DESC,number desc ORDER BY oper_time DESC,number desc
</select> </select>
<select id="findStatementAccount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStatementAccount"> <select id="getStatementAccount" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
select dh.number,concat(dh.sub_type,dh.type) as type,dh.discount_last_money,dh.other_money,dh.change_amount,s.supplier supplierName, select * from
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depot_head dh (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
where s.type=#{supType} and (dh.sub_type='采购' or dh.sub_type='销售') (select
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} 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 &lt;= #{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 &lt;= #{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 &lt;= #{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 &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
<if test="organId != null"> <if test="organId != null">
and dh.organ_id=#{organId} and s.id = #{organId}
</if> </if>
and ifnull(dh.delete_flag,'0') !='1' and ifnull(s.delete_flag,'0') !='1') tb
UNION ALL where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0
select ah.bill_no number,ah.type as newType,ah.total_price discount_last_money, 0 other_money,ah.change_amount,s.supplier supplierName, order by begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney desc
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 &lt;=#{endTime}
<if test="organId != null">
and ah.organ_id=#{organId}
</if>
and ifnull(ah.delete_flag,'0') !='1'
ORDER BY oTime desc
<if test="offset != null and rows != null"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
</select> </select>
<select id="findStatementAccountCount" resultType="java.lang.Integer"> <select id="getStatementAccountCount" resultType="java.lang.Integer">
select sum(a) from select count(1) from
( (select s.id, s.supplier, s.contacts, s.telephone, s.phone_num, s.email,
select count(1) a from jsh_depot_head dh (case when s.type='供应商' then ifnull(s.begin_need_pay,0) else ifnull(s.begin_need_get,0) end) begin_need,
left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1' (select
where s.type=#{supType} and (dh.sub_type='采购' or dh.sub_type='销售') 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))
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime} from jsh_depot_head dh
<if test="organId != null"> where dh.organ_id=s.id
and dh.organ_id=#{organId} and dh.type=#{type} and dh.sub_type=#{subType}
</if> and dh.oper_time &lt;= #{beginTime}
and ifnull(dh.delete_flag,'0') !='1' and ifnull(dh.delete_flag,'0') !='1') preDebtMoney,
UNION ALL (select abs(ifnull(sum(ai.each_amount),0)) from jsh_account_item ai
select count(1) a from jsh_account_head ah left join jsh_depot_head dh on ai.bill_id=dh.id and ifnull(dh.delete_flag,'0') !='1'
left join jsh_supplier s on s.id=ah.organ_id and ifnull(s.delete_Flag,'0') !='1' where dh.organ_id=s.id
where s.type=#{supType} and (ah.type='收款' or ah.type='付款') and dh.oper_time &lt;= #{beginTime}
and ah.bill_time >=#{beginTime} and ah.bill_time &lt;=#{endTime} and ifnull(ai.delete_flag,'0') !='1') preBackMoney,
<if test="organId != null"> (select
and ah.organ_id=#{organId} 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))
</if> from jsh_depot_head dh
and ifnull(ah.delete_flag,'0') !='1' where dh.organ_id=s.id
) cc and dh.type=#{type} and dh.sub_type=#{subType}
and dh.oper_time>#{beginTime} and dh.oper_time &lt;= #{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 &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
<if test="organId != null">
and s.id = #{organId}
</if>
and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0
</select>
<select id="getStatementAccountTotalPay" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
select sum(begin_need) begin_need, sum(preDebtMoney) preDebtMoney, sum(preBackMoney) preBackMoney,
sum(debtMoney) debtMoney, sum(backMoney) backMoney from
(select s.id,
(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 &lt;= #{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 &lt;= #{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 &lt;= #{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 &lt;= #{endTime}
and ifnull(ai.delete_flag,'0') !='1') backMoney
from jsh_supplier s
where s.enabled=1
and s.type=#{supplierType}
<if test="organId != null">
and s.id = #{organId}
</if>
and ifnull(s.delete_flag,'0') !='1') tb
where begin_need+preDebtMoney-preBackMoney+debtMoney-backMoney>0
</select> </select>
<select id="findAllMoney" resultType="java.math.BigDecimal"> <select id="findAllMoney" resultType="java.math.BigDecimal">
@@ -714,4 +784,5 @@
and dh.number!=#{number} and dh.number!=#{number}
and ifnull(dh.delete_flag,'0') !='1' and ifnull(dh.delete_flag,'0') !='1'
</select> </select>
</mapper> </mapper>