make incomestatement respect options

This commit is contained in:
Simon Michael 2012-04-16 16:45:24 +00:00
parent b4b2b67236
commit 8c7eea9ee0
2 changed files with 22 additions and 4 deletions

View File

@ -21,6 +21,7 @@ module Hledger.Reports (
journalSelectingDateFromOpts, journalSelectingDateFromOpts,
journalSelectingAmountFromOpts, journalSelectingAmountFromOpts,
filterSpecFromOpts, filterSpecFromOpts,
queryFromOpts,
-- * Entries report -- * Entries report
EntriesReport, EntriesReport,
EntriesReportItem, EntriesReportItem,
@ -63,7 +64,7 @@ import Text.Printf
import Hledger.Data import Hledger.Data
import Hledger.Utils import Hledger.Utils
-- report options, used in hledger-lib and above -- standard report options, used in hledger-lib and above
data ReportOpts = ReportOpts { data ReportOpts = ReportOpts {
begin_ :: Maybe Day begin_ :: Maybe Day
,end_ :: Maybe Day ,end_ :: Maybe Day
@ -166,7 +167,7 @@ journalSelectingAmountFromOpts opts
| cost_ opts = journalConvertAmountsToCost | cost_ opts = journalConvertAmountsToCost
| otherwise = id | otherwise = id
-- | Convert application options to the library's generic filter specification. -- | Convert report options to a (old) filter specification.
filterSpecFromOpts :: ReportOpts -> Day -> FilterSpec filterSpecFromOpts :: ReportOpts -> Day -> FilterSpec
filterSpecFromOpts opts@ReportOpts{..} d = FilterSpec { filterSpecFromOpts opts@ReportOpts{..} d = FilterSpec {
datespan=dateSpanFromOpts d opts datespan=dateSpanFromOpts d opts
@ -179,6 +180,21 @@ filterSpecFromOpts opts@ReportOpts{..} d = FilterSpec {
} }
where (apats,dpats) = parsePatternArgs patterns_ where (apats,dpats) = parsePatternArgs patterns_
-- | Convert report options to a (new) query.
queryFromOpts :: ReportOpts -> Day -> Matcher
queryFromOpts opts@ReportOpts{..} d = -- strace $
MatchAnd $
[MatchDate $ dateSpanFromOpts d opts]
++ (if null apats then [] else [MatchOr $ map MatchAcct apats])
++ (if null dpats then [] else [MatchOr $ map MatchDesc dpats])
-- ++ (if null mds then [] else [MatchOr $ map MatchMetadata mds])
++ (if real_ then [MatchReal True] else [])
++ (if empty_ then [MatchEmpty True] else [])
++ (maybe [] ((:[]) . MatchStatus) (clearedValueFromOpts opts))
++ (maybe [] ((:[]) . MatchDepth) depth_)
where
(apats,dpats,mds) = parsePatternArgs patterns_
-- | Gather filter pattern arguments into a list of account patterns and a -- | Gather filter pattern arguments into a list of account patterns and a
-- list of description patterns. We interpret pattern arguments as -- list of description patterns. We interpret pattern arguments as
-- follows: those prefixed with "desc:" are description patterns, all -- follows: those prefixed with "desc:" are description patterns, all

View File

@ -21,8 +21,10 @@ import Hledger.Cli.Balance
-- | Print a standard income statement. -- | Print a standard income statement.
incomestatement :: CliOpts -> Journal -> IO () incomestatement :: CliOpts -> Journal -> IO ()
incomestatement CliOpts{reportopts_=ropts} j = do incomestatement CliOpts{reportopts_=ropts} j = do
let incomereport@(_,income) = accountsReport2 ropts (journalIncomeAccountQuery j) j d <- getCurrentDay
expensereport@(_,expenses) = accountsReport2 ropts (journalExpenseAccountQuery j) j let m = queryFromOpts ropts d
incomereport@(_,income) = accountsReport2 ropts (MatchAnd [m, journalIncomeAccountQuery j]) j
expensereport@(_,expenses) = accountsReport2 ropts (MatchAnd [m, journalExpenseAccountQuery j]) j
total = income + expenses total = income + expenses
LT.putStr $ [lt|Income Statement LT.putStr $ [lt|Income Statement