diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 6a16fe7..8f57eb9 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,10 +1,12 @@ + - + + diff --git a/BI/销售业绩/市场费用报销明细.sql b/BI/销售业绩/市场费用报销明细.sql new file mode 100644 index 0000000..735e8cf --- /dev/null +++ b/BI/销售业绩/市场费用报销明细.sql @@ -0,0 +1,34 @@ +select +bill_code -- 报销单号 +,bill_status -- 审核状态 +,ct_code -- 合同付款单号 +,budget_code -- 预算编号 +,credence_code -- 凭证号 +,plan_code -- 方案号 +,bill_date -- 报销时间 +,stat_year -- 年 +,stat_month -- 月 +,deal_code -- 经销商编码 +,deal_name -- 经销商名称 +,src_deal_code -- 子经销商编码 +,src_deal_name -- 子经销商名称 +,city_unit_code -- 城市单元编码 +,city_unit_name -- 城市单元名称 +,office_code -- 办事处编码 +,office_name -- 办事处 +,region_code -- 大区编码 +,region_name -- 大区 +,bu_name -- 事业部 +,prodline_name -- 产品线 +,fist_item -- 一级项目 +,cost_source -- 费用来源 +,cost_item -- 费用项目 +,activity_type -- 活动类型 +,pay_way -- 支付方式 +,pay_way_class -- 支付方式类别 +,is_valid +,audit_name -- 终审人 +-- 单据状态 +,amt_fill -- 填报金额 +,amt_approval -- 审批金额 +from dm.v_ag_str_sale_use_budget diff --git a/FineReport/财务主题/报表/费用/1-财务销售费用汇总表.sql b/FineReport/财务主题/报表/费用/1-财务销售费用汇总表.sql new file mode 100644 index 0000000..4e94dea --- /dev/null +++ b/FineReport/财务主题/报表/费用/1-财务销售费用汇总表.sql @@ -0,0 +1,353 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +), + base_info_curr AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6601%' + AND A.acnt_year = '${YEAR(sQueryDate)}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + base_info_last AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6601%' + AND A.acnt_year = '${YEAR(sQueryDate) - 1}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + subject_result AS ( + -- 本期统计 + SELECT + '广宣费' AS subject_name -- 科目名称 + ,'660114,660127' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE (subject_code like '660114%' or subject_code like '660127%') + UNION ALL + SELECT + '其中: 广告费' AS subject_name -- 科目名称 + ,'660114' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660114%' + UNION ALL + SELECT + ' 业务宣传费' AS subject_name -- 科目名称 + ,'660127' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660127%' + UNION ALL + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,'660150' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660150%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,'660115' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660115%' + UNION ALL + SELECT + '折旧费' AS subject_name -- 科目名称 + ,'660117' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660117%' + UNION ALL + SELECT + '电商运营费' AS subject_name -- 科目名称 + ,'660136' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660136%' + UNION ALL + SELECT + '房租费' AS subject_name -- 科目名称 + ,'660130' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660130%' + UNION ALL + SELECT + '会议费' AS subject_name -- 科目名称 + ,'660125' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660125%' + UNION ALL + SELECT + '业务招待费' AS subject_name -- 科目名称 + ,'660167' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660167%' + UNION ALL + SELECT + '仓储费' AS subject_name -- 科目名称 + ,'660121' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660121%' + UNION ALL + SELECT + '通讯费' AS subject_name -- 科目名称 + ,'660164' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660164%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,'0000' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '6601%' + AND (subject_code not like '660114%' + AND subject_code not like '660127%' + AND subject_code NOT like '660150%' + AND subject_code NOT like '660115%' + AND subject_code NOT like '660117%' + AND subject_code NOT like '660136%' + AND subject_code NOT like '660130%' + AND subject_code NOT like '660125%' + AND subject_code NOT like '660167%' + AND subject_code NOT like '660121%' + AND subject_code NOT like '660164%' + ) + UNION ALL + SELECT + '合计' AS subject_name -- 科目名称 + ,'6601' AS subject_code -- 科目编码 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '6601%' + UNION ALL + -- 上期统计 + SELECT + '广宣费' AS subject_name -- 科目名称 + ,'660114,660127' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE (subject_code like '660114%' OR subject_code like '660127%') + + UNION ALL + SELECT + '其中: 广告费' AS subject_name -- 科目名称 + ,'660114' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660114%' + UNION ALL + SELECT + ' 业务宣传费' AS subject_name -- 科目名称 + ,'660127' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660127%' + UNION ALL + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,'660150' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660150%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,'660115' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660115%' + UNION ALL + SELECT + '折旧费' AS subject_name -- 科目名称 + ,'660117' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660117%' + UNION ALL + SELECT + '电商运营费' AS subject_name -- 科目名称 + ,'660136' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660136%' + UNION ALL + SELECT + '房租费' AS subject_name -- 科目名称 + ,'660130' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660130%' + UNION ALL + SELECT + '会议费' AS subject_name -- 科目名称 + ,'660125' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660125%' + UNION ALL + SELECT + '业务招待费' AS subject_name -- 科目名称 + ,'660167' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660167%' + UNION ALL + SELECT + '仓储费' AS subject_name -- 科目名称 + ,'660121' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660121%' + UNION ALL + SELECT + '通讯费' AS subject_name -- 科目名称 + ,'660164' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660164%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,'0000' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '6601%' + AND (subject_code NOT LIKE '660114%' + AND subject_code NOT LIKE '660127%' + AND subject_code NOT LIKE '660150%' + AND subject_code NOT LIKE '660115%' + AND subject_code NOT LIKE '660117%' + AND subject_code NOT LIKE '660136%' + AND subject_code NOT LIKE '660130%' + AND subject_code NOT LIKE '660125%' + AND subject_code NOT LIKE '660167%' + AND subject_code NOT LIKE '660121%' + AND subject_code NOT LIKE '660164%') + UNION ALL + SELECT + '合计' AS subject_name -- 科目名称 + ,'6601' AS subject_code -- 科目编码 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '6601%' + + ) +SELECT + subject_name AS subject_name -- 科目名称 + ,subject_code AS subject_code -- 科目编码 + ,IFNULL(SUM(debit_amt_m ) / 10000,0) AS debit_amt_m -- 借方金额_当月累计 + ,IFNULL(SUM(debit_amt_y ) / 10000,0) AS debit_amt_y -- 借方金额_当年累计 + ,IFNULL(SUM(debit_amt_last_m) / 10000,0) AS debit_amt_last_m -- 借方金额_上年同期 + ,IFNULL(SUM(debit_amt_last_y) / 10000,0) AS debit_amt_last_y -- 借方金额_上年累计 +FROM subject_result +GROUP BY + subject_name,subject_code +ORDER BY + DECODE(subject_name,'广宣费','a','其中: 广告费','b',' 业务宣传费','c','职工薪酬','d','差旅费','e','折旧费','f','电商运营费','g','房租费','h','会议费','i','业务招待费','j','仓储费','k','通讯费','l','其他','m','合计','n') \ No newline at end of file diff --git a/FineReport/财务主题/报表/费用/1_1_1OA表单下钻.sql b/FineReport/财务主题/报表/费用/1_1_1OA表单下钻.sql new file mode 100644 index 0000000..470193a --- /dev/null +++ b/FineReport/财务主题/报表/费用/1_1_1OA表单下钻.sql @@ -0,0 +1,38 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +) +SELECT + bill_date -- 制单日期 + ,audit_date -- 终审日期 + ,pay_time -- 付款时间 + ,bill_code -- 单据号 + ,bill_status -- 单据状态 + ,budget_code -- 预算编号 + ,plan_code -- 资金计划编号 + ,corp_code -- 公司编码 + ,dept_code -- 部门编码 + ,fund_year -- 资金年度 + ,fund_month -- 资金月度 + ,fee_type -- 费用类型 + ,plan_item_code -- 资金项目编号 + ,plan_item_name -- 资金项目名称 + ,fund_item -- 支出项目 + ,owner_bank_account -- 本方帐号 + ,opp_account_name -- 对方户名 + ,opp_bank_account -- 对方帐号 + ,opp_name -- 对方名称 + ,amt -- 金额 + ,remark -- 备注 + ,budget_type -- 预算类型 + ,fund_content -- 支出内容 +FROM dwi.dwi_fim_oa_payment +WHERE corp_code in(SELECT corp_code FROM corp) +AND bill_date >= '${sQueryStartDate}' +AND bill_date <= '${FORMAT(sQueryDate,"MM-01")}' + diff --git a/FineReport/财务主题/报表/费用/1_1财务凭证下钻.sql b/FineReport/财务主题/报表/费用/1_1财务凭证下钻.sql new file mode 100644 index 0000000..5714aa4 --- /dev/null +++ b/FineReport/财务主题/报表/费用/1_1财务凭证下钻.sql @@ -0,0 +1,53 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +) +SELECT + bill_date -- 制单日期 +,bill_emp_code -- 制单人工号 +,corp_code -- 公司编码 +,acnt_book_name -- 主体账簿 +,vouch_type -- 凭证类别 +,vouch_code -- 凭证号 +,acnt_year -- 账期年度 +,acnt_mon -- 账期月度 +,main_abstract -- 主表摘要 +,entry_code -- 分录号 +,sub_abstract -- 子表摘要 +,subject_code -- 科目编码 +,subject_name -- 科目名称 +,subject_full_name -- 科目全称 +,aux_content -- 辅助核算 +,debit_amt -- 借方金额 +,credit_amt -- 贷方金额 +,src_bill_codes -- 来源单据号 +,acnt_date -- 记账日期 +FROM dwi.dwi_fim_voucher WHERE src_bill_codes = 'BR08020240302938' +where subject_code like '6601%' +and corp_code in(SELECT corp_code FROM corp) +-- AND acnt_year = '${YEAR(sQueryDate)}' +-- AND acnt_mon <= '${FORMAT(sQueryDate,"MM")}' +${switch(sCalcType +,"m","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'" +,"y","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'" +)} +${nvl(switch(sSubject +,"0000","AND subject_code like '6601%' AND (subject_code not like '660114%' + AND subject_code not like '660127%' + AND subject_code NOT like '660150%' + AND subject_code NOT like '660115%' + AND subject_code NOT like '660117%' + AND subject_code NOT like '660136%' + AND subject_code NOT like '660130%' + AND subject_code NOT like '660125%' + AND subject_code NOT like '660167%' + AND subject_code NOT like '660121%' + AND subject_code NOT like '660164%' + )" +,"660114,660127","AND (subject_code like '660114%' or subject_code like '660127%')") +,"and subject_code like '" + sSubject +"%'")} diff --git a/FineReport/财务主题/报表/费用/2-财务管理费用汇总表.sql b/FineReport/财务主题/报表/费用/2-财务管理费用汇总表.sql new file mode 100644 index 0000000..c5364c6 --- /dev/null +++ b/FineReport/财务主题/报表/费用/2-财务管理费用汇总表.sql @@ -0,0 +1,386 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +), + base_info_curr AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6602%' + AND A.acnt_year = '${YEAR(sQueryDate)}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + base_info_last AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6602%' + AND A.acnt_year = '${YEAR(sQueryDate) - 1}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + subject_result AS ( + -- 本期统计 + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660297%' + UNION ALL + SELECT + '折旧费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660219%' + UNION ALL + SELECT + '物料消耗' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660289%' + UNION ALL + SELECT + '存货损耗' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660243%' + UNION ALL + SELECT + '办公费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660226%' + UNION ALL + SELECT + '咨询服务费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660234%' + UNION ALL + SELECT + '无形资产摊销' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660221%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660227%' + UNION ALL + SELECT + '物业管理费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660232%' + UNION ALL + SELECT + '水电气费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660233%' + UNION ALL + SELECT + '车辆使用费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660231%' + UNION ALL + SELECT + '业务招待费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660273%' + UNION ALL + SELECT + '使用权资产摊销' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660290%' + UNION ALL + SELECT + '租赁费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660237%' + UNION ALL + SELECT + '通讯费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660287%' + UNION ALL + SELECT + '会议费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660228%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE (subject_code NOT LIKE '660297%' + AND subject_code NOT LIKE '660219%' + AND subject_code NOT LIKE '660289%' + AND subject_code NOT LIKE '660243%' + AND subject_code NOT LIKE '660226%' + AND subject_code NOT LIKE '660234%' + AND subject_code NOT LIKE '660221%' + AND subject_code NOT LIKE '660227%' + AND subject_code NOT LIKE '660232%' + AND subject_code NOT LIKE '660233%' + AND subject_code NOT LIKE '660231%' + AND subject_code NOT LIKE '660273%' + AND subject_code NOT LIKE '660290%' + AND subject_code NOT LIKE '660237%' + AND subject_code NOT LIKE '660287%' + AND subject_code NOT LIKE '660228%' + ) + UNION ALL + -- 上期统计 + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660297%' + UNION ALL + SELECT + '折旧费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660219%' + UNION ALL + SELECT + '物料消耗' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660289%' + UNION ALL + SELECT + '存货损耗' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660243%' + UNION ALL + SELECT + '办公费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660226%' + UNION ALL + SELECT + '咨询服务费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660234%' + UNION ALL + SELECT + '无形资产摊销' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660221%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660227%' + UNION ALL + SELECT + '物业管理费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660232%' + UNION ALL + SELECT + '水电气费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660233%' + UNION ALL + SELECT + '车辆使用费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660231%' + UNION ALL + SELECT + '业务招待费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660273%' + UNION ALL + SELECT + '使用权资产摊销' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660290%' + UNION ALL + SELECT + '租赁费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660237%' + UNION ALL + SELECT + '通讯费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660287%' + UNION ALL + SELECT + '会议费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660228%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE (subject_code NOT LIKE '660297%' + AND subject_code NOT LIKE '660219%' + AND subject_code NOT LIKE '660289%' + AND subject_code NOT LIKE '660243%' + AND subject_code NOT LIKE '660226%' + AND subject_code NOT LIKE '660234%' + AND subject_code NOT LIKE '660221%' + AND subject_code NOT LIKE '660227%' + AND subject_code NOT LIKE '660232%' + AND subject_code NOT LIKE '660233%' + AND subject_code NOT LIKE '660231%' + AND subject_code NOT LIKE '660273%' + AND subject_code NOT LIKE '660290%' + AND subject_code NOT LIKE '660237%' + AND subject_code NOT LIKE '660287%' + AND subject_code NOT LIKE '660228%' + ) + + ) +SELECT + subject_name AS subject_name -- 科目名称 + ,IFNULL(SUM(debit_amt_m ) / 10000,0) AS debit_amt_m -- 借方金额_当月累计 + ,IFNULL(SUM(debit_amt_y ) / 10000,0) AS debit_amt_y -- 借方金额_当年累计 + ,IFNULL(SUM(debit_amt_last_m) / 10000,0) AS debit_amt_last_m -- 借方金额_上年同期 + ,IFNULL(SUM(debit_amt_last_y) / 10000,0) AS debit_amt_last_y -- 借方金额_上年累计 +FROM subject_result +GROUP BY + subject_name +ORDER BY + DECODE(subject_name,'职工薪酬','a','折旧费','b','物料消耗','c','存货损耗','d','办公费','e','咨询服务费','f','无形资产摊销','g','差旅费','h','物业管理费','i','水电气费','j','车辆使用费','k','业务招待费','l','使用权资产摊销','m','租赁费','n','通讯费','o','会议费','p','其他','q') \ No newline at end of file diff --git a/FineReport/财务主题/报表/费用/3-研发费用汇总表.sql b/FineReport/财务主题/报表/费用/3-研发费用汇总表.sql new file mode 100644 index 0000000..e174b85 --- /dev/null +++ b/FineReport/财务主题/报表/费用/3-研发费用汇总表.sql @@ -0,0 +1,164 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +), + base_info_curr AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6604%' + AND A.acnt_year = '${YEAR(sQueryDate)}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + base_info_last AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6604%' + AND A.acnt_year = '${YEAR(sQueryDate) - 1}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + subject_result AS ( + -- 本期统计 + SELECT + '材料费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660401%' + UNION ALL + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660403%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660409%' + UNION ALL + SELECT + '加工费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660408%' + UNION ALL + SELECT + '技术服务费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '660402%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE (subject_code NOT like '660401%' + AND subject_code NOT like '660403%' + AND subject_code NOT like '660409%' + AND subject_code NOT like '660408%' + AND subject_code NOT like '660402%') + UNION ALL + -- 上期统计 + SELECT + '材料费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660401%' + UNION ALL + SELECT + '职工薪酬' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660403%' + UNION ALL + SELECT + '差旅费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660409%' + UNION ALL + SELECT + '加工费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660408%' + UNION ALL + SELECT + '技术服务费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code like '660402%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE (subject_code NOT like '660401%' + AND subject_code NOT like '660403%' + AND subject_code NOT like '660409%' + AND subject_code NOT like '660408%' + AND subject_code NOT like '660402%') + + ) +SELECT + subject_name AS subject_name -- 科目名称 + ,IFNULL(SUM(debit_amt_m ) / 10000,0) AS debit_amt_m -- 借方金额_当月累计 + ,IFNULL(SUM(debit_amt_y ) / 10000,0) AS debit_amt_y -- 借方金额_当年累计 + ,IFNULL(SUM(debit_amt_last_m) / 10000,0) AS debit_amt_last_m -- 借方金额_上年同期 + ,IFNULL(SUM(debit_amt_last_y) / 10000,0) AS debit_amt_last_y -- 借方金额_上年累计 +FROM subject_result +GROUP BY + subject_name +ORDER BY + DECODE(subject_name,'材料费','a','职工薪酬','b','差旅费','c','加工费','d','技术服务费','e','其他','f') \ No newline at end of file diff --git a/FineReport/财务主题/报表/费用/4-财务费用汇总表.sql b/FineReport/财务主题/报表/费用/4-财务费用汇总表.sql new file mode 100644 index 0000000..f0ad3c5 --- /dev/null +++ b/FineReport/财务主题/报表/费用/4-财务费用汇总表.sql @@ -0,0 +1,160 @@ +WITH corp AS ( + SELECT + corp_code -- 公司编码 + ,corp_name -- 公司名称 + FROM dwr.dim_corp + WHERE corp_type = '实体' + AND (parent_corp_code LIKE '02%' OR corp_code = '0301') + ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")} +), + base_info_curr AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6603%' + AND A.acnt_year = '${YEAR(sQueryDate)}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + base_info_last AS ( + SELECT + A.subject_code AS subject_code -- 科目编码 + ,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计 + ,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计 + FROM dwr.fact_fim_subject_balance A-- 科目余额 + JOIN corp B ON A.corp_code = B.corp_code + WHERE A.subject_code like '6603%' + AND A.acnt_year = '${YEAR(sQueryDate) - 1}' + AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}' + GROUP BY A.subject_code + ), + subject_result AS ( + -- 本期统计 + SELECT + '利息支出' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code LIKE '660301%' + UNION ALL + SELECT + '减:利息收入' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code LIKE '660302%' + UNION ALL + SELECT + '汇兑损益' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code LIKE '660303%' + UNION ALL + SELECT + '金融机构手续费' AS subject_name -- 科目名称 + ,SUM(debit_amt_m) AS debit_amt_m -- 借方金额_当月累计 + ,SUM(debit_amt_y) AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code LIKE '660304%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END) + + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END) + AS debit_amt_m -- 借方金额_当月累计 + ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END) + + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END) + + AS debit_amt_y -- 借方金额_当年累计 + ,0 AS debit_amt_last_m -- 借方金额_上年同期 + ,0 AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_curr + WHERE subject_code like '6603%' + UNION ALL + -- 上期统计 + SELECT + '利息支出' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code LIKE '660301%' + UNION ALL + SELECT + '减:利息收入' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code LIKE '660302%' + UNION ALL + SELECT + '汇兑损益' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code LIKE '660303%' + UNION ALL + SELECT + '金融机构手续费' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(debit_amt_m) AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计 + FROM base_info_last + WHERE subject_code LIKE '660304%' + UNION ALL + SELECT + '其他' AS subject_name -- 科目名称 + ,0 AS debit_amt_m -- 借方金额_当月累计 + ,0 AS debit_amt_y -- 借方金额_当年累计 + ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END) + + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END) + AS debit_amt_last_m -- 借方金额_上年同期 + ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END) + - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END) + + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END) + + AS debit_amt_last_y -- 借方金额_上年累计 + + FROM base_info_last + WHERE subject_code like '6603%' +) +SELECT + subject_name AS subject_name -- 科目名称 + ,IFNULL(SUM(debit_amt_m ) / 10000,0) AS debit_amt_m -- 借方金额_当月累计 + ,IFNULL(SUM(debit_amt_y ) / 10000,0) AS debit_amt_y -- 借方金额_当年累计 + ,IFNULL(SUM(debit_amt_last_m) / 10000,0) AS debit_amt_last_m -- 借方金额_上年同期 + ,IFNULL(SUM(debit_amt_last_y) / 10000,0) AS debit_amt_last_y -- 借方金额_上年累计 +FROM subject_result +GROUP BY + subject_name +ORDER BY + DECODE(subject_name,'利息支出','a','减:利息收入','b','汇兑损益','c','金融机构手续费','d','其他','e') \ No newline at end of file diff --git a/FineReport/明细表/销售业绩组合统计表.sql b/FineReport/销售主题/报表/销售业绩/销售业绩组合统计表.sql similarity index 99% rename from FineReport/明细表/销售业绩组合统计表.sql rename to FineReport/销售主题/报表/销售业绩/销售业绩组合统计表.sql index fbd3ae0..262dc79 100644 --- a/FineReport/明细表/销售业绩组合统计表.sql +++ b/FineReport/销售主题/报表/销售业绩/销售业绩组合统计表.sql @@ -11,6 +11,11 @@ -- 动态维度:年、季、月、日、事业部、事业部大区、办事处、城市单元、公司大区、省、市、区、产品线、品项、产品、主经销商、子经销商 -- 指标:合同、订单、回款、发货(金额、件数、瓶数)、实物库存、 +-- 默认展示到办事处维度 指标展示全部 +-- 去除区 +-- 年月季度日 单选 可以选择区间 +-- 根据不同的 + -- EXTRACT(YEAR FROM order_time) AS order_year -- 订单年度 @@ -79,7 +84,6 @@ SELECT ,SUM(T1.real_amt) AS real_amt -- 实物库存 FROM - ( -- 销售订单(订单金额) SELECT bu_name -- 事业部名称 @@ -135,7 +139,7 @@ FROM ,product_name -- 产品名称 ,deal_name -- 经销商名称 ,src_deal_name -- 子经销商名称 - UNION ALL +/* UNION ALL -- 合同汇总 SELECT bu_name -- 事业部名称 @@ -356,6 +360,8 @@ FROM ,product_name -- 产品名称 ,deal_name -- 经销商名称 ,src_deal_name -- 子经销商名称 + + */ )T1 GROUP BY T1.bu_name