incomestatement: show revenue and expense accounts separately

This commit is contained in:
Simon Michael 2012-04-15 00:05:10 +00:00
parent abb470aadb
commit b4b2b67236
2 changed files with 49 additions and 12 deletions

View File

@ -37,6 +37,11 @@ module Hledger.Data.Journal (
-- * Standard account types -- * Standard account types
journalBalanceSheetAccountQuery, journalBalanceSheetAccountQuery,
journalProfitAndLossAccountQuery, journalProfitAndLossAccountQuery,
journalIncomeAccountQuery,
journalExpenseAccountQuery,
journalAssetAccountQuery,
journalLiabilityAccountQuery,
journalEquityAccountQuery,
-- * Misc -- * Misc
groupPostings, groupPostings,
matchpats, matchpats,
@ -159,21 +164,45 @@ journalAccountNameTree = accountNameTreeFrom . journalAccountNames
-- standard account types -- standard account types
balanceSheetAccountRegex, profitAndLossAccountRegex :: String -- | A query for Profit & Loss accounts in this journal.
balanceSheetAccountRegex = "^(assets?|liabilit(y|ies)|equity)(:|$)" -- Cf <http://en.wikipedia.org/wiki/Chart_of_accounts#Profit_.26_Loss_accounts>.
profitAndLossAccountRegex = "^(income|expenses?|profits?|loss(es)?)(:|$)" journalProfitAndLossAccountQuery :: Journal -> Matcher
journalProfitAndLossAccountQuery j = MatchOr [journalIncomeAccountQuery j
,journalExpenseAccountQuery j
]
-- | A query for Income (Revenue) accounts in this journal.
-- This is currently hard-coded to the case-insensitive regex @^(income|revenue)s?(:|$)@.
journalIncomeAccountQuery :: Journal -> Matcher
journalIncomeAccountQuery _ = MatchAcct "^(income|revenue)s?(:|$)"
-- | A query for Expense accounts in this journal.
-- This is currently hard-coded to the case-insensitive regex @^expenses?(:|$)@.
journalExpenseAccountQuery :: Journal -> Matcher
journalExpenseAccountQuery _ = MatchAcct "^expenses?(:|$)"
-- | A query for Asset, Liability & Equity accounts in this journal. -- | A query for Asset, Liability & Equity accounts in this journal.
-- Cf <http://en.wikipedia.org/wiki/Chart_of_accounts#Balance_Sheet_Accounts>. -- Cf <http://en.wikipedia.org/wiki/Chart_of_accounts#Balance_Sheet_Accounts>.
-- This is currently hard-coded to the case-insensitive regex @^(assets?|liabilit(y|ies)|equity)(:|$)@.
journalBalanceSheetAccountQuery :: Journal -> Matcher journalBalanceSheetAccountQuery :: Journal -> Matcher
journalBalanceSheetAccountQuery _ = MatchAcct balanceSheetAccountRegex journalBalanceSheetAccountQuery j = MatchOr [journalAssetAccountQuery j
,journalLiabilityAccountQuery j
,journalEquityAccountQuery j
]
-- | A query for Profit & Loss accounts in this journal. -- | A query for Asset accounts in this journal.
-- Cf <http://en.wikipedia.org/wiki/Chart_of_accounts#Profit_.26_Loss_accounts>. -- This is currently hard-coded to the case-insensitive regex @^assets?(:|$)@.
-- This is currently hard-coded to the case-insensitive regex @^(income|expenses?|profits?|loss(es)?)(:|$)@. journalAssetAccountQuery :: Journal -> Matcher
journalProfitAndLossAccountQuery :: Journal -> Matcher journalAssetAccountQuery _ = MatchAcct "^assets?(:|$)"
journalProfitAndLossAccountQuery _ = MatchAcct profitAndLossAccountRegex
-- | A query for Liability accounts in this journal.
-- This is currently hard-coded to the case-insensitive regex @^liabilit(y|ies)(:|$)@.
journalLiabilityAccountQuery :: Journal -> Matcher
journalLiabilityAccountQuery _ = MatchAcct "^liabilit(y|ies)(:|$)"
-- | A query for Equity accounts in this journal.
-- This is currently hard-coded to the case-insensitive regex @^equity(:|$)@.
journalEquityAccountQuery :: Journal -> Matcher
journalEquityAccountQuery _ = MatchAcct "^equity(:|$)"
-- Various kinds of filtering on journals. We do it differently depending -- Various kinds of filtering on journals. We do it differently depending
-- on the command. -- on the command.

View File

@ -21,10 +21,18 @@ 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 report = accountsReport2 ropts (journalProfitAndLossAccountQuery j) j let incomereport@(_,income) = accountsReport2 ropts (journalIncomeAccountQuery j) j
expensereport@(_,expenses) = accountsReport2 ropts (journalExpenseAccountQuery j) j
total = income + expenses
LT.putStr $ [lt|Income Statement LT.putStr $ [lt|Income Statement
#{unlines $ accountsReportAsText ropts report}|] Revenues:
#{unlines $ accountsReportAsText ropts incomereport}
Expenses:
#{unlines $ accountsReportAsText ropts expensereport}
Total: #{show total}
|]
tests_Hledger_Cli_Incomestatement :: Test tests_Hledger_Cli_Incomestatement :: Test
tests_Hledger_Cli_Incomestatement = TestList tests_Hledger_Cli_Incomestatement = TestList