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

Safe Haskell | None

Hledger.Data.Transaction

Contents

- Transaction
- operations
- date operations
- arithmetic
- rendering
- misc.

Description

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

Synopsis

- nulltransaction :: Transaction
- txnTieKnot :: Transaction -> Transaction
- showAccountName :: Maybe Int -> PostingType -> AccountName -> String
- hasRealPostings :: Transaction -> Bool
- realPostings :: Transaction -> [Posting]
- virtualPostings :: Transaction -> [Posting]
- balancedVirtualPostings :: Transaction -> [Posting]
- transactionsPostings :: [Transaction] -> [Posting]
- isTransactionBalanced :: Maybe (Map Commodity AmountStyle) -> Transaction -> Bool
- transactionDate2 :: Transaction -> Day
- transactionPostingBalances :: Transaction -> (MixedAmount, MixedAmount, MixedAmount)
- balanceTransaction :: Maybe (Map Commodity AmountStyle) -> Transaction -> Either String Transaction
- showTransaction :: Transaction -> String
- showTransactionUnelided :: Transaction -> String
- tests_Hledger_Data_Transaction :: Test

# Transaction

nulltransaction :: Transaction Source

txnTieKnot :: Transaction -> Transaction Source

Ensure a transaction's postings refer back to it.

# operations

showAccountName :: Maybe Int -> PostingType -> AccountName -> String Source

Show an account name, clipped to the given width if any, and appropriately bracketed/parenthesised for the given posting type.

hasRealPostings :: Transaction -> Bool Source

realPostings :: Transaction -> [Posting]Source

virtualPostings :: Transaction -> [Posting]Source

balancedVirtualPostings :: Transaction -> [Posting]Source

transactionsPostings :: [Transaction] -> [Posting]Source

isTransactionBalanced :: Maybe (Map Commodity AmountStyle) -> Transaction -> Bool Source

Is this transaction balanced ? A balanced transaction's real (non-virtual) postings sum to 0, and any balanced virtual postings also sum to 0.

# date operations

transactionDate2 :: Transaction -> Day Source

# arithmetic

transactionPostingBalances :: Transaction -> (MixedAmount, MixedAmount, MixedAmount)Source

Get the sums of a transaction's real, virtual, and balanced virtual postings.

balanceTransaction :: Maybe (Map Commodity AmountStyle) -> Transaction -> Either String Transaction Source

Ensure this transaction is balanced, possibly inferring a missing amount or conversion price, or return an error message.

Balancing is affected by commodity display precisions, so those may be provided.

We can infer a missing real amount when there are multiple real postings and exactly one of them is amountless (likewise for balanced virtual postings). Inferred amounts are converted to cost basis when possible.

We can infer a conversion price when all real amounts are specified and the sum of real postings' amounts is exactly two non-explicitly-priced amounts in different commodities (likewise for balanced virtual postings).

# rendering

showTransaction :: Transaction -> String Source

Show a journal transaction, formatted for the print command. ledger 2.x's standard format looks like this:

    yyyymmdd[ *][ 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

showTransactionUnelided :: Transaction -> String Source

# misc.

tests_Hledger_Data_Transaction :: Test Source