From f5a530d620c6d12a7e5b3cf3cb9a10a915792b86 Mon Sep 17 00:00:00 2001 From: Justin Le Date: Fri, 17 Mar 2017 17:44:52 -0700 Subject: [PATCH] bugfix for #514, is and cf are now period reports, and bs, as a snapshot report, is treated as a special case --- hledger/Hledger/Cli/BalanceView.hs | 24 ++++++++++++++---------- hledger/Hledger/Cli/Balancesheet.hs | 15 ++++++++------- hledger/Hledger/Cli/Cashflow.hs | 11 ++++++----- hledger/Hledger/Cli/Incomestatement.hs | 15 ++++++++------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/hledger/Hledger/Cli/BalanceView.hs b/hledger/Hledger/Cli/BalanceView.hs index 085ff5691..d2431b3aa 100644 --- a/hledger/Hledger/Cli/BalanceView.hs +++ b/hledger/Hledger/Cli/BalanceView.hs @@ -27,11 +27,13 @@ import Hledger.Cli.CliOptions -- | Describes a view for the balance, which can consist of multiple -- separate named queries that are aggregated and totaled. data BalanceView = BalanceView { - bvmode :: String, -- ^ command line mode of the view - 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 + bvmode :: String, -- ^ command line mode of the view + 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 + 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) diff --git a/hledger/Hledger/Cli/Balancesheet.hs b/hledger/Hledger/Cli/Balancesheet.hs index 91bf319c6..5689134c3 100644 --- a/hledger/Hledger/Cli/Balancesheet.hs +++ b/hledger/Hledger/Cli/Balancesheet.hs @@ -19,13 +19,14 @@ import Hledger.Cli.CliOptions import Hledger.Cli.BalanceView bsBV = BalanceView { - bvmode = "balancesheet", - bvaliases = ["bs"], - bvhelp = "show a balance sheet", - bvtitle = "Balance Sheet", - bvqueries = [ ("Assets" , journalAssetAccountQuery), - ("Liabilities", journalLiabilityAccountQuery) - ] + bvmode = "balancesheet", + bvaliases = ["bs"], + bvhelp = "show a balance sheet", + bvtitle = "Balance Sheet", + bvqueries = [ ("Assets" , journalAssetAccountQuery), + ("Liabilities", journalLiabilityAccountQuery) + ], + bvsnapshot = True } balancesheetmode :: Mode RawOpts diff --git a/hledger/Hledger/Cli/Cashflow.hs b/hledger/Hledger/Cli/Cashflow.hs index 5decaad01..6d06f7165 100644 --- a/hledger/Hledger/Cli/Cashflow.hs +++ b/hledger/Hledger/Cli/Cashflow.hs @@ -22,11 +22,12 @@ import Hledger.Cli.CliOptions import Hledger.Cli.BalanceView cfBV = BalanceView { - bvmode = "cashflow", - bvaliases = ["cf"], - bvhelp = "show a cashflow statement", - bvtitle = "Cashflow Statement", - bvqueries = [("Cash flows", journalCashAccountQuery)] + bvmode = "cashflow", + bvaliases = ["cf"], + bvhelp = "show a cashflow statement", + bvtitle = "Cashflow Statement", + bvqueries = [("Cash flows", journalCashAccountQuery)], + bvsnapshot = False } cashflowmode :: Mode RawOpts diff --git a/hledger/Hledger/Cli/Incomestatement.hs b/hledger/Hledger/Cli/Incomestatement.hs index df3e8ca62..3ffcc4e66 100644 --- a/hledger/Hledger/Cli/Incomestatement.hs +++ b/hledger/Hledger/Cli/Incomestatement.hs @@ -19,13 +19,14 @@ import Hledger.Cli.CliOptions import Hledger.Cli.BalanceView isBV = BalanceView { - bvmode = "incomestatement", - bvaliases = ["is"], - bvhelp = "show an income statement", - bvtitle = "Income Statement", - bvqueries = [ ("Revenues", journalIncomeAccountQuery), - ("Expenses", journalExpenseAccountQuery) - ] + bvmode = "incomestatement", + bvaliases = ["is"], + bvhelp = "show an income statement", + bvtitle = "Income Statement", + bvqueries = [ ("Revenues", journalIncomeAccountQuery), + ("Expenses", journalExpenseAccountQuery) + ], + bvsnapshot = False } incomestatementmode :: Mode RawOpts