diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 5414ccb..6a7032c 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -2,7 +2,7 @@ - + diff --git a/BI/销售业绩/经销商出货-废弃.sql b/BI/销售业绩/经销商出货-废弃.sql deleted file mode 100644 index a33e614..0000000 --- a/BI/销售业绩/经销商出货-废弃.sql +++ /dev/null @@ -1,77 +0,0 @@ --- ====================================== --- 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 -- 城市单元 - ) - ) \ No newline at end of file diff --git a/BI/销售业绩/经销商出货.sql b/BI/销售业绩/经销商出货.sql new file mode 100644 index 0000000..820a10e --- /dev/null +++ b/BI/销售业绩/经销商出货.sql @@ -0,0 +1,79 @@ +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 -- 报表大区 +,year(bill_time) AS bill_year +,quarter(bill_time) as bill_quar +,month(bill_time) AS bill_month +,round(num_dealer / pack_base_num,4) AS dealer_num -- 计经销商件数 +,round(num_city_unit / pack_base_num,4) AS city_num -- 计业务区件数 +FROM dm.v_ag_sal_cust_flow a +-- 出货时间 +WHERE 1 =1 + +-- 事业部 + ${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(sPi_name) == 0,"","and pi_name in ('" + sPi_name + "')")} +-- 产品线 + ${if(len(sPl_name) == 0,"","and pl_name in ('" + sPl_name + "')")} + +-- 子主经销商筛选 + ${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 like ('%" + sOpposite_name + "%')")} + +-- 单据号 bill_code + ${if(len(sBill) == 0,"","and bill_code in ('" + sBill + "')")} + + and bill_time >= date('${sStart_date}') + and bill_time < date('${sEnd_date}') + INTERVAL '1 days' + +-- 权限控制 + 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 -- 城市单元 + ) + ) \ No newline at end of file diff --git a/BI/销售业绩/营销指标汇总.sql b/BI/销售业绩/营销指标汇总.sql index 7cfa2f7..ca6666e 100644 --- a/BI/销售业绩/营销指标汇总.sql +++ b/BI/销售业绩/营销指标汇总.sql @@ -1,5 +1,7 @@ select stat_date -- 统计时间 +,year(stat_date) AS stat_year +,month(stat_date) AS stat_month ,bu_code -- 事业部编码 ,bu_name -- 事业部名称 ,region_code -- 大区编码 @@ -43,8 +45,8 @@ select ,SUM(CASE WHEN indi_type = '现金分润' THEN num ELSE 0 END) AS cash_num -- 现金分润 from dm.v_mak_indicator_day a -- 订单时间 -WHERE stat_date >= '${CONCATENATE(sStart_date," 00:00:00")}' -AND stat_date <= '${CONCATENATE(sEnd_date," 00:00:00")}' +WHERE stat_date >= date('${sStart_date}') +AND stat_date <= date('${sEnd_date}') + INTERVAL '1 days' -- 产品线 ${if(len(sPl_name) == 0,"","and a.pl_name in ('" + sPl_name + "')")} -- 事业部 @@ -84,4 +86,6 @@ stat_date -- 统计时间 ,deal_code -- 经销商编码 ,deal_name -- 经销商名称 ,pl_name -- 产品线 -,pi_name -- 品项 \ No newline at end of file +,pi_name -- 品项 +,year(stat_date) +,month(stat_date) \ No newline at end of file diff --git a/BI/销售业绩/销售发货明细-废弃.sql b/BI/销售业绩/销售发货明细-废弃.sql deleted file mode 100644 index 17a33b2..0000000 --- a/BI/销售业绩/销售发货明细-废弃.sql +++ /dev/null @@ -1,52 +0,0 @@ --- ====================================== --- 2024-11-21:由李维调整完毕 --- ====================================== -select - * - ,CASE - WHEN deli_type = '内部用酒' THEN '内部用酒' - 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 AS report_bu_name -- 报表事业部 - ,CASE - WHEN deli_type = '内部用酒' THEN '内部用酒' - WHEN bu_code = '0202/0223' - THEN(CASE WHEN pl_name = '小郎酒' THEN '小郎酒川渝大区' - WHEN pl_name in ('郎牌特曲', '郎牌原浆', '新郎酒') THEN '郎特四川大区' - WHEN pl_name in ('青花郎', '老郎酒', '藏品') THEN '青花郎川渝大区' - END - ) - ELSE region_name - END AS report_region_name -- 报表大区 -from dm.v_ag_sal_deliver --- 发货时间 -WHERE deli_time >= '${sStart_date}' - AND deli_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(sIs_srcdeal== "主经销商",if(len(sDeal)==0,"","and deal_code in ('" + sDeal + "')"),if(len(sDeal)==0,"","and src_deal_code in ('" +sDeal + "')"))} - --- 产品 -${if(len(sProd) == 0,"","and product_code in ('" + sProd + "')")} - --- 发货单号 -${if(len(sDeli_code) == 0,"","and deli_code = '" + sDeli_code + "'")} - --- 订单号 -${if(len(sOrder) == 0,"","and order_code = '" + sOrder + "'")} diff --git a/BI/销售业绩/销售发货明细.sql b/BI/销售业绩/销售发货明细.sql new file mode 100644 index 0000000..65a73ea --- /dev/null +++ b/BI/销售业绩/销售发货明细.sql @@ -0,0 +1,68 @@ +select + * + ,CASE + WHEN deli_type = '内部用酒' THEN '内部用酒' + 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 AS report_bu_name -- 报表事业部 + ,CASE + WHEN deli_type = '内部用酒' THEN '内部用酒' + WHEN bu_code = '0202/0223' + THEN(CASE WHEN pl_name = '小郎酒' THEN '小郎酒川渝大区' + WHEN pl_name in ('郎牌特曲', '郎牌原浆', '新郎酒') THEN '郎特四川大区' + WHEN pl_name in ('青花郎', '老郎酒', '藏品') THEN '青花郎川渝大区' + END + ) + ELSE region_name + END AS report_region_name -- 报表大区 +,year(deli_time) AS deli_year +,quarter(deli_time) as deli_quar +,month(deli_time) AS deli_month +,deli_num / pack_base_num AS ship_num -- 发货件数 +,d_amt + e_amt + f_amt + fz_amt + q_amt AS total_amt -- 费用合计 +,'' AS region_opera_code -- 区域运营商编码 +,'' AS region_opera_name -- 区域运营商名称 +from dm.v_ag_sal_deliver a +where 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 + ) +) +-- 产品线 + ${if(len(sPl_name) == 0,"","and pl_name in ('" + sPl_name + "')")} +-- 品项 + ${if(len(sPi_name) == 0,"","and pi_name in ('" + sPi_name + "')")} +-- 产品 + ${if(len(sProd) == 0,"","and product_code in ('" + sProd + "')")} + +-- 事业部 + ${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(sSub_main== "主经销商",if(len(sDeal)==0,"","and deal_code in ('" + sDeal + "')"),if(len(sDeal)==0,"","and src_deal_code in ('" +sDeal + "')"))} +-- 订单号/发货单号 + ${if(len(sOrder) == 0,"","and (order_code = '" + sOrder + "' or deli_code = '" + sOrder + "')")} +-- 发货时间 + and deli_time >= date('${sStart_date}') + and deli_time < date('${sEnd_date}') + INTERVAL '1 days' diff --git a/BI/销售业绩/销售订单.sql b/BI/销售业绩/销售订单.sql index af38620..d178a5d 100644 --- a/BI/销售业绩/销售订单.sql +++ b/BI/销售业绩/销售订单.sql @@ -1,80 +1,67 @@ SELECT -pk -,order_code -- 订单号 -,src_order_code -- 来源订单号 -,order_time -- 订单时间 -,order_type -- 订单类型 -,city_unit_code -- 城市单元编码 -,city_unit_name -- 城市单元 -,office_code -- 办事处编码 -,office_name -- 办事处 -,region_code -- 大区编码 -,region_name -- 大区名称 -,bu_code -- 事业部编码 -,bu_name -- 事业部 -,province_name -- 省份 -,city_name -- 市区 -,deal_code -- 主经销商编码 -,deal_name -- 主经销商名称 -,src_deal_code -- 子经销商编码 -,src_deal_name -- 子经销商名称 -,deal_type -- 经销商类型 -,yys_code -- 运营商编码 -,yys_name -- 运营商名称 -,product_code -- 产品编码 -,product_name -- 产品名称 -,aroma_type -- 香型 -,pi_name -- 品项 -,pr_name -- 产品系列 -,report_pi_name -- 报表品项 -,plan_pi_name -- 计划品项 -,plan_type -- 计划类型 -,pl_name -- 产品线 -,p_bu_code -- 产品所属事业部编码 -,p_bu_name -- 产品所属事业部名称 -,price_item -- 价格项 -,spec -- 规格 -,is_jxzx -- 酱酒执行 -,price -- 单价 -,discount_price -- 折后价 -,order_num -- 订单数量 -,pack_base_num -- 转换率 -,ton_num -- 订单吨数 -,x_amt -- x类金额 -,adj_amt -- 调整金额 -,e_amt -- E类费用 -,f_amt -- F类费用 -,q_amt -- Q类费用 -,d_amt -- D类金额 -,fz_amt -- FZ类金额 -,other_amt -- 其他费用 -,amt_bu -- 计事业部金额 -,amt_region -- 计大区金额 -,amt_office -- 计办事处金额 -,amt_city_unit -- 计城市单元金额 -,amt_dealer -- 计经销商金额 + pk + ,order_code -- 订单号 + ,src_order_code -- 来源订单号 + ,order_time -- 订单时间 + ,order_type -- 订单类型 + ,city_unit_code -- 城市单元编码 + ,city_unit_name -- 城市单元 + ,office_code -- 办事处编码 + ,office_name -- 办事处 + ,region_code -- 大区编码 + ,region_name -- 大区名称 + ,bu_code -- 事业部编码 + ,bu_name -- 事业部 + ,province_name -- 省份 + ,city_name -- 市区 + ,deal_code -- 主经销商编码 + ,deal_name -- 主经销商名称 + ,src_deal_code -- 子经销商编码 + ,src_deal_name -- 子经销商名称 + ,deal_type -- 经销商类型 + ,yys_code -- 运营商编码 + ,yys_name -- 运营商名称 + ,product_code -- 产品编码 + ,product_name -- 产品名称 + ,aroma_type -- 香型 + ,pi_name -- 品项 + ,pr_name -- 产品系列 + ,report_pi_name -- 报表品项 + ,plan_pi_name -- 计划品项 + ,plan_type -- 计划类型 + ,pl_name -- 产品线 + ,p_bu_code -- 产品所属事业部编码 + ,p_bu_name -- 产品所属事业部名称 + ,price_item -- 价格项 + ,spec -- 规格 + ,is_jxzx -- 酱酒执行 + ,price -- 单价 + ,discount_price -- 折后价 + ,order_num -- 订单数量 + ,pack_base_num -- 转换率 + ,round(ton_num,4) as ton_num -- 订单吨数 + ,x_amt -- x类金额 + ,adj_amt -- 调整金额 + ,e_amt -- E类费用 + ,f_amt -- F类费用 + ,q_amt -- Q类费用 + ,d_amt -- D类金额 + ,fz_amt -- FZ类金额 + ,other_amt -- 其他费用 + ,amt_bu -- 计事业部金额 + ,amt_region -- 计大区金额 + ,amt_office -- 计办事处金额 + ,amt_city_unit -- 计城市单元金额 + ,amt_dealer -- 计经销商金额 + ,year(order_time) AS order_year -- 订单年度 + ,quarter(order_time) as order_quar -- 订单季度 + ,month(order_time) AS order_month -- 订单月度 + ,order_num / pack_base_num AS order_number-- 订单件数 + ,d_amt + e_amt + f_amt + fz_amt + q_amt + other_amt AS total_fee-- 费用合计 FROM dm.v_ag_sal_order a --- 订单时间 -WHERE order_time >= '${CONCATENATE(sOrder_start_date," 00:00:00")}' -AND order_time <= '${CONCATENATE(sOrder_end_date," 00:00:00")}' --- 事业部 -${if(len(sBu) == 0,"","and a.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(sProduct) == 0,"","and product_code IN ('"+ sProduct +"')")} --- 子主经销商 -${if(sSub_main == '主经销商',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))} --- 单据号 -${if(len(sBill) == 0,"","and order_code in ('" + sBill + "')")} --- 酱酒执行计划 -${if(len(sBill) == 0,"","and order_code in ('" + sBill + "')")} +WHERE -- 权限控制 -AND exists ( +exists ( select 1 from @@ -89,4 +76,27 @@ AND exists ( OR per_code = a.office_code -- 城市单元 OR per_code = a.city_unit_code -- 城市单元 ) - ) \ No newline at end of file + ) +-- 酱酒执行计划 + ${if(len(sIs_jxzx) == 0,"","and is_jxzx in ('" + switch(sIs_jxzx,'是','1','否','0') + "')")} +-- 事业部 + ${if(len(sBu) == 0,"","and a.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(sProduct) == 0,"","and product_code IN ('"+sProduct+"')")} +-- 品项 +${if(len(sPi_name) == 0,"","and pi_name IN ('"+sPi_name+"')")} +-- 产品线 +${if(len(sPl_name) == 0,"","and pl_name IN ('"+ sPl_name +"')")} +-- 子主经销商 +${if(sSub_main == '主经销商',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))} +-- 单据号 +${if(len(sBill) == 0,"","and order_code in ('" + sBill + "')")} +-- 订单时间 +${if(len(sOrder_start_date) == 0,"","and order_time >= date('"+sOrder_start_date+"')")} +${if(len(sOrder_end_date) == 0,"","and order_time < date('"+sOrder_end_date+"')")} + INTERVAL '1 days' \ No newline at end of file diff --git a/FineReport/财务主题/看板/资金管理驾驶舱.sql b/FineReport/财务主题/看板/资金管理驾驶舱.sql index 33a131f..8276926 100644 --- a/FineReport/财务主题/看板/资金管理驾驶舱.sql +++ b/FineReport/财务主题/看板/资金管理驾驶舱.sql @@ -20,7 +20,7 @@ WITH base_date AS dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -84,7 +84,7 @@ where corp_code not in ('0101','0103','0102') dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -144,7 +144,7 @@ SELECT amt_type dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -177,7 +177,7 @@ SELECT amt_type dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -217,6 +217,7 @@ SELECT THEN amt ELSE 0 END) AS frozen_amt_last_y -- 去年冻结资金 FROM base_data +; @@ -234,7 +235,7 @@ FROM base_data -- ====================================== - +-- 【图表_资金收支总览收入支出】 -- 银行收支 with day_amt as ( @@ -256,7 +257,7 @@ with day_amt as ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -281,7 +282,7 @@ with day_amt as ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -308,7 +309,7 @@ m_y_amt AS ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -352,6 +353,8 @@ FROM m_y_amt -- ====================================== -- 资金余额 -- ====================================== + +-- 【图表_资金收支总览资金】 with base_data AS ( select 0 AS begin_year_amt -- 年初可用资金余额 @@ -375,7 +378,7 @@ with base_data AS ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -403,7 +406,7 @@ with base_data AS ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -436,14 +439,14 @@ AND nvl(a.is_usable, 1) = 1 dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 ) ) GROUP BY amt_type - +ORDER BY amt_type -- 银行余额分布 SELECT @@ -468,7 +471,7 @@ WHERE a.corp_code NOT IN ('0101', '0103', '0102') dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -503,7 +506,7 @@ WITH base_date AS dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -543,7 +546,7 @@ where corp_code not in ('0101','0103','0102') dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -551,7 +554,7 @@ where corp_code not in ('0101','0103','0102') ) GROUP BY plan_item_name - +ORDER BY plan_item_name -- 收入趋势 @@ -573,7 +576,7 @@ with re as ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -597,7 +600,7 @@ with re as ( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -660,7 +663,7 @@ WITH base_date AS( dm.dm_bi_user_permisson where bi_user = '${fine_username}' - and per_model IN ('all','sal') + and per_model IN ('all','fim') and ( is_all = 1 OR per_code = a.corp_code -- 事业部 @@ -679,4 +682,86 @@ GROUP BY plan_item_name ORDER BY SUM(CASE WHEN to_char(stat_date,'yyyy') = '${FORMAT(sStart_date,"yyyy")}' AND to_char(stat_date,'yyyy-MM-dd') <= '${FORMAT(sStart_date,"yyyy-MM-dd")}' THEN amt ELSE 0 END) DESC LIMIT 10 -; \ No newline at end of file +; + + + +-- 支出趋势 +with re as ( + select + trade_time, + trade_direction, + plan_item_name, + amt + from dm.v_ag_fim_bank_account_flow a + where trade_time>=date'2021-01-01' + AND owner_bank_account <> '22195101040012008' + AND corp_code not in ('0101','0103','0102') + ${IF(LEN(sCorp)!=0," AND a.corp_code IN ('"+ sCorp +"')", "")} + AND exists ( + select + 1 + from + dm.dm_bi_user_permisson + where + bi_user = '${fine_username}' + and per_model IN ('all','fim') + and ( + is_all = 1 + OR per_code = a.corp_code -- 事业部 + ) +) + union all + select + trade_time, + trade_direction, + plan_item_name, + amt + from dm.v_ag_fim_draft_flow a + where trade_time>=date'2021-01-01' + AND owner_bank_account <> '22195101040012008' + AND corp_code not in ('0101','0103','0102') + ${IF(LEN(sCorp)!=0," AND a.corp_code IN ('"+ sCorp +"')", "")} + AND exists ( + select + 1 + from + dm.dm_bi_user_permisson + where + bi_user = '${fine_username}' + and per_model IN ('all','fim') + and ( + is_all = 1 + OR per_code = a.corp_code -- 事业部 + ) + ) +) +-- 近15天 + ${if(sData_type_out=1,"","/*")} +select + to_char(trade_time,'MM-dd') AS trade_time + ,SUM(CASE WHEN trade_direction = '收入' AND plan_item_name NOT IN ('内部调拨收入','取得贷款') THEN amt ELSE 0 END ) / 10000 AS 收入 + ,SUM(CASE WHEN trade_direction = '支出' AND plan_item_name NOT IN ('内部调拨支出','偿还贷款') THEN amt ELSE 0 END ) / 10000 AS 支出 +from re +WHERE trade_direction IN('收入','支出') + AND to_char(trade_time,'yyyy-MM-dd') >= '${FORMAT(DATEDELTA(sStart_date,-15),"yyyy-MM-dd")}' + AND to_char(trade_time,'yyyy-MM-dd') <= '${FORMAT(sStart_date,"yyyy-MM-dd")}' + +GROUP BY to_char(trade_time,'MM-dd') +ORDER BY to_char(trade_time,'MM-dd') + ${if(sData_type_out=1,"","*/")} + +-- 近12个月 + ${if(sData_type_out=2,"","/*")} +select + to_char(trade_time,'MM') AS trade_time + ,SUM(CASE WHEN trade_direction = '收入' AND plan_item_name NOT IN ('内部调拨收入','取得贷款') THEN amt ELSE 0 END ) / 10000 AS 收入 + ,SUM(CASE WHEN trade_direction = '支出' AND plan_item_name NOT IN ('内部调拨支出','偿还贷款') THEN amt ELSE 0 END ) / 10000 AS 支出 +from re +WHERE trade_direction IN('收入','支出') + AND to_char(trade_time,'yyyy-MM') >= '${FORMAT(MONTHDELTA(sStart_date,-12),"yyyy-MM")}' + AND to_char(trade_time,'yyyy-MM') <= '${FORMAT(sStart_date,"yyyy-MM")}' + +GROUP BY to_char(trade_time,'MM') +ORDER BY to_char(trade_time,'MM') + ${if(sData_type_out=2,"","*/")} \ No newline at end of file diff --git a/FineReport/销售主题/看板/电商KA驾驶舱.sql b/FineReport/销售主题/看板/电商KA驾驶舱.sql index 1d4d87e..88c2aaf 100644 --- a/FineReport/销售主题/看板/电商KA驾驶舱.sql +++ b/FineReport/销售主题/看板/电商KA驾驶舱.sql @@ -41,15 +41,15 @@ WITH base_data AS ( SELECT T.payment_target_m / 10000 AS payment_target_m -- 月度回款目标当期 ,T.yy_payment_target_m / 10000 AS yy_payment_target_m -- 月度回款目标同期 -,CASE WHEN yy_payment_target_m = 0 THEN 0 ELSE (T.payment_target_m - yy_payment_target_m) / yy_payment_target_m END AS yyrate_payment_target_m -- 月度回款同比 +,CASE WHEN yy_payment_target_m = 0 THEN 0 ELSE (T.payment_target_m - yy_payment_target_m) / ABS(yy_payment_target_m) END AS yyrate_payment_target_m -- 月度回款同比 ,T.mm_payment_target_m / 10000 AS mm_payment_target_m -- 月度回款目标往期 -,CASE WHEN mm_payment_target_m = 0 THEN 0 ELSE (T.payment_target_m - mm_payment_target_m) / mm_payment_target_m END AS mmrate_payment_target_m -- 月度回款环比 +,CASE WHEN mm_payment_target_m = 0 THEN 0 ELSE (T.payment_target_m - mm_payment_target_m) / ABS(mm_payment_target_m) END AS mmrate_payment_target_m -- 月度回款环比 ,T.payment_m / 10000 AS payment_m -- 月度回款达成当期 ,T.yy_payment_m / 10000 AS yy_payment_m -- 月度回款达成同期 -,CASE WHEN yy_payment_m = 0 THEN 0 ELSE (T.payment_m - yy_payment_m) / yy_payment_m END AS yyrate_payment_m -- 月度回款达成同比 +,CASE WHEN yy_payment_m = 0 THEN 0 ELSE (T.payment_m - yy_payment_m) / ABS(yy_payment_m) END AS yyrate_payment_m -- 月度回款达成同比 ,T.mm_payment_m / 10000 AS mm_payment_m -- 月度回款达成往期 -,CASE WHEN mm_payment_m = 0 THEN 0 ELSE (T.payment_m - mm_payment_m) / mm_payment_m END AS mmrate_payment_m -- 月度回款达成环比 +,CASE WHEN mm_payment_m = 0 THEN 0 ELSE (T.payment_m - mm_payment_m) / ABS(mm_payment_m) END AS mmrate_payment_m -- 月度回款达成环比 ,CASE WHEN T.payment_target_m = 0 THEN 0 ELSE (T.payment_m / T.payment_target_m) * 100 END AS payment_rate_m -- 月度回款达成率 ,CASE WHEN T.yy_payment_target_m = 0 THEN 0 ELSE (T.yy_payment_m / T.yy_payment_target_m) * 100 END AS yy_payment_rate_m -- 月度回款达成率同期 @@ -57,16 +57,16 @@ SELECT ,T.payment_target_q / 10000 AS payment_target_q -- 季度回款目标当期 ,T.yy_payment_target_q / 10000 AS yy_payment_target_q -- 季度回款目标同期 -,CASE WHEN yy_payment_target_q = 0 THEN 0 ELSE (T.payment_target_q - yy_payment_target_q) / yy_payment_target_q END AS yyrate_payment_target_q -- 季度回款目标同比 +,CASE WHEN yy_payment_target_q = 0 THEN 0 ELSE (T.payment_target_q - yy_payment_target_q) / ABS(yy_payment_target_q) END AS yyrate_payment_target_q -- 季度回款目标同比 ,T.mm_payment_target_q / 10000 AS mm_payment_target_q -- 季度回款目标往期 -,CASE WHEN mm_payment_target_q = 0 THEN 0 ELSE (T.payment_target_q - mm_payment_target_q) / mm_payment_target_q END AS mmrate_payment_target_q -- 季度回款目标环比 +,CASE WHEN mm_payment_target_q = 0 THEN 0 ELSE (T.payment_target_q - mm_payment_target_q) / ABS(mm_payment_target_q) END AS mmrate_payment_target_q -- 季度回款目标环比 ,T.payment_q / 10000 AS payment_q -- 季度回款达成当期 ,T.yy_payment_q / 10000 AS yy_payment_q -- 季度回款达成同期 -,CASE WHEN yy_payment_q = 0 THEN 0 ELSE (T.payment_q - yy_payment_q) / yy_payment_q END AS yyrate_payment_q -- 季度回款达成同比 +,CASE WHEN yy_payment_q = 0 THEN 0 ELSE (T.payment_q - yy_payment_q) / ABS(yy_payment_q) END AS yyrate_payment_q -- 季度回款达成同比 ,T.mm_payment_q / 10000 AS mm_payment_q -- 季度回款达成往期 -,CASE WHEN mm_payment_q = 0 THEN 0 ELSE (T.payment_q - mm_payment_q) / mm_payment_q END AS mmrate_payment_q -- 季度回款达成同比 +,CASE WHEN mm_payment_q = 0 THEN 0 ELSE (T.payment_q - mm_payment_q) / ABS(mm_payment_q) END AS mmrate_payment_q -- 季度回款达成同比 ,CASE WHEN T.payment_target_q = 0 THEN 0 ELSE (T.payment_q / T.payment_target_q) * 100 END AS payment_rate_q -- 季度回款达成率 ,CASE WHEN T.yy_payment_target_q = 0 THEN 0 ELSE (T.yy_payment_q / T.yy_payment_target_q) * 100 END AS yy_payment_rate_q -- 季度回款达成率同期 @@ -81,9 +81,9 @@ SELECT ,T.ship_amt_m / 10000 AS ship_amt_m -- 月度出货达成当期 ,T.yy_ship_amt_m / 10000 AS yy_ship_amt_m -- 月度出货达成同期 -,CASE WHEN T.yy_ship_amt_m = 0 THEN 0 ELSE (T.ship_amt_m - T.yy_ship_amt_m) / T.yy_ship_amt_m END AS yyrate_ship_amt_m -- 月度出货目标同比 +,CASE WHEN T.yy_ship_amt_m = 0 THEN 0 ELSE (T.ship_amt_m - T.yy_ship_amt_m) / ABS(T.yy_ship_amt_m) END AS yyrate_ship_amt_m -- 月度出货目标同比 ,T.mm_ship_amt_m / 10000 AS mm_ship_amt_m -- 月度出货达成往期 -,CASE WHEN T.mm_ship_amt_m = 0 THEN 0 ELSE (T.ship_amt_m - T.mm_ship_amt_m) / T.mm_ship_amt_m END AS mmrate_ship_amt_m -- 月度出货目标同比 +,CASE WHEN T.mm_ship_amt_m = 0 THEN 0 ELSE (T.ship_amt_m - T.mm_ship_amt_m) / ABS(T.mm_ship_amt_m) END AS mmrate_ship_amt_m -- 月度出货目标同比 ,CASE WHEN T.ship_amt_target_m = 0 THEN 0 ELSE (T.ship_amt_m / T.ship_amt_target_m) * 100 END AS ship_rate_m -- 月度出货达成率 ,CASE WHEN T.yy_ship_amt_target_m = 0 THEN 0 ELSE (T.yy_ship_amt_m / T.yy_ship_amt_target_m) * 100 END AS yy_ship_rate_m -- 月度出货达成率同期 @@ -98,9 +98,9 @@ SELECT ,T.ship_amt_q / 10000 AS ship_amt_q -- 季度出货达成当期 ,T.yy_ship_amt_q / 10000 AS yy_ship_amt_q -- 季度出货达成同期 -,CASE WHEN T.yy_ship_amt_q = 0 THEN 0 ELSE (T.ship_amt_q - T.yy_ship_amt_q) / T.yy_ship_amt_q END AS yyrate_ship_amt_q -- 季度出货目标同比 +,CASE WHEN T.yy_ship_amt_q = 0 THEN 0 ELSE (T.ship_amt_q - T.yy_ship_amt_q) / ABS(T.yy_ship_amt_q) END AS yyrate_ship_amt_q -- 季度出货目标同比 ,T.mm_ship_amt_q / 10000 AS mm_ship_amt_q -- 季度出货达成往期 -,CASE WHEN T.mm_ship_amt_q = 0 THEN 0 ELSE (T.ship_amt_q - T.mm_ship_amt_q) / T.mm_ship_amt_q END AS mmrate_ship_amt_q -- 季度出货目标同比 +,CASE WHEN T.mm_ship_amt_q = 0 THEN 0 ELSE (T.ship_amt_q - T.mm_ship_amt_q) / ABS(T.mm_ship_amt_q) END AS mmrate_ship_amt_q -- 季度出货目标同比 ,CASE WHEN T.ship_amt_target_q = 0 THEN 0 ELSE (T.ship_amt_q / T.ship_amt_target_q) * 100 END AS ship_rate_q -- 季度出货达成率 ,CASE WHEN T.yy_ship_amt_target_q = 0 THEN 0 ELSE (T.yy_ship_amt_q / T.yy_ship_amt_target_q) * 100 END AS yy_ship_rate_q -- 季度出货达成率同期 @@ -272,24 +272,30 @@ base_date2 AS( GROUP BY city_unit_name )T ) +SELECT +* +FROM +( SELECT city_unit_name - , payment_target_m - , payment_m + , ROUND(payment_target_m,4) AS payment_target_m + , ROUND(payment_m,4) AS payment_m , payment_rate_m , row_number() OVER (ORDER BY payment_rate_m DESC ) AS rate_m_rk - , payment_target_q - , payment_q + , ROUND(payment_target_q,4) AS payment_target_q + , ROUND(payment_q,4) AS payment_q , payment_rate_q , row_number() OVER (ORDER BY payment_rate_q DESC ) AS rate_q_rk - , ship_amt_target_m - , ship_amt_m + , ROUND(ship_amt_target_m,4) AS ship_amt_target_m + , ROUND(ship_amt_m,4) AS ship_amt_m , ship_rate_m - , ship_amt_target_q - , ship_amt_q + , ROUND(ship_amt_target_q,4) AS ship_amt_target_q + , ROUND(ship_amt_q,4) AS ship_amt_q , ship_rate_q FROM base_date2 - +)T +ORDER BY rate_m_rk +LIMIT 8 ; @@ -390,24 +396,31 @@ WITH base_data AS ( FROM base_data GROUP BY city_unit_name )T - ) +) SELECT - city_unit_name - , payment_target_m - , payment_m - , payment_rate_m - , payment_target_q - , payment_q - , payment_rate_q - , ship_amt_target_m - , ship_amt_m - , ship_rate_m - , row_number() OVER (ORDER BY ship_rate_m DESC ) AS rate_m_rk - , ship_amt_target_q - , ship_amt_q - , ship_rate_q - , row_number() OVER (ORDER BY ship_rate_q DESC ) AS rate_q_rk -FROM base_date2 +* +FROM +( + SELECT + city_unit_name + , ROUND(payment_target_m,4) AS payment_target_m + , ROUND(payment_m,4) AS payment_m + , ROUND(payment_rate_m,4) AS payment_rate_m + , ROUND(payment_target_q,4) ASpayment_target_q + , ROUND(payment_q,4) AS payment_q + , payment_rate_q + , ROUND(ship_amt_target_m,4) AS ship_amt_target_m + , ROUND(ship_amt_m,4) AS ship_amt_m + , ship_rate_m + , row_number() OVER (ORDER BY ship_rate_m DESC ) AS rate_m_rk + , ROUND(ship_amt_target_q,4) AS ship_amt_target_q + , ROUND(ship_amt_q,4) AS ship_amt_q + , ship_rate_q + , row_number() OVER (ORDER BY ship_rate_q DESC ) AS rate_q_rk + FROM base_date2 +)T +ORDER BY rate_m_rk +LIMIT 8 ; diff --git a/FineReport/销售主题/看板/首页.sql b/FineReport/销售主题/看板/首页.sql index ce9c516..9537319 100644 --- a/FineReport/销售主题/看板/首页.sql +++ b/FineReport/销售主题/看板/首页.sql @@ -559,6 +559,7 @@ where ${switch(sPeriod -- 经销商库存 -- ====================================== +-- 要取时点值 with base_data AS ( @@ -594,17 +595,18 @@ SUM(amt) AS amt -- 库存总量 FROM base_data WHERE 1=1 -- 年 -${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")} -${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")} +-- ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') = '"+ FORMAT(ENDOFMONTH(sStart_date),'yyyy-MM-dd') +"'","")} -- 季 - ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")} - ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")} +-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 月 - ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")} - ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")} + ${IF(len(sStart_date) > 0,"AND to_char(stat_date,'yyyy-MM-dd') = '" + FORMAT(DATEINMONTH(sStart_date,1),'yyyy-MM-dd') + "'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 日