mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
lib: rename, clarify purpose of balanceReportFromMultiBalanceReport
This commit is contained in:
parent
6c60e4a97b
commit
88ef586480
@ -97,7 +97,7 @@ main = do
|
||||
d <- getCurrentDay
|
||||
j <- defaultJournal
|
||||
let ropts = (reportopts_ $ cliopts_ chopts)
|
||||
let balreport = singleBalanceReport ropts (queryFromOpts d ropts) j
|
||||
let balreport = balanceReportFromMultiBalanceReport ropts (queryFromOpts d ropts) j
|
||||
let go -- | "--help" `elem` (rawopts_ $ cliopts_ chopts) = putStr (showModeHelp chartmode) >> exitSuccess
|
||||
-- | "--version" `elem` (rawopts_ $ cliopts_ chopts) = putStrLn progversion >> exitSuccess
|
||||
| otherwise = withJournalAndChartOptsDo chopts (writeChart balreport)
|
||||
|
@ -43,7 +43,7 @@ import Hledger.Reports.ReportOptions
|
||||
|
||||
|
||||
|
||||
-- | A simple single-column balance report. It has:
|
||||
-- | A simple balance report. It has:
|
||||
--
|
||||
-- 1. a list of items, one per account, each containing:
|
||||
--
|
||||
|
@ -9,7 +9,7 @@ module Hledger.Reports.MultiBalanceReports (
|
||||
MultiBalanceReport(..),
|
||||
MultiBalanceReportRow,
|
||||
multiBalanceReport,
|
||||
singleBalanceReport,
|
||||
balanceReportFromMultiBalanceReport,
|
||||
-- mbrNegate,
|
||||
-- mbrNormaliseSign,
|
||||
|
||||
@ -74,23 +74,11 @@ instance Show MultiBalanceReport where
|
||||
-- type alias just to remind us which AccountNames might be depth-clipped, below.
|
||||
type ClippedAccountName = AccountName
|
||||
|
||||
-- | Generates a single column BalanceReport like balanceReport, but uses
|
||||
-- multiBalanceReport, so supports --historical.
|
||||
-- TODO Does not support boring parent eliding or --flat yet.
|
||||
singleBalanceReport :: ReportOpts -> Query -> Journal -> BalanceReport
|
||||
singleBalanceReport opts q j = (rows', total)
|
||||
where
|
||||
MultiBalanceReport (_, rows, (totals, _, _)) = multiBalanceReport opts q j
|
||||
rows' = [(a
|
||||
,if flat_ opts then a else a' -- BalanceReport expects full account name here with --flat
|
||||
,if tree_ opts then d-1 else 0 -- BalanceReport uses 0-based account depths
|
||||
, headDef nullmixedamt amts -- 0 columns is illegal, should not happen, return zeroes if it does
|
||||
) | (a,a',d, amts, _, _) <- rows]
|
||||
total = headDef nullmixedamt totals
|
||||
|
||||
-- | Generate a multicolumn balance report for the matched accounts,
|
||||
-- showing the change of balance, accumulated balance, or historical balance
|
||||
-- in each of the specified periods.
|
||||
-- in each of the specified periods. Does not support tree-mode boring parent eliding.
|
||||
-- If the normalbalance_ option is set, it adjusts the sorting and sign of amounts
|
||||
-- (see ReportOpts and CompoundBalanceCommand).
|
||||
multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport
|
||||
multiBalanceReport opts q j = MultiBalanceReport (displayspans, sorteditems, totalsrow)
|
||||
where
|
||||
@ -235,6 +223,21 @@ multiBalanceReport opts q j = MultiBalanceReport (displayspans, sorteditems, tot
|
||||
dbg1 s = let p = "multiBalanceReport" in Hledger.Utils.dbg1 (p++" "++s) -- add prefix in this function's debug output
|
||||
-- dbg1 = const id -- exclude this function from debug output
|
||||
|
||||
-- | Generates a simple non-columnar BalanceReport, but using multiBalanceReport,
|
||||
-- in order to support --historical. Does not support tree-mode boring parent eliding.
|
||||
-- If the normalbalance_ option is set, it adjusts the sorting and sign of amounts
|
||||
-- (see ReportOpts and CompoundBalanceCommand).
|
||||
balanceReportFromMultiBalanceReport :: ReportOpts -> Query -> Journal -> BalanceReport
|
||||
balanceReportFromMultiBalanceReport opts q j = (rows', total)
|
||||
where
|
||||
MultiBalanceReport (_, rows, (totals, _, _)) = multiBalanceReport opts q j
|
||||
rows' = [(a
|
||||
,if flat_ opts then a else a' -- BalanceReport expects full account name here with --flat
|
||||
,if tree_ opts then d-1 else 0 -- BalanceReport uses 0-based account depths
|
||||
, headDef nullmixedamt amts -- 0 columns is illegal, should not happen, return zeroes if it does
|
||||
) | (a,a',d, amts, _, _) <- rows]
|
||||
total = headDef nullmixedamt totals
|
||||
|
||||
|
||||
tests_multiBalanceReport =
|
||||
let
|
||||
|
@ -104,7 +104,7 @@ data ReportOpts = ReportOpts {
|
||||
,sort_amount_ :: Bool
|
||||
,normalbalance_ :: Maybe NormalSign
|
||||
-- ^ This can be set when running balance reports on a set of accounts
|
||||
-- with the same normal balance type (eg all assets, or all incomes).
|
||||
-- with the same normal balance type (eg all assets, or all incomes).
|
||||
-- - It helps --sort-amount know how to sort negative numbers
|
||||
-- (eg in the income section of an income statement)
|
||||
-- - It helps compound balance report commands (is, bs etc.) do
|
||||
|
@ -85,10 +85,10 @@ asInit d reset ui@UIState{
|
||||
-- run the report
|
||||
(items,_total) = report ropts' q j
|
||||
where
|
||||
-- still using the old balanceReport for change reports as it
|
||||
-- does not include every account from before the report period
|
||||
report | balancetype_ ropts == HistoricalBalance = singleBalanceReport
|
||||
report | balancetype_ ropts == HistoricalBalance = balanceReportFromMultiBalanceReport
|
||||
| otherwise = balanceReport
|
||||
-- still using the old balanceReport for change reports as it
|
||||
-- does not include every account from before the report period
|
||||
|
||||
|
||||
-- pre-render the list items
|
||||
|
@ -309,21 +309,15 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
|
||||
Right _ -> do
|
||||
let format = outputFormatFromOpts opts
|
||||
interval = interval_ ropts
|
||||
-- XXX shenanigans: use singleBalanceReport or multiBalanceReport when we must,
|
||||
-- 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.
|
||||
-- See also singleBalanceReport etc.
|
||||
case interval of
|
||||
NoInterval -> do
|
||||
let report
|
||||
-- For --historical/--cumulative, we must use multiBalanceReport.
|
||||
-- (This forces --no-elide.)
|
||||
| balancetype_ ropts `elem` [HistoricalBalance, CumulativeChange]
|
||||
= let ropts' | flat_ ropts = ropts
|
||||
| otherwise = ropts{accountlistmode_=ALTree}
|
||||
in singleBalanceReport ropts' (queryFromOpts d ropts) j
|
||||
| otherwise = balanceReport ropts (queryFromOpts d ropts) j
|
||||
in balanceReportFromMultiBalanceReport ropts' (queryFromOpts d ropts) j
|
||||
-- for historical balances we must use balanceReportFromMultiBalanceReport (also forces --no-elide)
|
||||
| otherwise = balanceReport ropts (queryFromOpts d ropts) j -- simple Ledger-style balance report
|
||||
render = case format of
|
||||
"csv" -> \ropts r -> (++ "\n") $ printCSV $ balanceReportAsCsv ropts r
|
||||
"html" -> \_ _ -> error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
|
||||
|
@ -70,7 +70,7 @@ close CliOpts{reportopts_=ropts} j = do
|
||||
q = queryFromOpts today ropts_
|
||||
openingdate = fromMaybe today $ queryEndDate False q
|
||||
closingdate = addDays (-1) openingdate
|
||||
(acctbals,_) = singleBalanceReport ropts_ q j
|
||||
(acctbals,_) = balanceReportFromMultiBalanceReport ropts_ q j
|
||||
balancingamt = negate $ sum $ map (\(_,_,_,b) -> normaliseMixedAmountSquashPricesForDisplay b) acctbals
|
||||
ps = [posting{paccount=a
|
||||
,pamount=mixed [b]
|
||||
|
@ -142,10 +142,10 @@ compoundBalanceCommand CompoundBalanceCommandSpec{..} opts@CliOpts{reportopts_=r
|
||||
CumulativeChange -> "(Cumulative Ending Balances)"
|
||||
HistoricalBalance -> "(Historical Ending Balances)"
|
||||
-- Set balance type in the report options.
|
||||
-- XXX Also, use tree mode (by default, at least?) if --cumulative/--historical
|
||||
-- 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..
|
||||
-- balanceReportFromMultiBalanceReport which does not support eliding boring parents,
|
||||
-- and tree mode hides this.. or something.. XXX
|
||||
ropts'
|
||||
| not (flat_ ropts) &&
|
||||
interval_ ropts==NoInterval &&
|
||||
|
Loading…
Reference in New Issue
Block a user