refactor compoundBalanceCommandMultiColumnReport etc., more correct docs
This commit is contained in:
parent
5d93c39922
commit
48d909c695
@ -115,6 +115,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
-- single-column report
|
-- single-column report
|
||||||
NoInterval -> do
|
NoInterval -> do
|
||||||
let
|
let
|
||||||
|
-- concatenate the rendering and sum the totals from each subreport
|
||||||
(subreportstr, total) =
|
(subreportstr, total) =
|
||||||
foldMap (uncurry (compoundBalanceCommandSingleColumnReport ropts' userq j)) cbcqueries
|
foldMap (uncurry (compoundBalanceCommandSingleColumnReport ropts' userq j)) cbcqueries
|
||||||
putStrLn $ title ++ "\n"
|
putStrLn $ title ++ "\n"
|
||||||
@ -132,8 +133,9 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
-- multi-column report
|
-- multi-column report
|
||||||
_ -> do
|
_ -> do
|
||||||
let
|
let
|
||||||
|
-- list the tables, list the totals rows, and sum the totals from each subreport
|
||||||
(subreporttables, subreporttotals, Sum overalltotal) =
|
(subreporttables, subreporttotals, Sum overalltotal) =
|
||||||
foldMap (uncurry (compoundBalanceCommandMultiColumnReports ropts' userq j)) cbcqueries
|
foldMap (uncurry (compoundBalanceCommandMultiColumnReport 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
|
||||||
@ -173,9 +175,9 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} CliOpts{command_=cmd, repo
|
|||||||
concatTables (Table hLeft hTop dat) (Table hLeft' _ dat') =
|
concatTables (Table hLeft hTop dat) (Table hLeft' _ dat') =
|
||||||
Table (T.Group DoubleLine [hLeft, hLeft']) hTop (dat ++ dat')
|
Table (T.Group DoubleLine [hLeft, hLeft']) hTop (dat ++ dat')
|
||||||
|
|
||||||
-- | Run one subreport for a single-column compound balance command.
|
-- | Run one subreport for a compound balance command in single-column mode.
|
||||||
-- Currently this returns the plain text rendering of the subreport,
|
-- Currently this returns the plain text rendering of the subreport, and its total.
|
||||||
-- and its total.
|
-- The latter is wrapped in a Sum for easy monoidal combining.
|
||||||
compoundBalanceCommandSingleColumnReport
|
compoundBalanceCommandSingleColumnReport
|
||||||
:: ReportOpts
|
:: ReportOpts
|
||||||
-> Query
|
-> Query
|
||||||
@ -183,40 +185,47 @@ compoundBalanceCommandSingleColumnReport
|
|||||||
-> String
|
-> String
|
||||||
-> (Journal -> Query)
|
-> (Journal -> Query)
|
||||||
-> ([String], Sum MixedAmount)
|
-> ([String], Sum MixedAmount)
|
||||||
compoundBalanceCommandSingleColumnReport ropts userq j t subreportq = ([subreportstr], Sum amt)
|
compoundBalanceCommandSingleColumnReport ropts userq j subreporttitle subreportq =
|
||||||
|
([subreportstr], Sum total)
|
||||||
where
|
where
|
||||||
q' = And [userq, subreportq j]
|
q = And [subreportq j, userq]
|
||||||
rep@(_ , amt)
|
r@(_,total)
|
||||||
-- XXX For --historical/--cumulative, we must use singleBalanceReport
|
-- XXX For --historical/--cumulative, we must use singleBalanceReport;
|
||||||
-- (which also forces --no-elide); otherwise we use balanceReport
|
-- otherwise we use balanceReport -- because it supports eliding boring parents.
|
||||||
-- because it supports eliding boring parents.
|
|
||||||
-- See also compoundBalanceCommand, Balance.hs -> balance.
|
-- See also compoundBalanceCommand, Balance.hs -> balance.
|
||||||
| balancetype_ ropts `elem` [CumulativeChange, HistoricalBalance] = singleBalanceReport ropts q' j
|
| balancetype_ ropts `elem` [CumulativeChange, HistoricalBalance] = singleBalanceReport ropts q j
|
||||||
| otherwise = balanceReport ropts q' j
|
| otherwise = balanceReport ropts q j
|
||||||
subreportstr = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
|
subreportstr = intercalate "\n" [subreporttitle <> ":", balanceReportAsText ropts r]
|
||||||
|
|
||||||
-- | Run all the subreports for a multi-column compound balance command.
|
-- | Run one subreport for a compound balance command in multi-column mode.
|
||||||
-- Currently this returns a table of rendered balance amounts for each
|
-- Currently this returns the table of rendered balance amounts, including the
|
||||||
-- subreport (including a totals row), the totals row for each subreport
|
-- totals row; the totals row again, as mixedamounts; and the grand total.
|
||||||
-- (again, as mixedamounts), and the grand total.
|
-- The first two are wrapped in a list and the third in a Sum, for easy
|
||||||
compoundBalanceCommandMultiColumnReports
|
-- monoidal combining.
|
||||||
|
compoundBalanceCommandMultiColumnReport
|
||||||
:: ReportOpts
|
:: ReportOpts
|
||||||
-> Query
|
-> Query
|
||||||
-> Journal
|
-> Journal
|
||||||
-> String
|
-> String
|
||||||
-> (Journal -> Query)
|
-> (Journal -> Query)
|
||||||
-> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount)
|
-> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount)
|
||||||
compoundBalanceCommandMultiColumnReports ropts q0 j t q = ([tabl], [coltotals], Sum tot)
|
compoundBalanceCommandMultiColumnReport ropts userq j subreporttitle subreportq =
|
||||||
|
([tabl], [coltotals], Sum tot)
|
||||||
where
|
where
|
||||||
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]
|
where
|
||||||
MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = multiBalanceReport ropts' q' j
|
singlesection = "Cash" `isPrefixOf` subreporttitle -- TODO temp
|
||||||
|
q = And [subreportq j, userq]
|
||||||
|
-- run the report
|
||||||
|
MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = multiBalanceReport ropts' q j
|
||||||
|
-- maybe filter all-zero rows from the report
|
||||||
|
r = MultiBalanceReport (dates, rows', (coltotals, tot, avg))
|
||||||
|
where
|
||||||
rows' | empty_ ropts = rows
|
rows' | empty_ ropts = rows
|
||||||
| otherwise = filter (not . emptyRow) rows
|
| otherwise = filter (not . emptyRow) rows
|
||||||
where
|
where
|
||||||
emptyRow (_,_,_,amts,_,_) = all isZeroMixedAmount amts
|
emptyRow (_,_,_,amts,_,_) = all isZeroMixedAmount amts
|
||||||
r = MultiBalanceReport (dates, rows', (coltotals, tot, avg))
|
-- convert to a table for rendering
|
||||||
Table hLeft hTop dat = balanceReportAsTable ropts' r
|
Table hLeft hTop dat = balanceReportAsTable ropts' r
|
||||||
tabl = Table (T.Group SingleLine [Header t, hLeft]) hTop ([]:dat)
|
-- tweak the table layout
|
||||||
|
tabl = Table (T.Group SingleLine [Header subreporttitle, hLeft]) hTop ([]:dat)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user