clarify balance report/cumulative/historical/tree mode shenanigans
This commit is contained in:
parent
783c4c155c
commit
5d93c39922
@ -298,9 +298,11 @@ balance opts@CliOpts{reportopts_=ropts} j = do
|
|||||||
Right _ -> do
|
Right _ -> do
|
||||||
let format = outputFormatFromOpts opts
|
let format = outputFormatFromOpts opts
|
||||||
interval = interval_ ropts
|
interval = interval_ ropts
|
||||||
-- shenanigans: use single/multiBalanceReport when we must,
|
-- XXX shenanigans: use singleBalanceReport or multiBalanceReport when we must,
|
||||||
-- ie when there's a report interval, or --historical or -- cumulative.
|
-- ie when there's a report interval, or when --historical or --cumulative
|
||||||
|
-- are used (balanceReport doesn't handle those).
|
||||||
-- Otherwise prefer the older balanceReport since it can elide boring parents.
|
-- Otherwise prefer the older balanceReport since it can elide boring parents.
|
||||||
|
-- See also compoundBalanceCommandSingleColumnReport, singleBalanceReport etc.
|
||||||
case interval of
|
case interval of
|
||||||
NoInterval -> do
|
NoInterval -> do
|
||||||
let report
|
let report
|
||||||
|
|||||||
@ -95,8 +95,12 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
PeriodChange -> "(Balance Changes)"
|
PeriodChange -> "(Balance Changes)"
|
||||||
CumulativeChange -> "(Cumulative Ending Balances)"
|
CumulativeChange -> "(Cumulative Ending Balances)"
|
||||||
HistoricalBalance -> "(Historical Ending Balances)"
|
HistoricalBalance -> "(Historical Ending Balances)"
|
||||||
-- Set balance type in the report options.
|
-- Set balance type in the report options.
|
||||||
-- Also default to tree mode if --cumulative/--historical are used in single column mode. TODO: why ?
|
-- XXX 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
|
||||||
|
-- singleBalanceReport which does not support eliding boring parents,
|
||||||
|
-- and tree mode hides this.. or something..
|
||||||
|
-- see also compoundBalanceCommandSingleColumnReport, #565
|
||||||
ropts'
|
ropts'
|
||||||
| not (flat_ ropts) &&
|
| not (flat_ ropts) &&
|
||||||
interval_ ropts==NoInterval &&
|
interval_ ropts==NoInterval &&
|
||||||
@ -110,7 +114,9 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
|
|
||||||
-- single-column report
|
-- single-column report
|
||||||
NoInterval -> do
|
NoInterval -> do
|
||||||
let (subreportstr, total) = foldMap (uncurry (compoundBalanceCommandSingleColumnReport ropts' userq j)) cbcqueries
|
let
|
||||||
|
(subreportstr, total) =
|
||||||
|
foldMap (uncurry (compoundBalanceCommandSingleColumnReport ropts' userq j)) cbcqueries
|
||||||
putStrLn $ title ++ "\n"
|
putStrLn $ title ++ "\n"
|
||||||
mapM_ putStrLn subreportstr
|
mapM_ putStrLn subreportstr
|
||||||
unless (no_total_ ropts' || cmd=="cashflow") . mapM_ putStrLn $
|
unless (no_total_ ropts' || cmd=="cashflow") . mapM_ putStrLn $
|
||||||
@ -126,7 +132,8 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
-- multi-column report
|
-- multi-column report
|
||||||
_ -> do
|
_ -> do
|
||||||
let
|
let
|
||||||
(subreporttables, subreporttotals, Sum overalltotal) = foldMap (uncurry (compoundBalanceCommandMultiColumnReports ropts' userq j)) cbcqueries
|
(subreporttables, subreporttotals, Sum overalltotal) =
|
||||||
|
foldMap (uncurry (compoundBalanceCommandMultiColumnReports ropts' userq j)) cbcqueries
|
||||||
overalltable = case subreporttables of
|
overalltable = case subreporttables of
|
||||||
t1:ts -> foldl' concatTables t1 ts
|
t1:ts -> foldl' concatTables t1 ts
|
||||||
[] -> T.empty
|
[] -> T.empty
|
||||||
@ -176,18 +183,17 @@ compoundBalanceCommandSingleColumnReport
|
|||||||
-> String
|
-> String
|
||||||
-> (Journal -> Query)
|
-> (Journal -> Query)
|
||||||
-> ([String], Sum MixedAmount)
|
-> ([String], Sum MixedAmount)
|
||||||
compoundBalanceCommandSingleColumnReport ropts q0 j t q = ([view], Sum amt)
|
compoundBalanceCommandSingleColumnReport ropts userq j t subreportq = ([subreportstr], Sum amt)
|
||||||
where
|
where
|
||||||
q' = And [q0, q j]
|
q' = And [userq, subreportq j]
|
||||||
rep@(_ , amt)
|
rep@(_ , amt)
|
||||||
-- For --historical/--cumulative, we must use multiBalanceReport.
|
-- XXX For --historical/--cumulative, we must use singleBalanceReport
|
||||||
-- (This forces --no-elide.)
|
-- (which also forces --no-elide); otherwise we use balanceReport
|
||||||
-- See Balance.hs's implementation of 'balance' for more information
|
-- because it supports eliding boring parents.
|
||||||
| balancetype_ ropts `elem` [HistoricalBalance, CumulativeChange]
|
-- See also compoundBalanceCommand, Balance.hs -> balance.
|
||||||
= singleBalanceReport ropts q' j
|
| balancetype_ ropts `elem` [CumulativeChange, HistoricalBalance] = singleBalanceReport ropts q' j
|
||||||
| otherwise
|
| otherwise = balanceReport ropts q' j
|
||||||
= balanceReport ropts q' j
|
subreportstr = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
|
||||||
view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
|
|
||||||
|
|
||||||
-- | Run all the subreports for a multi-column compound balance command.
|
-- | Run all the subreports for a multi-column compound balance command.
|
||||||
-- Currently this returns a table of rendered balance amounts for each
|
-- Currently this returns a table of rendered balance amounts for each
|
||||||
@ -205,8 +211,7 @@ compoundBalanceCommandMultiColumnReports ropts q0 j t q = ([tabl], [coltotals],
|
|||||||
singlesection = "Cash" `isPrefixOf` t -- TODO temp
|
singlesection = "Cash" `isPrefixOf` t -- TODO temp
|
||||||
ropts' = ropts { no_total_ = singlesection && no_total_ ropts, empty_ = True }
|
ropts' = ropts { no_total_ = singlesection && no_total_ ropts, empty_ = True }
|
||||||
q' = And [q0, q j]
|
q' = And [q0, q j]
|
||||||
MultiBalanceReport (dates, rows, (coltotals,tot,avg)) =
|
MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = multiBalanceReport ropts' q' j
|
||||||
multiBalanceReport ropts' q' j
|
|
||||||
rows' | empty_ ropts = rows
|
rows' | empty_ ropts = rows
|
||||||
| otherwise = filter (not . emptyRow) rows
|
| otherwise = filter (not . emptyRow) rows
|
||||||
where
|
where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user