move reports back to Hledger.Cli for now, forgot they still depend on cli options

This commit is contained in:
Simon Michael 2011-07-18 23:30:40 +00:00
parent e4c4405c62
commit 47b1142d49
8 changed files with 80 additions and 67 deletions

View File

@ -1,11 +1,9 @@
module Hledger (
module Hledger.Data
,module Hledger.Read
,module Hledger.Report
,module Hledger.Utils
)
where
import Hledger.Data
import Hledger.Read
import Hledger.Report
import Hledger.Utils

View File

@ -10,6 +10,7 @@ module Hledger.Cli (
module Hledger.Cli.Histogram,
module Hledger.Cli.Print,
module Hledger.Cli.Register,
module Hledger.Cli.Reports,
module Hledger.Cli.Stats,
module Hledger.Cli.Options,
module Hledger.Cli.Utils,
@ -30,6 +31,7 @@ import Hledger.Cli.Convert
import Hledger.Cli.Histogram
import Hledger.Cli.Print
import Hledger.Cli.Register
import Hledger.Cli.Reports
import Hledger.Cli.Stats
import Hledger.Cli.Options
import Hledger.Cli.Utils
@ -50,6 +52,7 @@ tests_Hledger_Cli = TestList
,tests_Hledger_Cli_Options
-- ,tests_Hledger_Cli_Print
,tests_Hledger_Cli_Register
,tests_Hledger_Cli_Reports
-- ,tests_Hledger_Cli_Stats

View File

@ -34,6 +34,7 @@ import Hledger.Utils.UTF8 (putStr, putStrLn, appendFile)
import Hledger.Cli.Options
import Hledger.Cli.Register (postingRegisterReportAsText)
import Hledger.Cli.Utils
import Hledger.Cli.Reports
{- | Information used as the basis for suggested account names, amounts,

View File

@ -111,6 +111,7 @@ import Hledger.Utils.UTF8 (putStr)
import Hledger.Cli.Format
import qualified Hledger.Cli.Format as Format
import Hledger.Cli.Options
import Hledger.Cli.Reports
-- | Print a balance report.

View File

@ -15,6 +15,7 @@ import Hledger
import Prelude hiding (putStr)
import Hledger.Utils.UTF8 (putStr)
import Hledger.Cli.Options
import Hledger.Cli.Reports
-- | Print journal transactions in standard format.
print' :: [Opt] -> [String] -> Journal -> IO ()

View File

@ -21,6 +21,7 @@ import Hledger
import Prelude hiding (putStr)
import Hledger.Utils.UTF8 (putStr)
import Hledger.Cli.Options
import Hledger.Cli.Reports
-- | Print a (posting) register report.

View File

@ -1,31 +1,37 @@
{-|
Generate several common kinds of report from a journal, as "Reports" -
Generate several common kinds of report from a journal, as \"*Report\" -
simple intermediate data structures intended to be easily rendered as
text, html, json, csv etc. by hledger commands, hamlet templates,
javascript, or whatever.
javascript, or whatever. This is under Hledger.Cli since it depends
on the command-line options, should move to hledger-lib later.
-}
module Hledger.Report (
tests_Hledger_Report
,JournalReport
,JournalReportItem
,PostingRegisterReport
,PostingRegisterReportItem
,AccountRegisterReport
,AccountRegisterReportItem
,BalanceReport
,BalanceReportItem
,ariDate
,ariBalance
,journalReport
,postingRegisterReport
,accountRegisterReport
,journalRegisterReport
,mkpostingRegisterItem -- for silly showPostingWithBalanceForVty in Hledger.Cli.Register
,balanceReport
,balanceReport2
module Hledger.Cli.Reports (
-- * Journal report
JournalReport,
JournalReportItem,
journalReport,
-- * Posting register report
PostingRegisterReport,
PostingRegisterReportItem,
postingRegisterReport,
mkpostingRegisterItem, -- for silly showPostingWithBalanceForVty in Hledger.Cli.Register
journalRegisterReport,
-- * Account register report
AccountRegisterReport,
AccountRegisterReportItem,
ariDate,
ariBalance,
accountRegisterReport,
-- * Balance report
BalanceReport,
BalanceReportItem,
balanceReport,
balanceReport2,
-- * Tests
tests_Hledger_Cli_Reports
)
where
@ -40,16 +46,26 @@ import Test.HUnit
import Text.ParserCombinators.Parsec
import Text.Printf
import Hledger.Cli.Options
import Hledger.Cli.Utils
import Hledger.Data
import Hledger.Utils
import Hledger.Cli.Options
import Hledger.Cli.Utils
-------------------------------------------------------------------------------
-- | A "journal report" is just a list of transactions.
type JournalReport = [JournalReportItem]
type JournalReportItem = Transaction
-- | Select transactions, as in the print command.
journalReport :: [Opt] -> FilterSpec -> Journal -> JournalReport
journalReport opts fspec j = sortBy (comparing tdate) $ jtxns $ filterJournalTransactions fspec j'
where
j' = journalSelectingDateFromOpts opts $ journalSelectingAmountFromOpts opts j
-------------------------------------------------------------------------------
-- | A posting register report lists postings to one or more accounts,
-- with a running total. Postings may be actual postings, or aggregate
-- postings corresponding to a reporting interval.
@ -62,46 +78,6 @@ type PostingRegisterReportItem = (Maybe (Day, String) -- transaction date and de
,MixedAmount -- the running total after this posting
)
-- | An account register report lists transactions to a single account (or
-- possibly subs as well), with the accurate running account balance when
-- possible (otherwise, a running total.)
type AccountRegisterReport = (String -- label for the balance column, eg "balance" or "total"
,[AccountRegisterReportItem] -- line items, one per transaction
)
type AccountRegisterReportItem = (Transaction -- the corresponding transaction
,Transaction -- the transaction with postings to the focussed account removed
,Bool -- is this a split (more than one other-account posting) ?
,String -- the (possibly aggregated) account info to display
,MixedAmount -- the (possibly aggregated) amount to display (sum of the other-account postings)
,MixedAmount -- the running balance for the focussed account after this transaction
)
ariDate (t,_,_,_,_,_) = tdate t
ariBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0"
(Amount{quantity=q}):_ -> show q
-- | A balance report is a chart of accounts with balances, and their grand total.
type BalanceReport = ([BalanceReportItem] -- line items, one per account
,MixedAmount -- total balance of all accounts
)
type BalanceReportItem = (AccountName -- full account name
,AccountName -- account name elided for display: the leaf name,
-- prefixed by any boring parents immediately above
,Int -- how many steps to indent this account (0-based account depth excluding boring parents)
,MixedAmount) -- account balance, includes subs unless --flat is present
-------------------------------------------------------------------------------
-- | Select transactions, as in the print command.
journalReport :: [Opt] -> FilterSpec -> Journal -> JournalReport
journalReport opts fspec j = sortBy (comparing tdate) $ jtxns $ filterJournalTransactions fspec j'
where
j' = journalSelectingDateFromOpts opts $ journalSelectingAmountFromOpts opts j
-------------------------------------------------------------------------------
-- | Select postings from the journal and get their running balance, as in
-- the register command.
postingRegisterReport :: [Opt] -> FilterSpec -> Journal -> PostingRegisterReport
@ -250,6 +226,25 @@ journalRegisterReport _ Journal{jtxns=ts} m = (totallabel, items)
-------------------------------------------------------------------------------
-- | An account register report lists transactions to a single account (or
-- possibly subs as well), with the accurate running account balance when
-- possible (otherwise, a running total.)
type AccountRegisterReport = (String -- label for the balance column, eg "balance" or "total"
,[AccountRegisterReportItem] -- line items, one per transaction
)
type AccountRegisterReportItem = (Transaction -- the corresponding transaction
,Transaction -- the transaction with postings to the focussed account removed
,Bool -- is this a split (more than one other-account posting) ?
,String -- the (possibly aggregated) account info to display
,MixedAmount -- the (possibly aggregated) amount to display (sum of the other-account postings)
,MixedAmount -- the running balance for the focussed account after this transaction
)
ariDate (t,_,_,_,_,_) = tdate t
ariBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0"
(Amount{quantity=q}):_ -> show q
-- | Select transactions within one (or more) specified accounts, and get
-- their running balance within that (those) account(s). Used for a
-- conventional quicker/gnucash/bank-style account register. Specifically,
@ -338,6 +333,17 @@ filterTransactionPostings m t@Transaction{tpostings=ps} = t{tpostings=filter (m
-------------------------------------------------------------------------------
-- | A balance report is a chart of accounts with balances, and their grand total.
type BalanceReport = ([BalanceReportItem] -- line items, one per account
,MixedAmount -- total balance of all accounts
)
type BalanceReportItem = (AccountName -- full account name
,AccountName -- account name elided for display: the leaf name,
-- prefixed by any boring parents immediately above
,Int -- how many steps to indent this account (0-based account depth excluding boring parents)
,MixedAmount) -- account balance, includes subs unless --flat is present
-- | Select accounts, and get their balances at the end of the selected
-- period, as in the balance command.
balanceReport :: [Opt] -> FilterSpec -> Journal -> BalanceReport
@ -408,8 +414,8 @@ isInterestingIndented opts l a
-------------------------------------------------------------------------------
tests_Hledger_Report :: Test
tests_Hledger_Report = TestList
tests_Hledger_Cli_Reports :: Test
tests_Hledger_Cli_Reports = TestList
[
"summarisePostingsByInterval" ~: do

View File

@ -53,6 +53,7 @@ library
Hledger.Cli.Histogram
Hledger.Cli.Print
Hledger.Cli.Register
Hledger.Cli.Reports
Hledger.Cli.Stats
-- should be the same as below
build-depends:
@ -99,6 +100,7 @@ executable hledger
Hledger.Cli.Histogram
Hledger.Cli.Print
Hledger.Cli.Register
Hledger.Cli.Reports
Hledger.Cli.Stats
-- XXX should set patchlevel here as in Makefile
cpp-options: -DPATCHLEVEL=0