-n flag for balance command
This commit is contained in:
		
							parent
							
								
									42bfc4afd9
								
							
						
					
					
						commit
						6fc8cdfe3e
					
				| @ -119,7 +119,7 @@ balance opts args l = putStr $ showBalanceReport opts args l | |||||||
| 
 | 
 | ||||||
| -- | Generate balance report output for a ledger, based on options. | -- | Generate balance report output for a ledger, based on options. | ||||||
| showBalanceReport :: [Opt] -> [String] -> Ledger -> String | showBalanceReport :: [Opt] -> [String] -> Ledger -> String | ||||||
| showBalanceReport opts args l = acctsstr ++ totalstr | showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) | ||||||
|     where  |     where  | ||||||
|       acctsstr = concatMap showatree $ subs t |       acctsstr = concatMap showatree $ subs t | ||||||
|       showatree t = showAccountTreeWithBalances matchedacctnames t |       showatree t = showAccountTreeWithBalances matchedacctnames t | ||||||
| @ -128,6 +128,7 @@ showBalanceReport opts args l = acctsstr ++ totalstr | |||||||
|       apats = fst $ parseAccountDescriptionArgs args |       apats = fst $ parseAccountDescriptionArgs args | ||||||
|       sub = SubTotal `elem` opts |       sub = SubTotal `elem` opts | ||||||
|       empty = Empty `elem` opts |       empty = Empty `elem` opts | ||||||
|  |       collapse = Collapse `elem` opts | ||||||
|       maxdepth = 9999 |       maxdepth = 9999 | ||||||
|       totalstr = if isZeroMixedAmount total  |       totalstr = if isZeroMixedAmount total  | ||||||
|                  then ""  |                  then ""  | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NOTES
									
									
									
									
									
								
							| @ -12,7 +12,6 @@ implementations were its consequences." --Niklaus Wirth | |||||||
| *** parse commented lines at end of file  | *** parse commented lines at end of file  | ||||||
| *** display mixed amounts vertically, not horizontally | *** display mixed amounts vertically, not horizontally | ||||||
| ** features | ** features | ||||||
| *** -n to skip total, for compound reports |  | ||||||
| *** flexible date expressions, for easier time reports | *** flexible date expressions, for easier time reports | ||||||
| *** commodity @ rate, for tracking client hours in main ledger | *** commodity @ rate, for tracking client hours in main ledger | ||||||
| *** actual/effective entry & txn dates, for ... | *** actual/effective entry & txn dates, for ... | ||||||
|  | |||||||
| @ -29,6 +29,7 @@ options = [ | |||||||
|  Option ['C'] ["cleared"]      (NoArg  Cleared)            "report only on cleared entries", |  Option ['C'] ["cleared"]      (NoArg  Cleared)            "report only on cleared entries", | ||||||
|  Option ['E'] ["empty"]        (NoArg  Empty)              "balance report: show accounts with zero balance", |  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 ['R'] ["real"]         (NoArg  Real)               "report only on real (non-virtual) transactions", | ||||||
|  |  Option ['n'] ["collapse"]     (NoArg  Collapse)           "balance report: no grand total", | ||||||
|  Option ['s'] ["subtotal"]     (NoArg  SubTotal)           "balance report: show subaccounts", |  Option ['s'] ["subtotal"]     (NoArg  SubTotal)           "balance report: show subaccounts", | ||||||
|  Option ['h'] ["help","usage"] (NoArg  Help)               "show this help", |  Option ['h'] ["help","usage"] (NoArg  Help)               "show this help", | ||||||
|  Option ['V'] ["version"]      (NoArg  Version)            "show version" |  Option ['V'] ["version"]      (NoArg  Version)            "show version" | ||||||
| @ -42,6 +43,7 @@ data Opt = | |||||||
|     Cleared |  |     Cleared |  | ||||||
|     Empty |  |     Empty |  | ||||||
|     Real |  |     Real |  | ||||||
|  |     Collapse | | ||||||
|     SubTotal | |     SubTotal | | ||||||
|     Help | |     Help | | ||||||
|     Version |     Version | ||||||
|  | |||||||
							
								
								
									
										5
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -222,6 +222,11 @@ balancecommand_tests = TestList [ | |||||||
|    "--------------------\n" ++ |    "--------------------\n" ++ | ||||||
|    "                 $-1\n" ++ |    "                 $-1\n" ++ | ||||||
|    "") |    "") | ||||||
|  |  , | ||||||
|  |   "balance report with -n omits the total" ~: | ||||||
|  |   ([Collapse], ["cash"]) `gives` | ||||||
|  |   ("                 $-2  assets:cash\n" ++ | ||||||
|  |    "") | ||||||
|  ] where |  ] where | ||||||
|     gives (opts,pats) e = do  |     gives (opts,pats) e = do  | ||||||
|       l <- ledgerfromfile pats "sample.ledger" |       l <- ledgerfromfile pats "sample.ledger" | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user