refactor: clarify the two register types, "posting register" and "account register"

See the docstrings for details. Possibly temporary names, but at least
make the naming consistent and distinct.
This commit is contained in:
Simon Michael 2011-06-24 02:44:31 +00:00
parent 4637e5b018
commit 33a1c6533b
9 changed files with 119 additions and 120 deletions

View File

@ -270,7 +270,7 @@ updateData :: Day -> AppState -> AppState
updateData d a@AppState{aopts=opts,ajournal=j} =
case screen a of
BalanceScreen -> a{abuf=balanceReportAsText opts $ balanceReport opts fspec j}
RegisterScreen -> a{abuf=lines $ registerReportAsText opts $ registerReport opts fspec j}
RegisterScreen -> a{abuf=lines $ postingRegisterReportAsText opts $ postingRegisterReport opts fspec j}
PrintScreen -> a{abuf=lines $ showTransactions opts fspec j}
where fspec = optsToFilterSpec opts (currentArgs a) d

View File

@ -6,5 +6,5 @@
<th.amount align=right>Amount
<th.balance align=right>#{balancelabel}
$forall i <- numberTransactions items
$forall i <- numberAccountRegisterReportItems items
^{itemAsHtml vd i}

View File

@ -6,5 +6,5 @@
<th.amount align=right>Amount
<th.balance align=right>#{balancelabel}
$forall i <- numberRegisterReport2Items items
$forall i <- numberPostingRegisterReportItems items
^{itemAsHtml vd i}

View File

