cli: Allow overriding with --periodic (rather than the old --change) and properly calculate requestedspan in CompoundBalanceReport.

This commit is contained in:
Stephen Morgan 2021-03-04 09:58:36 +11:00 committed by Simon Michael
parent e9f04d5ed6
commit d931e4919e
2 changed files with 34 additions and 22 deletions

View File

@ -111,7 +111,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
parse = \case parse = \case
"historical" -> Just HistoricalBalance "historical" -> Just HistoricalBalance
"cumulative" -> Just CumulativeChange "cumulative" -> Just CumulativeChange
"change" -> Just PeriodChange "periodic" -> Just PeriodChange
_ -> Nothing _ -> Nothing
balancetype = fromMaybe cbctype mBalanceTypeOverride balancetype = fromMaybe cbctype mBalanceTypeOverride
-- Set balance type in the report options. -- Set balance type in the report options.
@ -135,8 +135,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportspec_=r
_ -> showDateSpan requestedspan _ -> showDateSpan requestedspan
where where
enddates = map (addDays (-1)) . mapMaybe spanEnd $ cbrDates cbr -- these spans will always have a definite end date enddates = map (addDays (-1)) . mapMaybe spanEnd $ cbrDates cbr -- these spans will always have a definite end date
requestedspan = queryDateSpan date2_ (rsQuery rspec) requestedspan = reportSpan j rspec
`spanDefaultsFrom` journalDateSpan date2_ j
-- when user overrides, add an indication to the report title -- when user overrides, add an indication to the report title
-- Do we need to deal with overridden ReportType? -- Do we need to deal with overridden ReportType?

View File

@ -7,16 +7,16 @@ P 2000/03/01 A 3 B
P 2000/04/01 A 4 B P 2000/04/01 A 4 B
1999/01/01 1999/01/01
(a) 2 A @ 4 B (assets) 2 A @ 4 B
2000/01/01 2000/01/01
(a) 1 A @ 6 B (assets) 1 A @ 6 B
2000/02/01 2000/02/01
(a) 1 A @ 7 B (assets) 1 A @ 7 B
2000/03/01 2000/03/01
(a) 1 A @ 8 B (assets) 1 A @ 8 B
# 1. multicolumn balance report showing changes in period-end values # 1. multicolumn balance report showing changes in period-end values
# Initial balance 2 A, valued at 10 B each, total 20 B # Initial balance 2 A, valued at 10 B each, total 20 B
@ -27,29 +27,42 @@ P 2000/04/01 A 4 B
$ hledger -f- bal -M --valuechange -b 2000 $ hledger -f- bal -M --valuechange -b 2000
Period-end value changes in 2000-01-01..2000-04-30: Period-end value changes in 2000-01-01..2000-04-30:
|| Jan Feb Mar Apr || Jan Feb Mar Apr
===++====================== ========++======================
a || -5 B -7 B 7 B 5 B assets || -5 B -7 B 7 B 5 B
---++---------------------- --------++----------------------
|| -5 B -7 B 7 B 5 B || -5 B -7 B 7 B 5 B
# 2. Cumulative multicolumn balance report showing changes in period-end values # 2. Cumulative multicolumn balance report showing changes in period-end values
$ hledger -f- bal -M --valuechange --cumulative -b 2000 $ hledger -f- bal -M --valuechange --cumulative -b 2000
Cumulative period-end value changes in 2000-01-01..2000-04-30: Cumulative period-end value changes in 2000-01-01..2000-04-30:
|| 2000-01-31 2000-02-29 2000-03-31 2000-04-30 || 2000-01-31 2000-02-29 2000-03-31 2000-04-30
===++================================================ ========++================================================
a || -5 B -12 B -5 B 0 assets || -5 B -12 B -5 B 0
---++------------------------------------------------ --------++------------------------------------------------
|| -5 B -12 B -5 B 0 || -5 B -12 B -5 B 0
# 3. Historical multicolumn balance report showing changes in period-end values is # 3. Historical multicolumn balance report showing changes in period-end values is
# the same as a historical report # the same as a historical report
$ hledger -f- bal -M --valuechange --historical -b 2000 $ hledger -f- bal -M --valuechange --historical -b 2000
Ending balances (historical) in 2000-01-01..2000-04-30, valued at period ends: Ending balances (historical) in 2000-01-01..2000-04-30, valued at period ends:
|| 2000-01-31 2000-02-29 2000-03-31 2000-04-30 || 2000-01-31 2000-02-29 2000-03-31 2000-04-30
===++================================================ ========++================================================
a || 15 B 8 B 15 B 20 B assets || 15 B 8 B 15 B 20 B
---++------------------------------------------------ --------++------------------------------------------------
|| 15 B 8 B 15 B 20 B || 15 B 8 B 15 B 20 B
# 4. Balance sheet also reports on value change
$ hledger -f- balancesheet -MN --valuechange --periodic -b 2000
Balance Sheet 2000-01-01..2000-04-30 (Period-End Value Changes)
|| Jan Feb Mar Apr
=============++======================
Assets ||
-------------++----------------------
assets || -5 B -7 B 7 B 5 B
=============++======================
Liabilities ||
-------------++----------------------