hledger-0.3: A ledger-compatible text-based accounting tool.



An Amount is some quantity of money, shares, or anything else.

A simple amount is a Commodity, quantity pair:

  EUR 3.44 
  GOOG 500

A MixedAmount is zero or more simple amounts:

  $50, EUR 3, AAPL 500
  16h, $13.55, oranges 6

Not implemented: Commodities may be convertible or not. A mixed amount containing only convertible commodities can be converted to a simple amount. Arithmetic examples:

  $1 - $5 = $-4
  $1 + EUR 0.76 = $2
  EUR0.76 + $1 = EUR 1.52
  EUR0.76 - $1 = 0
  ($5, 2h) + $1 = ($6, 2h)
  ($50, EUR 3, AAPL 500) + ($13.55, oranges 6) = $67.51, AAPL 500, oranges 6
  ($50, EUR 3) * $-1 = $-53.96
  ($50, AAPL 500) * $-1 = error



amountop :: (Double -> Double -> Double) -> Amount -> Amount -> AmountSource

Apply a binary arithmetic operator to two amounts - converting to the second one's commodity, adopting the lowest precision, and discarding any price information. (Using the second commodity is best since sum and other folds start with a no-commodity amount.)

costOfAmount :: Amount -> AmountSource

Convert an amount to the commodity of its saved price, if any.

convertAmountTo :: Commodity -> Amount -> AmountSource

Convert an amount to the specified commodity using the appropriate exchange rate (which is currently always 1).

showAmount :: Amount -> StringSource

Get the string representation of an amount, based on its commodity's display settings.

showAmount' :: Amount -> StringSource

Get the string representation (of the number part of) of an amount

punctuatethousands :: String -> StringSource

Add thousands-separating commas to a decimal number string

isZeroAmount :: Amount -> BoolSource

Does this amount appear to be zero when displayed with its given precision ?

amounts :: MixedAmount -> [Amount]Source

Access a mixed amount's components.

isZeroMixedAmount :: MixedAmount -> BoolSource

Does this mixed amount appear to be zero - empty, or containing only simple amounts which appear to be zero ?

mixedAmountEquals :: MixedAmount -> MixedAmount -> BoolSource

MixedAmount derives Eq in Types.hs, but that doesn't know that we want $0 = EUR0 = 0. Yet we don't want to drag all this code in there. When zero equality is important, use this, for now; should be used everywhere.

showMixedAmount :: MixedAmount -> StringSource

Get the string representation of a mixed amount, showing each of its component amounts. NB a mixed amount can have an empty amounts list in which case it shows as "".

showMixedAmountOrZero :: MixedAmount -> StringSource

Get the string representation of a mixed amount, and if it appears to be all zero just show a bare 0, ledger-style.

normaliseMixedAmount :: MixedAmount -> MixedAmountSource

Simplify a mixed amount by combining any component amounts which have the same commodity and the same price. Also removes redundant zero amounts and adds a single zero amount if there are no amounts at all.

costOfMixedAmount :: MixedAmount -> MixedAmountSource

Convert a mixed amount's component amounts to the commodity of their saved price, if any.

nullamt :: AmountSource

The empty simple amount.

nullmixedamt :: MixedAmountSource

The empty mixed amount.

missingamt :: MixedAmountSource

A temporary value for parsed transactions which had no amount specified.