fully haddockise Ledger

This commit is contained in:
Simon Michael 2008-10-03 07:39:09 +00:00
parent a7b1269d86
commit 8bcb3c25a4
3 changed files with 23 additions and 14 deletions

View File

@ -1,7 +1,7 @@
{-| {-|
An 'Entry' represents a normal entry in the ledger file. It contains An 'Entry' represents a normal entry in the ledger file. It normally
two or more 'RawTransaction's which balance. contains two or more 'RawTransaction's which balance.
-} -}

View File

@ -2,6 +2,8 @@
A 'Ledger' stores, for efficiency, a 'RawLedger' plus its tree of account A 'Ledger' stores, for efficiency, a 'RawLedger' plus its tree of account
names, a map from account names to 'Account's, and the display precision. names, a map from account names to 'Account's, and the display precision.
Also, the Account 'Transaction's are filtered according to the provided
account name/description patterns.
-} -}
@ -42,10 +44,7 @@ instance Show Ledger where
(length $ periodic_entries $ rawledger l)) (length $ periodic_entries $ rawledger l))
(length $ accountnames l) (length $ accountnames l)
-- | at startup, to improve performance, we refine the parsed ledger entries: -- | Convert a raw ledger to a more efficient filtered and cached type, described above.
-- 1. filter based on account/description patterns, if any
-- 2. cache per-account info
-- 3. figure out the precision(s) to use
cacheLedger :: RawLedger -> (Regex,Regex) -> Ledger cacheLedger :: RawLedger -> (Regex,Regex) -> Ledger
cacheLedger l pats = cacheLedger l pats =
let let
@ -89,7 +88,7 @@ filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) =
otherwise -> True otherwise -> True
-- | in each ledger entry, filter out transactions which do not match the -- | in each ledger entry, filter out transactions which do not match the
-- account patterns. (Entries are no longer balanced after this.) -- filter patterns. (The entries are no longer balanced after this.)
filterLedgerTransactions :: (Regex,Regex) -> RawLedger -> RawLedger filterLedgerTransactions :: (Regex,Regex) -> RawLedger -> RawLedger
filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) = filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) =
RawLedger ms ps (map filterentrytxns es) f RawLedger ms ps (map filterentrytxns es) f
@ -99,13 +98,17 @@ filterLedgerTransactions (acctpat,descpat) (RawLedger ms ps es f) =
Nothing -> False Nothing -> False
otherwise -> True otherwise -> True
-- | List a 'Ledger' 's account names.
accountnames :: Ledger -> [AccountName] accountnames :: Ledger -> [AccountName]
accountnames l = flatten $ accountnametree l accountnames l = flatten $ accountnametree l
-- | Get the named account from a ledger.
ledgerAccount :: Ledger -> AccountName -> Account ledgerAccount :: Ledger -> AccountName -> Account
ledgerAccount l a = (accounts l) ! a ledgerAccount l a = (accounts l) ! a
-- | This sets all amount precisions to that of the highest-precision -- | List a ledger's transactions.
--
-- NB this sets the amount precisions to that of the highest-precision
-- amount, to help with report output. It should perhaps be done in the -- amount, to help with report output. It should perhaps be done in the
-- display functions, but those are far removed from the ledger. Keep in -- display functions, but those are far removed from the ledger. Keep in
-- mind if doing more arithmetic with these. -- mind if doing more arithmetic with these.
@ -115,27 +118,30 @@ ledgerTransactions l =
where where
setprecisions = map (transactionSetPrecision (lprecision l)) setprecisions = map (transactionSetPrecision (lprecision l))
-- | Get a ledger's tree of accounts to the specified depth.
ledgerAccountTree :: Ledger -> Int -> Tree Account ledgerAccountTree :: Ledger -> Int -> Tree Account
ledgerAccountTree l depth = ledgerAccountTree l depth =
addDataToAccountNameTree l $ treeprune depth $ accountnametree l addDataToAccountNameTree l $ treeprune depth $ accountnametree l
-- | Convert a tree of account names into a tree of accounts, using their
-- parent ledger.
addDataToAccountNameTree :: Ledger -> Tree AccountName -> Tree Account addDataToAccountNameTree :: Ledger -> Tree AccountName -> Tree Account
addDataToAccountNameTree = treemap . ledgerAccount addDataToAccountNameTree = treemap . ledgerAccount
-- | for the print command -- | Print a print report.
printentries :: Ledger -> IO () printentries :: Ledger -> IO ()
printentries l = putStr $ showEntries $ setprecisions $ entries $ rawledger l printentries l = putStr $ showEntries $ setprecisions $ entries $ rawledger l
where setprecisions = map (entrySetPrecision (lprecision l)) where setprecisions = map (entrySetPrecision (lprecision l))
-- | for the register command -- | Print a register report.
printregister :: Ledger -> IO () printregister :: Ledger -> IO ()
printregister l = putStr $ showTransactionsWithBalances printregister l = putStr $ showTransactionsWithBalances
(sortBy (comparing date) $ ledgerTransactions l) (sortBy (comparing date) $ ledgerTransactions l)
nullamt{precision=lprecision l} nullamt{precision=lprecision l}
{-| {-|
This and the functions below generate ledger-compatible balance report This and the helper functions below generate ledger-compatible balance
output. Here's how it should work: report output. Here's how it should work:
a sample account tree: a sample account tree:
@ -219,6 +225,9 @@ showLedgerAccounts l maxdepth =
(branches $ ledgerAccountTree l maxdepth) (branches $ ledgerAccountTree l maxdepth)
-- XXX need to add up and show balances too -- XXX need to add up and show balances too
-- | Get the string representation of a tree of accounts.
-- The ledger from which the accounts come is also required, so that
-- we can check for boring accounts.
showAccountTree :: Ledger -> Tree Account -> String showAccountTree :: Ledger -> Tree Account -> String
showAccountTree l = showAccountTree' l 0 . pruneBoringBranches showAccountTree l = showAccountTree' l 0 . pruneBoringBranches

View File

@ -1,7 +1,7 @@
{-| {-|
A 'Transaction' is a 'RawTransaction' with its parent 'Entry' \'s A 'Transaction' is a 'RawTransaction' with its parent 'Entry' \'s date and
date and description attached, for easier querying. description attached. These are what we actually query when doing reports.
-} -}