cli: Use PeriodicReport.
This commit is contained in:
parent
2e20d0717f
commit
8882b6fc85
@ -458,18 +458,19 @@ renderComponent1 opts (acctname, depth, total) (FormatField ljust min max field)
|
|||||||
-- The CSV will always include the initial headings row,
|
-- The CSV will always include the initial headings row,
|
||||||
-- and will include the final totals row unless --no-total is set.
|
-- and will include the final totals row unless --no-total is set.
|
||||||
multiBalanceReportAsCsv :: ReportOpts -> MultiBalanceReport -> CSV
|
multiBalanceReportAsCsv :: ReportOpts -> MultiBalanceReport -> CSV
|
||||||
multiBalanceReportAsCsv opts@ReportOpts{average_, row_total_} (MultiBalanceReport (colspans, items, (coltotals,tot,avg))) =
|
multiBalanceReportAsCsv opts@ReportOpts{average_, row_total_}
|
||||||
|
(PeriodicReport colspans items (PeriodicReportRow _ _ coltotals tot avg)) =
|
||||||
maybetranspose $
|
maybetranspose $
|
||||||
("Account" : map showDateSpan colspans
|
("Account" : map showDateSpan colspans
|
||||||
++ ["Total" | row_total_]
|
++ ["Total" | row_total_]
|
||||||
++ ["Average" | average_]
|
++ ["Average" | average_]
|
||||||
) :
|
) :
|
||||||
[T.unpack (maybeAccountNameDrop opts a) :
|
[T.unpack (maybeAccountNameDrop opts $ acctFull a) :
|
||||||
map showMixedAmountOneLineWithoutPrice
|
map showMixedAmountOneLineWithoutPrice
|
||||||
(amts
|
(amts
|
||||||
++ [rowtot | row_total_]
|
++ [rowtot | row_total_]
|
||||||
++ [rowavg | average_])
|
++ [rowavg | average_])
|
||||||
| (a, _, _, amts, rowtot, rowavg) <- items]
|
| PeriodicReportRow a _ amts rowtot rowavg <- items]
|
||||||
++
|
++
|
||||||
if no_total_ opts
|
if no_total_ opts
|
||||||
then []
|
then []
|
||||||
@ -583,7 +584,7 @@ multiBalanceReportAsText ropts@ReportOpts{..} r =
|
|||||||
PeriodChange -> "Balance changes"
|
PeriodChange -> "Balance changes"
|
||||||
CumulativeChange -> "Ending balances (cumulative)"
|
CumulativeChange -> "Ending balances (cumulative)"
|
||||||
HistoricalBalance -> "Ending balances (historical)")
|
HistoricalBalance -> "Ending balances (historical)")
|
||||||
(showDateSpan $ multiBalanceReportSpan r)
|
(showDateSpan $ periodicReportSpan r)
|
||||||
(case value_ of
|
(case value_ of
|
||||||
Just (AtCost _mc) -> ", valued at cost"
|
Just (AtCost _mc) -> ", valued at cost"
|
||||||
Just (AtEnd _mc) -> ", valued at period ends"
|
Just (AtEnd _mc) -> ", valued at period ends"
|
||||||
@ -596,7 +597,8 @@ multiBalanceReportAsText ropts@ReportOpts{..} r =
|
|||||||
|
|
||||||
-- | Build a 'Table' from a multi-column balance report.
|
-- | Build a 'Table' from a multi-column balance report.
|
||||||
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount
|
balanceReportAsTable :: ReportOpts -> MultiBalanceReport -> Table String String MixedAmount
|
||||||
balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_} (MultiBalanceReport (colspans, items, (coltotals,tot,avg))) =
|
balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_}
|
||||||
|
(PeriodicReport colspans items (PeriodicReportRow _ _ coltotals tot avg)) =
|
||||||
maybetranspose $
|
maybetranspose $
|
||||||
addtotalrow $
|
addtotalrow $
|
||||||
Table
|
Table
|
||||||
@ -612,10 +614,10 @@ balanceReportAsTable opts@ReportOpts{average_, row_total_, balancetype_} (MultiB
|
|||||||
++ [" Total" | totalscolumn]
|
++ [" Total" | totalscolumn]
|
||||||
++ ["Average" | average_]
|
++ ["Average" | average_]
|
||||||
accts = map renderacct items
|
accts = map renderacct items
|
||||||
renderacct (a,a',i,_,_,_)
|
renderacct (PeriodicReportRow (AccountLeaf a a') i _ _ _)
|
||||||
| tree_ opts = replicate ((i-1)*2) ' ' ++ T.unpack a'
|
| tree_ opts = replicate ((i-1)*2) ' ' ++ T.unpack a'
|
||||||
| otherwise = T.unpack $ maybeAccountNameDrop opts a
|
| otherwise = T.unpack $ maybeAccountNameDrop opts a
|
||||||
rowvals (_,_,_,as,rowtot,rowavg) = as
|
rowvals (PeriodicReportRow _ _ as rowtot rowavg) = as
|
||||||
++ [rowtot | totalscolumn]
|
++ [rowtot | totalscolumn]
|
||||||
++ [rowavg | average_]
|
++ [rowavg | average_]
|
||||||
addtotalrow | no_total_ opts = id
|
addtotalrow | no_total_ opts = id
|
||||||
|
|||||||
@ -151,15 +151,15 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
|
|||||||
subreports =
|
subreports =
|
||||||
map (\CBCSubreportSpec{..} ->
|
map (\CBCSubreportSpec{..} ->
|
||||||
(cbcsubreporttitle
|
(cbcsubreporttitle
|
||||||
,mbrNormaliseSign cbcsubreportnormalsign $ -- <- convert normal-negative to normal-positive
|
,prNormaliseSign cbcsubreportnormalsign $ -- <- convert normal-negative to normal-positive
|
||||||
compoundBalanceSubreport ropts' userq j priceoracle cbcsubreportquery cbcsubreportnormalsign
|
compoundBalanceSubreport ropts' userq j priceoracle cbcsubreportquery cbcsubreportnormalsign
|
||||||
,cbcsubreportincreasestotal
|
,cbcsubreportincreasestotal
|
||||||
))
|
))
|
||||||
cbcqueries
|
cbcqueries
|
||||||
|
|
||||||
subtotalrows =
|
subtotalrows =
|
||||||
[(coltotals, increasesoveralltotal)
|
[(prrAmounts $ prTotals report, increasesoveralltotal)
|
||||||
| (_, MultiBalanceReport (_,_,(coltotals,_,_)), increasesoveralltotal) <- subreports
|
| (_, report, increasesoveralltotal) <- subreports
|
||||||
]
|
]
|
||||||
|
|
||||||
-- Sum the subreport totals by column. Handle these cases:
|
-- Sum the subreport totals by column. Handle these cases:
|
||||||
@ -186,7 +186,7 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
|
|||||||
|
|
||||||
colspans =
|
colspans =
|
||||||
case subreports of
|
case subreports of
|
||||||
(_, MultiBalanceReport (ds,_,_), _):_ -> ds
|
(_, PeriodicReport ds _ _, _):_ -> ds
|
||||||
[] -> []
|
[] -> []
|
||||||
|
|
||||||
title =
|
title =
|
||||||
@ -261,20 +261,20 @@ compoundBalanceSubreport ropts@ReportOpts{..} userq j priceoracle subreportqfn s
|
|||||||
ropts' = ropts { empty_=True, normalbalance_=Just subreportnormalsign }
|
ropts' = ropts { empty_=True, normalbalance_=Just subreportnormalsign }
|
||||||
-- run the report
|
-- run the report
|
||||||
q = And [subreportqfn j, userq]
|
q = And [subreportqfn j, userq]
|
||||||
r@(MultiBalanceReport (dates, rows, totals)) = multiBalanceReportWith ropts' q j priceoracle
|
r@(PeriodicReport dates rows totals) = multiBalanceReportWith ropts' q j priceoracle
|
||||||
-- if user didn't specify --empty, now remove the all-zero rows, unless they have non-zero subaccounts
|
-- if user didn't specify --empty, now remove the all-zero rows, unless they have non-zero subaccounts
|
||||||
-- in this report
|
-- in this report
|
||||||
r' | empty_ = r
|
r' | empty_ = r
|
||||||
| otherwise = MultiBalanceReport (dates, rows', totals)
|
| otherwise = PeriodicReport dates rows' totals
|
||||||
where
|
where
|
||||||
nonzeroaccounts =
|
nonzeroaccounts =
|
||||||
dbg1 "nonzeroaccounts" $
|
dbg1 "nonzeroaccounts" $
|
||||||
catMaybes $ map (\(act,_,_,amts,_,_) ->
|
mapMaybe (\(PeriodicReportRow act _ amts _ _) ->
|
||||||
if not (all isZeroMixedAmount amts) then Just act else Nothing) rows
|
if not (all isZeroMixedAmount amts) then Just (acctFull act) else Nothing) rows
|
||||||
rows' = filter (not . emptyRow) rows
|
rows' = filter (not . emptyRow) rows
|
||||||
where
|
where
|
||||||
emptyRow (act,_,_,amts,_,_) =
|
emptyRow (PeriodicReportRow act _ amts _ _) =
|
||||||
all isZeroMixedAmount amts && all (not . (act `isAccountNamePrefixOf`)) nonzeroaccounts
|
all isZeroMixedAmount amts && all (not . (acctFull act `isAccountNamePrefixOf`)) nonzeroaccounts
|
||||||
|
|
||||||
-- | Render a compound balance report as plain text suitable for console output.
|
-- | Render a compound balance report as plain text suitable for console output.
|
||||||
{- Eg:
|
{- Eg:
|
||||||
@ -367,8 +367,7 @@ compoundBalanceReportAsCsv ropts (title, colspans, subreports, (coltotals, grand
|
|||||||
(if row_total_ ropts then (1+) else id) $
|
(if row_total_ ropts then (1+) else id) $
|
||||||
(if average_ ropts then (1+) else id) $
|
(if average_ ropts then (1+) else id) $
|
||||||
maximum $ -- depends on non-null subreports
|
maximum $ -- depends on non-null subreports
|
||||||
map (\(MultiBalanceReport (amtcolheadings, _, _)) -> length amtcolheadings) $
|
map (length . prDates . second3) subreports
|
||||||
map second3 subreports
|
|
||||||
addtotals
|
addtotals
|
||||||
| no_total_ ropts || length subreports == 1 = id
|
| no_total_ ropts || length subreports == 1 = id
|
||||||
| otherwise = (++
|
| otherwise = (++
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user