budget: show a budget report even with no interval (for whole journal period)
This commit is contained in:
parent
568a442307
commit
9151f5004e
@ -66,18 +66,24 @@ budgetReport :: ReportOpts -> Bool -> Bool -> DateSpan -> Day -> Journal -> Budg
|
|||||||
budgetReport ropts assrt showunbudgeted reportspan d j =
|
budgetReport ropts assrt showunbudgeted reportspan d j =
|
||||||
let
|
let
|
||||||
q = queryFromOpts d ropts
|
q = queryFromOpts d ropts
|
||||||
budgetj = budgetJournal assrt ropts reportspan j
|
|
||||||
budgetedaccts =
|
budgetedaccts =
|
||||||
dbg2 "budgetedacctsinperiod" $
|
dbg2 "budgetedacctsinperiod" $
|
||||||
accountNamesFromPostings $
|
accountNamesFromPostings $
|
||||||
concatMap tpostings $
|
concatMap tpostings $
|
||||||
concatMap (flip runPeriodicTransaction reportspan) $
|
concatMap (flip runPeriodicTransaction reportspan) $
|
||||||
jperiodictxns j
|
jperiodictxns j
|
||||||
actualj = budgetRollUp budgetedaccts showunbudgeted j
|
actualj = dbg1 "actualj" $ budgetRollUp budgetedaccts showunbudgeted j
|
||||||
budgetgoalreport = dbg1 "budgetgoalreport" $ multiBalanceReport ropts q budgetj
|
budgetj = dbg1 "budgetj" $ budgetJournal assrt ropts reportspan j
|
||||||
actualreport = dbg1 "actualreport" $ multiBalanceReport ropts q actualj
|
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
|
in
|
||||||
dbg1 "budgetreport" $ combineBudgetAndActual budgetgoalreport actualreport
|
dbg1 "budgetreport" $ combineBudgetAndActual 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 transactions in the specified report period.
|
||||||
|
|||||||
@ -308,9 +308,23 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
|
|||||||
Left err -> error' $ unlines [err]
|
Left err -> error' $ unlines [err]
|
||||||
Right _ -> do
|
Right _ -> do
|
||||||
let format = outputFormatFromOpts opts
|
let format = outputFormatFromOpts opts
|
||||||
|
budget = boolopt "budget" rawopts
|
||||||
interval = interval_ ropts
|
interval = interval_ ropts
|
||||||
case interval of
|
case (budget, interval) of
|
||||||
NoInterval -> do
|
(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
|
-- single column balance report
|
||||||
let report
|
let report
|
||||||
| balancetype_ ropts `elem` [HistoricalBalance, CumulativeChange]
|
| balancetype_ ropts `elem` [HistoricalBalance, CumulativeChange]
|
||||||
@ -325,20 +339,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
|
|||||||
_ -> balanceReportAsText
|
_ -> balanceReportAsText
|
||||||
writeOutput opts $ render ropts report
|
writeOutput opts $ render ropts report
|
||||||
|
|
||||||
_ | boolopt "budget" rawopts -> do
|
_ -> 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
|
|
||||||
-- multi column balance report
|
-- multi column balance report
|
||||||
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
|
let report = multiBalanceReport ropts (queryFromOpts d ropts) j
|
||||||
render = case format of
|
render = case format of
|
||||||
|
|||||||
@ -124,13 +124,18 @@ Budget performance in 2016/12/01-2016/12/03:
|
|||||||
(b) 1
|
(b) 1
|
||||||
(c) 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
|
$ hledger -f- bal --budget
|
||||||
2 a
|
Budget performance in 2018/01/01-2018/01/03:
|
||||||
2 b
|
|
||||||
2 c
|
|| 2018/01/01-2018/01/03
|
||||||
--------------------
|
===++==========================
|
||||||
6
|
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.
|
# 5. Multiple periodic transactions with different intervals are combined.
|
||||||
# Budget goals with lower frequency than the report are posted in the
|
# Budget goals with lower frequency than the report are posted in the
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user