hledger-lib-0.19: Core data types, parsers and utilities for the hledger accounting tool.

Safe HaskellNone



Most data types are defined here to avoid import cycles. Here is an overview of the hledger data model:

 Journal                  -- a journal is read from one or more data files. It contains..
  [Transaction]           -- journal transactions (aka entries), which have date, status, code, description and..
   [Posting]              -- multiple account postings, which have account name and amount
  [HistoricalPrice]       -- historical commodity prices

 Ledger                   -- a ledger is derived from a journal, by applying a filter specification and doing some further processing. It contains..
  Journal                 -- a filtered copy of the original journal, containing only the transactions and postings we are interested in
  [Account]               -- all accounts, in tree order beginning with a "root" account", with their balances and sub/parent accounts

For more detailed documentation on each type, see the corresponding modules.



data Side Source




data Commodity Source




symbol :: String

the commodity's symbol display preferences for amounts of this commodity

side :: Side

should the symbol appear on the left or the right

spaced :: Bool

should there be a space between symbol and quantity

precision :: Int

number of decimal places to display XXX these three might be better belonging to Journal

decimalpoint :: Char

character to use as decimal point

separator :: Char

character to use for separating digit groups (eg thousands)

separatorpositions :: [Int]

positions of separators, counting leftward from decimal point

data Price Source

An amount's price in another commodity may be written as @ unit price or @@ total price. Note although a MixedAmount is used, it should be in a single commodity, also the amount should be positive; these are not enforced currently.


data Amount Source




commodity :: Commodity
quantity :: Quantity
price :: Maybe Price

the price for this amount at posting time

data Posting Source




pstatus :: Bool
paccount :: AccountName
pamount :: MixedAmount
pcomment :: String

this posting's non-tag comment lines, as a single non-indented string

ptype :: PostingType
ptags :: [Tag]
ptransaction :: Maybe Transaction

this posting's parent transaction (co-recursive types). Tying this knot gets tedious, Maybe makes it easier/optional.


data Transaction Source




tdate :: Day
teffectivedate :: Maybe Day
tstatus :: Bool
tcode :: String
tdescription :: String
tcomment :: String

this transaction's non-tag comment lines, as a single non-indented string

ttags :: [Tag]
tpostings :: [Posting]

this transaction's postings

tpreceding_comment_lines :: String

data JournalContext Source

A journal context is some data which can change in the course of parsing a journal. An example is the default year, which changes when a Y directive is encountered. At the end of parsing, the final context is saved for later use by eg the add command.




ctxYear :: !(Maybe Year)

the default year most recently specified with Y

ctxCommodity :: !(Maybe Commodity)

the default commodity most recently specified with D

ctxAccount :: ![AccountName]

the current stack of parent accounts/account name components specified with account directive(s). Concatenated, these are the account prefix prepended to parsed account names.

ctxAliases :: ![(AccountName, AccountName)]

the current list of account name aliases in effect

data Journal Source




jmodifiertxns :: [ModifierTransaction]
jperiodictxns :: [PeriodicTransaction]
jtxns :: [Transaction]
open_timelog_entries :: [TimeLogEntry]
historical_prices :: [HistoricalPrice]
final_comment_lines :: String

any trailing comments from the journal file

jContext :: JournalContext

the context (parse state) at the end of parsing

files :: [(FilePath, String)]

the file path and raw text of the main and any included journal files. The main file is first followed by any included files in the order encountered (XXX reversed, cf journalAddFile).

filereadtime :: ClockTime

when this journal was last read from its file(s)

type JournalUpdate = ErrorT String IO (Journal -> Journal)Source

A JournalUpdate is some transformation of a Journal. It can do I/O or raise an error.

type Format = StringSource

The id of a data format understood by hledger, eg journal or csv.

data Reader Source

A hledger journal reader is a triple of format name, format-detecting predicate, and a parser to Journal.


data Account Source

An account, with name, balances and links to parent/subaccounts which let you walk up or down the account tree.




aname :: AccountName

this account's full name

aebalance :: MixedAmount

this account's balance, excluding subaccounts

asubs :: [Account]

sub-accounts derived from the above:

aibalance :: MixedAmount

this account's balance, including subaccounts

aparent :: Maybe Account

parent account

aboring :: Bool

used in the accounts report to label elidable parents


data Ledger Source

A Ledger has the journal it derives from, and the accounts derived from that. Accounts are accessible both list-wise and tree-wise, since each one knows its parent and subs; the first account is the root of the tree and always exists.