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

Safe Haskell | None
Language | Haskell2010

Hledger.Data.Types

Description

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, cleared 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.

Synopsis

- type SmartDate = (String, String, String)
- data WhichDate
  - = PrimaryDate
  - | SecondaryDate
- data DateSpan = DateSpan (Maybe Day) (Maybe Day)
- data Interval
  - = NoInterval
  - | Days Int
  - | Weeks Int
  - | Months Int
  - | Quarters Int
  - | Years Int
  - | DayOfMonth Int
  - | DayOfWeek Int
- type AccountName = String
- data AccountAlias
  - = BasicAlias AccountName AccountName
  - | RegexAlias Regexp Replacement
- data Side
  - = L
  - | R
- type Commodity = String
- numberRepresentation :: String
- type Quantity = Decimal
- data Price
  - = NoPrice
  - | UnitPrice Amount
  - | TotalPrice Amount
- data AmountStyle = AmountStyle {
  - ascommodityside :: Side
  - ascommodityspaced :: Bool
  - asprecision :: Int
  - asdecimalpoint :: Maybe Char
  - asdigitgroups :: Maybe DigitGroupStyle
  }
- data DigitGroupStyle = DigitGroups Char [Int]
- data Amount = Amount {
  - acommodity :: Commodity
  - aquantity :: Quantity
  - aprice :: Price
  - astyle :: AmountStyle
  }
- newtype MixedAmount = Mixed [Amount]
- data PostingType
  - = RegularPosting
  - | VirtualPosting
  - | BalancedVirtualPosting
- type Tag = (String, String)
- data ClearedStatus
  - = Uncleared
  - | Pending
  - | Cleared
- data Posting = Posting {
  - pdate :: Maybe Day
  - pdate2 :: Maybe Day
  - pstatus :: ClearedStatus
  - paccount :: AccountName
  - pamount :: MixedAmount
  - pcomment :: String
  - ptype :: PostingType
  - ptags :: [Tag]
  - pbalanceassertion :: Maybe MixedAmount
  - ptransaction :: Maybe Transaction
  }
- data Transaction = Transaction {
  - tsourcepos :: SourcePos
  - tdate :: Day
  - tdate2 :: Maybe Day
  - tstatus :: ClearedStatus
  - tcode :: String
  - tdescription :: String
  - tcomment :: String
  - ttags :: [Tag]
  - tpostings :: [Posting]
  - tpreceding_comment_lines :: String
  }
- data ModifierTransaction = ModifierTransaction {
  - mtvalueexpr :: String
  - mtpostings :: [Posting]
  }
- data PeriodicTransaction = PeriodicTransaction {
  - ptperiodicexpr :: String
  - ptpostings :: [Posting]
  }
- data TimeLogCode
  - = SetBalance
  - | SetRequiredHours
  - | In
  - | Out
  - | FinalOut
- data TimeLogEntry = TimeLogEntry {
  - tlsourcepos :: SourcePos
  - tlcode :: TimeLogCode
  - tldatetime :: LocalTime
  - tlaccount :: String
  - tldescription :: String
  }
- data HistoricalPrice = HistoricalPrice {
  - hdate :: Day
  - hcommodity :: Commodity
  - hamount :: Amount
  }
- type Year = Integer
- data JournalContext = Ctx {
  - ctxYear :: !(Maybe Year)
  - ctxDefaultCommodityAndStyle :: !(Maybe (Commodity, AmountStyle))
  - ctxAccount :: ![AccountName]
  - ctxAliases :: ![AccountAlias]
  }
- data Journal = Journal {
  - jmodifiertxns :: [ModifierTransaction]
  - jperiodictxns :: [PeriodicTransaction]
  - jtxns :: [Transaction]
  - open_timelog_entries :: [TimeLogEntry]
  - historical_prices :: [HistoricalPrice]
  - final_comment_lines :: String
  - jContext :: JournalContext
  - files :: [(FilePath, String)]
  - filereadtime :: ClockTime
  - jcommoditystyles :: Map Commodity AmountStyle
  }
- type JournalUpdate = ExceptT String IO (Journal -> Journal)
- type StorageFormat = String
- data Reader = Reader {
  - rFormat :: StorageFormat
  - rDetector :: FilePath -> String -> Bool
  - rParser :: Maybe FilePath -> Bool -> FilePath -> String -> ExceptT String IO Journal
  }
