Professional Documents
Culture Documents
RFA Script
RFA Script
select
OPRJ.PrjCode as 'Project Code',
OPRJ.PrjName as 'Project Name',
--Get Open Bal.
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) as 'Opening Bal.',
--Get Additional
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) as 'Additional',
--Get TRF. to FA
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) as 'TRF. to FA',
--Write off to OH/Adjust
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0) as 'Write off to OH/Adjust',
--Period Totals
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))
as 'Period Total',
--Closing Bal.
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) -
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))
as 'Closing Bal.',
--RFA Budget after cap. to FA
isnull(OPRJ.U_RFABgAmt,0) as 'RFA Budget after cap. to FA',
--Budget Variance
isnull(OPRJ.U_RFABgAmt,0) -
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate < cast(@PeriodFR+'01' as date)
),0) -
(isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in ('18',
'19','59','60')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Transtype in
('1470000049', '1470000060')
),0) +
isnull((select sum(T1.Debit) - sum(T1.Credit) from JDT1 T1 where T1.Project =
OPRJ.PrjCode and T1.Account = @OBACCT and T1.RefDate >= cast(@PeriodFR+'01' as
date)
and T1.RefDate <= EOMONTH(cast(@PeriodTO+'01' as date)) and T1.Ref3Line = 'OH'
),0))as 'Budget Variance'