;lib: rename some budget report helpers

The new names are of course verbose, but more consistent and revealing.
This commit is contained in:
Simon Michael 2020-11-19 14:59:08 -08:00
parent 372c9724a8
commit 4a74680a22
2 changed files with 15 additions and 16 deletions

View File

@ -612,7 +612,7 @@ journalCheckBalanceAssertions = either Just (const Nothing) . journalBalanceTran
-- WARN tricky algorithm and code ahead. -- WARN tricky algorithm and code ahead.
-- --
-- Code overview as of 20190219, this could/should be simplified/documented more: -- 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 -- journalBalanceTransactions
-- runST -- runST
-- runExceptT -- runExceptT

View File

@ -72,7 +72,7 @@ type BudgetDisplayCell = ((String, Int), Maybe ((String, Int), Maybe (String, In
-- | Calculate budget goals from all periodic transactions, -- | Calculate budget goals from all periodic transactions,
-- actual balance changes from the regular transactions, -- actual balance changes from the regular transactions,
-- and compare these to get a 'BudgetReport'. -- 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 :: ReportSpec -> Bool -> DateSpan -> Journal -> BudgetReport
budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport
where where
@ -88,12 +88,8 @@ budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport
concatMap tpostings $ concatMap tpostings $
concatMap (`runPeriodicTransaction` reportspan) $ concatMap (`runPeriodicTransaction` reportspan) $
jperiodictxns j jperiodictxns j
actualj = actualj = journalWithBudgetAccountNames budgetedaccts showunbudgeted j
dbg5With (("account names adjusted for budget report:\n"++).pshow.journalAccountNamesUsed) $ budgetj = journalAddBudgetGoalTransactions assrt ropts reportspan j
budgetRollUp budgetedaccts showunbudgeted j
budgetj =
-- dbg5With (("actual txns:\n"++).pshow.jtxns) $
budgetJournal assrt ropts reportspan j
actualreport@(PeriodicReport actualspans _ _) = actualreport@(PeriodicReport actualspans _ _) =
dbg5 "actualreport" $ multiBalanceReport rspec{rsOpts=ropts{empty_=True}} actualj dbg5 "actualreport" $ multiBalanceReport rspec{rsOpts=ropts{empty_=True}} actualj
budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) = budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) =
@ -107,11 +103,12 @@ budgetReport rspec assrt reportspan j = dbg4 "sortedbudgetreport" budgetreport
budgetreport = combineBudgetAndActual ropts j budgetgoalreport' actualreport budgetreport = combineBudgetAndActual ropts j budgetgoalreport' actualreport
-- | Use all periodic transactions in the journal to generate -- | Use all periodic transactions in the journal to generate
-- budget transactions in the specified report period. -- budget goal transactions in the specified report period.
-- Budget transactions are similar to forecast transactions except -- Budget goal transactions are similar to forecast transactions except
-- their purpose is to define balance change goals, per account and period. -- their purpose and effect is to define balance change goals, per account and period,
budgetJournal :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal -- for BudgetReport.
budgetJournal assrt _ropts reportspan j = journalAddBudgetGoalTransactions :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal
journalAddBudgetGoalTransactions assrt _ropts reportspan j =
either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts } -- PARTIAL: either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts } -- PARTIAL:
where where
budgetspan = dbg3 "budget span" $ reportspan 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 -- 2. subaccounts with no budget goal are merged with their closest parent account
-- with a budget goal, so that only budgeted accounts are shown. -- 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 journalWithBudgetAccountNames :: [AccountName] -> Bool -> Journal -> Journal
budgetRollUp budgetedaccts showunbudgeted j = j { jtxns = remapTxn <$> jtxns j } journalWithBudgetAccountNames budgetedaccts showunbudgeted j =
dbg5With (("budget account names: "++).pshow.journalAccountNamesUsed) $
j { jtxns = remapTxn <$> jtxns j }
where where
remapTxn = mapPostings (map remapPosting) remapTxn = mapPostings (map remapPosting)
where where