From 4a74680a2225de7bb1489947a55fb3c7cf370320 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 19 Nov 2020 14:59:08 -0800 Subject: [PATCH] ;lib: rename some budget report helpers The new names are of course verbose, but more consistent and revealing. --- hledger-lib/Hledger/Data/Journal.hs | 2 +- hledger-lib/Hledger/Reports/BudgetReport.hs | 29 ++++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index cd51f9f1c..837e57077 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -612,7 +612,7 @@ journalCheckBalanceAssertions = either Just (const Nothing) . journalBalanceTran -- WARN tricky algorithm and code ahead. -- -- Code overview as of 20190219, this could/should be simplified/documented more: --- parseAndFinaliseJournal['] (Cli/Utils.hs), journalAddForecast (Common.hs), budgetJournal (BudgetReport.hs), tests (BalanceReport.hs) +-- parseAndFinaliseJournal['] (Cli/Utils.hs), journalAddForecast (Common.hs), journalAddBudgetGoalTransactions (BudgetReport.hs), tests (BalanceReport.hs) -- journalBalanceTransactions -- runST -- runExceptT diff --git a/hledger-lib/Hledger/Reports/BudgetReport.hs b/hledger-lib/Hledger/Reports/BudgetReport.hs index 25fb1d98a..8a168cf0b 100644 --- a/hledger-lib/Hledger/Reports/BudgetReport.hs +++ b/hledger-lib/Hledger/Reports/BudgetReport.hs @@ -72,7 +72,7 @@ type BudgetDisplayCell = ((String, Int), Maybe ((String, Int), Maybe (String, In -- | Calculate budget goals from all periodic transactions, -- actual balance changes from the regular transactions, -- and compare these to get a 'BudgetReport'. --- Unbudgeted accounts may be hidden or renamed (see budgetRollup). +-- Unbudgeted accounts may be hidden or renamed (see journalWithBudgetAccountNames). budgetReport :: ReportSpec -> Bool -> DateSpan -> Journal -> BudgetReport budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport where @@ -88,12 +88,8 @@ budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport concatMap tpostings $ concatMap (`runPeriodicTransaction` reportspan) $ jperiodictxns j - actualj = - dbg5With (("account names adjusted for budget report:\n"++).pshow.journalAccountNamesUsed) $ - budgetRollUp budgetedaccts showunbudgeted j - budgetj = - -- dbg5With (("actual txns:\n"++).pshow.jtxns) $ - budgetJournal assrt ropts reportspan j + actualj = journalWithBudgetAccountNames budgetedaccts showunbudgeted j + budgetj = journalAddBudgetGoalTransactions assrt ropts reportspan j actualreport@(PeriodicReport actualspans _ _) = dbg5 "actualreport" $ multiBalanceReport rspec{rsOpts=ropts{empty_=True}} actualj budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) = @@ -107,11 +103,12 @@ budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport budgetreport = combineBudgetAndActual ropts j budgetgoalreport' actualreport -- | Use all periodic transactions in the journal to generate --- budget transactions in the specified report period. --- Budget transactions are similar to forecast transactions except --- their purpose is to define balance change goals, per account and period. -budgetJournal :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal -budgetJournal assrt _ropts reportspan j = +-- budget goal transactions in the specified report period. +-- Budget goal transactions are similar to forecast transactions except +-- their purpose and effect is to define balance change goals, per account and period, +-- for BudgetReport. +journalAddBudgetGoalTransactions :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal +journalAddBudgetGoalTransactions assrt _ropts reportspan j = either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts } -- PARTIAL: where budgetspan = dbg3 "budget span" $ reportspan @@ -130,10 +127,12 @@ budgetJournal assrt _ropts reportspan j = -- -- 2. subaccounts with no budget goal are merged with their closest parent account -- with a budget goal, so that only budgeted accounts are shown. --- This can be disabled by --empty. +-- This can be disabled by -E/--empty. -- -budgetRollUp :: [AccountName] -> Bool -> Journal -> Journal -budgetRollUp budgetedaccts showunbudgeted j = j { jtxns = remapTxn <$> jtxns j } +journalWithBudgetAccountNames :: [AccountName] -> Bool -> Journal -> Journal +journalWithBudgetAccountNames budgetedaccts showunbudgeted j = + dbg5With (("budget account names: "++).pshow.journalAccountNamesUsed) $ + j { jtxns = remapTxn <$> jtxns j } where remapTxn = mapPostings (map remapPosting) where