@ -64,8 +64,8 @@ getRegisterR = do
vd@VD{opts=opts,qopts=qopts,m=m,j=j} <- getViewData
let sidecontent = balanceReportAsHtml opts vd{q=""} $ balanceReport opts nullfilterspec j
maincontent =
case inAccountMatcher qopts of Just m' -> registerReport2AsHtml opts vd $ accountRegisterReport opts j m m'
Nothing -> registerReportAsHtml opts vd $ registerReport opts nullfilterspec $ filterJournalPostings2 m j
case inAccountMatcher qopts of Just m' -> accountRegisterReportAsHtml opts vd $ accountRegisterReport opts j m m'
Nothing -> postingRegisterReportAsHtml opts vd $ postingRegisterReport opts nullfilterspec $ filterJournalPostings2 m j
editform' = editform vd
defaultLayout $ do
setTitle "hledger-web register"
@ -92,18 +92,12 @@ getRegisterOnlyR = do
defaultLayout $ do
setTitle "hledger-web register only"
addHamlet $
case inAccountMatcher qopts of Just m' -> registerReport2AsHtml opts vd $ accountRegisterReport opts j m m'
Nothing -> registerReportAsHtml opts vd $ registerReport opts nullfilterspec $ filterJournalPostings2 m j
case inAccountMatcher qopts of Just m' -> accountRegisterReportAsHtml opts vd $ accountRegisterReport opts j m m'
Nothing -> postingRegisterReportAsHtml opts vd $ postingRegisterReport opts nullfilterspec $ filterJournalPostings2 m j
postRegisterOnlyR :: Handler RepPlain
postRegisterOnlyR = handlePost
-- -- temporary helper - use the new account register report when in:ACCT is specified.
-- accountOrJournalRegisterReport :: ViewData -> Journal -> RegisterReport
-- accountOrJournalRegisterReport VD{opts=opts,m=m,qopts=qopts} j =
-- case inAccountMatcher qopts of Just m' -> accountRegisterReport opts j m m'
-- Nothing -> registerReport opts nullfilterspec $ filterJournalPostings2 m j
-- | A simple accounts view, like hledger balance. If the Accept header
-- specifies json, returns the chart of accounts as json.
getAccountsR :: Handler RepHtmlJson
@ -155,11 +149,12 @@ journalReportAsHtml _ vd items = $(Settings.hamletFile "journalreport")
txn = trimnl $ showTransaction t where trimnl = reverse . dropWhile (=='\n') . reverse
-- | Render a register report as HTML.
registerReportAsHtml :: [Opt] -> ViewData -> RegisterReport -> Hamlet AppRoute
registerReportAsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "registerreport")
-- Journal-wide postings register, when no account has focus.
postingRegisterReportAsHtml :: [Opt] -> ViewData -> PostingRegisterReport -> Hamlet AppRoute
postingRegisterReportAsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "postingregisterreport")
where
itemAsHtml :: ViewData -> (Int, Bool, Bool, Bool, RegisterReportItem) -> Hamlet AppRoute
itemAsHtml VD{here=here} (n, newd, newm, newy, (ds, posting, b)) = $(Settings.hamletFile "registerreportitem")
itemAsHtml :: ViewData -> (Int, Bool, Bool, Bool, PostingRegisterReportItem) -> Hamlet AppRoute
itemAsHtml VD{here=here} (n, newd, newm, newy, (ds, posting, b)) = $(Settings.hamletFile "postingregisterreportitem")
where
evenodd = if even n then "even" else "odd" :: String
datetransition -- | newy && n > 1 = "newyear"
@ -171,12 +166,30 @@ registerReportAsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "register
acct = paccount posting
accturl = (here, [("q", pack $ accountUrl acct)])
-- mark II
registerReport2AsHtml :: [Opt] -> ViewData -> RegisterReport2 -> Hamlet AppRoute
registerReport2AsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "registerreport2")
-- Add incrementing transaction numbers to a list of register report items
-- starting at 1. Also add three flags that are true if the date, month,
-- and year is different from the previous item's.
numberPostingRegisterReportItems :: [PostingRegisterReportItem] -> [(Int,Bool,Bool,Bool,PostingRegisterReportItem)]
numberPostingRegisterReportItems [] = []
numberPostingRegisterReportItems is = number 0 nulldate is
where
number :: Int -> Day -> [PostingRegisterReportItem] -> [(Int,Bool,Bool,Bool,PostingRegisterReportItem)]
number _ _ [] = []
number n prevd (i@(Nothing, _, _) :is) = (n,False,False,False,i) :(number n prevd is)
number n prevd (i@(Just (d,_), _, _):is) = (n+1,newday,newmonth,newyear,i):(number (n+1) d is)
where
newday = d/=prevd
newmonth = dm/=prevdm || dy/=prevdy
newyear = dy/=prevdy
(dy,dm,_) = toGregorian d
(prevdy,prevdm,_) = toGregorian prevd
-- Account-specific transaction register, when an account is focussed.
accountRegisterReportAsHtml :: [Opt] -> ViewData -> AccountRegisterReport -> Hamlet AppRoute
accountRegisterReportAsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "accountregisterreport")
where
itemAsHtml :: ViewData -> (Int, Bool, Bool, Bool, RegisterReport2Item) -> Hamlet AppRoute
itemAsHtml VD{here=here} (n, newd, newm, newy, (t, acct, amt, bal)) = $(Settings.hamletFile "registerreport2item")
itemAsHtml :: ViewData -> (Int, Bool, Bool, Bool, AccountRegisterReportItem) -> Hamlet AppRoute
itemAsHtml VD{here=here} (n, newd, newm, newy, (t, acct, amt, bal)) = $(Settings.hamletFile "accountregisterreportitem")
where
evenodd = if even n then "even" else "odd" :: String
datetransition | newm = "newmonth"
@ -185,11 +198,11 @@ registerReport2AsHtml _ vd (balancelabel,items) = $(Settings.hamletFile "registe
(firstposting, date, desc) = (False, show $ tdate t, tdescription t)
accturl = (here, [("q", pack $ accountUrl acct)])
numberRegisterReport2Items :: [RegisterReport2Item] -> [(Int,Bool,Bool,Bool,RegisterReport2Item)]
numberRegisterReport2Items [] = []
numberRegisterReport2Items is = number 0 nulldate is
numberAccountRegisterReportItems :: [AccountRegisterReportItem] -> [(Int,Bool,Bool,Bool,AccountRegisterReportItem)]
numberAccountRegisterReportItems [] = []
numberAccountRegisterReportItems is = number 0 nulldate is
where
number :: Int -> Day -> [RegisterReport2Item] -> [(Int,Bool,Bool,Bool,RegisterReport2Item)]
number :: Int -> Day -> [AccountRegisterReportItem] -> [(Int,Bool,Bool,Bool,AccountRegisterReportItem)]
number _ _ [] = []
number n prevd (i@(Transaction{tdate=d},_,_,_):is) = (n+1,newday,newmonth,newyear,i):(number (n+1) d is)
where
@ -483,21 +496,3 @@ getMessageOr mnewmsg = do
numbered = zip [1..]
-- Add incrementing transaction numbers to a list of register report items
-- starting at 1. Also add three flags that are true if the date, month,
-- and year is different from the previous item's.
numberTransactions :: [RegisterReportItem] -> [(Int,Bool,Bool,Bool,RegisterReportItem)]
numberTransactions [] = []
numberTransactions is = number 0 nulldate is
where
number :: Int -> Day -> [RegisterReportItem] -> [(Int,Bool,Bool,Bool,RegisterReportItem)]
number _ _ [] = []
number n prevd (i@(Nothing, _, _) :is) = (n,False,False,False,i) :(number n prevd is)
number n prevd (i@(Just (d,_), _, _):is) = (n+1,newday,newmonth,newyear,i):(number (n+1) d is)
where
newday = d/=prevd
newmonth = dm/=prevdm || dy/=prevdy
newyear = dy/=prevdy
(dy,dm,_) = toGregorian d
(prevdy,prevdm,_) = toGregorian prevd

View File

@ -338,7 +338,7 @@ tests_Hledger_Cli = TestList
"register report with no args" ~:
do
j <- samplejournal
(registerReportAsText [] $ registerReport [] (optsToFilterSpec [] [] date1) j) `is` unlines
(postingRegisterReportAsText [] $ postingRegisterReport [] (optsToFilterSpec [] [] date1) j) `is` unlines
["2008/01/01 income assets:bank:checking $1 $1"
," income:salary $-1 0"
,"2008/06/01 gift assets:bank:checking $1 $1"
@ -356,7 +356,7 @@ tests_Hledger_Cli = TestList
do
let opts = [Cleared]
j <- readJournal' sample_journal_str
(registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
(postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
["2008/06/03 eat & shop expenses:food $1 $1"
," expenses:supplies $1 $2"
," assets:cash $-2 0"
@ -368,7 +368,7 @@ tests_Hledger_Cli = TestList
do
let opts = [UnCleared]
j <- readJournal' sample_journal_str
(registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
(postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
["2008/01/01 income assets:bank:checking $1 $1"
," income:salary $-1 0"
,"2008/06/01 gift assets:bank:checking $1 $1"
@ -388,19 +388,19 @@ tests_Hledger_Cli = TestList
," e 1"
," f"
]
registerdates (registerReportAsText [] $ registerReport [] (optsToFilterSpec [] [] date1) j) `is` ["2008/01/01","2008/02/02"]
registerdates (postingRegisterReportAsText [] $ postingRegisterReport [] (optsToFilterSpec [] [] date1) j) `is` ["2008/01/01","2008/02/02"]
,"register report with account pattern" ~:
do
j <- samplejournal
(registerReportAsText [] $ registerReport [] (optsToFilterSpec [] ["cash"] date1) j) `is` unlines
(postingRegisterReportAsText [] $ postingRegisterReport [] (optsToFilterSpec [] ["cash"] date1) j) `is` unlines
["2008/06/03 eat & shop assets:cash $-2 $-2"
]
,"register report with account pattern, case insensitive" ~:
do
j <- samplejournal
(registerReportAsText [] $ registerReport [] (optsToFilterSpec [] ["cAsH"] date1) j) `is` unlines
(postingRegisterReportAsText [] $ postingRegisterReport [] (optsToFilterSpec [] ["cAsH"] date1) j) `is` unlines
["2008/06/03 eat & shop assets:cash $-2 $-2"
]
@ -408,7 +408,7 @@ tests_Hledger_Cli = TestList
do
j <- samplejournal
let gives displayexpr =
(registerdates (registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is`)
(registerdates (postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is`)
where opts = [Display displayexpr]
"d<[2008/6/2]" `gives` ["2008/01/01","2008/06/01"]
"d<=[2008/6/2]" `gives` ["2008/01/01","2008/06/01","2008/06/02"]
@ -421,7 +421,7 @@ tests_Hledger_Cli = TestList
j <- samplejournal
let periodexpr `gives` dates = do
j' <- samplejournal
registerdates (registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j') `is` dates
registerdates (postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j') `is` dates
where opts = [Period periodexpr]
"" `gives` ["2008/01/01","2008/06/01","2008/06/02","2008/06/03","2008/12/31"]
"2008" `gives` ["2008/01/01","2008/06/01","2008/06/02","2008/06/03","2008/12/31"]
@ -430,7 +430,7 @@ tests_Hledger_Cli = TestList
"monthly" `gives` ["2008/01/01","2008/06/01","2008/12/01"]
"quarterly" `gives` ["2008/01/01","2008/04/01","2008/10/01"]
let opts = [Period "yearly"]
(registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
(postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
["2008/01/01 - 2008/12/31 assets:bank:saving $1 $1"
," assets:cash $-2 $-1"
," expenses:food $1 0"
@ -440,9 +440,9 @@ tests_Hledger_Cli = TestList
," liabilities:debts $1 0"
]
let opts = [Period "quarterly"]
registerdates (registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` ["2008/01/01","2008/04/01","2008/10/01"]
registerdates (postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` ["2008/01/01","2008/04/01","2008/10/01"]
let opts = [Period "quarterly",Empty]
registerdates (registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` ["2008/01/01","2008/04/01","2008/07/01","2008/10/01"]
registerdates (postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` ["2008/01/01","2008/04/01","2008/07/01","2008/10/01"]
]
@ -450,7 +450,7 @@ tests_Hledger_Cli = TestList
do
j <- samplejournal
let opts = [Depth "2"]
(registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
(postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] date1) j) `is` unlines
["2008/01/01 income assets:bank $1 $1"
," income:salary $-1 0"
,"2008/06/01 gift assets:bank $1 $1"
@ -481,7 +481,7 @@ tests_Hledger_Cli = TestList
,"unicode in register layout" ~: do
j <- readJournal'
"2009/01/01 * медвежья шкура\n расходы:покупки 100\n актив:наличные\n"
(registerReportAsText [] $ registerReport [] (optsToFilterSpec [] [] date1) j) `is` unlines
(postingRegisterReportAsText [] $ postingRegisterReport [] (optsToFilterSpec [] [] date1) j) `is` unlines
["2009/01/01 медвежья шкура расходы:покупки 100 100"
," актив:наличные -100 0"]

View File

@ -29,7 +29,7 @@ import qualified Data.Foldable as Foldable (find)
import qualified Data.Set as Set
import Hledger.Cli.Options
import Hledger.Cli.Register (registerReport, registerReportAsText)
import Hledger.Cli.Register (postingRegisterReport, postingRegisterReportAsText)
import Hledger.Cli.Utils
import Hledger.Data
import Hledger.Read.JournalReader (someamount)
@ -220,7 +220,7 @@ registerFromString :: String -> IO String
registerFromString s = do
d <- getCurrentDay
j <- readJournal' s
return $ registerReportAsText opts $ registerReport opts (optsToFilterSpec opts [] d) j
return $ postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts [] d) j
where opts = [Empty]
-- | Return a similarity measure, from 0 to 1, for two strings.

View File

@ -6,14 +6,14 @@ A ledger-compatible @register@ command.
-}
module Hledger.Cli.Register (
RegisterReport
,RegisterReportItem
,RegisterReport2
,RegisterReport2Item
PostingRegisterReport
,PostingRegisterReportItem
,AccountRegisterReport
,AccountRegisterReportItem
,register
,registerReport
,postingRegisterReport
,accountRegisterReport
,registerReportAsText
,postingRegisterReportAsText
,showPostingWithBalanceForVty
,tests_Hledger_Cli_Register
) where
@ -36,40 +36,42 @@ import Prelude hiding (putStr)
import Hledger.Utils.UTF8 (putStr)
-- | A register report is a list of postings to an account or set of
-- accounts, with a running total. Postings may be actual postings, or
-- virtual postings aggregated over a reporting interval.
-- And also some heading info.
type RegisterReport = (String -- a possibly null label for the running balance column
,[RegisterReportItem] -- line items, one per posting
)
-- | A posting register report lists postings to one or more accounts,
-- with a running total. Postings may be actual postings, or aggregate
-- postings corresponding to a reporting interval.
type PostingRegisterReport = (String -- label for the running balance column XXX remove
,[PostingRegisterReportItem] -- line items, one per posting
)
-- | The data for a single register report line item, representing one posting.
type RegisterReportItem = (Maybe (Day, String) -- transaction date and description if this is the first posting
,Posting -- the posting
,MixedAmount -- balance so far
)
-- | A single posting register line item, representing one posting.
type PostingRegisterReportItem = (Maybe (Day, String) -- transaction date and description if this is the first posting
,Posting -- the posting
,MixedAmount -- the running total after this posting
)
-- | Register report mark II, used in hledger-web's account register (see "accountRegisterReport".
type RegisterReport2 = (String -- a possibly null label for the running balance column
,[RegisterReport2Item] -- line items, one per transaction
)
-- | A single register report 2 line item, representing one transaction to/from the focussed account.
type RegisterReport2Item = (Transaction -- the corresponding transaction
,String -- the (possibly aggregated) account info to display
,MixedAmount -- the (possibly aggregated) amount to display (sum of the other-account postings)
,MixedAmount -- the running balance for the focussed account after this transaction
)
-- | An account register report lists transactions to a single account (or
-- possibly subs as well), with the accurate running account balance when
-- possible (otherwise, a running total.)
type AccountRegisterReport = (String -- label for the balance column, eg "balance" or "total"
,[AccountRegisterReportItem] -- line items, one per transaction
)
-- | Print a register report.
-- | A single account register line item, representing one transaction to/from the focussed account.
type AccountRegisterReportItem = (Transaction -- the corresponding transaction
,String -- the (possibly aggregated) account info to display
,MixedAmount -- the (possibly aggregated) amount to display (sum of the other-account postings)
,MixedAmount -- the running balance for the focussed account after this transaction
)
-- | Print a (posting) register report.
register :: [Opt] -> [String] -> Journal -> IO ()
register opts args j = do
d <- getCurrentDay
putStr $ registerReportAsText opts $ registerReport opts (optsToFilterSpec opts args d) j
putStr $ postingRegisterReportAsText opts $ postingRegisterReport opts (optsToFilterSpec opts args d) j
-- | Render a register report as plain text suitable for console output.
registerReportAsText :: [Opt] -> RegisterReport -> String
registerReportAsText opts = unlines . map (registerReportItemAsText opts) . snd
postingRegisterReportAsText :: [Opt] -> PostingRegisterReport -> String
postingRegisterReportAsText opts = unlines . map (postingRegisterReportItemAsText opts) . snd
-- | Render one register report line item as plain text. Eg:
-- @
@ -78,8 +80,8 @@ registerReportAsText opts = unlines . map (registerReportItemAsText opts) . snd
-- ^ displayed for first postings^
-- only, otherwise blank
-- @
registerReportItemAsText :: [Opt] -> RegisterReportItem -> String
registerReportItemAsText _ (dd, p, b) = concatTopPadded [datedesc, pstr, " ", bal]
postingRegisterReportItemAsText :: [Opt] -> PostingRegisterReportItem -> String
postingRegisterReportItemAsText _ (dd, p, b) = concatTopPadded [datedesc, pstr, " ", bal]
where
datedesc = case dd of Nothing -> replicate datedescwidth ' '
Just (da, de) -> printf "%s %s " date desc
@ -93,27 +95,31 @@ registerReportItemAsText _ (dd, p, b) = concatTopPadded [datedesc, pstr, " ", ba
pstr = showPostingForRegister p
bal = padleft 12 (showMixedAmountOrZeroWithoutPrice b)
showPostingWithBalanceForVty showtxninfo p b = registerReportItemAsText [] $ mkitem showtxninfo p b
showPostingWithBalanceForVty showtxninfo p b = postingRegisterReportItemAsText [] $ mkitem showtxninfo p b
totallabel = "Total"
balancelabel = "Balance"
-- | Get an account register report with the specified options for this
-- journal. An account register report is like the traditional account
-- register seen in bank statements and personal finance programs. It is
-- focussed on one account only; it shows this account's transactions'
-- postings to other accounts; and if there is no transaction filtering in
-- effect other than a start date, it shows a historically-accurate
-- running balance for this account. Once additional filters are applied,
-- the running balance reverts to a running total starting at 0.
-- Does not handle reporting intervals.
-- Items are returned most recent first.
accountRegisterReport :: [Opt] -> Journal -> Matcher -> Matcher -> RegisterReport2
-- | Get a quicken/gnucash-style account register report, with the
-- specified options, for the currently focussed account (or possibly the
-- focussed account plus sub-accounts.) This differs from
-- "postingRegisterReport" in several ways:
--
-- 1. it shows transactions, from the point of view of the focussed
-- account. The other account's name and posted amount is displayed,
-- aggregated if there is more than other account posting.
--
-- 2. With no transaction filtering in effect other than a start date, it
-- shows the accurate historical running balance for this
-- account. Otherwise it shows a running total starting at 0 like the posting register report.
--
-- 3. Currently this report does not handle reporting intervals.
--
-- 4. Report items will be most recent first.
--
accountRegisterReport :: [Opt] -> Journal -> Matcher -> Matcher -> AccountRegisterReport
accountRegisterReport opts j m thisacctmatcher = (label, items)
where
-- interval == NoInterval = items
-- otherwise = summarisePostingsByInterval interval depth empty filterspan displayps
-- transactions affecting this account, in date order
ts = sortBy (comparing tdate) $ filter (matchesTransaction thisacctmatcher) $ jtxns j
@ -141,7 +147,7 @@ accountRegisterReport opts j m thisacctmatcher = (label, items)
-- using the provided matcher (postings not matching this will not affect
-- the displayed item), starting transaction, starting balance, and
-- balance summing function.
accountRegisterReportItems :: [Transaction] -> Matcher -> Transaction -> MixedAmount -> (MixedAmount -> MixedAmount -> MixedAmount) -> [RegisterReport2Item]
accountRegisterReportItems :: [Transaction] -> Matcher -> Transaction -> MixedAmount -> (MixedAmount -> MixedAmount -> MixedAmount) -> [AccountRegisterReportItem]
accountRegisterReportItems [] _ _ _ _ = []
accountRegisterReportItems (t@Transaction{tpostings=ps}:ts) displaymatcher _ bal sumfn =
case i of Just i' -> i':is
@ -161,12 +167,10 @@ accountRegisterReportItems (t@Transaction{tpostings=ps}:ts) displaymatcher _ bal
bal' = bal `sumfn` amt
is = (accountRegisterReportItems ts displaymatcher t bal'' sumfn)
-- | Get a traditional register report with the specified options for this journal.
-- This is a journal register report, covering the whole journal like
-- ledger's register command; for an account-specific register see
-- accountRegisterReport.
registerReport :: [Opt] -> FilterSpec -> Journal -> RegisterReport
registerReport opts fspec j = (totallabel,postingsToRegisterReportItems ps nullposting startbal (+))
-- | Get a ledger-style posting register report, with the specified options,
-- for the whole journal. See also "accountRegisterReport".
postingRegisterReport :: [Opt] -> FilterSpec -> Journal -> PostingRegisterReport
postingRegisterReport opts fspec j = (totallabel,postingRegisterItems ps nullposting startbal (+))
where
ps | interval == NoInterval = displayableps
| otherwise = summarisePostingsByInterval interval depth empty filterspan displayableps
@ -181,10 +185,10 @@ registerReport opts fspec j = (totallabel,postingsToRegisterReportItems ps nullp
filterspan = datespan fspec
(interval, depth, empty) = (intervalFromOpts opts, depthFromOpts opts, Empty `elem` opts)
-- | Generate register report line items.
postingsToRegisterReportItems :: [Posting] -> Posting -> MixedAmount -> (MixedAmount -> MixedAmount -> MixedAmount) -> [RegisterReportItem]
postingsToRegisterReportItems [] _ _ _ = []
postingsToRegisterReportItems (p:ps) pprev b sumfn = i:(postingsToRegisterReportItems ps p b' sumfn)
-- | Generate posting register report line items.
postingRegisterItems :: [Posting] -> Posting -> MixedAmount -> (MixedAmount -> MixedAmount -> MixedAmount) -> [PostingRegisterReportItem]
postingRegisterItems [] _ _ _ = []
postingRegisterItems (p:ps) pprev b sumfn = i:(postingRegisterItems ps p b' sumfn)
where
i = mkitem isfirst p b'
isfirst = ptransaction p /= ptransaction pprev
@ -193,7 +197,7 @@ postingsToRegisterReportItems (p:ps) pprev b sumfn = i:(postingsToRegisterReport
-- | Generate one register report line item, from a flag indicating
-- whether to include transaction info, a posting, and the current running
-- balance.
mkitem :: Bool -> Posting -> MixedAmount -> RegisterReportItem
mkitem :: Bool -> Posting -> MixedAmount -> PostingRegisterReportItem
mkitem False p b = (Nothing, p, b)
mkitem True p b = (ds, p, b)
where ds = case ptransaction p of Just (Transaction{tdate=da,tdescription=de}) -> Just (da,de)