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

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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