diff --git a/finereport/xiazuan/1_finance/1_收缴下钻.sql b/finereport/xiazuan/1_finance/1_收缴下钻.sql index 0262f4d..c304e1d 100644 --- a/finereport/xiazuan/1_finance/1_收缴下钻.sql +++ b/finereport/xiazuan/1_finance/1_收缴下钻.sql @@ -8,48 +8,53 @@ FROM dim_organ_mapping WHERE 1=1 ${IF(LEN(p_area)>0," AND organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} - -- dic_片区 SELECT DISTINCT organ_code AS 片区id, organ_name AS 片区名称 -FROM dim_organ_mapping - +FROM dws_finance_fees_serial_m +where 1=1 and organ_code is not null + and organ_name not in ('东湖商管','领悦总部','演示机构') + ${if(GETUSERDEPARTMENTS(2)="领悦集团总部","","and organ_name = '"+GETUSERDEPARTMENTS(2)+"'")} -- dict_费用类型 -select distinct ParentCostCode, ParentCostName +select distinct ParentCostCode, case when ParentCostCode = '0008' then '代收代缴水电费' else ParentCostName end ParentCostName from dws_finance_fees_serial_m +where ParentCostCode in ('0001','0007','0008') order by ParentCostCode asc -- report_收缴率 -select - ${if(len(p_area) == 0,"a.organ_code code, a.organ_name name,","a.comm_id code, a.comm_name name,")} - a.ym, ParentCostCode, ParentCostName - , (pr_paid_cu_amt + cu_paid_cu_amt + pr_exempt_cu_amt + cu_exempt_cu_amt)/10000 cu_paid_amt - , (cu_receivable_amt + pr_exempt_cu_amt + cu_exempt_cu_amt)/10000 cu_receivable_amt - , (- cu_paid_pr_amt + cu_offset_pr_amt)/10000 pr_paid_amt - , (pr_total_receivable_amt + pr_total_received_amt + cu_early_exempt_pr_amt + cu_exempt_pr_amt)/10000 pr_receivable_amt - , case when a.ParentCostCode = '0001' then b.index_dq_target else 0 end cu_coll_rate_target - , case when a.ParentCostCode = '0001' then b.index_wq_target else 0 end pr_coll_rate_target - , case when a.ParentCostCode = '0008' then b.index_sd_target - when a.ParentCostCode = '0007' then b.index_dj_target else 0 end total_coll_rate_target -from dws_finance_fees_serial_m a - left join ods_finance_collection_target_area b - on a.organ_code = b.organ_code and a.ym = b.ym - left join ods_finance_collection_target_project c - on a.comm_id = c.comm_id and a.ym = c.ym -where 1=1 - ${if(len(p_startdate) == 0,"","and a.ym = '" + p_startdate + "'")} - ${if(len(p_feestype) == 0,"","and a.ParentCostCode = '" + p_feestype+ "'")} - ${if(len(p_area) == 0,"","and a.organ_code = '" + p_area+ "'")} -; - +select * from ( + select + ${if(len(p_area) == 0,"a.organ_code code, a.organ_name name,","a.comm_id code, a.comm_name name,")} + a.ym, ParentCostCode, ParentCostName + , (ifnull(pr_paid_cu_amt,0) + ifnull(cu_paid_cu_amt,0) - ifnull(pr_offset_cu_amt,0) - ifnull(cu_offset_cu_amt,0))/10000 cu_paid_amt + , (ifnull(cu_receivable_amt,0) + ifnull(pr_exempt_cu_amt,0) + ifnull(cu_exempt_cu_amt,0))/10000 cu_receivable_amt + , (- ifnull(cu_paid_pr_amt,0) - ifnull(cu_offset_pr_amt,0))/10000 pr_paid_amt + , (ifnull(pr_total_receivable_amt,0) + ifnull(pr_total_received_amt,0) + ifnull(cu_early_exempt_pr_amt,0) + ifnull(cu_exempt_pr_amt,0))/10000 pr_receivable_amt + , case when a.ParentCostCode = '0001' then b.index_dq_target else 0 end cu_coll_rate_target + , case when a.ParentCostCode = '0001' then b.index_wq_target else 0 end pr_coll_rate_target + , case when a.ParentCostCode = '0008' then b.index_sd_target + when a.ParentCostCode = '0007' then b.index_dj_target else 0 end total_coll_rate_target + from dws_finance_fees_serial_m a + left join ods_finance_collection_target_area b + on a.organ_code = b.organ_code and a.ym = b.ym + left join ods_finance_collection_target_project c + on a.comm_id = c.comm_id and a.ym = c.ym + where 1=1 and a.organ_code is not null + and a.organ_name not in ('东湖商管','领悦总部','演示机构') and a.comm_name not like '%天富%' + ${if(len(p_startdate) == 0,"","and a.ym = '" + p_startdate + "'")} + ${if(len(p_feestype) == 0,"","and a.ParentCostCode = '" + p_feestype+ "'")} + -- ${if(len(p_area) == 0,"","and a.organ_code = '" + p_area+ "'")} + ${IF(LEN(p_area)>0," AND a.organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")} + ${if(left(fine_role,2)=="项目","and a.comm_name = '"+GETUSERDEPARTMENTS(3)+"'","")} + ) a where not (cu_paid_amt=0 and cu_receivable_amt=0 and pr_paid_amt=0 and pr_receivable_amt = 0) -- report_收缴率目标