hledger-lib-1.31: A reusable library providing the core functionality of hledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hledger.Data.Transaction

Description

A Transaction represents a movement of some commodity(ies) between two or more accounts. It consists of multiple account Postings which balance to zero, a date, and optional extras like description, cleared status, and tags.

Synopsis

Transaction

transaction :: Day -> [Posting] -> Transaction #

Make a simple transaction with the given date and postings.

txnTieKnot :: Transaction -> Transaction #

Ensure a transaction's postings refer back to it, so that eg relatedPostings works right.

txnUntieKnot :: Transaction -> Transaction #

Ensure a transaction's postings do not refer back to it, so that eg recursiveSize and GHCI's :sprint work right.

operations

transactionTransformPostings :: (Posting -> Posting) -> Transaction -> Transaction #

Apply a transform function to this transaction's amounts.

transactionApplyValuation :: PriceOracle -> Map CommoditySymbol AmountStyle -> Day -> Day -> ValuationType -> Transaction -> Transaction #

Apply a specified valuation to this transaction's amounts, using the provided price oracle, commodity styles, and reference dates. See amountApplyValuation.

transactionToCost :: ConversionOp -> Transaction -> Transaction #

Maybe convert this Transactions amounts to cost.

transactionAddInferredEquityPostings :: Bool -> AccountName -> Transaction -> Transaction #

Add inferred equity postings to a Transaction using transaction prices.

transactionInferCostsFromEquity :: Bool -> Map AccountName AccountType -> Transaction -> Either String Transaction #

Add costs inferred from equity postings in this transaction. For every adjacent pair of conversion postings, it will first search the postings with costs to see if any match. If so, it will tag these as matched. If no postings with costs match, it will then search the postings without costs, and will match the first such posting which matches one of the conversion amounts. If it finds a match, it will add a cost and then tag it. If the first argument is true, do a dry run instead: identify and tag the costful and conversion postings, but don't add costs.

transactionApplyAliases :: [AccountAlias] -> Transaction -> Either RegexError Transaction #

Apply some account aliases to all posting account names in the transaction, as described by accountNameApplyAliases. This can fail due to a bad replacement pattern in a regular expression alias.

transactionMapPostings :: (Posting -> Posting) -> Transaction -> Transaction #

Apply a transformation to a transaction's postings.

transactionMapPostingAmounts :: (MixedAmount -> MixedAmount) -> Transaction -> Transaction #

Apply a transformation to a transaction's posting amounts.

partitionAndCheckConversionPostings :: Bool -> Map AccountName AccountType -> [IdxPosting] -> Either Text ([(IdxPosting, IdxPosting)], ([IdxPosting], [IdxPosting])) #

date operations

transaction description parts

rendering

showTransaction :: Transaction -> Text #

Render a journal transaction as text similar to the style of Ledger's print command.

Adapted from Ledger 2.x and 3.x standard format:

yyyy-mm-dd[ *][ CODE] description.........          [  ; comment...............]
    account name 1.....................  ...$amount1[  ; comment...............]
    account name 2.....................  ..$-amount1[  ; comment...............]

pcodewidth    = no limit -- 10          -- mimicking ledger layout.
pdescwidth    = no limit -- 20          -- I don't remember what these mean,
pacctwidth    = 35 minimum, no maximum  -- they were important at the time.
pamtwidth     = 11
pcommentwidth = no limit -- 22

The output will be parseable journal syntax. To facilitate this, postings with explicit multi-commodity amounts are displayed as multiple similar postings, one per commodity. (Normally does not happen with this function).

showTransactionOneLineAmounts :: Transaction -> Text #

Like showTransaction, but explicit multi-commodity amounts are shown on one line, comma-separated. In this case the output will not be parseable journal syntax.

transactionFile :: Transaction -> FilePath #

The file path from which this transaction was parsed.

transaction errors

tests

Orphan instances