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

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 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<String, Object> map = new HashMap<String, Object>();
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<DepotHeadVo4StatementAccount> list = depotHeadService.findStatementAccount(beginTime, endTime, organId, supType, (currentPage-1)*pageSize, pageSize);
int total = depotHeadService.findStatementAccountCount(beginTime, endTime, organId, supType);
List<DepotHeadVo4StatementAccount> 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<DepotHeadVo4StatementAccount> 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); //期末
}

View File

@ -121,19 +121,31 @@ public interface DepotHeadMapperEx {
@Param("depotFList") List<Long> depotFList,
@Param("remark") String remark);
List<DepotHeadVo4StatementAccount> findStatementAccount(
List<DepotHeadVo4StatementAccount> 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<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(
@Param("supplierId") Integer supplierId,

View File

@ -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;
}
}

View File

@ -511,72 +511,39 @@ public class DepotHeadService {
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;
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<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 {
String modeName = "";
BigDecimal allOtherMoney = BigDecimal.ZERO;

View File

@ -473,53 +473,123 @@
ORDER BY oper_time DESC,number desc
</select>
<select id="findStatementAccount" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultStatementAccount">
select dh.number,concat(dh.sub_type,dh.type) as type,dh.discount_last_money,dh.other_money,dh.change_amount,s.supplier supplierName,
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depot_head dh
left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} and (dh.sub_type='采购' or dh.sub_type='销售')
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<select id="getStatementAccount" resultType="com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount">
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 &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 dh.organ_id=#{organId}
and s.id = #{organId}
</if>
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 &lt;=#{endTime}
<if test="organId != null">
and ah.organ_id=#{organId}
</if>
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
<if test="offset != null and rows != null">
limit #{offset},#{rows}
</if>
</select>
<select id="findStatementAccountCount" resultType="java.lang.Integer">
select sum(a) from
(
select count(1) a from jsh_depot_head dh
left join jsh_supplier s on s.id=dh.organ_id and ifnull(s.delete_Flag,'0') !='1'
where s.type=#{supType} and (dh.sub_type='采购' or dh.sub_type='销售')
and dh.oper_time >=#{beginTime} and dh.oper_time &lt;=#{endTime}
<if test="organId != null">
and dh.organ_id=#{organId}
</if>
and ifnull(dh.delete_flag,'0') !='1'
UNION ALL
select count(1) a 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'
) cc
<select id="getStatementAccountCount" resultType="java.lang.Integer">
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 &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 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 id="findAllMoney" resultType="java.math.BigDecimal">
@ -714,4 +784,5 @@
and dh.number!=#{number}
and ifnull(dh.delete_flag,'0') !='1'
</select>
</mapper>