print: show effective dates (issue #12)
This commit is contained in:
parent
ddc176d83e
commit
f209305eef
@ -17,7 +17,7 @@ print' :: [Opt] -> [String] -> Ledger -> IO ()
|
|||||||
print' opts args = putStr . showLedgerTransactions opts args
|
print' opts args = putStr . showLedgerTransactions opts args
|
||||||
|
|
||||||
showLedgerTransactions :: [Opt] -> [String] -> Ledger -> String
|
showLedgerTransactions :: [Opt] -> [String] -> Ledger -> String
|
||||||
showLedgerTransactions opts args l = concatMap showLedgerTransactionUnelided txns
|
showLedgerTransactions opts args l = concatMap (showLedgerTransactionForPrint effective) txns
|
||||||
where
|
where
|
||||||
txns = sortBy (comparing ltdate) $
|
txns = sortBy (comparing ltdate) $
|
||||||
ledger_txns $
|
ledger_txns $
|
||||||
@ -25,4 +25,5 @@ showLedgerTransactions opts args l = concatMap showLedgerTransactionUnelided txn
|
|||||||
filterRawLedgerTransactionsByAccount apats $
|
filterRawLedgerTransactionsByAccount apats $
|
||||||
rawledger l
|
rawledger l
|
||||||
depth = depthFromOpts opts
|
depth = depthFromOpts opts
|
||||||
|
effective = Effective `elem` opts
|
||||||
(apats,_) = parsePatternArgs args
|
(apats,_) = parsePatternArgs args
|
||||||
|
|||||||
@ -51,21 +51,26 @@ pcommentwidth = no limit -- 22
|
|||||||
@
|
@
|
||||||
-}
|
-}
|
||||||
showLedgerTransaction :: LedgerTransaction -> String
|
showLedgerTransaction :: LedgerTransaction -> String
|
||||||
showLedgerTransaction = showLedgerTransaction' True
|
showLedgerTransaction = showLedgerTransaction' True False
|
||||||
|
|
||||||
showLedgerTransactionUnelided :: LedgerTransaction -> String
|
showLedgerTransactionUnelided :: LedgerTransaction -> String
|
||||||
showLedgerTransactionUnelided = showLedgerTransaction' False
|
showLedgerTransactionUnelided = showLedgerTransaction' False False
|
||||||
|
|
||||||
showLedgerTransaction' :: Bool -> LedgerTransaction -> String
|
showLedgerTransactionForPrint :: Bool -> LedgerTransaction -> String
|
||||||
showLedgerTransaction' elide t =
|
showLedgerTransactionForPrint effective = showLedgerTransaction' False effective
|
||||||
|
|
||||||
|
showLedgerTransaction' :: Bool -> Bool -> LedgerTransaction -> String
|
||||||
|
showLedgerTransaction' elide effective t =
|
||||||
unlines $ [description] ++ (showpostings $ ltpostings t) ++ [""]
|
unlines $ [description] ++ (showpostings $ ltpostings t) ++ [""]
|
||||||
where
|
where
|
||||||
description = concat [date, status, code, desc] -- , comment]
|
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 ""
|
status = if ltstatus t then " *" else ""
|
||||||
code = if (length $ ltcode t) > 0 then (printf " (%s)" $ ltcode t) else ""
|
code = if (length $ ltcode t) > 0 then (printf " (%s)" $ ltcode t) else ""
|
||||||
desc = " " ++ ltdescription t
|
desc = " " ++ ltdescription t
|
||||||
showdate = printf "%-10s" . showDate
|
showdate = printf "%-10s" . showDate
|
||||||
|
showedate = printf "[=%s]" . showdate
|
||||||
showpostings ps
|
showpostings ps
|
||||||
| elide && length ps > 1 && isLedgerTransactionBalanced t
|
| elide && length ps > 1 && isLedgerTransactionBalanced t
|
||||||
= map showposting (init ps) ++ [showpostingnoamt (last ps)]
|
= map showposting (init ps) ++ [showpostingnoamt (last ps)]
|
||||||
|
|||||||
10
tests/effective-print-2.test
Normal file
10
tests/effective-print-2.test
Normal 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
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user