module Hledger.Cli.Print (
JournalReport
,JournalReportItem
,print'
,journalReport
,showTransactions
) where
import Hledger.Cli.Options
import Hledger.Data
import Prelude hiding (putStr)
import Hledger.Data.UTF8 (putStr)
type JournalReport = [JournalReportItem]
type JournalReportItem = Transaction
print' :: [Opt] -> [String] -> Journal -> IO ()
print' opts args j = do
t <- getCurrentLocalTime
putStr $ showTransactions (optsToFilterSpec opts args t) j
showTransactions :: FilterSpec -> Journal -> String
showTransactions fspec j = journalReportAsText [] fspec $ journalReport [] fspec j
journalReportAsText :: [Opt] -> FilterSpec -> JournalReport -> String
journalReportAsText _ fspec items = concatMap (showTransactionForPrint effective) items
where effective = EffectiveDate == whichdate fspec
journalReport :: [Opt] -> FilterSpec -> Journal -> JournalReport
journalReport _ fspec j = sortBy (comparing tdate) $ jtxns $ filterJournalTransactions fspec j