bugfix for #514, is and cf are now period reports, and bs, as a snapshot report, is treated as a special case

This commit is contained in:
Justin Le 2017-03-17 17:44:52 -07:00 committed by Simon Michael
parent 3dab20c654
commit f5a530d620
4 changed files with 36 additions and 29 deletions

View File

@ -31,7 +31,9 @@ data BalanceView = BalanceView {
bvaliases :: [String], -- ^ command line aliases
bvhelp :: String, -- ^ command line help message
bvtitle :: String, -- ^ title of the view
bvqueries :: [(String, Journal -> Query)] -- ^ named queries that make up the view
bvqueries :: [(String, Journal -> Query)], -- ^ named queries that make up the view
bvsnapshot :: Bool -- ^ whether or not the view is a snapshot,
-- ignoring begin date in reporting period
}
balanceviewmode :: BalanceView -> Mode RawOpts
@ -52,14 +54,14 @@ balanceviewmode BalanceView{..} = (defCommandMode $ bvmode : bvaliases) {
balanceviewQueryReport
:: ReportOpts
-> Day
-> Query
-> Journal
-> String
-> (Journal -> Query)
-> ([String], Sum MixedAmount)
balanceviewQueryReport ropts currDay j t q = ([view], Sum amt)
balanceviewQueryReport ropts q0 j t q = ([view], Sum amt)
where
q' = And [queryFromOpts currDay (withoutBeginDate ropts), q j]
q' = And [q0, q j]
rep@(_ , amt) = balanceReport ropts q' j
view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep]
@ -67,8 +69,10 @@ balanceviewQueryReport ropts currDay j t q = ([view], Sum amt)
balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO ()
balanceviewReport BalanceView{..} CliOpts{reportopts_=ropts} j = do
currDay <- getCurrentDay
let (views, amt) =
foldMap (uncurry (balanceviewQueryReport ropts currDay j))
let q0 | bvsnapshot = queryFromOpts currDay (withoutBeginDate ropts)
| otherwise = queryFromOpts currDay ropts
(views, amt) =
foldMap (uncurry (balanceviewQueryReport ropts q0 j))
bvqueries
mapM_ putStrLn (bvtitle : "" : views)

View File

@ -25,7 +25,8 @@ bsBV = BalanceView {
bvtitle = "Balance Sheet",
bvqueries = [ ("Assets" , journalAssetAccountQuery),
("Liabilities", journalLiabilityAccountQuery)
]
],
bvsnapshot = True
}
balancesheetmode :: Mode RawOpts

View File

@ -26,7 +26,8 @@ cfBV = BalanceView {
bvaliases = ["cf"],
bvhelp = "show a cashflow statement",
bvtitle = "Cashflow Statement",
bvqueries = [("Cash flows", journalCashAccountQuery)]
bvqueries = [("Cash flows", journalCashAccountQuery)],
bvsnapshot = False
}
cashflowmode :: Mode RawOpts

View File

@ -25,7 +25,8 @@ isBV = BalanceView {
bvtitle = "Income Statement",
bvqueries = [ ("Revenues", journalIncomeAccountQuery),
("Expenses", journalExpenseAccountQuery)
]
],
bvsnapshot = False
}
incomestatementmode :: Mode RawOpts