- data HledgerFormatField
  - = AccountField
  - | DefaultDateField
  - | DescriptionField
  - | TotalField
  - | DepthSpacerField
  - | FieldNo Int
- data OutputFormat
  - = FormatLiteral String
  - | FormatField Bool (Maybe Int) (Maybe Int) HledgerFormatField
- data Account = Account {
  - aname :: AccountName
  - aebalance :: MixedAmount
  - asubs :: [Account]
  - anumpostings :: Int
  - aibalance :: MixedAmount
  - aparent :: Maybe Account
  - aboring :: Bool
  }
- data Ledger = Ledger {
  - ljournal :: Journal
  - laccounts :: [Account]
  }

# Documentation

type SmartDate = (String, String, String) Source

data WhichDate Source

Constructors

PrimaryDate |
SecondaryDate |

Instances

Eq WhichDate Source |
Show WhichDate Source |

data DateSpan Source

Constructors

DateSpan (Maybe Day) (Maybe Day) |

Instances

Eq DateSpan Source |
Data DateSpan Source |
Ord DateSpan Source |

data Interval Source

Constructors

NoInterval |
Days Int |
Weeks Int |
Months Int |
Quarters Int |
Years Int |
DayOfMonth Int |
DayOfWeek Int |

Instances

Eq Interval Source |
Data Interval Source |
Ord Interval Source |
Show Interval Source |

type AccountName = String Source

data AccountAlias Source

Constructors

BasicAlias AccountName AccountName |
RegexAlias Regexp Replacement |

Instances

Eq AccountAlias Source |
Data AccountAlias Source |
Ord AccountAlias Source |
Read AccountAlias Source |
Show AccountAlias Source |

data Side Source

Constructors

L |
R |

Instances

Eq Side Source |
Data Side Source |
Ord Side Source |
Read Side Source |
Show Side Source |

type Commodity = String Source

numberRepresentation :: String Source

The basic numeric type used in amounts. Different implementations can be selected via cabal flag for testing and benchmarking purposes.

type Quantity = Decimal Source

data Price Source

An amount's price (none, per unit, or total) in another commodity. Note the price should be a positive number, although this is not enforced.

Constructors

NoPrice |
UnitPrice Amount |
TotalPrice Amount |

Instances

Eq Price Source |
Data Price Source |
Ord Price Source |

data AmountStyle Source

Display style for an amount.

Constructors

AmountStyle |

Fields

ascommodityside :: Side

  does the symbol appear on the left or the right ?

ascommodityspaced :: Bool

  space between symbol and quantity ?

asprecision :: Int

  number of digits displayed after the decimal point

asdecimalpoint :: Maybe Char

  character used as decimal point: period or comma. Nothing means "unspecified, use default"

asdigitgroups :: Maybe DigitGroupStyle

  style for displaying digit groups, if any

Instances

Eq AmountStyle Source |
Data AmountStyle Source |
Ord AmountStyle Source |
Read AmountStyle Source |
Show AmountStyle Source |

data DigitGroupStyle Source

A style for displaying digit groups in the integer part of a floating point number. It consists of the character used to separate groups (comma or period, whichever is not used as decimal point), and the size of each group, starting with the one nearest the decimal point. The last group size is assumed to repeat. Eg, comma between thousands is DigitGroups ',' [3].

Constructors

DigitGroups Char [Int] |

Instances

Eq DigitGroupStyle Source |
Data DigitGroupStyle Source |
Ord DigitGroupStyle Source |
Read DigitGroupStyle Source |
Show DigitGroupStyle Source |

data Amount Source

Constructors

Amount |

Fields

acommodity :: Commodity
aquantity :: Quantity
aprice :: Price

  the (fixed) price for this amount, if any

astyle :: AmountStyle

Instances

Eq Amount Source |
Data Amount Source |
Ord Amount Source |

newtype MixedAmount Source

Constructors

Mixed [Amount] |

Instances

Eq MixedAmount Source |
Data MixedAmount Source |
Ord MixedAmount Source |

data PostingType Source

Constructors

RegularPosting |
VirtualPosting |
BalancedVirtualPosting |

Instances

Eq PostingType Source |
Data PostingType Source |
Show PostingType Source |

type Tag Source

Arguments

= (String, String) | A tag name and (possibly empty) value.

data ClearedStatus Source

