From f209305eefdab77f1a04d97575cd4899ebd39bc3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 7 Dec 2009 23:28:33 +0000 Subject: [PATCH] print: show effective dates (issue #12) --- Commands/Print.hs | 3 ++- Ledger/LedgerTransaction.hs | 15 ++++++++++----- tests/effective-print-2.test | 10 ++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 tests/effective-print-2.test diff --git a/Commands/Print.hs b/Commands/Print.hs index 180139064..c7d802be5 100644 --- a/Commands/Print.hs +++ b/Commands/Print.hs @@ -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 diff --git a/Ledger/LedgerTransaction.hs b/Ledger/LedgerTransaction.hs index df85ea374..ec859f86a 100644 --- a/Ledger/LedgerTransaction.hs +++ b/Ledger/LedgerTransaction.hs @@ -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)] diff --git a/tests/effective-print-2.test b/tests/effective-print-2.test new file mode 100644 index 000000000..238b1f64a --- /dev/null +++ b/tests/effective-print-2.test @@ -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 +