hledger-0.5: A ledger-compatible text-based accounting tool.Source codeContentsIndex
Ledger.Ledger
Description

A compound data type for efficiency. A Ledger caches information derived from a RawLedger for easier querying. Also it typically has had uninteresting LedgerTransactions and Postings filtered out. It contains:

  • the original unfiltered RawLedger
  • a tree of AccountNames
  • a map from account names to Accounts
  • the full text of the journal file, when available

This is the main object you'll deal with as a user of the Ledger library. The most useful functions also have shorter, lower-case aliases for easier interaction. Here's an example:

 > import Ledger
 > l <- readLedger "sample.ledger"
 > accountnames l
 ["assets","assets:bank","assets:bank:checking","assets:bank:saving",...
 > accounts l
 [Account assets with 0 txns and $-1 balance,Account assets:bank with...
 > topaccounts l
 [Account assets with 0 txns and $-1 balance,Account expenses with...
 > account l "assets"
 Account assets with 0 txns and $-1 balance
 > accountsmatching ["ch"] l
 accountsmatching ["ch"] l
 [Account assets:bank:checking with 4 txns and $0 balance]
 > subaccounts l (account l "assets")
 subaccounts l (account l "assets")
 [Account assets:bank with 0 txns and $1 balance,Account assets:cash...
 > head $ transactions l
 2008/01/01 income assets:bank:checking $1 RegularPosting
 > accounttree 2 l
 Node {rootLabel = Account top with 0 txns and 0 balance, subForest = [...
 > accounttreeat l (account l "assets")
 Just (Node {rootLabel = Account assets with 0 txns and $-1 balance, ...
 > datespan l
 DateSpan (Just 2008-01-01) (Just 2009-01-01)
 > rawdatespan l
 DateSpan (Just 2008-01-01) (Just 2009-01-01)
 > ledgeramounts l
 [$1,$-1,$1,$-1,$1,$-1,$1,$1,$-2,$1,$-1]
 > commodities l
 [Commodity {symbol = "$", side = L, spaced = False, comma = False, ...
Synopsis
cacheLedger :: [String] -> RawLedger -> Ledger
groupTransactions :: [Transaction] -> (Tree AccountName, AccountName -> [Transaction], AccountName -> MixedAmount, AccountName -> MixedAmount)
calculateBalances :: Tree AccountName -> (AccountName -> [Transaction]) -> Tree (AccountName, (MixedAmount, MixedAmount))
transactionsByAccount :: [Transaction] -> Map AccountName [Transaction]
filtertxns :: [String] -> [Transaction] -> [Transaction]
ledgerAccountNames :: Ledger -> [AccountName]
ledgerAccount :: Ledger -> AccountName -> Account
ledgerAccounts :: Ledger -> [Account]
ledgerTopAccounts :: Ledger -> [Account]
ledgerAccountsMatching :: [String] -> Ledger -> [Account]
ledgerSubAccounts :: Ledger -> Account -> [Account]
ledgerTransactions :: Ledger -> [Transaction]
ledgerAccountTree :: Int -> Ledger -> Tree Account
ledgerAccountTreeAt :: Ledger -> Account -> Maybe (Tree Account)
ledgerDateSpan :: Ledger -> DateSpan
accountnames :: Ledger -> [AccountName]
account :: Ledger -> AccountName -> Account
accounts :: Ledger -> [Account]
topaccounts :: Ledger -> [Account]
accountsmatching :: [String] -> Ledger -> [Account]
subaccounts :: Ledger -> Account -> [Account]
transactions :: Ledger -> [Transaction]
accounttree :: Int -> Ledger -> Tree Account
accounttreeat :: Ledger -> Account -> Maybe (Tree Account)
datespan :: Ledger -> DateSpan
rawdatespan :: Ledger -> DateSpan
ledgeramounts :: Ledger -> [MixedAmount]
Documentation
cacheLedger :: [String] -> RawLedger -> LedgerSource
Convert a raw ledger to a more efficient cached type, described above.
groupTransactions :: [Transaction] -> (Tree AccountName, AccountName -> [Transaction], AccountName -> MixedAmount, AccountName -> MixedAmount)Source
Given a list of transactions, return an account name tree and three query functions that fetch transactions, balance, and subaccount-including balance by account name. This is to factor out common logic from cacheLedger and summariseTransactionsInDateSpan.
calculateBalances :: Tree AccountName -> (AccountName -> [Transaction]) -> Tree (AccountName, (MixedAmount, MixedAmount))Source
Add subaccount-excluding and subaccount-including balances to a tree of account names somewhat efficiently, given a function that looks up transactions by account name.
transactionsByAccount :: [Transaction] -> Map AccountName [Transaction]Source
Convert a list of transactions to a map from account name to the list of all transactions in that account.
filtertxns :: [String] -> [Transaction] -> [Transaction]Source
ledgerAccountNames :: Ledger -> [AccountName]Source
List a ledger's account names.
ledgerAccount :: Ledger -> AccountName -> AccountSource
Get the named account from a ledger.
ledgerAccounts :: Ledger -> [Account]Source
List a ledger's accounts, in tree order
ledgerTopAccounts :: Ledger -> [Account]Source
List a ledger's top-level accounts, in tree order
ledgerAccountsMatching :: [String] -> Ledger -> [Account]Source
Accounts in ledger whose name matches the pattern, in tree order.
ledgerSubAccounts :: Ledger -> Account -> [Account]Source
List a ledger account's immediate subaccounts
ledgerTransactions :: Ledger -> [Transaction]Source
List a ledger's transactions.
ledgerAccountTree :: Int -> Ledger -> Tree AccountSource
Get a ledger's tree of accounts to the specified depth.
ledgerAccountTreeAt :: Ledger -> Account -> Maybe (Tree Account)Source
Get a ledger's tree of accounts rooted at the specified account.
ledgerDateSpan :: Ledger -> DateSpanSource
The date span containing all the ledger's (filtered) transactions, or DateSpan Nothing Nothing if there are none.
accountnames :: Ledger -> [AccountName]Source
Convenience aliases.
account :: Ledger -> AccountName -> AccountSource
accounts :: Ledger -> [Account]Source
topaccounts :: Ledger -> [Account]Source
accountsmatching :: [String] -> Ledger -> [Account]Source
subaccounts :: Ledger -> Account -> [Account]Source
transactions :: Ledger -> [Transaction]Source
accounttree :: Int -> Ledger -> Tree AccountSource
accounttreeat :: Ledger -> Account -> Maybe (Tree Account)Source
datespan :: Ledger -> DateSpanSource
rawdatespan :: Ledger -> DateSpanSource
ledgeramounts :: Ledger -> [MixedAmount]Source
Produced by Haddock version 2.7.2