cashflow: make totals row and -N more like balance/bs/is (#518)
This commit is contained in:
		
							parent
							
								
									b658a6b843
								
							
						
					
					
						commit
						e50dede708
					
				| @ -15,7 +15,7 @@ module Hledger.Cli.BalanceView ( | |||||||
| ) where | ) where | ||||||
| 
 | 
 | ||||||
| import Control.Monad (unless) | import Control.Monad (unless) | ||||||
| import Data.List (intercalate, foldl') | import Data.List (intercalate, foldl', isPrefixOf) | ||||||
| import Data.Maybe (fromMaybe) | import Data.Maybe (fromMaybe) | ||||||
| import Data.Monoid (Sum(..), (<>)) | import Data.Monoid (Sum(..), (<>)) | ||||||
| import System.Console.CmdArgs.Explicit as C | import System.Console.CmdArgs.Explicit as C | ||||||
| @ -100,7 +100,8 @@ multiBalanceviewQueryReport | |||||||
|     -> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount) |     -> ([Table String String MixedAmount], [[MixedAmount]], Sum MixedAmount) | ||||||
| multiBalanceviewQueryReport ropts q0 j t q = ([tabl], [coltotals], Sum tot) | multiBalanceviewQueryReport ropts q0 j t q = ([tabl], [coltotals], Sum tot) | ||||||
|     where |     where | ||||||
|       ropts' = ropts { no_total_ = False, empty_ = True } |       singlesection = "Cash" `isPrefixOf` t -- TODO temp  | ||||||
|  |       ropts' = ropts { no_total_ = singlesection && no_total_ ropts, empty_ = True } | ||||||
|       q' = And [q0, q j] |       q' = And [q0, q j] | ||||||
|       MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = |       MultiBalanceReport (dates, rows, (coltotals,tot,avg)) = | ||||||
|           multiBalanceReport ropts' q' j |           multiBalanceReport ropts' q' j | ||||||
| @ -114,7 +115,7 @@ multiBalanceviewQueryReport ropts q0 j t q = ([tabl], [coltotals], Sum tot) | |||||||
| 
 | 
 | ||||||
| -- | Prints out a balance report according to a given view | -- | Prints out a balance report according to a given view | ||||||
| balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO () | balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO () | ||||||
| balanceviewReport BalanceView{..} CliOpts{reportopts_=ropts, rawopts_=raw} j = do | balanceviewReport BalanceView{..} CliOpts{command_=cmd, reportopts_=ropts, rawopts_=raw} j = do | ||||||
|     currDay   <- getCurrentDay |     currDay   <- getCurrentDay | ||||||
|     let q0 = queryFromOpts currDay ropts' |     let q0 = queryFromOpts currDay ropts' | ||||||
|     let title = bvtitle ++ maybe "" (' ':) balanceclarification |     let title = bvtitle ++ maybe "" (' ':) balanceclarification | ||||||
| @ -125,7 +126,7 @@ balanceviewReport BalanceView{..} CliOpts{reportopts_=ropts, rawopts_=raw} j = d | |||||||
|                  bvqueries |                  bvqueries | ||||||
|         mapM_ putStrLn (title : "" : views) |         mapM_ putStrLn (title : "" : views) | ||||||
| 
 | 
 | ||||||
