This is not something we're really going to be able to help much with without similar table data to be honest.
In terms of understanding the Execution Plan you may find this CodeProject article useful:
SQL Tuning Tutorial - Understanding a Database Execution Plan (1)[
^]
You do appear to have a lot of sub-queries that you may want to try to rationalise. I'll have a another look to see if there is anything else to try.
[UPDATE] I can't prove it, but I'm fairly sure that if you take some of those sub-queries and insert the data into a temporary table or table variable you are going to get better performance. Given that you notices an improved when you are not using the data from
postdata
it's a good bet that that is the problem.
Something like this:
select glP.fkosControlNumberStatus, glP.SourceJENumber, AccountSegment,
sum(case when glP.DistAmount > 0 then glP.DistAmount else 0 end) Debit,
sum(case when glP.DistAmount < 0 then glP.DistAmount else 0 end) Credit,
sum(glP.DistAmount) DistAmountTotal
INTO #postdata
from glPost glP WITH (NOLOCK)
join glAccountingPeriod WITH (NOLOCK) on glAccountingPeriod.pk = glP.fkglAccountingPeriod
join glFiscalYear WITH (NOLOCK) on glFiscalYear.pk = glAccountingPeriod.fkglFiscalYear
join glAccount WITH (NOLOCK) on glAccount.pk = glFiscalYear.fkglAccount
where dbo.fnGetDatePartOnly(glFiscalYear.PeriodEnd) = @YearEndDate
and glP.fkMLSosCodeEntryType = 2202
group by glP.fkosControlNumberStatus, glP.SourceJENumber, AccountSegment
then
Select Distinct
glPostExtended.BatchNumber,
pd.fkosControlNumberStatus,
pd.AccountSegment Fund,
pd.Debit,
pd.Credit,
pd.DistAmountTotal,
glPostExtended.SubLedger Module,
glPost.SourceJENumber,
glPost.PostToDate
From
glPost WITH (NOLOCK)
join (Select fkglPost, MAX(fkglDist) as fkglDist, COUNT(fkglDist) as RecordCount From glPostExtended WITH (NOLOCK) Group By fkglPost) as glPostExtendedLimiter on glPost.PK = glPostExtendedLimiter.fkglPost
join #postdata pd on pd.fkosControlNumberStatus = glPost.fkosControlNumberStatus and pd.SourceJENumber = glPost.SourceJENumber
where pd.DistAmountTotal <> 0
and glPost.fkMLSosCodeEntryType = 2202
order by glPostExtended.BatchNumber, glPost.SourceJENumber, pd.AccountSegment
If nothing else it's going to be easier to interpret the execution plan!