优化供应商客户金额统计

This commit is contained in:
季圣华
2021-07-09 00:09:09 +08:00
parent d72baacfd8
commit 07025a3881
5 changed files with 15 additions and 29 deletions

View File

@@ -211,9 +211,9 @@ public class DepotHeadController {
beginNeed = supplier.getBeginNeedPay(); beginNeed = supplier.getBeginNeedPay();
} }
BigDecimal firstMoney = depotHeadService.findTotalPay(organId, beginTime, supType) BigDecimal firstMoney = depotHeadService.findTotalPay(organId, beginTime, supType)
.add(accountHeadService.findTotalPay(organId, beginTime, supType)).add(beginNeed); .subtract(accountHeadService.findTotalPay(organId, beginTime, supType)).add(beginNeed);
BigDecimal lastMoney = depotHeadService.findTotalPay(organId, endTime, supType) BigDecimal lastMoney = depotHeadService.findTotalPay(organId, endTime, supType)
.add(accountHeadService.findTotalPay(organId, endTime, supType)).add(beginNeed); .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

@@ -313,7 +313,7 @@ public class AccountHeadService {
} }
/** /**
* 查询单位的累计应收和累计应付,收预付款不计入此处 * 查询往来单位的累计应收和累计应付,只计入收款或付款
* @param supplierId * @param supplierId
* @param endTime * @param endTime
* @param supType * @param supType
@@ -322,17 +322,11 @@ public class AccountHeadService {
public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) { public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) {
BigDecimal sum = BigDecimal.ZERO; BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString(); String getS = supplierId.toString();
int i = 1;
if (("客户").equals(supType)) { //客户 if (("客户").equals(supType)) { //客户
i = 1; sum = allMoney(getS, "收款", "合计",endTime);
} else if (("供应商").equals(supType)) { //供应商 } else if (("供应商").equals(supType)) { //供应商
i = -1; sum = allMoney(getS, "付款", "合计",endTime);
} }
//收付款部分
sum = sum.subtract((allMoney(getS, "收款", "合计",endTime)).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "付款", "合计",endTime)).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "收入", "合计",endTime).subtract(allMoney(getS, "收入", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.subtract((allMoney(getS, "支出", "合计",endTime).subtract(allMoney(getS, "支出", "实际",endTime))).multiply(new BigDecimal(i)));
return sum; return sum;
} }

View File

@@ -551,17 +551,11 @@ public class DepotHeadService {
public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) { public BigDecimal findTotalPay(Integer supplierId, String endTime, String supType) {
BigDecimal sum = BigDecimal.ZERO; BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString(); String getS = supplierId.toString();
int i = 1;
if (("客户").equals(supType)) { //客户 if (("客户").equals(supType)) { //客户
i = 1; sum = allMoney(getS, "出库", "销售", "合计",endTime).subtract(allMoney(getS, "出库", "销售", "实际",endTime));
} else if (("供应商").equals(supType)) { //供应商 } else if (("供应商").equals(supType)) { //供应商
i = -1; sum = allMoney(getS, "入库", "采购", "合计",endTime).subtract(allMoney(getS, "入库", "采购", "实际",endTime));
} }
//进销部分
sum = sum.subtract((allMoney(getS, "入库", "采购", "合计",endTime).subtract(allMoney(getS, "入库", "采购", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.subtract((allMoney(getS, "入库", "销售退货", "合计",endTime).subtract(allMoney(getS, "入库", "销售退货", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "出库", "销售", "合计",endTime).subtract(allMoney(getS, "出库", "销售", "实际",endTime))).multiply(new BigDecimal(i)));
sum = sum.add((allMoney(getS, "出库", "采购退货", "合计",endTime).subtract(allMoney(getS, "出库", "采购退货", "实际",endTime))).multiply(new BigDecimal(i)));
return sum; return sum;
} }

View File

@@ -105,15 +105,13 @@ public class SupplierService {
if(beginNeedPay==null) { if(beginNeedPay==null) {
beginNeedPay = BigDecimal.ZERO; beginNeedPay = BigDecimal.ZERO;
} }
sum = sum.add(depotHeadService.findTotalPay(supplierId, endTime, supType)); sum = sum.add(depotHeadService.findTotalPay(supplierId, endTime, supType))
sum = sum.add(accountHeadService.findTotalPay(supplierId, endTime, supType)); .subtract(accountHeadService.findTotalPay(supplierId, endTime, supType));
if(("客户").equals(s.getType())) { if(("客户").equals(s.getType())) {
sum = sum.add(beginNeedGet).subtract(beginNeedPay); sum = sum.add(beginNeedGet);
s.setAllNeedGet(sum); s.setAllNeedGet(sum);
s.setAllNeedPay(BigDecimal.ZERO);
} else if(("供应商").equals(s.getType())) { } else if(("供应商").equals(s.getType())) {
sum = sum.add(beginNeedPay).subtract(beginNeedGet); sum = sum.add(beginNeedPay);
s.setAllNeedGet(BigDecimal.ZERO);
s.setAllNeedPay(sum); s.setAllNeedPay(sum);
} }
resList.add(s); resList.add(s);

View File

@@ -187,8 +187,8 @@
and dh.oper_time <= #{endTime} and dh.oper_time <= #{endTime}
</if> </if>
and ifnull(m.delete_flag,'0') !='1' and ifnull(m.delete_flag,'0') !='1'
group by m.id,m.name, m.model, m.unit, m.color, u.name group by m.id
order by m.name, m.model asc order by m.id desc
<if test="offset != null and rows != null"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>
@@ -265,12 +265,12 @@
<select id="getStockByParam" resultMap="StockMap"> <select id="getStockByParam" resultMap="StockMap">
select ifnull((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal),0) as in_stock, select ifnull((curep.inTotal+curep.transfInTotal+curep.assemInTotal+curep.disAssemInTotal),0) as in_stock,
ifnull((curep.transfOutTotal+curep.outTotal+curep.assemOutTotal+curep.disAssemOutTotal),0) out_stock ifnull((curep.outTotal+curep.transfOutTotal+curep.assemOutTotal+curep.disAssemOutTotal),0) out_stock
from from
(select sum(if(dh.type='入库' <if test="depotId != null">and di.depot_id=#{depotId}</if>, di.basic_number,0)) as inTotal, (select sum(if(dh.type='入库' <if test="depotId != null">and di.depot_id=#{depotId}</if>, di.basic_number,0)) as inTotal,
sum(if(dh.type='出库' and dh.sub_type!='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as outTotal,
sum(if(dh.sub_type='调拨' <if test="depotId != null">and di.another_depot_id=#{depotId}</if>,di.basic_number,0)) as transfInTotal, sum(if(dh.sub_type='调拨' <if test="depotId != null">and di.another_depot_id=#{depotId}</if>,di.basic_number,0)) as transfInTotal,
sum(if(dh.sub_type='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as transfOutTotal, sum(if(dh.sub_type='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as transfOutTotal,
sum(if(dh.type='出库' and dh.sub_type!='调拨' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as outTotal,
sum(if(dh.sub_type='组装单' and di.material_type='组合件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as assemInTotal, sum(if(dh.sub_type='组装单' and di.material_type='组合件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as assemInTotal,
sum(if(dh.sub_type='组装单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as assemOutTotal, sum(if(dh.sub_type='组装单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as assemOutTotal,
sum(if(dh.sub_type='拆卸单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as disAssemInTotal, sum(if(dh.sub_type='拆卸单' and di.material_type='普通子件' <if test="depotId != null">and di.depot_id=#{depotId}</if>,di.basic_number,0)) as disAssemInTotal,