diff --git a/hledger-lib/Hledger/Reports/BudgetReport.hs b/hledger-lib/Hledger/Reports/BudgetReport.hs index 23605fb6a..e6afb6be0 100644 --- a/hledger-lib/Hledger/Reports/BudgetReport.hs +++ b/hledger-lib/Hledger/Reports/BudgetReport.hs @@ -3,6 +3,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} module Hledger.Reports.BudgetReport @@ -268,11 +269,18 @@ budgetReportSpan (PeriodicReport (spans, _, _)) = DateSpan (spanStart $ head spa -- | Render a budget report as plain text suitable for console output. budgetReportAsText :: ReportOpts -> BudgetReport -> String -budgetReportAsText ropts budgetr@(PeriodicReport ( _, rows, _)) = - printf "Budget performance in %s:\n\n" (showDateSpan $ budgetReportSpan budgetr) - ++ +budgetReportAsText ropts@ReportOpts{..} budgetr@(PeriodicReport ( _, rows, _)) = + title ++ "\n\n" ++ tableAsText ropts showcell (maybetranspose $ budgetReportAsTable ropts budgetr) where + title = printf "Budget performance in %s%s:" + (showDateSpan $ budgetReportSpan budgetr) + (case valueTypeFromOpts ropts of + Just AtTransaction -> ", valued at transaction dates" + Just AtPeriod -> ", valued at period ends" + Just AtNow -> ", current value" + Just (AtDate d) -> ", valued at "++showDate d + Nothing -> "") actualwidth = maximum [ maybe 0 (length . showMixedAmountOneLineWithoutPrice) amt | (_, _, _, amtandgoals, _, _) <- rows @@ -314,14 +322,14 @@ budgetReportAsText ropts budgetr@(PeriodicReport ( _, rows, _)) = toCost = normaliseMixedAmount . costOfMixedAmount showamt :: MixedAmount -> String - showamt | color_ ropts = cshowMixedAmountOneLineWithoutPrice - | otherwise = showMixedAmountOneLineWithoutPrice + showamt | color_ = cshowMixedAmountOneLineWithoutPrice + | otherwise = showMixedAmountOneLineWithoutPrice -- don't show the budget amount in color, it messes up alignment showbudgetamt = showMixedAmountOneLineWithoutPrice - maybetranspose | transpose_ ropts = \(Table rh ch vals) -> Table ch rh (transpose vals) - | otherwise = id + maybetranspose | transpose_ = \(Table rh ch vals) -> Table ch rh (transpose vals) + | otherwise = id -- | Build a 'Table' from a multi-column balance report. budgetReportAsTable :: ReportOpts -> BudgetReport -> Table String String (Maybe MixedAmount, Maybe MixedAmount) diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index 898edffb9..c43c83a95 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -573,15 +573,21 @@ multiBalanceReportHtmlFootRow ropts (acct:rest) = -- | Render a multi-column balance report as plain text suitable for console output. multiBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> String -multiBalanceReportAsText opts r = - printf "%s in %s:\n\n" desc (showDateSpan $ multiBalanceReportSpan r) - ++ balanceReportTableAsText opts tabl +multiBalanceReportAsText ropts@ReportOpts{..} r = + title ++ "\n\n" ++ (balanceReportTableAsText ropts $ balanceReportAsTable ropts r) where - tabl = balanceReportAsTable opts r - desc = case balancetype_ opts of - PeriodChange -> "Balance changes" - CumulativeChange -> "Ending balances (cumulative)" - HistoricalBalance -> "Ending balances (historical)" + title = printf "%s in %s%s:" + (case balancetype_ of + PeriodChange -> "Balance changes" + CumulativeChange -> "Ending balances (cumulative)" + HistoricalBalance -> "Ending balances (historical)") + (showDateSpan $ multiBalanceReportSpan r) + (case valueTypeFromOpts ropts of + Just AtTransaction -> ", valued at transaction dates" + Just AtPeriod -> ", valued at period ends" + Just AtNow -> ", current value" + Just (AtDate d) -> ", valued at "++showDate d + Nothing -> "") -- | Build a 'Table' from a multi-column balance report. balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 4f57b3181..7a8f73a58 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -128,7 +128,10 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r "change":_ -> Just PeriodChange _ -> Nothing balancetype = fromMaybe cbctype mBalanceTypeOverride - title = cbctitle ++ " " ++ showDateSpan requestedspan ++ maybe "" (' ':) mtitleclarification + title = + cbctitle ++ " " ++ showDateSpan requestedspan + ++ maybe "" (' ':) mtitleclarification + ++ valuation where requestedspan = queryDateSpan (date2_ ropts) userq `spanDefaultsFrom` journalDateSpan (date2_ ropts) j -- when user overrides, add an indication to the report title @@ -137,6 +140,13 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r PeriodChange -> "(Balance Changes)" CumulativeChange -> "(Cumulative Ending Balances)" HistoricalBalance -> "(Historical Ending Balances)" + valuation = case valueTypeFromOpts ropts of + Just AtTransaction -> ", valued at transaction dates" + Just AtPeriod -> ", valued at period ends" + Just AtNow -> ", current value" + Just (AtDate d) -> ", valued at "++showDate d + Nothing -> "" + -- Set balance type in the report options. -- Also, use tree mode (by default, at least?) if --cumulative/--historical -- are used in single column mode, since in that situation we will be using diff --git a/tests/budget/budget.test b/tests/budget/budget.test index 509c4121e..75164d441 100644 --- a/tests/budget/budget.test +++ b/tests/budget/budget.test @@ -339,7 +339,7 @@ P 2018/01/26 SHARE €10 assets:bank $ hledger -f - bal -M --budget --cumulative --forecast --value -Budget performance in 2018/05/01-2018/06/30: +Budget performance in 2018/05/01-2018/06/30, current value: || May Jun ================++========================================== diff --git a/tests/journal/market-prices.test b/tests/journal/market-prices.test index be25ae2c5..d9260b755 100644 --- a/tests/journal/market-prices.test +++ b/tests/journal/market-prices.test @@ -360,7 +360,7 @@ $ hledger -f- bal -V # 32. multicolumn balance report valued at transaction $ hledger -f- bal -MTA --value-at=transaction -Balance changes in 2000q1: +Balance changes in 2000q1, valued at transaction dates: || Jan Feb Mar Total Average ===++================================= @@ -370,7 +370,7 @@ Balance changes in 2000q1: # 33. multicolumn balance report valued at period end $ hledger -f- bal -M --value-at=period -Balance changes in 2000q1: +Balance changes in 2000q1, valued at period ends: || Jan Feb Mar ===++=============== @@ -380,7 +380,7 @@ Balance changes in 2000q1: # 34. multicolumn balance report valued at period end with -T or -A $ hledger -f- bal -M --value-at=period -TA -Balance changes in 2000q1: +Balance changes in 2000q1, valued at period ends: || Jan Feb Mar Total Average ===++================================= @@ -390,7 +390,7 @@ Balance changes in 2000q1: # 35. multicolumn balance report valued at other date $ hledger -f- bal -MTA --value-at=2000-01-15 -Balance changes in 2000q1: +Balance changes in 2000q1, valued at 2000/01/15: || Jan Feb Mar Total Average ===++================================= @@ -400,7 +400,7 @@ Balance changes in 2000q1: # 36. multicolumn balance report valued today (with today >= 2000-04-01) $ hledger -f- bal -M --value-at=now -Balance changes in 2000q1: +Balance changes in 2000q1, current value: || Jan Feb Mar ===++=============== @@ -410,7 +410,7 @@ Balance changes in 2000q1: # 37. multicolumn balance report valued at default date (same as above) $ hledger -f- bal -M -V -Balance changes in 2000q1: +Balance changes in 2000q1, current value: || Jan Feb Mar ===++=============== @@ -423,7 +423,7 @@ Balance changes in 2000q1: # 38. multicolumn balance report with -H valued at transaction. # The starting balance is 1 B (1 A valued at 2000/1/1, transaction date). $ hledger -f- bal -M -H -b 200002 --value-at=transaction -Ending balances (historical) in 2000/02/01-2000/03/31: +Ending balances (historical) in 2000/02/01-2000/03/31, valued at transaction dates: || 2000/02/29 2000/03/31 ===++======================== @@ -434,7 +434,7 @@ Ending balances (historical) in 2000/02/01-2000/03/31: # 39. multicolumn balance report with -H valued at period end. # The starting balance is 5 B (1 A valued at 2000/1/31, day before report start).. and has no effect here. $ hledger -f- bal -M -H -b 200002 --value-at=period -Ending balances (historical) in 2000/02/01-2000/03/31: +Ending balances (historical) in 2000/02/01-2000/03/31, valued at period ends: || 2000/02/29 2000/03/31 ===++======================== @@ -445,7 +445,7 @@ Ending balances (historical) in 2000/02/01-2000/03/31: # 40. multicolumn balance report with -H valued at other date. # The starting balance is 5 B (1 A valued at 2000/1/15). $ hledger -f- bal -M -H -b 200002 --value-at=2000-01-15 -Ending balances (historical) in 2000/02/01-2000/03/31: +Ending balances (historical) in 2000/02/01-2000/03/31, valued at 2000/01/15: || 2000/02/29 2000/03/31 ===++======================== @@ -465,7 +465,7 @@ P 2000/04/01 A 4 B (a) 1 A $ hledger -f- bal -ME -H -p200001-200004 --value-at=t -Ending balances (historical) in 2000q1: +Ending balances (historical) in 2000q1, valued at transaction dates: || 2000/01/31 2000/02/29 2000/03/31 ===++==================================== @@ -474,18 +474,18 @@ Ending balances (historical) in 2000q1: || 1 B 1 B 1 B # 42. multicolumn balance report with -H, valuing each period's carried-over balances at period end. -# $ hledger -f- bal -ME -H -p200001-200004 --value-at=p -# Ending balances (historical) in 2000q1: +$ hledger -f- bal -ME -H -p200001-200004 --value-at=p +Ending balances (historical) in 2000q1, valued at period ends: -# || 2000/01/31 2000/02/29 2000/03/31 -# ===++==================================== -# a || 5 B 2 B 3 B -# ---++------------------------------------ -# || 5 B 2 B 3 B + || 2000/01/31 2000/02/29 2000/03/31 +===++==================================== + a || 5 B 2 B 3 B +---++------------------------------------ + || 5 B 2 B 3 B # 43. multicolumn balance report with -H, valuing each period's carried-over balances at other date. $ hledger -f- bal -ME -H -p200001-200004 --value-at=2000-01-15 -Ending balances (historical) in 2000q1: +Ending balances (historical) in 2000q1, valued at 2000/01/15: || 2000/01/31 2000/02/29 2000/03/31 ===++==================================== @@ -527,7 +527,7 @@ Budget performance in 2000q1: # 45. budget report, valued at transaction dates. $ hledger -f- bal -MTA --budget --value-at=t -Budget performance in 2000q1: +Budget performance in 2000q1, valued at transaction dates: || Jan Feb Mar Total Average ===++===================================================================================================== @@ -537,7 +537,7 @@ Budget performance in 2000q1: # 46. budget report, valued at period ends. $ hledger -f- bal -MTA --budget --value-at=p -Budget performance in 2000q1: +Budget performance in 2000q1, valued at period ends: || Jan Feb Mar Total Average ===++========================================================================================================= @@ -547,7 +547,7 @@ Budget performance in 2000q1: # 47. budget report, valued at other date. $ hledger -f- bal -MTA --budget --value-at=2000-01-15 -Budget performance in 2000q1: +Budget performance in 2000q1, valued at 2000/01/15: || Jan Feb Mar Total Average ===++==========================================================================================================