77 lines
2.3 KiB
SQL
77 lines
2.3 KiB
SQL
-- ======================================
|
||
-- 2024-11-21:由李维调整完毕
|
||
-- ======================================
|
||
SELECT
|
||
*
|
||
,CASE WHEN bu_code ='0202/0223'
|
||
THEN (CASE WHEN pl_name = '小郎酒' THEN '小郎酒事业部'
|
||
WHEN pl_name IN ('郎牌特曲', '郎牌原浆', '新郎酒') THEN '郎牌特曲事业部'
|
||
WHEN pl_name in ('青花郎', '老郎酒', '藏品') THEN '青花郎事业部'END)
|
||
ELSE bu_name END report_bu_name -- 报表事业部
|
||
,CASE WHEN office_name LIKE '%成都%'
|
||
THEN '成都市场'
|
||
ELSE region_name
|
||
END AS report_region_name -- 报表大区
|
||
FROM dm.v_ag_sal_cust_flow a
|
||
-- 出货时间
|
||
WHERE bill_time >= '${sStart_date}'
|
||
AND bill_time <= '${sEnd_date}'
|
||
|
||
-- 事业部
|
||
${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_type) == 0,"","and deal_type in ('" + sDeal_type + "')")}
|
||
|
||
-- 产品
|
||
${if(len(sProd) == 0,"","and product_code in ('" + sProd + "')")}
|
||
|
||
-- 产品线
|
||
${if(len(sPl_name) == 0,"","and pl_name in ('" + sPl_name + "')")}
|
||
|
||
-- 金额区间
|
||
${if(len(sStart_amt) == 0,"","and ordered_amt >= " + sStart_amt + "")}
|
||
${if(len(sEnd_amt) == 0,"","and ordered_amt <= " + sEnd_amt + "")}
|
||
|
||
-- 子主经销商筛选
|
||
${if(sSub_main== "主经销商",if(len(sDeal)==0,"","and deal_code in ('" + sDeal + "')"),if(len(sDeal)==0,"","and src_deal_code in ('" +sDeal + "')"))}
|
||
|
||
-- 收货方
|
||
${if(len(sOpposite_name) == 0,"","and opposite_name in ('" + sOpposite_name + "')")}
|
||
|
||
-- 单据号 bill_code
|
||
${if(len(sBill) == 0,"","and bill_code in ('" + sBill + "')")}
|
||
|
||
|
||
-- 权限控制
|
||
AND exists (
|
||
select
|
||
1
|
||
from
|
||
dm.dm_bi_user_permisson
|
||
where
|
||
bi_user = '${fine_username}'
|
||
and per_model IN ('all','sal')
|
||
and (
|
||
is_all = 1
|
||
OR per_code = a.bu_code -- 事业部
|
||
OR per_code = a.region_code -- 大区
|
||
OR per_code = a.office_code -- 城市单元
|
||
OR per_code = a.city_unit_code -- 城市单元
|
||
)
|
||
) |