美文网首页
K3事业部资金收支汇总表

K3事业部资金收支汇总表

作者: 刘刘琼Max | 来源:发表于2020-04-20 09:09 被阅读0次

1、需求背景

财务想做通过选择一个日期,累计至所选日期统计出不同部门收入、支出的收款、业务成本、其他支出、净收支的人民币金额数据。

image.png

2、难点

1) 部门如何维护。--辅助资料列表–事业部中维护

2) 何为业务成本?其他成本?

根据费用项目备注来判断
 
--其他成本
T_BD_EXPENSE_L.FDESCRIPTION not like '01、业务成本'
--业务成本
T_BD_EXPENSE_L.FDESCRIPTION like '01、业务成本'

3)付款表读取付款明细表的事业部,收款表读取单据头的事业部

T_AP_PAYBILLENTRY.F_kd_Assistant_SYB =  T_BAS_ASSISTANTDATAENTRY_L.FENTRYID  --付款明细表 与辅助信息明细表(找事业部)连接
T_AR_RECEIVEBILL.F_SYB_ASSISTANT = T_BAS_ASSISTANTDATAENTRY_L.FENTRYID --收款单表【事业部】 与辅助信息明细表(找事业部)连接

4)汇率取当月汇率

left join #HL
on SK.FCURRENCYID = #HL.YB
and  convert(char(7),#HL.BDATE, 120) = convert(char(7), SK.FDATE, 120),

5)最后一行显示合计

 case when A2 is not null then A2 else '合计' end A2

SQL源码

select X.FBEGDATE as BDATE,X.FCYFORID as YB, X.FEXCHANGERATE as ZJHL 
into #HL
from T_BD_Rate X
where convert(char(4), X.FBEGDATE, 120) = convert(char(4), '#BDate#', 120)
and X.FRATETYPEID = '8355919'


--收款临时表
select SK.FDATE as A1 
,SYB.FDATAVALUE A2
,SYB.FDESCRIPTION A4

,(case when SK.FCURRENCYID = '1' 
then  
     SKMX.FREALRECAMOUNTFOR  
else 
     SKMX.FREALRECAMOUNTFOR * #HL.ZJHL
end) as A5

