@ -79,21 +79,109 @@ select
' 当期 ' AS time_type
, sum ( ct_amt ) / 10000 AS amt
from dm . v_ag_sal_contract a
where 1 = 1
$ { IF ( sPeriod = 1 , " AND ct_year =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(signed_date,'yyyy'),EXTRACT(QUARTER FROM signed_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(signed_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(signed_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
-- 权限控制
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 ( sStart_date ) > 0 , " AND ct_year =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 年
-- ${IF(sPeriod=1,"AND ct_year ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
-- 季
-- ${IF(sPeriod=2,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
-- ${IF(sPeriod=2,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
-- 月
-- ${IF(sPeriod=3,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
- -- ${IF(sPeriod=3,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
-- 日
-- ${IF(sPeriod=4,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
-- ${IF(sPeriod=4,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
UNION ALL
select
' 同期 ' AS time_type
, sum ( ct_amt ) / 10000 AS amt
from dm . v_ag_sal_contract a
WHERE 1 = 1
$ { IF ( sPeriod = 1 , " AND ct_year = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year') " , " " ) } -- 去年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(signed_date,'yyyy'),EXTRACT(QUARTER FROM signed_date)) = CONCAT(EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year'),EXTRACT(QUARTER FROM CURRENT_DATE)) " , " " ) } -- 去年同季
$ { IF ( sPeriod = 3 , " AND to_char(signed_date,'yyyy-MM') = to_char(CURRENT_DATE - INTERVAL '12 month','yyyy-MM') " , " " ) } -- 去年同月
$ { IF ( sPeriod = 4 , " AND to_char(signed_date,'yyyy-MM-dd') = to_char((CURRENT_DATE - INTERVAL '1 day') - INTERVAL '1 year','yyyy-MM-dd') " , " " ) } -- 当前时间的前天
-- 权限控制
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 ( sStart_date ) > 0 , " AND ct_year = ' " + left ( yeardelta ( sStart_date , - 1 ) , 4 ) + " ' " , " " ) }
-- 去年
-- ${IF(sPeriod=1,"AND ct_year = '" + left(yeardelta(sStart_date,-1),4) + "'","")}
-- 去年同季
-- ${IF(sPeriod=2,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
-- ${IF(sPeriod=2,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
-- 去年同月
-- ${IF(sPeriod=3,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
-- ${IF(sPeriod=3,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
-- 去年同日
-- ${IF(sPeriod=4,"AND to_char(signed_date,'yyyy-MM-dd') >='"+ yeardelta(sStart_date,-1) +"'","")}
-- ${IF(sPeriod=4,"AND to_char(signed_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")}
UNION ALL
select
' 当期回款 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu a
where ( indi_type = ' 回款 ' OR indi_type = ' 电商订单 ' )
-- 权限控制
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 -- 城市单元
)
)
$ { IF ( len ( sStart_date ) > 0 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 年
-- ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")}
-- 季
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
-- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
-- 月
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
-- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
-- 日
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date +"'","")}
-- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")}
-- ======================================
@ -103,39 +191,108 @@ ${IF(sPeriod=4,"AND to_char(signed_date,'yyyy-MM-dd') = to_char((CURRENT_DATE -
select
' 当期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 回款 ' OR indi_type = ' 电商订单 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
-- 权限控制
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
UNION ALL
select
' 同期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 回款 ' OR indi_type = ' 电商订单 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year') " , " " ) } -- 去年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) = CONCAT(EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year'),EXTRACT(QUARTER FROM CURRENT_DATE)) " , " " ) } -- 去年同季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') = to_char(CURRENT_DATE - INTERVAL '12 month','yyyy-MM') " , " " ) } -- 去年同月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char((CURRENT_DATE - INTERVAL '1 day') - INTERVAL '1 year','yyyy-MM-dd') " , " " ) } -- 当前时间的前天
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 -- 城市单元
)
)
-- 去年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = ' " + left ( yeardelta ( sStart_date , - 1 ) , 4 ) + " ' " , " " ) }
-- 去年同季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
UNION
select
' 目标 ' time_type ,
sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where $ { switch ( sPeriod
, 1 , " indi_type='年度目标_事业部_回款' "
, 2 , " indi_type='季度目标_事业部_回款' "
, 3 , " indi_type='月度目标_事业部_回款' "
, 4 , " indi_type='不存在' " ) }
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- ======================================
-- 经销商出货
@ -144,37 +301,111 @@ where ${switch(sPeriod
select
' 当期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 出货 ' OR indi_type = ' 电商订单 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
-- 权限控制
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
UNION ALL
select
' 同期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 出货 ' OR indi_type = ' 电商订单 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year') " , " " ) } -- 去年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) = CONCAT(EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year'),EXTRACT(QUARTER FROM CURRENT_DATE)) " , " " ) } -- 去年同季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') = to_char(CURRENT_DATE - INTERVAL '12 month','yyyy-MM') " , " " ) } -- 去年同月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char((CURRENT_DATE - INTERVAL '1 day') - INTERVAL '1 year','yyyy-MM-dd') " , " " ) } -- 当前时间的前天
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 -- 城市单元
)
)
-- 去年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = ' " + left ( yeardelta ( sStart_date , - 1 ) , 4 ) + " ' " , " " ) }
-- 去年同季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
UNION
select
' 目标 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where $ { switch ( sPeriod
, 1 , " indi_type='年度目标_事业部_出货' "
, 2 , " indi_type='季度目标_事业部_出货' "
, 3 , " indi_type='月度目标_事业部_出货' "
, 4 , " indi_type='不存在' " ) }
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- ======================================
@ -184,33 +415,478 @@ ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - IN
select
' 当期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 发货 ' OR indi_type = ' 费用发货 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
-- 权限控制
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
UNION ALL
select
' 同期 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where ( indi_type = ' 发货 ' OR indi_type = ' 费用发货 ' )
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year') " , " " ) } -- 去年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) = CONCAT(EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL '1 year'),EXTRACT(QUARTER FROM CURRENT_DATE)) " , " " ) } -- 去年同季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') = to_char(CURRENT_DATE - INTERVAL '12 month','yyyy-MM') " , " " ) } -- 去年同月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char((CURRENT_DATE - INTERVAL '1 day') - INTERVAL '1 year','yyyy-MM-dd') " , " " ) } -- 当前时间的前天
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 -- 城市单元
)
)
-- 去年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') = ' " + left ( yeardelta ( sStart_date , - 1 ) , 4 ) + " ' " , " " ) }
-- 去年同季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
-- 去年同日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + yeardelta ( sStart_date , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + yeardelta ( sEnd_date , - 1 ) + " ' " , " " ) }
UNION
select
' 目标 ' time_type
, sum ( amt_bu ) AS amt
from dm . v_sal_indicator_bu
from dm . v_sal_indicator_bu a
where $ { switch ( sPeriod
, 1 , " indi_type IN('年度目标_事业部_费用发货','年度目标_事业部_销售发货') "
, 2 , " indi_type IN('季度目标_事业部_费用发货','季度目标_事业部_销售发货') "
, 3 , " indi_type IN('月度目标_事业部_费用发货','月度目标_事业部_销售发货') "
, 4 , " indi_type IN('不存在') " ) }
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( TODAY ( ) , ' yyyy ' ) + " ' " , " " ) } -- 年
$ { IF ( sPeriod = 2 , " AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) =' " + CONCATENATE ( left ( today ( ) , 4 ) , roundup ( month ( today ( ) ) / 3 ) ) + " ' " , " " ) } -- 季
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( TODAY ( ) , ' yyyy-MM ' ) + " ' " , " " ) } -- 月
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') = to_char(CURRENT_DATE - INTERVAL '1 day','yyyy-MM-dd') " , " " ) } -- 日
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 -- 城市单元
)
)
-- 年
$ { IF ( sPeriod = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date , ' yyyy ' ) + " ' " , " " ) }
-- 季
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 2 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 月
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 3 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- 日
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date + " ' " , " " ) }
$ { IF ( sPeriod = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sEnd_date + " ' " , " " ) }
-- ======================================
-- 财务资金状况
-- ======================================
-- 资金计划与执行
select
' 当期 ' AS time_type
, ' 收入 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 收入 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 收入 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨收入 ' , ' 取得贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') = ' " + FORMAT ( sStart_date_fin , ' yyyy-MM ' ) + " ' " , " " ) }
-- 日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >= ' " + sStart_date_fin + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <= ' " + sStart_date_fin + " ' " , " " ) }
UNION ALL
select
' 当期 ' AS time_type
, ' 支出 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 支出 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 支出 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨支出 ' , ' 偿还贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( sStart_date_fin , ' yyyy-MM ' ) + " ' " , " " ) }
-- 日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date_fin + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sStart_date_fin + " ' " , " " ) }
UNION ALL
-- 月初资金余额要取上月的月初的, 年初要取上年末12月份的
select
' 当期 ' AS time_type
, ' 余额 ' AS fee_type
, sum ( amt ) / 10000 AS AMT
from dm . dm_fim_fud_balance a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND owner_bank_account NOT IN ( ' 20351059900100000512291 '
, ' 22195101040012008 '
, ' 信用证保证金 '
, ' 22195162750000012 '
, ' 22195162650000017 '
, ' 22195162350000014 '
, ' 22195162050000015 '
, ' 951018033000447470 ' )
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( MONTHDELTA ( sStart_date_fin , - 1 ) , ' yyyy-MM ' ) + " ' " , " " ) }
-- 日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >=' " + sStart_date_fin + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <=' " + sStart_date_fin + " ' " , " " ) }
UNION ALL
-- 资金计划与执行
select
' 上期 ' AS time_type
, ' 收入 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 收入 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 收入 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨收入 ' , ' 取得贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 上年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( YEARDELTA ( sStart_date_fin , - 1 ) , ' yyyy ' ) + " ' " , " " ) }
-- 上月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') = ' " + FORMAT ( MONTHDELTA ( sStart_date_fin , - 1 ) , ' yyyy-MM ' ) + " ' " , " " ) }
-- 昨日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
UNION ALL
select
' 上期 ' AS time_type
, ' 支出 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 支出 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 支出 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨支出 ' , ' 偿还贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 上年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( YEARDELTA ( sStart_date_fin , - 1 ) , ' yyyy ' ) + " ' " , " " ) }
-- 上月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') = ' " + FORMAT ( MONTHDELTA ( sStart_date_fin , - 1 ) , ' yyyy-MM ' ) + " ' " , " " ) }
-- 昨日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
UNION ALL
-- 月初资金余额要取上月的月初的, 年初要取上年末12月份的
select
' 上期 ' AS time_type
, ' 余额 ' AS fee_type
, sum ( amt ) / 10000 AS AMT
from dm . dm_fim_fud_balance a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND owner_bank_account NOT IN ( ' 20351059900100000512291 '
, ' 22195101040012008 '
, ' 信用证保证金 '
, ' 22195162750000012 '
, ' 22195162650000017 '
, ' 22195162350000014 '
, ' 22195162050000015 '
, ' 951018033000447470 ' )
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
-- 上年
$ { IF ( sPeriod_fin = 1 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( YEARDELTA ( sStart_date_fin , - 1 ) , ' yyyy ' ) + " ' " , " " ) }
-- 上月
$ { IF ( sPeriod_fin = 2 , " AND to_char(stat_date,'yyyy-MM') =' " + FORMAT ( MONTHDELTA ( sStart_date_fin , - 2 ) , ' yyyy-MM ' ) + " ' " , " " ) }
-- 昨日
$ { IF ( sPeriod_fin = 3 , " AND to_char(stat_date,'yyyy-MM-dd') >= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
$ { IF ( sPeriod_fin = 4 , " AND to_char(stat_date,'yyyy-MM-dd') <= ' " + DATEDELTA ( sStart_date_fin , - 1 ) + " ' " , " " ) }
-- ======================================
-- 财务资金月度
-- ======================================
;
-- 资金计划与执行
SELECT
t . stat_date AS stat_date
, to_char ( t . stat_date , ' MM ' ) as month
, CASE WHEN t . fee_type = ' 收入 ' THEN amt ELSE 0 END AS revenue_fee -- 收入
, CASE WHEN t . fee_type = ' 支出 ' THEN amt ELSE 0 END AS expend_fee -- 支出
, CASE WHEN t . fee_type = ' 余额 ' THEN amt ELSE 0 END AS balance_fee -- 余额
FROM
(
select
stat_date
, ' 收入 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 收入 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 收入 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨收入 ' , ' 取得贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
$ { IF ( len ( sStart_date_fin ) > 0 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 年
-- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")}
-- 月
-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(sStart_date_fin,'yyyy-MM') +"'","")}
-- 日
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ sStart_date_fin +"'","")}
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ sStart_date_fin +"'","")}
group by stat_date
UNION ALL
select
stat_date
, ' 支出 ' AS fee_type -- 收支方向 收入/支出
, SUM ( CASE WHEN trade_direction = ' 支出 ' THEN amt ELSE 0 END ) / 10000 AS amt
from dm . dm_fim_fud_indicator a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND trade_direction = ' 支出 '
AND indi_type = ' 执行 '
AND plan_item_name NOT IN ( ' 内部调拨支出 ' , ' 偿还贷款 ' )
AND owner_bank_account < > ' 22195101040012008 '
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
$ { IF ( len ( sStart_date_fin ) > 0 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 年
-- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")}
-- 月
-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date_fin,'yyyy-MM') +"'","")}
-- 日
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
group by stat_date
UNION ALL
-- 月初资金余额要取上月的月初的, 年初要取上年末12月份的
select
stat_date AS stat_date
, ' 余额 ' AS fee_type
, sum ( amt ) / 10000 AS AMT
from dm . dm_fim_fud_balance a
where corp_code not in ( ' 0101 ' , ' 0103 ' , ' 0102 ' )
AND owner_bank_account NOT IN ( ' 20351059900100000512291 '
, ' 22195101040012008 '
, ' 信用证保证金 '
, ' 22195162750000012 '
, ' 22195162650000017 '
, ' 22195162350000014 '
, ' 22195162050000015 '
, ' 951018033000447470 ' )
-- 权限控制
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 . corp_code -- 事业部
-- OR per_code = a.region_code -- 大区
-- OR per_code = a.office_code -- 办事处
-- OR per_code = a.city_unit_code -- 城市单元
)
)
$ { IF ( len ( sStart_date_fin ) > 0 , " AND to_char(stat_date,'yyyy') =' " + FORMAT ( sStart_date_fin , ' yyyy ' ) + " ' " , " " ) }
-- 年
-- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")}
-- 月
-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM') +"'","")}
-- 日
-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")}
-- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")}
group by stat_date
) t
ORDER BY to_char ( t . stat_date , ' MM ' )