;bal: cleanup

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

View File

@ -306,13 +306,11 @@ 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
-- single or multicolumn budget report
reportspan <- reportSpan j ropts reportspan <- reportSpan j ropts
let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j let budgetreport = dbg1 "budgetreport" $ budgetReport ropts assrt reportspan d j
where where
@ -323,12 +321,24 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
_ -> budgetReportAsText ropts _ -> budgetReportAsText ropts
writeOutput opts $ render budgetreport writeOutput opts $ render budgetreport
(False, NoInterval) -> do else
-- single column balance report 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
"csv" -> (++ "\n") . printCSV . multiBalanceReportAsCsv ropts
"html" -> (++ "\n") . TL.unpack . L.renderText . multiBalanceReportAsHtml ropts
_ -> multiBalanceReportAsText ropts
writeOutput opts $ render report
else do -- single period simple 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.