|         unless (no_total_ ropts') . mapM_ putStrLn $ |         unless (no_total_ ropts' || cmd=="cashflow") . mapM_ putStrLn $ -- TODO temp | ||||||
|           [ "Total:" |           [ "Total:" | ||||||
|           , "--------------------" |           , "--------------------" | ||||||
|           , padleft 20 $ showMixedAmountWithoutPrice (getSum amt) |           , padleft 20 $ showMixedAmountWithoutPrice (getSum amt) | ||||||
|  | |||||||
| @ -12,9 +12,6 @@ Cash flows: | |||||||
| -------------------- | -------------------- | ||||||
|                    1 |                    1 | ||||||
| 
 | 
 | ||||||
| Total: |  | ||||||
| -------------------- |  | ||||||
|                    1 |  | ||||||
| >>>2 | >>>2 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| @ -48,9 +45,6 @@ Cash flows: | |||||||
| -------------------- | -------------------- | ||||||
|              $-40.00 |              $-40.00 | ||||||
| 
 | 
 | ||||||
| Total: |  | ||||||
| -------------------- |  | ||||||
|              $-40.00 |  | ||||||
| >>>2 | >>>2 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| @ -84,9 +78,6 @@ Cash flows: | |||||||
| -------------------- | -------------------- | ||||||
|            $9,960.00 |            $9,960.00 | ||||||
| 
 | 
 | ||||||
| Total: |  | ||||||
| -------------------- |  | ||||||
|            $9,960.00 |  | ||||||
| >>>2 | >>>2 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| @ -120,9 +111,6 @@ Cash flows: | |||||||
| -------------------- | -------------------- | ||||||
|           $10,000.00 |           $10,000.00 | ||||||
| 
 | 
 | ||||||
| Total: |  | ||||||
| -------------------- |  | ||||||
|           $10,000.00 |  | ||||||
| >>>2 | >>>2 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| @ -155,9 +143,6 @@ Cash flows: | |||||||
| -------------------- | -------------------- | ||||||
|                    0 |                    0 | ||||||
| 
 | 
 | ||||||
| Total: |  | ||||||
| -------------------- |  | ||||||
|                    0 |  | ||||||
| >>>2 | >>>2 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| @ -179,7 +164,7 @@ Cashflow Statement | |||||||
| 
 | 
 | ||||||
| >>>= 0 | >>>= 0 | ||||||
| 
 | 
 | ||||||
| # 6. Multicolumn test (historical) | # 7. Multicolumn test (historical) | ||||||
| hledger -f sample.journal cashflow -p 'monthly in 2008' -A --historical | hledger -f sample.journal cashflow -p 'monthly in 2008' -A --historical | ||||||
| >>> | >>> | ||||||
| Cashflow Statement (Historical Ending Balances) | Cashflow Statement (Historical Ending Balances) | ||||||
| @ -196,3 +181,65 @@ Cashflow Statement (Historical Ending Balances) | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| >>>= 0 | >>>= 0 | ||||||
|  | 
 | ||||||
|  | # 8. without -N/--no-total (single column) | ||||||
|  | hledger -f sample.journal cf  | ||||||
|  | >>> | ||||||
|  | Cashflow Statement | ||||||
|  | 
 | ||||||
|  | Cash flows: | ||||||
|  |                  $-1  assets | ||||||
|  |                   $1    bank:saving | ||||||
|  |                  $-2    cash | ||||||
|  | -------------------- | ||||||
|  |                  $-1 | ||||||
|  | 
 | ||||||
|  | >>>2 | ||||||
|  | >>>= | ||||||
|  | 
 | ||||||
|  | # 9. with -N (single column) | ||||||
|  | hledger -f sample.journal cf -N | ||||||
|  | >>> | ||||||
|  | Cashflow Statement | ||||||
|  | 
 | ||||||
|  | Cash flows: | ||||||
|  |                  $-1  assets | ||||||
|  |                   $1    bank:saving | ||||||
|  |                  $-2    cash | ||||||
|  | 
 | ||||||
|  | >>>2 | ||||||
|  | >>>= | ||||||
|  | 
 | ||||||
|  | # 10. without -N (multi column) | ||||||
|  | hledger -f sample.journal cf -Y | ||||||
|  | >>> | ||||||
|  | Cashflow Statement | ||||||
|  | 
 | ||||||
|  |                     ||  2008  | ||||||
|  | ====================++======= | ||||||
|  |  Cash flows         ||        | ||||||
|  | --------------------++------- | ||||||
|  |  assets:bank:saving ||    $1  | ||||||
|  |  assets:cash        ||   $-2  | ||||||
|  | --------------------++------- | ||||||
|  |                     ||   $-1  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | >>>2 | ||||||
|  | >>>= | ||||||
|  | 
 | ||||||
|  | # 11. with -N (multi column) | ||||||
|  | hledger -f sample.journal cf -Y -N | ||||||
|  | >>> | ||||||
|  | Cashflow Statement | ||||||
|  | 
 | ||||||
|  |                     ||  2008  | ||||||
|  | ====================++======= | ||||||
|  |  Cash flows         ||        | ||||||
|  | --------------------++------- | ||||||
|  |  assets:bank:saving ||    $1  | ||||||
|  |  assets:cash        ||   $-2  | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | >>>2 | ||||||
|  | >>>= | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user