| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Data.Posting
Description
A Posting represents a change (by some MixedAmount) of the balance in
some Account. Each Transaction contains two or more postings which
should add up to 0. Postings reference their parent transaction, so we can
look up the date or description there.
Synopsis
- nullposting :: Posting
- posting :: Posting
- post :: AccountName -> Amount -> Posting
- vpost :: AccountName -> Amount -> Posting
- post' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting
- vpost' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting
- nullassertion :: BalanceAssertion
- balassert :: Amount -> Maybe BalanceAssertion
- balassertTot :: Amount -> Maybe BalanceAssertion
- balassertParInc :: Amount -> Maybe BalanceAssertion
- balassertTotInc :: Amount -> Maybe BalanceAssertion
- originalPosting :: Posting -> Posting
- postingStatus :: Posting -> Status
- isReal :: Posting -> Bool
- isVirtual :: Posting -> Bool
- isBalancedVirtual :: Posting -> Bool
- isEmptyPosting :: Posting -> Bool
- hasBalanceAssignment :: Posting -> Bool
- hasAmount :: Posting -> Bool
- isExplicitAmount :: Posting -> Bool
- postingAllTags :: Posting -> [Tag]
- transactionAllTags :: Transaction -> [Tag]
- relatedPostings :: Posting -> [Posting]
- postingStripCosts :: Posting -> Posting
- postingApplyAliases :: [AccountAlias] -> Posting -> Either RegexError Posting
- postingApplyCommodityStyles :: Map CommoditySymbol AmountStyle -> Posting -> Posting
- postingStyleAmounts :: Map CommoditySymbol AmountStyle -> Posting -> Posting
- postingAddTags :: Posting -> [Tag] -> Posting
- postingAddHiddenAndMaybeVisibleTag :: Bool -> Bool -> HiddenTag -> Posting -> Posting
- postingRemoveHiddenAndVisibleTag :: HiddenTag -> Posting -> Posting
- postingDate :: Posting -> Day
- postingDate2 :: Posting -> Day
- postingDateOrDate2 :: WhichDate -> Posting -> Day
- accountNamesFromPostings :: [Posting] -> [AccountName]
- commentJoin :: Text -> Text -> Text
- commentAddTag :: Text -> Tag -> Text
- commentAddTagUnspaced :: Text -> Tag -> Text
- commentAddTagNextLine :: Text -> Tag -> Text
- commentPrependTag :: Text -> Tag -> Text
- generatedTransactionTagName :: TagName
- modifiedTransactionTagName :: TagName
- generatedPostingTagName :: TagName
- feesplitPostingTagName :: TagName
- lotsplitPostingTagName :: TagName
- lotParentAssertionTagName :: TagName
- postingHasTag :: TagName -> Posting -> Bool
- costPostingTagName :: TagName
- conversionPostingTagName :: TagName
- imbalancePostingTagName :: TagName
- sumPostings :: [Posting] -> MixedAmount
- postingNegate :: Posting -> Posting
- postingNegateMainAmount :: Posting -> Posting
- showPosting :: Posting -> String
- showPostingLines :: Posting -> [Text]
- postingAsLines :: AmountFormat -> Bool -> Bool -> Int -> Int -> AmountCols -> Posting -> ([Text], PostingWidths)
- postingsAsLines :: AmountFormat -> Bool -> [Posting] -> [Text]
- postingsAsLinesWithLayout :: AmountFormat -> Bool -> PostingLayout -> [Posting] -> [Text]
- postingIndent :: Text -> Text
- showAccountName :: Maybe Int -> PostingRealness -> AccountName -> Text
- renderCommentLines :: Text -> [Text]
- showBalanceAssertion :: BalanceAssertion -> WideBuilder
- balanceAssertionOperatorB :: BalanceAssertion -> WideBuilder
- balanceAssertionAmountB :: AmountFormat -> BalanceAssertion -> WideBuilder
- data PostingLayout
- = LayoutHledger1
- | LayoutDecimal !Int
- defaultPostingLayout :: PostingLayout
- defaultDecimalMarkColumn :: Int
- data PostingWidths = PostingWidths {
- pwAcct :: !Int
- pwLeft :: !Int
- pwRight :: !Int
- pwOperator :: !Int
- pwAsnLeft :: !Int
- data AmountCols = AmountCols {
- acDecMark :: !Int
- acEquals :: !Int
- acAssDecMark :: !Int
- amountIntegerWidth :: AmountFormat -> Amount -> Int
- postingTransformAmount :: (MixedAmount -> MixedAmount) -> Posting -> Posting
- postingApplyValuation :: PriceOracle -> Map CommoditySymbol AmountStyle -> Day -> Day -> ValuationType -> Posting -> Posting
- postingToCost :: ConversionOp -> Posting -> Maybe Posting
- postingAddInferredEquityPostings :: Bool -> Text -> Posting -> [Posting]
- postingsAddInferredEquityPostings :: Bool -> Text -> [Posting] -> [Posting]
- postingPriceDirectivesFromCost :: Posting -> [PriceDirective]
- postingCommodities :: Posting -> [CommoditySymbol]
- tests_Posting :: TestTree
Posting
vpost :: AccountName -> Amount -> Posting Source #
Make a virtual (unbalanced) posting to an account.
post' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting Source #
Make a posting to an account, maybe with a balance assertion.
vpost' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting Source #
Make a virtual (unbalanced) posting to an account, maybe with a balance assertion.
balassert :: Amount -> Maybe BalanceAssertion Source #
Make a partial, exclusive balance assertion.
balassertTot :: Amount -> Maybe BalanceAssertion Source #
Make a total, exclusive balance assertion.
balassertParInc :: Amount -> Maybe BalanceAssertion Source #
Make a partial, inclusive balance assertion.
balassertTotInc :: Amount -> Maybe BalanceAssertion Source #
Make a total, inclusive balance assertion.
operations
originalPosting :: Posting -> Posting Source #
postingStatus :: Posting -> Status Source #
Get a posting's status. This is cleared or pending if those are explicitly set on the posting, otherwise the status of its parent transaction, or unmarked if there is no parent transaction. (Note the ambiguity, unmarked can mean "posting and transaction are both unmarked" or "posting is unmarked and don't know about the transaction".
isBalancedVirtual :: Posting -> Bool Source #
isEmptyPosting :: Posting -> Bool Source #
hasBalanceAssignment :: Posting -> Bool Source #
isExplicitAmount :: Posting -> Bool Source #
Was this posting's amount explicitly written by the user, rather than inferred by hledger ? Amounts inferred from a balance assignment are also counted as explicit, since they are the same as what the user wrote. Inferred postings are recognised by their preserved original posting having a missing amount.
postingAllTags :: Posting -> [Tag] Source #
Tags for this posting including any inherited from its parent transaction.
transactionAllTags :: Transaction -> [Tag] Source #
Tags for this transaction including any from its postings (which includes any from the postings' accounts).
relatedPostings :: Posting -> [Posting] Source #
postingStripCosts :: Posting -> Posting Source #
Strip all prices from a Posting.
postingApplyAliases :: [AccountAlias] -> Posting -> Either RegexError Posting Source #
Apply some account aliases to the posting's account name, as described by accountNameApplyAliases. This can fail due to a bad replacement pattern in a regular expression alias.
postingApplyCommodityStyles :: Map CommoditySymbol AmountStyle -> Posting -> Posting Source #
Deprecated: please use styleAmounts instead
Find and apply the appropriate display style to the posting amounts in each commodity (see journalCommodityStyles). Main amount precisions may be set or not according to the styles, but cost precisions are not set.
postingStyleAmounts :: Map CommoditySymbol AmountStyle -> Posting -> Posting Source #
Deprecated: please use styleAmounts instead
Like postingApplyCommodityStyles, but neither main amount precisions or cost precisions are set.
postingAddTags :: Posting -> [Tag] -> Posting Source #
Add tags to a posting, discarding any for which the posting already has a value. Note this does not add tags to the posting's comment.
postingAddHiddenAndMaybeVisibleTag :: Bool -> Bool -> HiddenTag -> Posting -> Posting Source #
Add the given hidden tag to a posting; and with a true argument, also add the equivalent visible tag to the posting's tags and comment fields. If the posting already has these tags (with any value), do nothing.
postingRemoveHiddenAndVisibleTag :: HiddenTag -> Posting -> Posting Source #
Remove the given hidden tag from a posting, and the equivalent visible tag
if postingAddHiddenAndMaybeVisibleTag added one: from the posting's tags,
and from its comment, where it appears as NAME: VALUE, comma-separated from
any other content.
date operations
postingDate :: Posting -> Day Source #
Get a posting's (primary) date - it's own primary date if specified, otherwise the parent transaction's primary date, or the null date if there is no parent transaction.
postingDate2 :: Posting -> Day Source #
Get a posting's secondary (secondary) date, which is the first of: posting's secondary date, transaction's secondary date, posting's primary date, transaction's primary date, or the null date if there is no parent transaction.
postingDateOrDate2 :: WhichDate -> Posting -> Day Source #
Get a posting's primary or secondary date, as specified.
account name operations
accountNamesFromPostings :: [Posting] -> [AccountName] Source #
Sorted unique account names referenced by these postings.
comment/tag operations
commentJoin :: Text -> Text -> Text Source #
Join two parts of a comment, eg a tag and another tag, or a tag and a non-tag, on a single line. Interpolates a comma and space unless one of the parts is empty.
commentAddTag :: Text -> Tag -> Text Source #
Add a tag to a comment, comma-separated from any prior content. A space is inserted following the colon, before the value.
commentAddTagUnspaced :: Text -> Tag -> Text Source #
Like commentAddTag, but omits the space after the colon.
commentAddTagNextLine :: Text -> Tag -> Text Source #
Add a tag on its own line to a comment, preserving any prior content. A space is inserted following the colon, before the value.
commentPrependTag :: Text -> Tag -> Text Source #
Add a tag at the start of a comment, comma-separated from any prior content. A space is inserted following the colon, before the value.
generatedTransactionTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
modifiedTransactionTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
generatedPostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
feesplitPostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
lotsplitPostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
lotParentAssertionTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
postingHasTag :: TagName -> Posting -> Bool Source #
True if the posting has a tag with the given name (hidden or visible).
costPostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
conversionPostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
imbalancePostingTagName :: TagName Source #
Special tags hledger sometimes adds to mark various things. These should be hidden tag names, beginning with _. With --verbose-tags, the equivalent visible tags will also be added. These tag names are mentioned in docs and can be matched by user queries, so consider the impact before changing them.
arithmetic
sumPostings :: [Posting] -> MixedAmount Source #
Sum all amounts from a list of postings.
postingNegate :: Posting -> Posting Source #
Negate the posting's main amount and balance assertion amount if any.
postingNegateMainAmount :: Posting -> Posting Source #
Negate the posting's main amount but not the balance assertion amount.
rendering
showPosting :: Posting -> String Source #
showPostingLines :: Posting -> [Text] Source #
Render a posting, at the appropriate width for aligning with its siblings if any. Used by the rewrite command.
postingAsLines :: AmountFormat -> Bool -> Bool -> Int -> Int -> AmountCols -> Posting -> ([Text], PostingWidths) Source #
Render one posting, on one or more lines, suitable for print output.
Also returns the PostingWidths computed from this posting's structural
data (account name, main amount, assertion operator / amount), used by the
caller's lazy knot to derive the layout columns.
There will be an indented account name, plus one or more of status flag, posting amount, balance assertion, same-line comment, next-line comments.
If the posting's amount is implicit or if elideamount is true, no amount is shown. If the posting's amount is explicit and multi-commodity, multiple similar postings are shown, one for each commodity, to help produce parseable journal syntax. Or if onelineamounts is true, such amounts are shown on one line, comma-separated (and the output will not be valid journal syntax).
If an amount is zero, any commodity symbol attached to it is shown (and the corresponding commodity display style is used).
Three target columns are supplied via AmountCols:
acDecMark— the main amount's decimal mark is left-padded to land here. With multi-commodity postings rendered on multiple lines, every line is aligned at this column. Callers (postingsAsLines, showPostingLines) pick it so that at least 2 spaces remain between the widest account name and the start of the amount area.acEquals— the first=of any balance-assertion operator (=,==,=*, or==*) is padded to land here, one space past the rightmost main amount across all postings.acAssDecMark— the assertion amount's decimal mark is padded to land here. The leftmost assertion amount starts one space past the widest operator; narrower-operator postings get extra space so all assertion amounts line up on their decimals.
acEquals and acAssDecMark are unused (and may be 0) when no posting in the
group has a balance assertion.
Note: this function overrides four fields of the caller's AmountFormat:
displayZeroCommodity = True— always show the commodity on zero amounts so they participate in alignment.displayForceDecimalMark = True— force a decimal mark when digit groups are shown, for unambiguous display.displayOneLine = onelineamounts— driven by this function's parameter.displayMinWidth = Nothing— disable the legacy right-alignment of multi-commodity amount lines, since this function provides its own decimal-mark alignment.
postingsAsLines :: AmountFormat -> Bool -> [Posting] -> [Text] Source #
Render a transaction's postings as indented lines, suitable for print output,
using the default posting layout (decimal-mark alignment at column 53).
Normally these will be in valid journal syntax which hledger can reparse (though they may include no-longer-valid balance assertions). Explicit amounts are shown, implicit amounts are not.
Postings with multicommodity explicit amounts are handled as follows: if onelineamounts is true, these amounts are shown on one line, comma-separated, and the output will not be valid journal syntax. Otherwise, they are shown as several similar postings, one per commodity. When the posting has a balance assertion, it is attached to the last of these postings.
Note: a few fields of the caller's AmountFormat are overridden internally;
see postingAsLines for details.
postingsAsLinesWithLayout :: AmountFormat -> Bool -> PostingLayout -> [Posting] -> [Text] Source #
Like postingsAsLines but with an explicit PostingLayout: either the
new decimal-mark alignment (with a target column) or the older hledger 1.x
right-aligned layout.
postingIndent :: Text -> Text Source #
Prepend a suitable indent for a posting (or transaction/posting comment) line.
showAccountName :: Maybe Int -> PostingRealness -> AccountName -> Text Source #
Show an account name, clipped to the given width if any, and appropriately bracketed/parenthesised for the given posting realness.
renderCommentLines :: Text -> [Text] Source #
Render a transaction or posting's comment as indented, semicolon-prefixed comment lines. The first line (unless empty) will have leading space, subsequent lines will have a larger indent.
showBalanceAssertion :: BalanceAssertion -> WideBuilder Source #
Render a balance assertion, as the =[=][*] symbol and expected amount, separated by a single space. Used by the legacy hledger 1.x layout path; the decimal-aligned path renders the operator and amount separately so it can pad between them.
balanceAssertionOperatorB :: BalanceAssertion -> WideBuilder Source #
Render the balance-assertion operator glyph: "=", "==", "=*", or "==*".
balanceAssertionAmountB :: AmountFormat -> BalanceAssertion -> WideBuilder Source #
Render a balance assertion's expected amount, using the given AmountFormat.
data PostingLayout Source #
How posting lines should be aligned by postingsAsLines / showTransaction.
Constructors
| LayoutHledger1 | Right-align amounts in a 12+-char field, as in hledger 1.x. |
| LayoutDecimal !Int | Align the first decimal mark of each amount at the given target column. |
Instances
| Eq PostingLayout Source # | |
Defined in Hledger.Data.Posting | |
| Show PostingLayout Source # | |
Defined in Hledger.Data.Posting Methods showsPrec :: Int -> PostingLayout -> ShowS show :: PostingLayout -> String showList :: [PostingLayout] -> ShowS | |
defaultPostingLayout :: PostingLayout Source #
Default posting layout: decimal-mark alignment at column defaultDecimalMarkColumn.
defaultDecimalMarkColumn :: Int Source #
Default visible column (1-indexed) where posting amount decimal marks
should be aligned in print output. Used as the target unless a
transaction's account names + amount widths force amounts further right.
data PostingWidths Source #
Visible-character widths derived from one posting, for cross-posting
alignment in postingsAsLinesDecimal. All fields are independent of
layout (decimalcol etc.), so they can be safely consumed inside the
lazy knot that decides those columns.
Constructors
| PostingWidths | |
Fields
| |
Instances
| Eq PostingWidths Source # | |
Defined in Hledger.Data.Posting | |
| Show PostingWidths Source # | |
Defined in Hledger.Data.Posting Methods showsPrec :: Int -> PostingWidths -> ShowS show :: PostingWidths -> String showList :: [PostingWidths] -> ShowS | |
data AmountCols Source #
The three target columns derived in the knot of postingsAsLinesDecimal
and consumed by postingAsLines for aligning the main amount, the = glyph,
and the assertion amount. acEquals and acAssDecMark are 0 when no posting in
the group has a balance assertion (in which case the renderer never
consults them).
Constructors
| AmountCols | |
Fields
| |
Instances
| Eq AmountCols Source # | |
Defined in Hledger.Data.Posting | |
| Show AmountCols Source # | |
Defined in Hledger.Data.Posting Methods showsPrec :: Int -> AmountCols -> ShowS show :: AmountCols -> String showList :: [AmountCols] -> ShowS | |
amountIntegerWidth :: AmountFormat -> Amount -> Int Source #
Visible width of the part of a rendered amount that appears before its
(real or virtual) decimal mark — i.e. from the start of the amount through
the last digit of the integer portion (including any L-side commodity
prefix). Computed structurally from the Amount data rather than by
parsing the rendered text, so it is unaffected by trailing cost annotations,
lot syntax, comments, or digits that may appear inside a commodity name.
Used to align integer-ends across postings at decimalcol-1.
misc.
postingTransformAmount :: (MixedAmount -> MixedAmount) -> Posting -> Posting Source #
Apply a transform function to this posting's main amount (but not its balance assertion amount).
postingApplyValuation :: PriceOracle -> Map CommoditySymbol AmountStyle -> Day -> Day -> ValuationType -> Posting -> Posting Source #
Apply a specified valuation to this posting's amount, using the provided price oracle, commodity styles, and reference dates. See amountApplyValuation.
postingToCost :: ConversionOp -> Posting -> Maybe Posting Source #
Maybe convert this Postings amount to cost: to cost basis where known,
else transacted cost (ToCost); or to transacted cost (ToTransactedCost).
postingAddInferredEquityPostings :: Bool -> Text -> Posting -> [Posting] Source #
Given a posting with costs, tag it as a cost posting and add
equity conversion postings after it, one pair per cost: one removing
the quantity transacted, one adding what it cost. See
postingsAddInferredEquityPostings.
postingsAddInferredEquityPostings :: Bool -> Text -> [Posting] -> [Posting] Source #
Like postingAddInferredEquityPostings, for a posting or for the
consecutive per-lot fragments of one posting (cf transactionInferEquityPostings):
postings with costs are tagged as cost postings, and one pair of equity
conversion postings is added after them for each (commodity, cost commodity)
pair, with the fragments' quantities and costs summed, so that collapsing
lot detail can still merge the fragments.
The cost used is the cost basis where known (a lot disposal, after lot processing), otherwise the transacted cost. So a disposal's conversion postings record the disposed units at what they cost, keeping the entry balanced at cost basis, and the difference from the proceeds stays in the realised gain posting.
Postings already tagged as cost postings (having conversion postings) are left alone.
postingPriceDirectivesFromCost :: Posting -> [PriceDirective] Source #
Make a market price equivalent to this posting's amount's unit price, if any.
postingCommodities :: Posting -> [CommoditySymbol] Source #
Get the commodity symbols used in a posting's amounts (not including costs).
Orphan instances
| HasAmounts BalanceAssertion Source # | |
Methods styleAmounts :: Map CommoditySymbol AmountStyle -> BalanceAssertion -> BalanceAssertion Source # | |
| HasAmounts Posting Source # | |
Methods styleAmounts :: Map CommoditySymbol AmountStyle -> Posting -> Posting Source # | |