From 165e70df7ae9e2ec41e49a86b63db3a6a6ccb6e8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 17 Jul 2024 08:26:43 +0100 Subject: [PATCH] imp: bs,cf,is: show interval in report title This makes the report interval clearer, eg when it's set unexpectedly by a config file. --- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 24 ++++++++++++++++++- hledger/test/balance/layout.test | 2 +- hledger/test/balancesheet.test | 10 ++++---- hledger/test/cashflow.test | 4 ++-- hledger/test/incomestatement.test | 6 ++--- hledger/test/journal/gain.test | 2 +- hledger/test/journal/valuechange.test | 2 +- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 37aa0f223..912b19a3e 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE LambdaCase #-} {-| Common helpers for making multi-section balance report commands @@ -124,7 +125,8 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r ropts' = ropts{balanceaccum_=balanceaccumulation} title = - T.pack cbctitle + maybe "" (<>" ") mintervalstr + <> T.pack cbctitle <> " " <> titledatestr <> maybe "" (" "<>) mtitleclarification @@ -143,6 +145,8 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r enddates = map (addDays (-1)) . mapMaybe spanEnd $ cbrDates cbr -- these spans will always have a definite end date requestedspan = fst $ reportSpan j rspec + mintervalstr = showInterval interval_ + -- when user overrides, add an indication to the report title -- Do we need to deal with overridden BalanceCalculation? mtitleclarification = case (balancecalc_, balanceaccumulation, mbalanceAccumulationOverride) of @@ -186,6 +190,24 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r "json" -> toJsonText x -> error' $ unsupportedOutputFormatError x +-- | Show a simplified description of an Interval. +showInterval :: Interval -> Maybe T.Text +showInterval = \case + NoInterval -> Nothing + Days 1 -> Just "Daily" + Weeks 1 -> Just "Weekly" + Weeks 2 -> Just "Biweekly" + Months 1 -> Just "Monthly" + Months 2 -> Just "Bimonthly" + Months 3 -> Just "Quarterly" + Months 6 -> Just "Half-yearly" + Months 12 -> Just "Yearly" + Quarters 1 -> Just "Quarterly" + Quarters 2 -> Just "Half-yearly" + Years 1 -> Just "Yearly" + Years 2 -> Just "Biannual" + _ -> Just "Periodic" + -- | Summarise one or more (inclusive) end dates, in a way that's -- visually different from showDateSpan, suggesting discrete end dates -- rather than a continuous span. diff --git a/hledger/test/balance/layout.test b/hledger/test/balance/layout.test index ee183eec7..30e440508 100644 --- a/hledger/test/balance/layout.test +++ b/hledger/test/balance/layout.test @@ -142,7 +142,7 @@ Balance changes in 2012-01-01..2014-12-31: # ** 13. Multicolumn income statement with --row-total, --average, and --summary-only $ hledger -f bcexample.hledger is -Y income expenses:food -3 --layout=bare --row-total --average --summary-only -Income Statement 2012-01-01..2014-12-31 +Yearly Income Statement 2012-01-01..2014-12-31 || Commodity Total Average ==========================++================================= diff --git a/hledger/test/balancesheet.test b/hledger/test/balancesheet.test index 5c88dc38a..3011a6264 100644 --- a/hledger/test/balancesheet.test +++ b/hledger/test/balancesheet.test @@ -69,7 +69,7 @@ Balance Sheet 2016-01-01 # Total || $1 $1 $1 $1 $1 0 0 0 0 0 0 0 # $ hledger -f sample.journal balancesheet -p 'monthly in 2008' -Balance Sheet 2008-01-31..2008-12-31 +Monthly Balance Sheet 2008-01-31..2008-12-31 || 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 ======================++================================================================================================================================================ @@ -113,7 +113,7 @@ Balance Sheet 2008-01-31..2008-12-31 # Total || $1 $1 $1 $1 $1 0 0 0 0 0 0 0 # $ hledger -f sample.journal balancesheet -p 'monthly in 2008' --tree -Balance Sheet 2008-01-31..2008-12-31 +Monthly Balance Sheet 2008-01-31..2008-12-31 || 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 ===================++================================================================================================================================================ @@ -139,7 +139,7 @@ Balance Sheet 2008-01-31..2008-12-31 # Total column is requested but not shown because balancesheet is in historical mode # by default (shows ending balances). $ hledger -f sample.journal balancesheet -p 'monthly in 2008' -NAT -Balance Sheet 2008-01-31..2008-12-31 +Monthly Balance Sheet 2008-01-31..2008-12-31 || 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 Average ======================++========================================================================================================================================================= @@ -202,7 +202,7 @@ Balance Sheet 2017-01-01 2017/1/1 (assets) $1 $ hledger -f- balancesheet -YA -Balance Sheet 2017-12-31 +Yearly Balance Sheet 2017-12-31 || 2017-12-31 Average =============++===================== @@ -226,7 +226,7 @@ Balance Sheet 2017-12-31 b $ hledger -f - balancesheet -M --pretty -Balance Sheet 2016-01-31 +Monthly Balance Sheet 2016-01-31 ┌─────────────╥────────────┐ │ ║ 2016-01-31 │ diff --git a/hledger/test/cashflow.test b/hledger/test/cashflow.test index f27977758..6f6424e82 100644 --- a/hledger/test/cashflow.test +++ b/hledger/test/cashflow.test @@ -95,7 +95,7 @@ Cashflow Statement 2016-10 # ** 6. Multicolumn test $ hledger -f sample.journal cashflow -p 'monthly in 2008' -Cashflow Statement 2008 +Monthly Cashflow Statement 2008 || Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ======================++============================================================ @@ -110,7 +110,7 @@ Cashflow Statement 2008 # ** 7. Multicolumn test (historical) $ hledger -f sample.journal cashflow -p 'monthly in 2008' -A --historical -Cashflow Statement 2008-01-31..2008-12-31 (Historical Ending Balances) +Monthly Cashflow Statement 2008-01-31..2008-12-31 (Historical Ending Balances) || 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 Average ======================++========================================================================================================================================================= diff --git a/hledger/test/incomestatement.test b/hledger/test/incomestatement.test index a9d6043ab..6c3ddf668 100644 --- a/hledger/test/incomestatement.test +++ b/hledger/test/incomestatement.test @@ -203,7 +203,7 @@ Income Statement 2016-10 # Total || $-1 0 0 0 0 $1 0 0 0 0 0 0 0 0 # $ hledger -f sample.journal incomestatement -p 'monthly in 2008' -AT -Income Statement 2008 +Monthly Income Statement 2008 || Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total Average ===================++============================================================================== @@ -246,7 +246,7 @@ Income Statement 2008 # Total || $-1 $-1 $-1 $-1 $-1 0 0 0 0 0 0 0 # $ hledger -f sample.journal incomestatement -p 'monthly in 2008' --historical -Income Statement 2008-01-31..2008-12-31 (Historical Ending Balances) +Monthly Income Statement 2008-01-31..2008-12-31 (Historical Ending Balances) || 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 ===================++================================================================================================================================================ @@ -268,7 +268,7 @@ Income Statement 2008-01-31..2008-12-31 (Historical Ending Balances) # ** 8. Percentage test $ hledger -f sample.journal incomestatement -p 'quarterly 2008' -T --average -% --no-total -Income Statement 2008 +Quarterly Income Statement 2008 || 2008Q1 2008Q2 2008Q3 2008Q4 Total Average ===================++==================================================== diff --git a/hledger/test/journal/gain.test b/hledger/test/journal/gain.test index c55d7a6df..a56a8f98b 100644 --- a/hledger/test/journal/gain.test +++ b/hledger/test/journal/gain.test @@ -81,7 +81,7 @@ Historical gain in 2000-01, valued at 2000-02-01: # ** 7. also works in balancesheet $ hledger -f- bs -M --gain --no-total -Balance Sheet 1999-12-31..2000-02-29 (Historical Gain), valued at period ends +Monthly Balance Sheet 1999-12-31..2000-02-29 (Historical Gain), valued at period ends || 1999-12-31 2000-01-31 2000-02-29 =============++==================================== diff --git a/hledger/test/journal/valuechange.test b/hledger/test/journal/valuechange.test index 654e24809..812c080ad 100644 --- a/hledger/test/journal/valuechange.test +++ b/hledger/test/journal/valuechange.test @@ -59,7 +59,7 @@ Ending balances (historical) in 2000-01-01..2000-04-30, valued at period ends: # ** 4. Balance sheet also reports on value change, and --valuechange overrides # the historical period $ hledger -f- balancesheet -MN --valuechange -b 2000 -Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes) +Monthly Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes) || Jan Feb Mar Apr =============++======================