lib: simplify account txns report running total

The account transactions report used for hledger-ui and -web registers
now gives either the "period total" or "historical total", depending
strictly on the --historical flag. It doesn't try to tell the user
whether the historical total is the accurate historical balance (which
depends on the report query).
This commit is contained in:
Simon Michael 2016-08-12 17:26:34 -07:00
parent 69ebc3b159
commit f3bcf570e5

View File

@ -57,7 +57,9 @@ type TransactionsReportItem = (Transaction -- the original journal transaction,
,Bool -- is this a split, ie more than one other account posting ,Bool -- is this a split, ie more than one other account posting
,String -- a display string describing the other account(s), if any ,String -- a display string describing the other account(s), if any
,MixedAmount -- the amount posted to the current account(s) by the filtered postings (or total amount posted) ,MixedAmount -- the amount posted to the current account(s) by the filtered postings (or total amount posted)
,MixedAmount -- the running balance for the current account(s) after the above ,MixedAmount -- the running total of item amounts, starting from zero;
-- or with --historical, the running total including items
-- (matched by the report query) preceding the report period
) )
triOrigTransaction (torig,_,_,_,_,_) = torig triOrigTransaction (torig,_,_,_,_,_) = torig
@ -108,8 +110,10 @@ journalTransactionsReport opts j q = (totallabel, items)
-- --
-- - the total increase/decrease to the current account -- - the total increase/decrease to the current account
-- --
-- - the register's running total after this transaction, or -- - the report transactions' running total after this transaction;
-- the current account's historical balance after this transaction -- or if historical balance is requested, the historical running total,
-- including transactions (filtered by the report query) from before
-- the report start date
-- --
-- Items are sorted by transaction context date, most recent first. -- Items are sorted by transaction context date, most recent first.
-- Reporting intervals are currently ignored. -- Reporting intervals are currently ignored.
@ -147,39 +151,24 @@ accountTransactionsReport opts j reportq thisacctq = (label, items)
-- better sort by the transaction's register date, for accurate starting balance -- better sort by the transaction's register date, for accurate starting balance
ts = sortBy (comparing (transactionRegisterDate reportq thisacctq)) ts3 ts = sortBy (comparing (transactionRegisterDate reportq thisacctq)) ts3
-- starting balance: if we are filtering by a start date and nothing else, (startbal,label)
-- this is the sum of the (possibly realness or status-filtered) postings -- queryIsNull q = (nullmixedamt, balancelabel)
-- to this account before that date; otherwise start from zero. | balancetype_ opts == HistoricalBalance = (sumPostings priorps, balancelabel)
(startbal,label) | queryIsNull q = (nullmixedamt, balancelabel) | otherwise = (nullmixedamt, totallabel)
| queryIsStartBalancePreserving opts q = (sumPostings priorps, balancelabel) where
| otherwise = (nullmixedamt, totallabel) priorps = -- ltrace "priorps" $
where filter (matchesPosting
priorps = -- ltrace "priorps" $ (-- ltrace "priormatcher" $
filter (matchesPosting And [thisacctq, realq, statusq, tostartdatequery]))
(-- ltrace "priormatcher" $ $ transactionsPostings ts
And [thisacctq, realq, statusq, tostartdatequery])) tostartdatequery = Date (DateSpan Nothing startdate)
$ transactionsPostings ts startdate = queryStartDate (date2_ opts) q
tostartdatequery = Date (DateSpan Nothing startdate)
startdate = queryStartDate (date2_ opts) q
items = reverse $ -- see also registerChartHtml items = reverse $ -- see also registerChartHtml
accountTransactionsReportItems q thisacctq startbal negate ts accountTransactionsReportItems q thisacctq startbal negate ts
-- Assuming this query specifies a start date, if we switch that to totallabel = "Period Total"
-- an end date, will the resulting query calculate an accurate balancelabel = "Historical Total"
-- starting balance ?
-- XXX WIP, probably misses many balance-preserving cases,
-- not sure how this should work.
queryIsStartBalancePreserving :: ReportOpts -> Query -> Bool
queryIsStartBalancePreserving opts q =
queryIsStartDateOnly (date2_ opts) $
filterQuery (\q -> not (
queryIsEmpty q
|| queryIsSym q
)) q
totallabel = "Running Total"
balancelabel = "Historical Balance"
-- | Generate transactions report items from a list of transactions, -- | Generate transactions report items from a list of transactions,
-- using the provided user-specified report query, a query specifying -- using the provided user-specified report query, a query specifying