refactor compoundBalanceCommandMultiColumnReport etc.

This commit is contained in:
Simon Michael 2017-07-25 15:44:47 -07:00
parent 9d1ef30ecb
commit f49756231a

View File

@ -185,10 +185,10 @@ compoundBalanceCommandSingleColumnReport
-> String -> String
-> (Journal -> Query) -> (Journal -> Query)
-> ([String], Sum MixedAmount) -> ([String], Sum MixedAmount)
compoundBalanceCommandSingleColumnReport ropts userq j subreporttitle subreportq = compoundBalanceCommandSingleColumnReport ropts userq j subreporttitle subreportqfn =
([subreportstr], Sum total) ([subreportstr], Sum total)
where where
q = And [subreportq j, userq] q = And [subreportqfn j, userq]
r@(_,total) r@(_,total)
-- XXX For --historical/--cumulative, we must use singleBalanceReport; -- XXX For --historical/--cumulative, we must use singleBalanceReport;
-- otherwise we use balanceReport -- because it supports eliding boring parents. -- otherwise we use balanceReport -- because it supports eliding boring parents.
@ -198,7 +198,7 @@ compoundBalanceCommandSingleColumnReport ropts userq j subreporttitle subreportq
subreportstr = intercalate "\n" [subreporttitle <> ":", balanceReportAsText ropts r] subreportstr = intercalate "\n" [subreporttitle <> ":", balanceReportAsText ropts r]
-- | Run one subreport for a compound balance command in multi-column mode. -- | Run one subreport for a compound balance command in multi-column mode.
-- Currently this returns the table of rendered balance amounts, including the -- Currently this returns a table of rendered balance amounts, including the
-- totals row; the totals row again, as mixedamounts; and the grand total. -- totals row; the totals row again, as mixedamounts; and the grand total.
-- The first two are wrapped in a list and the third in a Sum, for easy -- The first two are wrapped in a list and the third in a Sum, for easy
-- monoidal combining. -- monoidal combining.
@ -209,16 +209,18 @@ compoundBalanceCommandMultiColumnReport
-> String -> String
-> (Journal -> Query) -> (Journal -> Query)
-> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount) -> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount)
compoundBalanceCommandMultiColumnReport ropts userq j subreporttitle subreportq = compoundBalanceCommandMultiColumnReport ropts userq j subreporttitle subreportqfn =
([tabl], [coltotals], Sum tot) ([tabl], [coltotals], Sum tot)
where where
-- disable totals row if there's just one section and --no-total
-- force --empty to ensure same columns in all sections, or something
ropts' = ropts { no_total_ = singlesection && no_total_ ropts, empty_ = True } ropts' = ropts { no_total_ = singlesection && no_total_ ropts, empty_ = True }
where where
singlesection = "Cash" `isPrefixOf` subreporttitle -- TODO temp singlesection = "Cash" `isPrefixOf` subreporttitle -- TODO temp
q = And [subreportq j, userq]
-- run the report -- run the report
q = And [subreportqfn j, userq]
MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = multiBalanceReport ropts' q j MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = multiBalanceReport ropts' q j
-- maybe filter all-zero rows from the report -- if user didn't specify --empty, now remove the all-zero rows
r = MultiBalanceReport (dates, rows', (coltotals, tot, avg)) r = MultiBalanceReport (dates, rows', (coltotals, tot, avg))
where where
rows' | empty_ ropts = rows rows' | empty_ ropts = rows
@ -226,6 +228,6 @@ compoundBalanceCommandMultiColumnReport ropts userq j subreporttitle subreportq
where where
emptyRow (_,_,_,amts,_,_) = all isZeroMixedAmount amts emptyRow (_,_,_,amts,_,_) = all isZeroMixedAmount amts
-- convert to a table for rendering -- convert to a table for rendering
Table hLeft hTop dat = balanceReportAsTable ropts' r Table lefthdrs tophdrs cells = balanceReportAsTable ropts' r
-- tweak the table layout -- tweak the table layout
tabl = Table (T.Group SingleLine [Header subreporttitle, hLeft]) hTop ([]:dat) tabl = Table (T.Group SingleLine [Header subreporttitle, lefthdrs]) tophdrs ([]:cells)