print: show effective dates (issue #12)

This commit is contained in:
Simon Michael 2009-12-07 23:28:33 +00:00
parent ddc176d83e
commit f209305eef
3 changed files with 22 additions and 6 deletions

View File

@ -17,7 +17,7 @@ print' :: [Opt] -> [String] -> Ledger -> IO ()
print' opts args = putStr . showLedgerTransactions opts args
showLedgerTransactions :: [Opt] -> [String] -> Ledger -> String
showLedgerTransactions opts args l = concatMap showLedgerTransactionUnelided txns
showLedgerTransactions opts args l = concatMap (showLedgerTransactionForPrint effective) txns
where
txns = sortBy (comparing ltdate) $
ledger_txns $
@ -25,4 +25,5 @@ showLedgerTransactions opts args l = concatMap showLedgerTransactionUnelided txn
filterRawLedgerTransactionsByAccount apats $
rawledger l
depth = depthFromOpts opts
effective = Effective `elem` opts
(apats,_) = parsePatternArgs args

View File

@ -51,21 +51,26 @@ pcommentwidth = no limit -- 22
@
-}
showLedgerTransaction :: LedgerTransaction -> String
showLedgerTransaction = showLedgerTransaction' True
showLedgerTransaction = showLedgerTransaction' True False
showLedgerTransactionUnelided :: LedgerTransaction -> String
showLedgerTransactionUnelided = showLedgerTransaction' False
showLedgerTransactionUnelided = showLedgerTransaction' False False
showLedgerTransaction' :: Bool -> LedgerTransaction -> String
showLedgerTransaction' elide t =
showLedgerTransactionForPrint :: Bool -> LedgerTransaction -> String
showLedgerTransactionForPrint effective = showLedgerTransaction' False effective
showLedgerTransaction' :: Bool -> Bool -> LedgerTransaction -> String
showLedgerTransaction' elide effective t =
unlines $ [description] ++ (showpostings $ ltpostings t) ++ [""]
where
description = concat [date, status, code, desc] -- , comment]
date = showdate $ ltdate t
date | effective = showdate $ fromMaybe (ltdate t) $ lteffectivedate t
| otherwise = showdate (ltdate t) ++ maybe "" showedate (lteffectivedate t)
status = if ltstatus t then " *" else ""
code = if (length $ ltcode t) > 0 then (printf " (%s)" $ ltcode t) else ""
desc = " " ++ ltdescription t
showdate = printf "%-10s" . showDate
showedate = printf "[=%s]" . showdate
showpostings ps
| elide && length ps > 1 && isLedgerTransactionBalanced t
= map showposting (init ps) ++ [showpostingnoamt (last ps)]

View File

@ -0,0 +1,10 @@
-f - print
<<<
2009/1/1[=2010/1/1] x
a 1
b
>>>
2009/01/01[=2010/01/01] x
a 1
b -1