bal/bs/cf/is: mention valuation type in report title

This commit is contained in:
Simon Michael 2019-05-09 15:39:43 -07:00
parent e5339218f7
commit 76342a3fd0
5 changed files with 62 additions and 38 deletions

View File

@ -3,6 +3,7 @@
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
module Hledger.Reports.BudgetReport 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. -- | Render a budget report as plain text suitable for console output.
budgetReportAsText :: ReportOpts -> BudgetReport -> String budgetReportAsText :: ReportOpts -> BudgetReport -> String
budgetReportAsText ropts budgetr@(PeriodicReport ( _, rows, _)) = budgetReportAsText ropts@ReportOpts{..} budgetr@(PeriodicReport ( _, rows, _)) =
printf "Budget performance in %s:\n\n" (showDateSpan $ budgetReportSpan budgetr) title ++ "\n\n" ++
++
tableAsText ropts showcell (maybetranspose $ budgetReportAsTable ropts budgetr) tableAsText ropts showcell (maybetranspose $ budgetReportAsTable ropts budgetr)
where 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 = actualwidth =
maximum [ maybe 0 (length . showMixedAmountOneLineWithoutPrice) amt maximum [ maybe 0 (length . showMixedAmountOneLineWithoutPrice) amt
| (_, _, _, amtandgoals, _, _) <- rows | (_, _, _, amtandgoals, _, _) <- rows
@ -314,14 +322,14 @@ budgetReportAsText ropts budgetr@(PeriodicReport ( _, rows, _)) =
toCost = normaliseMixedAmount . costOfMixedAmount toCost = normaliseMixedAmount . costOfMixedAmount
showamt :: MixedAmount -> String showamt :: MixedAmount -> String
showamt | color_ ropts = cshowMixedAmountOneLineWithoutPrice showamt | color_ = cshowMixedAmountOneLineWithoutPrice
| otherwise = showMixedAmountOneLineWithoutPrice | otherwise = showMixedAmountOneLineWithoutPrice
-- don't show the budget amount in color, it messes up alignment -- don't show the budget amount in color, it messes up alignment
showbudgetamt = showMixedAmountOneLineWithoutPrice showbudgetamt = showMixedAmountOneLineWithoutPrice
maybetranspose | transpose_ ropts = \(Table rh ch vals) -> Table ch rh (transpose vals) maybetranspose | transpose_ = \(Table rh ch vals) -> Table ch rh (transpose vals)
| otherwise = id | otherwise = id
-- | Build a 'Table' from a multi-column balance report. -- | Build a 'Table' from a multi-column balance report.
budgetReportAsTable :: ReportOpts -> BudgetReport -> Table String String (Maybe MixedAmount, Maybe MixedAmount) budgetReportAsTable :: ReportOpts -> BudgetReport -> Table String String (Maybe MixedAmount, Maybe MixedAmount)

View File

@ -573,15 +573,21 @@ multiBalanceReportHtmlFootRow ropts (acct:rest) =
-- | Render a multi-column balance report as plain text suitable for console output. -- | Render a multi-column balance report as plain text suitable for console output.
multiBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> String multiBalanceReportAsText :: ReportOpts -> MultiBalanceReport -> String
multiBalanceReportAsText opts r = multiBalanceReportAsText ropts@ReportOpts{..} r =
printf "%s in %s:\n\n" desc (showDateSpan $ multiBalanceReportSpan r) title ++ "\n\n" ++ (balanceReportTableAsText ropts $ balanceReportAsTable ropts r)
++ balanceReportTableAsText opts tabl
where where
tabl = balanceReportAsTable opts r title = printf "%s in %s%s:"
desc = case balancetype_ opts of (case balancetype_ of
PeriodChange -> "Balance changes" PeriodChange -> "Balance changes"
CumulativeChange -> "Ending balances (cumulative)" CumulativeChange -> "Ending balances (cumulative)"
HistoricalBalance -> "Ending balances (historical)" 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. -- | Build a 'Table' from a multi-column balance report.
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount

View File

@ -128,7 +128,10 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
"change":_ -> Just PeriodChange "change":_ -> Just PeriodChange
_ -> Nothing _ -> Nothing
balancetype = fromMaybe cbctype mBalanceTypeOverride balancetype = fromMaybe cbctype mBalanceTypeOverride
title = cbctitle ++ " " ++ showDateSpan requestedspan ++ maybe "" (' ':) mtitleclarification title =
cbctitle ++ " " ++ showDateSpan requestedspan
++ maybe "" (' ':) mtitleclarification
++ valuation
where where
requestedspan = queryDateSpan (date2_ ropts) userq `spanDefaultsFrom` journalDateSpan (date2_ ropts) j requestedspan = queryDateSpan (date2_ ropts) userq `spanDefaultsFrom` journalDateSpan (date2_ ropts) j
-- when user overrides, add an indication to the report title -- when user overrides, add an indication to the report title
@ -137,6 +140,13 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
PeriodChange -> "(Balance Changes)" PeriodChange -> "(Balance Changes)"
CumulativeChange -> "(Cumulative Ending Balances)" CumulativeChange -> "(Cumulative Ending Balances)"
HistoricalBalance -> "(Historical 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. -- Set balance type in the report options.
-- Also, use tree mode (by default, at least?) if --cumulative/--historical -- 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 -- are used in single column mode, since in that situation we will be using

View File

@ -339,7 +339,7 @@ P 2018/01/26 SHARE €10
assets:bank assets:bank
$ hledger -f - bal -M --budget --cumulative --forecast --value $ 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 || May Jun
================++========================================== ================++==========================================

View File

@ -360,7 +360,7 @@ $ hledger -f- bal -V
# 32. multicolumn balance report valued at transaction # 32. multicolumn balance report valued at transaction
$ hledger -f- bal -MTA --value-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 || Jan Feb Mar Total Average
===++================================= ===++=================================
@ -370,7 +370,7 @@ Balance changes in 2000q1:
# 33. multicolumn balance report valued at period end # 33. multicolumn balance report valued at period end
$ hledger -f- bal -M --value-at=period $ hledger -f- bal -M --value-at=period
Balance changes in 2000q1: Balance changes in 2000q1, valued at period ends:
|| Jan Feb Mar || Jan Feb Mar
===++=============== ===++===============
@ -380,7 +380,7 @@ Balance changes in 2000q1:
# 34. multicolumn balance report valued at period end with -T or -A # 34. multicolumn balance report valued at period end with -T or -A
$ hledger -f- bal -M --value-at=period -TA $ 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 || Jan Feb Mar Total Average
===++================================= ===++=================================
@ -390,7 +390,7 @@ Balance changes in 2000q1:
# 35. multicolumn balance report valued at other date # 35. multicolumn balance report valued at other date
$ hledger -f- bal -MTA --value-at=2000-01-15 $ 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 || Jan Feb Mar Total Average
===++================================= ===++=================================
@ -400,7 +400,7 @@ Balance changes in 2000q1:
# 36. multicolumn balance report valued today (with today >= 2000-04-01) # 36. multicolumn balance report valued today (with today >= 2000-04-01)
$ hledger -f- bal -M --value-at=now $ hledger -f- bal -M --value-at=now
Balance changes in 2000q1: Balance changes in 2000q1, current value:
|| Jan Feb Mar || Jan Feb Mar
===++=============== ===++===============
@ -410,7 +410,7 @@ Balance changes in 2000q1:
# 37. multicolumn balance report valued at default date (same as above) # 37. multicolumn balance report valued at default date (same as above)
$ hledger -f- bal -M -V $ hledger -f- bal -M -V
Balance changes in 2000q1: Balance changes in 2000q1, current value:
|| Jan Feb Mar || Jan Feb Mar
===++=============== ===++===============
@ -423,7 +423,7 @@ Balance changes in 2000q1:
# 38. multicolumn balance report with -H valued at transaction. # 38. multicolumn balance report with -H valued at transaction.
# The starting balance is 1 B (1 A valued at 2000/1/1, transaction date). # 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 $ 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 || 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. # 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. # 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 $ 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 || 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. # 40. multicolumn balance report with -H valued at other date.
# The starting balance is 5 B (1 A valued at 2000/1/15). # 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 $ 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 || 2000/02/29 2000/03/31
===++======================== ===++========================
@ -465,7 +465,7 @@ P 2000/04/01 A 4 B
(a) 1 A (a) 1 A
$ hledger -f- bal -ME -H -p200001-200004 --value-at=t $ 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 || 2000/01/31 2000/02/29 2000/03/31
===++==================================== ===++====================================
@ -474,18 +474,18 @@ Ending balances (historical) in 2000q1:
|| 1 B 1 B 1 B || 1 B 1 B 1 B
# 42. multicolumn balance report with -H, valuing each period's carried-over balances at period end. # 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 $ hledger -f- bal -ME -H -p200001-200004 --value-at=p
# Ending balances (historical) in 2000q1: Ending balances (historical) in 2000q1, valued at period ends:
# || 2000/01/31 2000/02/29 2000/03/31 || 2000/01/31 2000/02/29 2000/03/31
# ===++==================================== ===++====================================
# a || 5 B 2 B 3 B a || 5 B 2 B 3 B
# ---++------------------------------------ ---++------------------------------------
# || 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. # 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 $ 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 || 2000/01/31 2000/02/29 2000/03/31
===++==================================== ===++====================================
@ -527,7 +527,7 @@ Budget performance in 2000q1:
# 45. budget report, valued at transaction dates. # 45. budget report, valued at transaction dates.
$ hledger -f- bal -MTA --budget --value-at=t $ 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 || Jan Feb Mar Total Average
===++===================================================================================================== ===++=====================================================================================================
@ -537,7 +537,7 @@ Budget performance in 2000q1:
# 46. budget report, valued at period ends. # 46. budget report, valued at period ends.
$ hledger -f- bal -MTA --budget --value-at=p $ 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 || Jan Feb Mar Total Average
===++========================================================================================================= ===++=========================================================================================================
@ -547,7 +547,7 @@ Budget performance in 2000q1:
# 47. budget report, valued at other date. # 47. budget report, valued at other date.
$ hledger -f- bal -MTA --budget --value-at=2000-01-15 $ 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 || Jan Feb Mar Total Average
===++========================================================================================================== ===++==========================================================================================================