2010-02-13 23:00:34 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
2008-10-10 07:32:12 +04:00
|
|
|
{-|
|
|
|
|
|
|
|
|
A ledger-compatible @print@ command.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2009-06-02 22:29:01 +04:00
|
|
|
module Commands.Print
|
2008-10-10 07:32:12 +04:00
|
|
|
where
|
|
|
|
import Ledger
|
|
|
|
import Options
|
2010-02-13 23:00:34 +03:00
|
|
|
#if __GLASGOW_HASKELL__ <= 610
|
|
|
|
import Prelude hiding ( putStr )
|
2009-05-15 00:44:06 +04:00
|
|
|
import System.IO.UTF8
|
2010-02-13 23:00:34 +03:00
|
|
|
#endif
|
2008-10-10 07:32:12 +04:00
|
|
|
|
|
|
|
|
2009-04-03 14:58:05 +04:00
|
|
|
-- | Print ledger transactions in standard format.
|
2008-10-12 13:17:21 +04:00
|
|
|
print' :: [Opt] -> [String] -> Ledger -> IO ()
|
2009-12-21 08:23:07 +03:00
|
|
|
print' opts args l = do
|
|
|
|
t <- getCurrentLocalTime
|
|
|
|
putStr $ showTransactions (optsToFilterSpec opts args t) l
|
2008-10-12 13:17:21 +04:00
|
|
|
|
2009-12-21 08:23:07 +03:00
|
|
|
showTransactions :: FilterSpec -> Ledger -> String
|
|
|
|
showTransactions filterspec l =
|
|
|
|
concatMap (showTransactionForPrint effective) $ sortBy (comparing tdate) txns
|
|
|
|
where
|
|
|
|
effective = EffectiveDate == whichdate filterspec
|
|
|
|
txns = jtxns $ filterJournalTransactions filterspec $ journal l
|