From 42bfc4afd9c8d63bdb44c6d9195d47984cf4a422 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 22 Nov 2008 09:39:58 +0000 Subject: [PATCH] --empty/-E flag --- BalanceCommand.hs | 3 ++- NOTES | 1 - Options.hs | 2 ++ Tests.hs | 10 ++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/BalanceCommand.hs b/BalanceCommand.hs index 5d9f2bc0e..dc07b9af1 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -124,9 +124,10 @@ showBalanceReport opts args l = acctsstr ++ totalstr acctsstr = concatMap showatree $ subs t showatree t = showAccountTreeWithBalances matchedacctnames t matchedacctnames = balancereportacctnames l sub apats t - t = pruneZeroBalanceLeaves $ ledgerAccountTree maxdepth l + t = (if empty then id else pruneZeroBalanceLeaves) $ ledgerAccountTree maxdepth l apats = fst $ parseAccountDescriptionArgs args sub = SubTotal `elem` opts + empty = Empty `elem` opts maxdepth = 9999 totalstr = if isZeroMixedAmount total then "" diff --git a/NOTES b/NOTES index 8f1c4db9e..2e20181f7 100644 --- a/NOTES +++ b/NOTES @@ -12,7 +12,6 @@ implementations were its consequences." --Niklaus Wirth *** parse commented lines at end of file *** display mixed amounts vertically, not horizontally ** features -*** -E to show zero amounts, for reports and showing informational timelog entries *** -n to skip total, for compound reports *** flexible date expressions, for easier time reports *** commodity @ rate, for tracking client hours in main ledger diff --git a/Options.hs b/Options.hs index 56a19303e..4435ac33f 100644 --- a/Options.hs +++ b/Options.hs @@ -27,6 +27,7 @@ options = [ Option ['b'] ["begin"] (ReqArg Begin "YYYY/MM/DD") "report on entries on or after this date", Option ['e'] ["end"] (ReqArg End "YYYY/MM/DD") "report on entries prior to this date", Option ['C'] ["cleared"] (NoArg Cleared) "report only on cleared entries", + Option ['E'] ["empty"] (NoArg Empty) "balance report: show accounts with zero balance", Option ['R'] ["real"] (NoArg Real) "report only on real (non-virtual) transactions", Option ['s'] ["subtotal"] (NoArg SubTotal) "balance report: show subaccounts", Option ['h'] ["help","usage"] (NoArg Help) "show this help", @@ -39,6 +40,7 @@ data Opt = Begin String | End String | Cleared | + Empty | Real | SubTotal | Help | diff --git a/Tests.hs b/Tests.hs index 5125e7c92..3bb1676e4 100644 --- a/Tests.hs +++ b/Tests.hs @@ -212,6 +212,16 @@ balancecommand_tests = TestList [ "--------------------\n" ++ " $1\n" ++ "") + , + "balance report with -E shows zero-balance accounts" ~: + ([SubTotal,Empty], ["assets"]) `gives` + (" $-1 assets\n" ++ + " $-2 cash\n" ++ + " $0 checking\n" ++ + " $1 saving\n" ++ + "--------------------\n" ++ + " $-1\n" ++ + "") ] where gives (opts,pats) e = do l <- ledgerfromfile pats "sample.ledger"