budget: show a budget report even with no interval (for whole journal period)

This commit is contained in:
Simon Michael 2018-04-24 23:00:05 -07:00
parent 568a442307
commit 9151f5004e
3 changed files with 39 additions and 27 deletions

View File

@ -66,18 +66,24 @@ budgetReport :: ReportOpts -> Bool -> Bool -> DateSpan -> Day -> Journal -> Budg
budgetReport ropts assrt showunbudgeted reportspan d j =
let
q = queryFromOpts d ropts
budgetj = budgetJournal assrt ropts reportspan j
budgetedaccts =
dbg2 "budgetedacctsinperiod" $
accountNamesFromPostings $
concatMap tpostings $
concatMap (flip runPeriodicTransaction reportspan) $
jperiodictxns j
actualj = budgetRollUp budgetedaccts showunbudgeted j
budgetgoalreport = dbg1 "budgetgoalreport" $ multiBalanceReport ropts q budgetj
actualreport = dbg1 "actualreport" $ multiBalanceReport ropts q actualj
actualj = dbg1 "actualj" $ budgetRollUp budgetedaccts showunbudgeted j
budgetj = dbg1 "budgetj" $ budgetJournal assrt ropts reportspan j
actualreport@(MultiBalanceReport (actualspans, _, _)) = dbg1 "actualreport" $ multiBalanceReport ropts q actualj
budgetgoalreport@(MultiBalanceReport (_, budgetgoalitems, budgetgoaltotals)) = dbg1 "budgetgoalreport" $ multiBalanceReport ropts q budgetj
budgetgoalreport'
-- If no interval is specified:
-- budgetgoalreport's span might be shorter actualreport's due to periodic txns;
-- it should be safe to replace it with the latter, so they combine well.
| interval_ ropts == NoInterval = MultiBalanceReport (actualspans, budgetgoalitems, budgetgoaltotals)
| otherwise = budgetgoalreport
in
dbg1 "budgetreport" $ combineBudgetAndActual budgetgoalreport actualreport
dbg1 "budgetreport" $ combineBudgetAndActual budgetgoalreport' actualreport
-- | Use all periodic transactions in the journal to generate
-- budget transactions in the specified report period.

View File

@ -308,9 +308,23 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
Left err -> error' $ unlines [err]
Right _ -> do
let format = outputFormatFromOpts opts
budget = boolopt "budget" rawopts
interval = interval_ ropts
case interval of
NoInterval -> do
case (budget, interval) of
(True, _) -> do
-- single or multicolumn budget report
reportspan <- reportSpan j ropts
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt showunbudgeted reportspan d j
where
showunbudgeted = boolopt "show-unbudgeted" rawopts
assrt = not $ ignore_assertions_ $ inputopts_ opts
render = case format of
"csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
_ -> budgetReportAsText ropts
writeOutput opts $ render budgetreport
(False, NoInterval) -> do
-- single column balance report
let report
| balancetype_ ropts `elem` [HistoricalBalance, CumulativeChange]
@ -325,20 +339,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
_ -> balanceReportAsText
writeOutput opts $ render ropts report
_ | boolopt "budget" rawopts -> do
-- multi column budget report
reportspan <- reportSpan j ropts
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt showunbudgeted reportspan d j
where
showunbudgeted = boolopt "show-unbudgeted" rawopts
assrt = not $ ignore_assertions_ $ inputopts_ opts
render = case format of
"csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
_ -> budgetReportAsText ropts
writeOutput opts $ render budgetreport
| otherwise -> do
_ -> do
-- multi column balance report
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
render = case format of

View File

@ -124,13 +124,18 @@ Budget performance in 2016/12/01-2016/12/03:
(b) 1
(c) 1
# 4. --budget with no interval has no effect.
# 4. --budget with no interval shows total budget for the journal period
# (in tabular format).
$ hledger -f- bal --budget
2 a
2 b
2 c
--------------------
6
Budget performance in 2018/01/01-2018/01/03:
|| 2018/01/01-2018/01/03
===++==========================
a || 2 [ 7% of 30]
b || 2 [ 2% of 100]
c || 2 [ 0% of 1000]
---++--------------------------
|| 6 [ 1% of 1130]
# 5. Multiple periodic transactions with different intervals are combined.
# Budget goals with lower frequency than the report are posted in the