;bal: cleanup

This commit is contained in:
Simon Michael 2019-05-04 12:21:23 -07:00
parent 12c0bfb39b
commit 3a79e300c9

View File

@ -306,29 +306,39 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
case lineFormatFromOpts ropts of case lineFormatFromOpts ropts of
Left err -> error' $ unlines [err] Left err -> error' $ unlines [err]
Right _ -> do Right _ -> do
let format = outputFormatFromOpts opts let budget = boolopt "budget" rawopts
budget = boolopt "budget" rawopts multiperiod = interval_ /= NoInterval
interval = interval_ format = outputFormatFromOpts opts
case (budget, interval) of if budget then do -- single or multi period budget report
(True, _) -> do reportspan <- reportSpan j ropts
-- single or multicolumn budget report let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j
reportspan <- reportSpan j ropts where
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j assrt = not $ ignore_assertions_ $ inputopts_ opts
where render = case format of
assrt = not $ ignore_assertions_ $ inputopts_ opts "csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO
_ -> budgetReportAsText ropts
writeOutput opts $ render budgetreport
else
if multiperiod then do -- multi period balance report
-- With --value-at=transaction, convert all amounts to value before summing them.
let j' | value_at_ == AtTransaction =
error' "sorry, --value-at=transaction with balance reports is not yet supported" -- journalValueAtTransactionDate ropts j
| otherwise = j
report = multiBalanceReport ropts (queryFromOpts d ropts) j'
render = case format of render = case format of
"csv" -> const $ error' "Sorry, CSV output is not yet implemented for this kind of report." -- TODO "csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
"html" -> const $ error' "Sorry, HTML output is not yet implemented for this kind of report." -- TODO "html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
_ -> budgetReportAsText ropts _ -> multiBalanceReportAsText ropts
writeOutput opts $ render budgetreport writeOutput opts $ render report
(False, NoInterval) -> do else do -- single period simple balance report
-- single column balance report
-- With --value-at=transaction, convert all amounts to value before summing them. -- With --value-at=transaction, convert all amounts to value before summing them.
let j' | value_at_ == AtTransaction = journalValueAtTransactionDate ropts j let j' | value_at_ == AtTransaction = journalValueAtTransactionDate ropts j
| otherwise = j | otherwise = j
let report report
| balancetype_ `elem` [HistoricalBalance, CumulativeChange] | balancetype_ `elem` [HistoricalBalance, CumulativeChange]
= let ropts' | flat_ ropts = ropts = let ropts' | flat_ ropts = ropts
| otherwise = ropts{accountlistmode_=ALTree} | otherwise = ropts{accountlistmode_=ALTree}
@ -341,21 +351,6 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
_ -> balanceReportAsText _ -> balanceReportAsText
writeOutput opts $ render ropts report writeOutput opts $ render ropts report
_ -> do
-- multi column balance report
-- With --value-at=transaction, convert all amounts to value before summing them.
let j' | value_at_ == AtTransaction =
error' "sorry, --value-at=transaction with balance reports is not yet supported" -- journalValueAtTransactionDate ropts j
| otherwise = j
let report = multiBalanceReport ropts (queryFromOpts d ropts) j'
render = case format of
"csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
_ -> multiBalanceReportAsText ropts
writeOutput opts $ render report
-- rendering single-column balance reports -- rendering single-column balance reports
-- | Render a single-column balance report as CSV. -- | Render a single-column balance report as CSV.