define Ledger's exports

This commit is contained in:
Simon Michael 2008-10-03 07:38:46 +00:00
parent 7acd389624
commit a7b1269d86
2 changed files with 36 additions and 18 deletions

View File

@ -5,7 +5,23 @@ names, a map from account names to 'Account's, and the display precision.
-}
module Ledger.Ledger
module Ledger.Ledger (
cacheLedger,
filterLedgerEntries,
filterLedgerTransactions,
accountnames,
ledgerAccount,
ledgerTransactions,
ledgerAccountTree,
addDataToAccountNameTree,
printentries,
printregister,
showLedgerAccounts,
showAccountTree,
isBoringInnerAccount,
isBoringInnerAccountName,
pruneBoringBranches,
)
where
import qualified Data.Map as Map
import Data.Map ((!))
@ -19,22 +35,6 @@ import Ledger.RawLedger
import Ledger.Entry
rawLedgerTransactions :: RawLedger -> [Transaction]
rawLedgerTransactions = txns . entries
where
txns :: [Entry] -> [Transaction]
txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1)
rawLedgerAccountNamesUsed :: RawLedger -> [AccountName]
rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions
rawLedgerAccountNames :: RawLedger -> [AccountName]
rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed
rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l
instance Show Ledger where
show l = printf "Ledger with %d entries, %d accounts"
((length $ entries $ rawledger l) +
@ -266,3 +266,21 @@ pruneBoringBranches =
hasbalance = (/= 0) . abalance
hastxns = (> 0) . length . atransactions
-- helpers
rawLedgerTransactions :: RawLedger -> [Transaction]
rawLedgerTransactions = txns . entries
where
txns :: [Entry] -> [Transaction]
txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1)
rawLedgerAccountNamesUsed :: RawLedger -> [AccountName]
rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions
rawLedgerAccountNames :: RawLedger -> [AccountName]
rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed
rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l

View File

@ -372,7 +372,7 @@ test_ledgerAccountNames =
["assets","assets:cash","assets:checking","assets:saving","equity","equity:opening balances",
"expenses","expenses:food","expenses:food:dining","expenses:phone","expenses:vacation",
"liabilities","liabilities:credit cards","liabilities:credit cards:discover"]
(rawLedgerAccountNames ledger7)
(accountnames l7)
test_cacheLedger =
assertEqual' 15 (length $ Map.keys $ accounts $ cacheLedger ledger7 nullpats)