hledger-lib-0.14: Reusable types and utilities for the hledger accounting tool and financial apps in general.

Hledger.Data.Amount

Description

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

A simple amount is a Commodity, quantity pair:

  $1 
  -50
  EUR 3.44 
  GOOG 500
  1.5h
  90 apples
  0 

An amount may also have a per-unit price, or conversion rate, in terms of some other commodity. If present, this is displayed after @:

  EUR 3 @ $1.35

A MixedAmount is zero or more simple amounts. Mixed amounts are usually normalised so that there is no more than one amount in each commodity, and no zero amounts (or, there is just a single zero amount and no others.):

  $50 + EUR 3
  16h + $13.55 + AAPL 500 + 6 oranges
  0

We can do limited arithmetic with simple or mixed amounts: either price-preserving arithmetic with similarly-priced amounts, or price-discarding arithmetic which ignores and discards prices.

Synopsis

Documentation

amounts :: MixedAmount -> [Amount]Source

Access a mixed amount's components.

canonicaliseAmount :: Maybe (Map String Commodity) -> Amount -> AmountSource

Set an amount's commodity to the canonicalised commodity from the provided commodity map.

canonicaliseMixedAmount :: Maybe (Map String Commodity) -> MixedAmount -> MixedAmountSource

Set a mixed amount's commodity to the canonicalised commodity from the provided commodity map.

convertMixedAmountToSimilarCommodity :: Commodity -> MixedAmount -> AmountSource

Convert a mixed amount to the specified commodity, assuming an exchange rate of 1.

costOfAmount :: Amount -> AmountSource

Convert an amount to the commodity of its saved price, if any. Notes: - price amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error) - price amounts should be positive, though this is not currently enforced

costOfMixedAmount :: MixedAmount -> MixedAmountSource

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

divideAmount :: Amount -> Double -> AmountSource

Divide an amount's quantity by some constant.

divideMixedAmount :: MixedAmount -> Double -> MixedAmountSource

Divide a mixed amount's quantities by some constant.

isNegativeMixedAmount :: MixedAmount -> Maybe BoolSource

Is this mixed amount negative, if it can be normalised to a single commodity ?

isReallyZeroMixedAmountCost :: MixedAmount -> BoolSource

Is this mixed amount really zero, after converting to cost commodities where possible ?

isZeroMixedAmount :: MixedAmount -> BoolSource

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

missingamt :: MixedAmountSource

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

normaliseMixedAmount :: MixedAmount -> MixedAmountSource

Simplify a mixed amount by removing redundancy in its component amounts, as follows: 1. sum amounts which have the same commodity (ignoring their price) 2. remove zero amounts 3. if there are no amounts at all, add a single zero amount

nullamt :: AmountSource

The empty simple amount.

nullmixedamt :: MixedAmountSource

The empty mixed amount.

punctuatethousands :: String -> StringSource

Add thousands-separating commas to a decimal number string

showAmountDebug :: Amount -> StringSource

Get the unambiguous string representation of an amount, for debugging.

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 "".

showMixedAmountDebug :: MixedAmount -> StringSource

Get an unambiguous string representation of a mixed amount for debugging.

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.

showMixedAmountOrZeroWithoutPrice :: MixedAmount -> StringSource

Get the string representation of a mixed amount, or a bare 0, without any @ prices.

showMixedAmountWithoutPrice :: MixedAmount -> StringSource

Get the string representation of a mixed amount, but without any @ prices.

showMixedAmountWithPrecision :: Int -> MixedAmount -> StringSource

Get the string representation of a mixed amount, showing each of its component amounts with the specified precision, ignoring their commoditys' display precision settings. NB a mixed amount can have an empty amounts list in which case it shows as "".