销售业绩组合表样式优化
This commit is contained in:
parent
219845a129
commit
e7f0060125
@ -7,11 +7,7 @@ SELECT
|
||||
${if(FIND('发货件数', sIndex)>0," ROUND(SUM(T1.ship_num) / 10000,2) AS 发货件数,","")}
|
||||
${if(FIND('发货瓶数', sIndex)>0," ROUND(SUM(T1.ship_botnum),0) AS 发货瓶数,","")}
|
||||
${if(FIND('实物库存', sIndex)>0," ROUND(SUM(T1.real_amt) / 10000,2) AS 实物库存,","")}
|
||||
-- ${if(len(sIndex)=0," max(1)","")}
|
||||
-- ${if(len(sIndex)>0," 1","")}
|
||||
${if(len(sIndex)>0&& FIND(sIndex,sIndex)>0," 1","")}
|
||||
|
||||
|
||||
FROM
|
||||
(
|
||||
-- 销售订单(订单金额)
|
||||
@ -35,36 +31,28 @@ FROM
|
||||
,0 AS ship_botnum -- 发货瓶数
|
||||
,0 AS real_amt -- 实物库存
|
||||
FROM dm.v_ag_sal_order -- 销售订单视图
|
||||
WHERE 1 = 1
|
||||
-- AND TO_CHAR(order_time, 'YYYY-MM-DD') >= '2024-10-11'
|
||||
-- AND TO_CHAR(order_time, 'YYYY-MM-DD') < '${sEndDate}'
|
||||
|
||||
${SWITCH(sDateGroup
|
||||
,"'y'","AND LEFT(order_time, 4) > LFET('" + sStartDate + "', 4) AND LFET(order_time, 4) < LFET('" + sEndDate + "', 4)"
|
||||
,"'q'","AND TO_CHAR(order_time, 'YYYY-MM-DD') > TO_CHAR('" + sStartDate + "', 'YYYY-MM-DD') AND TO_CHAR(order_time, 'YYYY-MM-DD') < TO_CHAR('" + sEndDate + "', 'YYYY-MM-DD')"
|
||||
,"'m'","AND LFET(order_time,7) > LFET('" + sStartDate + "', 7) AND LFET(order_time, 7) < LFET('" + sEndDate + "', 7)"
|
||||
,"'d'","AND TO_CHAR(order_time, 'YYYY-MM-DD') > TO_CHAR('" + sStartDate + "', 'YYYY-MM-DD') AND TO_CHAR(order_time, 'YYYY-MM-DD') < TO_CHAR('" + sEndDate + "', 'YYYY-MM-DD')")}
|
||||
|
||||
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 品项
|
||||
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")}
|
||||
-- 子主经销商
|
||||
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
|
||||
|
||||
WHERE order_time >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
|
||||
AND order_time < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 经销商
|
||||
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 品项
|
||||
${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
|
||||
-- 产品
|
||||
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
|
||||
GROUP BY
|
||||
bu_name -- 事业部名称
|
||||
,region_name -- 大区名称
|
||||
@ -100,27 +88,28 @@ FROM
|
||||
,0 AS ship_botnum-- 发货瓶数
|
||||
,0 AS real_amt -- 实物库存
|
||||
FROM dm.v_ag_sal_contract -- 合同表 产品+合同ID
|
||||
WHERE 1 = 1
|
||||
AND TO_CHAR(signed_date, 'YYYY-MM-DD') >= '${sStartDate}'
|
||||
AND TO_CHAR(signed_date, 'YYYY-MM-DD') < '${sEndDate}'
|
||||
-- 事业部
|
||||
WHERE signed_date >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
|
||||
AND signed_date < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")}
|
||||
-- 办事处
|
||||
-- 大区
|
||||
${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
|
||||
-- 省
|
||||
-- 城市单元
|
||||
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 产品线
|
||||
-- 经销商
|
||||
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 品项
|
||||
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")}
|
||||
-- 子主经销商
|
||||
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
|
||||
-- 品项
|
||||
${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
|
||||
-- 产品
|
||||
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
|
||||
|
||||
GROUP BY
|
||||
bu_name -- 事业部名称
|
||||
@ -157,25 +146,28 @@ FROM
|
||||
,0 AS real_amt -- 实物库存
|
||||
FROM dm.v_ag_sal_collection -- 销售回款
|
||||
WHERE 1=1
|
||||
AND TO_CHAR(bill_date, 'YYYY-MM-DD') >= '${sStartDate}'
|
||||
AND TO_CHAR(bill_date, 'YYYY-MM-DD') < '${sEndDate}'
|
||||
AND bill_date >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
|
||||
AND bill_date < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")}
|
||||
${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
|
||||
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 经销商
|
||||
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 子主经销商
|
||||
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
|
||||
|
||||
-- 品项
|
||||
${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
|
||||
-- 产品
|
||||
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
|
||||
GROUP BY
|
||||
bu_name -- 事业部名称
|
||||
,region_name -- 大区名称
|
||||
@ -210,27 +202,28 @@ FROM
|
||||
,0 AS real_amt -- 实物库存
|
||||
FROM dm.v_ag_sal_deliver
|
||||
WHERE 1=1
|
||||
AND TO_CHAR(deli_time, 'YYYY-MM-DD') >= '${sStartDate}'
|
||||
AND TO_CHAR(deli_time, 'YYYY-MM-DD') < '${sEndDate}'
|
||||
AND deli_time >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
|
||||
AND deli_time < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")}
|
||||
${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
|
||||
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 经销商
|
||||
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 品项
|
||||
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")}
|
||||
-- 子主经销商
|
||||
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
|
||||
|
||||
${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
|
||||
-- 产品
|
||||
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
|
||||
GROUP BY
|
||||
bu_name -- 事业部名称
|
||||
,region_name -- 大区名称
|
||||
@ -265,28 +258,29 @@ FROM
|
||||
,0 AS ship_botnum-- 发货瓶数
|
||||
,SUM(end_num * price) AS real_amt -- 实物库存金额
|
||||
FROM dm.v_ag_sal_deal_stock
|
||||
WHERE 1=1
|
||||
AND CONCAT(stock_year, '-', stock_month, '-01') >= '${sStartDate}'
|
||||
AND CONCAT(stock_year, '-', stock_month, '-01') < '${sEndDate}'
|
||||
WHERE stock_year=left('${sEnd_date}',4)
|
||||
AND stock_month < right('${sEnd_date}',2)
|
||||
AND stock_month >= right('${sStart_date}',2)
|
||||
-- 事业部
|
||||
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
|
||||
-- 大区
|
||||
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")}
|
||||
${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
|
||||
-- 办事处
|
||||
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
|
||||
-- 城市单元
|
||||
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
|
||||
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
|
||||
-- 省
|
||||
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
|
||||
-- 市
|
||||
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
|
||||
-- 经销商
|
||||
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
|
||||
-- 产品线
|
||||
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
|
||||
-- 品项
|
||||
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")}
|
||||
-- 子主经销商
|
||||
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
|
||||
|
||||
${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
|
||||
-- 产品
|
||||
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
|
||||
GROUP BY
|
||||
bu_name -- 事业部名称
|
||||
,region_name -- 大区名称
|
||||
@ -300,5 +294,4 @@ FROM
|
||||
,deal_name -- 经销商名称
|
||||
,src_deal_name -- 子经销商名称
|
||||
)T1
|
||||
|
||||
${if(len(sDim)>0," GROUP BY " + sDim ," ")}
|
Loading…
Reference in New Issue
Block a user