Constructors

Uncleared |
Pending |
Cleared |

Instances

Eq ClearedStatus Source |
Data ClearedStatus Source |
Ord ClearedStatus Source |
Show ClearedStatus Source |

data Posting Source

Constructors

Posting |

Fields

pdate :: Maybe Day

  this posting's date, if different from the transaction's

pdate2 :: Maybe Day

  this posting's secondary date, if different from the transaction's

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

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

ptype :: PostingType
ptags :: [Tag]

  tag names and values, extracted from the comment

pbalanceassertion :: Maybe MixedAmount

  optional: the expected balance in the account after this posting

ptransaction :: Maybe Transaction

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

Instances

Eq Posting Source |
Data Posting Source |

data Transaction Source

Constructors

Transaction |

Fields

tsourcepos :: SourcePos
tdate :: Day
tdate2 :: Maybe Day
tstatus :: ClearedStatus
tcode :: String
tdescription :: String
tcomment :: String

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

ttags :: [Tag]

  tag names and values, extracted from the comment

tpostings :: [Posting]

  this transaction's postings

tpreceding_comment_lines :: String

  any comment lines immediately preceding this transaction

Instances

Eq Transaction Source |
Data Transaction Source |

data ModifierTransaction Source

Constructors

ModifierTransaction |

Fields

mtvalueexpr :: String
mtpostings :: [Posting]

Instances

Eq ModifierTransaction Source |
Data ModifierTransaction Source |

data PeriodicTransaction Source

Constructors

PeriodicTransaction |

Fields

ptperiodicexpr :: String
ptpostings :: [Posting]

Instances

Eq PeriodicTransaction Source |
Data PeriodicTransaction Source |

data TimeLogCode Source

Constructors

SetBalance |
SetRequiredHours |
In |
Out |
FinalOut |

Instances

Eq TimeLogCode Source |
Data TimeLogCode Source |
Ord TimeLogCode Source |

data TimeLogEntry Source

Constructors

TimeLogEntry |

Fields

tlsourcepos :: SourcePos
tlcode :: TimeLogCode
tldatetime :: LocalTime
tlaccount :: String
tldescription :: String

Instances

Eq TimeLogEntry Source |
Data TimeLogEntry Source |
Ord TimeLogEntry Source |

data HistoricalPrice Source

Constructors

HistoricalPrice |

Fields

hdate :: Day
hcommodity :: Commodity
hamount :: Amount

Instances

Eq HistoricalPrice Source |
Data HistoricalPrice Source |

type Year = Integer Source

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.

Constructors

Ctx |

Fields

ctxYear :: !(Maybe Year)

  the default year most recently specified with Y

ctxDefaultCommodityAndStyle :: !(Maybe (Commodity, AmountStyle))

  the default commodity and amount style 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 :: ![AccountAlias]

  the current list of account name aliases in effect

Instances

Eq JournalContext Source |
Data JournalContext Source |
Read JournalContext Source |
Show JournalContext Source |

data Journal Source

Constructors

Journal |

Fields

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.

filereadtime :: ClockTime

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

jcommoditystyles :: Map Commodity AmountStyle

  how to display amounts in each commodity

Instances

Eq Journal Source |
Data Journal Source |

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

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

type StorageFormat = String Source

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.

Constructors

Reader |

Fields

rFormat :: StorageFormat
rDetector :: FilePath -> String -> Bool
rParser :: Maybe FilePath -> Bool -> FilePath -> String -> ExceptT String IO Journal

Instances

Show Reader Source |

data HledgerFormatField Source

Constructors

AccountField |
DefaultDateField |
DescriptionField |
TotalField |
DepthSpacerField |
FieldNo Int |

Instances

Eq HledgerFormatField Source |
Show HledgerFormatField Source |

data OutputFormat Source

Constructors

FormatLiteral String |
FormatField Bool (Maybe Int) (Maybe Int) HledgerFormatField |

Instances

Eq OutputFormat Source |
Show OutputFormat Source |

data Account Source

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

Constructors

Account |

Fields

aname :: AccountName

  this account's full name

aebalance :: MixedAmount

  this account's balance, excluding subaccounts

asubs :: [Account]

  sub-accounts

anumpostings :: Int

  number of postings to this account 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.

Constructors

Ledger |

Fields

ljournal :: Journal
laccounts :: [Account]