lib: journalPayeesUsed, journalPayeesDeclaredOrUsed

This commit is contained in:
Simon Michael 2021-01-17 15:18:16 -08:00
parent db9b034037
commit 422329fbfa

View File

@ -54,6 +54,8 @@ module Hledger.Data.Journal (
-- traverseJournalAmounts, -- traverseJournalAmounts,
-- journalCanonicalCommodities, -- journalCanonicalCommodities,
journalPayeesDeclared, journalPayeesDeclared,
journalPayeesUsed,
journalPayeesDeclaredOrUsed,
journalCommoditiesDeclared, journalCommoditiesDeclared,
journalDateSpan, journalDateSpan,
journalStartDate, journalStartDate,
@ -265,10 +267,6 @@ journalNextTransaction j t = journalTransactionAt j (tindex t + 1)
journalPrevTransaction :: Journal -> Transaction -> Maybe Transaction journalPrevTransaction :: Journal -> Transaction -> Maybe Transaction
journalPrevTransaction j t = journalTransactionAt j (tindex t - 1) journalPrevTransaction j t = journalTransactionAt j (tindex t - 1)
-- | Unique transaction descriptions used in this journal.
journalDescriptions :: Journal -> [Text]
journalDescriptions = nubSort . map tdescription . jtxns
-- | All postings from this journal's transactions, in order. -- | All postings from this journal's transactions, in order.
journalPostings :: Journal -> [Posting] journalPostings :: Journal -> [Posting]
journalPostings = concatMap tpostings . jtxns journalPostings = concatMap tpostings . jtxns
@ -277,10 +275,22 @@ journalPostings = concatMap tpostings . jtxns
journalCommoditiesDeclared :: Journal -> [AccountName] journalCommoditiesDeclared :: Journal -> [AccountName]
journalCommoditiesDeclared = nubSort . M.keys . jcommodities journalCommoditiesDeclared = nubSort . M.keys . jcommodities
-- | Unique transaction descriptions used in this journal.
journalDescriptions :: Journal -> [Text]
journalDescriptions = nubSort . map tdescription . jtxns
-- | Sorted unique payees declared by payee directives in this journal. -- | Sorted unique payees declared by payee directives in this journal.
journalPayeesDeclared :: Journal -> [Payee] journalPayeesDeclared :: Journal -> [Payee]
journalPayeesDeclared = nubSort . map fst . jdeclaredpayees journalPayeesDeclared = nubSort . map fst . jdeclaredpayees
-- | Sorted unique payees used by transactions in this journal.
journalPayeesUsed :: Journal -> [Payee]
journalPayeesUsed = nubSort . map transactionPayee . jtxns
-- | Sorted unique payees used in transactions or declared by payee directives in this journal.
journalPayeesDeclaredOrUsed :: Journal -> [Payee]
journalPayeesDeclaredOrUsed j = nubSort $ journalPayeesDeclared j ++ journalPayeesUsed j
-- | Sorted unique account names posted to by this journal's transactions. -- | Sorted unique account names posted to by this journal's transactions.
journalAccountNamesUsed :: Journal -> [AccountName] journalAccountNamesUsed :: Journal -> [AccountName]
journalAccountNamesUsed = accountNamesFromPostings . journalPostings journalAccountNamesUsed = accountNamesFromPostings . journalPostings