into #SKSUM
from T_AR_RECEIVEBILL as SK
left join #HL 
on SK.FCURRENCYID = #HL.YB
and  convert(char(7),#HL.BDATE, 120) = convert(char(7), SK.FDATE, 120),
T_AR_RECEIVEBILLENTRY as SKMX, 
T_CN_RECPAYPURPOSE_L as JCZL,
T_BAS_ASSISTANTDATAENTRY_L as SYB
where SK.FID = SKMX.FID
and SKMX.FPURPOSEID = JCZL.FID
and SK.F_SYB_ASSISTANT = SYB.FENTRYID 
and JCZL.FLOCALEID = '2052'
and JCZL.FNAME not Like '%调拨%'
and SK.FDOCUMENTSTATUS = 'C'
and SK.FCANCELSTATUS = 'A'
and datepart(yy,SK.FDATE) = datepart(yy, '#BDate#')

select 
FK.FDATE as A1 
,SYB.FDATAVALUE A2 
,SYB.FDESCRIPTION A4

,(case when FK.FCURRENCYID = '1'
then
    FKMX.FREALPAYAMOUNTFOR
else
    FKMX.FREALPAYAMOUNTFOR * #HL.ZJHL
end) as A5

into #YWCB
from T_AP_PAYBILL as FK
left join #HL 
on FK.FCURRENCYID = #HL.YB
and  convert(char(7),#HL.BDATE, 120) = convert(char(7), FK.FDATE, 120)

,T_AP_PAYBILLENTRY as FKMX
,T_BAS_ASSISTANTDATAENTRY_L as SYB
,T_BD_EXPENSE_L as FY

where  FK.FID = FKMX.FID
and FKMX.F_kd_Assistant_SYB = SYB.FENTRYID 
and FKMX.FCOSTID = FY.FEXPID
and FK.FDOCUMENTSTATUS = 'C'
and FK.FCANCELSTATUS = 'A'
and FKMX.FCOSTID <>''
and FY.FDESCRIPTION like '01、业务成本'
and datepart(yy,FK.FDATE) = datepart(yy, '#BDate#')



--其他支出明细临时表
select FK.FDATE as A1 
,SYB.FDATAVALUE A2 
,SYB.FDESCRIPTION A4 
,(case when FK.FCURRENCYID = '1'
then
    FKMX.FREALPAYAMOUNTFOR
else
    FKMX.FREALPAYAMOUNTFOR * #HL.ZJHL
end) as A5

into #QTFK
from T_AP_PAYBILL as FK
left join #HL 
on FK.FCURRENCYID = #HL.YB
and  convert(char(7),#HL.BDATE, 120) = convert(char(7), FK.FDATE, 120)

,T_AP_PAYBILLENTRY as FKMX
,T_BAS_ASSISTANTDATAENTRY_L as SYB
,T_BD_EXPENSE_L as FY
where  FK.FID = FKMX.FID
and FKMX.F_kd_Assistant_SYB = SYB.FENTRYID
and FKMX.FCOSTID = FY.FEXPID
and FK.FDOCUMENTSTATUS = 'C'
and FK.FCANCELSTATUS = 'A'
and FKMX.FCOSTID <>''
and FY.FDESCRIPTION not like '%01、业务成本%'
and FY.FDESCRIPTION <>''
and datepart(yy,FK.FDATE) = datepart(yy, '#BDate#')



--查询需要统计事业部备注 #SYB
select FDATAVALUE A1 --事业部
,FDESCRIPTION A2--备注
into #SYB
from T_BAS_ASSISTANTDATAENTRY a,T_BAS_ASSISTANTDATAENTRY_L b 
where a.FID = '59832ad438268e'
and a.FMASTERID =b.FENTRYID
and FDESCRIPTION <>''
order by FDESCRIPTION

-----------组装起来------------------
select
 case when A2 is not null then A2 else '合计' end A2
,SUM(SBDLJ)
,SUM(FBDLJ)
,SUM(F2BDLJ)
,SUM(SUMBDLJ)

,SUM(SBWLJ)
,SUM(FBWLJ)
,SUM(F2BWLJ)
,SUM(SUMBWLJ)

,SUM(SBMLJ)
,SUM(FBMLJ)
,SUM(F2BMLJ)
,SUM(SUMBMLJ)

,SUM(SBYLJ)
,SUM(FBYLJ)
,SUM(F2BYLJ)
,SUM(SUMBYLJ)

from(
select 
#SYB.A2 as A2--备注
--,A1 --事业部

,(case when SBDLJ is not null then SBDLJ else '0' end ) as SBDLJ  
,(case when FBDLJ is not null then FBDLJ else '0' end ) as FBDLJ  
,(case when F2BDLJ is not null then F2BDLJ else '0' end ) as F2BDLJ
,(case when SBDLJ is not null then SBDLJ else '0' end ) 
-(case when FBDLJ is not null then FBDLJ else '0' end ) 
-(case when F2BDLJ is not null then F2BDLJ else '0' end ) as SUMBDLJ


,(case when SBWLJ is not null then SBWLJ  else '0' end ) as SBWLJ  
,(case when FBWLJ is not null then FBWLJ else '0' end ) as FBWLJ  
,(case when F2BWLJ is not null then F2BWLJ else '0' end ) as F2BWLJ
,(case when SBWLJ is not null then SBWLJ  else '0' end )  
-(case when FBWLJ is not null then FBWLJ else '0' end )
-(case when F2BWLJ is not null then F2BWLJ else '0' end ) as SUMBWLJ


,(case when SBMLJ is not null then SBMLJ else '0' end ) as SBMLJ  
,(case when FBMLJ is not null then FBMLJ else '0' end ) as FBMLJ  
,(case when F2BMLJ is not null then F2BMLJ else '0' end ) as F2BMLJ
,(case when SBMLJ is not null then SBMLJ else '0' end ) 
-(case when FBMLJ is not null then FBMLJ else '0' end )
-(case when F2BMLJ is not null then F2BMLJ else '0' end ) as SUMBMLJ

,(case when SBYLJ is not null then SBYLJ else '0' end ) as SBYLJ  
,(case when FBYLJ is not null then FBYLJ else '0' end ) as FBYLJ  
,(case when F2BYLJ is not null then F2BYLJ else '0' end ) as F2BYLJ
,(case when SBYLJ is not null then SBYLJ else '0' end )  
-(case when FBYLJ is not null then FBYLJ else '0' end )
-(case when F2BYLJ is not null then F2BYLJ else '0' end ) as SUMBYLJ


from #SYB

LEFT JOIN 
(
--本日收款
select A2,sum(A5) as SBDLJ
from #SKSUM 
where convert(char(10), A1, 120) = '#BDate#'
group by A2
) as SBDLJ
 ON #SYB.A1 = SBDLJ.A2

LEFT JOIN 
(
--本周收款
select A2,sum(A5) as SBWLJ
from #SKSUM 
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --小于查询日期范围  
and datepart(mm,A1) = datepart(mm,'#BDate#')    --是当前月
and datepart(WW,A1) = datepart(WW, '#BDate#')   --开始查周
group by A2
) as SBWLJ
 ON #SYB.A1 = SBWLJ.A2

LEFT JOIN 
(
--本月收款
select A2,sum(A5) as SBMLJ
from #SKSUM
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(mm,A1) = datepart(mm,'#BDate#')

group by A2
) as SBMLJ
 ON #SYB.A1 = SBMLJ.A2

LEFT JOIN 
(
--本年收款
select A2,sum(A5) as SBYLJ
from #SKSUM 
where  convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(yy,A1) = datepart(yy, '#BDate#')
group by A2
) as SBYLJ 
ON #SYB.A1 = SBYLJ.A2
--------业务支出---------
LEFT JOIN 
(
--本日业务支出
select A2,sum(A5) as FBDLJ
from #YWCB 
where convert(char(10), A1, 120) = '#BDate#'
group by A2
) as FBDLJ
ON #SYB.A1 = FBDLJ.A2

LEFT JOIN 
(
--本周业务支出
select A2,sum(A5) as FBWLJ
from #YWCB 
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --小于查询日期范围  
and datepart(mm,A1) = datepart(mm,'#BDate#')    --是当前月
and datepart(WW,A1) = datepart(WW, '#BDate#')   --开始查周
group by A2
) as FBWLJ
 ON #SYB.A1 = FBWLJ.A2

LEFT JOIN 
(
--本月业务支出
select A2,sum(A5) as FBMLJ
from #YWCB
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(mm,A1) = datepart(mm,'#BDate#')

group by A2
) as FBMLJ
 ON #SYB.A1 =  FBMLJ.A2

LEFT JOIN 
(
--本年支出
select A2,sum(A5) as FBYLJ
from #YWCB 
where  convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(yy,A1) = datepart(yy, '#BDate#')
group by A2
) as FBYLJ 
ON #SYB.A1 = FBYLJ.A2

---其他支出---------
LEFT JOIN 
(
--本日其他支出
select A2,sum(A5) as F2BDLJ
from #QTFK 
where convert(char(10), A1, 120) = '#BDate#'
group by A2
) as F2BDLJ
ON #SYB.A1 = F2BDLJ.A2

LEFT JOIN 
(
--本周其他支出
select A2,sum(A5) as F2BWLJ
from #QTFK 
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --小于查询日期范围  
and datepart(mm,A1) = datepart(mm,'#BDate#')    --是当前月
and datepart(WW,A1) = datepart(WW, '#BDate#')   --开始查周
group by A2
) as F2BWLJ
 ON #SYB.A1 = F2BWLJ.A2

LEFT JOIN 
(
--本月业务支出
select A2,sum(A5) as F2BMLJ
from #QTFK 
where convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(mm,A1) = datepart(mm,'#BDate#')

group by A2
) as F2BMLJ 
 ON #SYB.A1 = F2BMLJ.A2

LEFT JOIN 
(
--本年支出
select A2,sum(A5) as F2BYLJ
from #QTFK  
where  convert(char(10), A1, 120) < dateadd(day, 1, '#BDate#')     --查询日期范围
and datepart(yy,A1) = datepart(yy, '#BDate#')
group by A2
) as F2BYLJ 
ON #SYB.A1 = F2BYLJ.A2

) A
group by A2 with rollup
having grouping(A2) = 0 or grouping(A2) = 1 --合计行

相关文章

  • K3事业部资金收支汇总表

    1、需求背景 财务想做通过选择一个日期,累计至所选日期统计出不同部门收入、支出的收款、业务成本、其他支出、净收支的...

  • 2017年CPA《审计》各章节要点归纳(四)

    货币资金的审计 货币资金的内部控制应:资金收支与记账的岗位分离、资金收支有依据、入账及时并支出有核准手续、当日收入...

  • 拆分

    互联网金融又分为资金盘和资金流。 资金盘的特性就是“中心化收支”,什么是中心化收支?收到和支出都是在一个指定账户,...

  • 2017年2月5日十班同学聚会收支明细和结余资金处置情况

    2017年2月5日十班同学聚会收支明细和结余资金处置情况 一、收支明细 1、收入:参加聚会师生共计十九人,...

  • 检视你拥有的资产

    一、掌控自己目前的净资产 二、搞清自己每月收支状况 三、目标资金提前规划 四、核心资金组合方案 五、检视和提高你拥...

  • 每天进步一点点—【针对月光、资金不清的、负债的】解决方式

    理财知识学习: 针对月光负债、资金不清的解决方法: 1、月光的,资金不清的,不用说啦。做下收支规划就好了~比如限制...

  • 信用的含义与作用二

    4、国际收支中的盈余与赤字:当一国出现国际收支顺差时,其盈余部分的外汇资金就成为国际间货币借货的主要供给来源;...

  • 月工资4千,本年存款36000元

    一、关于资金情况说明 12.16收支工资收入:4467元 (工资4千,加班467元)支 出:127.56元 ...

  • SQL做K3资金滚动报表

    本人产品,sql小白。 在同事网友指导下,做出一点小模样。晒晒,求交流更好方案。 财务需求如下表:——资金滚动月报...

  • 在平凡的岗位上绽放青春

    财务人员正在对项目建设,设备购买,人员工资等10多项资金的清单汇总表,做最后核对工作。 陕北地区因小型...

网友评论

      本文标题:K3事业部资金收支汇总表

      本文链接:https://www.haomeiwen.com/subject/drzkihtx.html