diff --git a/hledger-lib/Hledger/Data/Posting.hs b/hledger-lib/Hledger/Data/Posting.hs index 165aee930..796419bd4 100644 --- a/hledger-lib/Hledger/Data/Posting.hs +++ b/hledger-lib/Hledger/Data/Posting.hs @@ -54,10 +54,6 @@ module Hledger.Data.Posting ( concatAccountNames, accountNameApplyAliases, accountNameApplyAliasesMemo, - -- * transaction description operations - transactionPayee, - transactionNote, - payeeAndNoteFromDescription, -- * arithmetic sumPostings, -- * rendering @@ -233,23 +229,6 @@ postingStatus Posting{pstatus=s, ptransaction=mt} Nothing -> Unmarked | otherwise = s -transactionPayee :: Transaction -> Text -transactionPayee = fst . payeeAndNoteFromDescription . tdescription - -transactionNote :: Transaction -> Text -transactionNote = snd . payeeAndNoteFromDescription . tdescription - --- | Parse a transaction's description into payee and note (aka narration) fields, --- assuming a convention of separating these with | (like Beancount). --- Ie, everything up to the first | is the payee, everything after it is the note. --- When there's no |, payee == note == description. -payeeAndNoteFromDescription :: Text -> (Text,Text) -payeeAndNoteFromDescription t - | T.null n = (t, t) - | otherwise = (textstrip p, textstrip $ T.drop 1 n) - where - (p, n) = T.span (/= '|') t - -- | Tags for this posting including any inherited from its parent transaction. postingAllTags :: Posting -> [Tag] postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p) diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 8dfc6cb8f..ed5438bb9 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -35,6 +35,10 @@ module Hledger.Data.Transaction ( transactionDate2, -- * arithmetic transactionPostingBalances, + -- * transaction description parts + transactionPayee, + transactionNote, + -- payeeAndNoteFromDescription, -- * rendering showTransaction, showTransactionUnelided, @@ -100,6 +104,23 @@ nulltransaction = Transaction { transaction :: String -> [Posting] -> Transaction transaction datestr ps = txnTieKnot $ nulltransaction{tdate=parsedate datestr, tpostings=ps} +transactionPayee :: Transaction -> Text +transactionPayee = fst . payeeAndNoteFromDescription . tdescription + +transactionNote :: Transaction -> Text +transactionNote = snd . payeeAndNoteFromDescription . tdescription + +-- | Parse a transaction's description into payee and note (aka narration) fields, +-- assuming a convention of separating these with | (like Beancount). +-- Ie, everything up to the first | is the payee, everything after it is the note. +-- When there's no |, payee == note == description. +payeeAndNoteFromDescription :: Text -> (Text,Text) +payeeAndNoteFromDescription t + | T.null n = (t, t) + | otherwise = (textstrip p, textstrip $ T.drop 1 n) + where + (p, n) = T.span (/= '|') t + {-| Render a journal transaction as text in the style of Ledger's print command.