bal: --budget: don't always convert to cost
And don't show a percentage when budgeted and actual amounts are in different commodities.
This commit is contained in:
		
							parent
							
								
									2355da0f93
								
							
						
					
					
						commit
						adbce22152
					
				| @ -308,19 +308,19 @@ budgetReportAsText ropts@ReportOpts{..} budgetr@(PeriodicReport ( _, rows, _)) = | ||||
|                        (showbudgetamt budget) | ||||
| 
 | ||||
|     -- | Calculate the percentage of actual change to budget goal to show, if any. | ||||
|     -- Both amounts are converted to cost, if possible, before comparing. | ||||
|     -- If valuing at cost, both amounts are converted to cost before comparing. | ||||
|     -- A percentage will not be shown if: | ||||
|     -- - actual or goal are not the same, single, commodity | ||||
|     -- - the goal is zero | ||||
|     percentage :: Change -> BudgetGoal -> Maybe Percentage | ||||
|     percentage actual budget = | ||||
|       case (toCost actual, toCost budget) of | ||||
|       case (maybecost $ normaliseMixedAmount actual, maybecost $ normaliseMixedAmount budget) of | ||||
|         (Mixed [a], Mixed [b]) | (acommodity a == acommodity b || isZeroAmount a) && not (isZeroAmount b)  | ||||
|             -> Just $ 100 * aquantity a / aquantity b | ||||
|         _   -> Nothing | ||||
|         _   -> -- trace (pshow $ (maybecost actual, maybecost budget))  -- debug missing percentage | ||||
|                Nothing | ||||
|       where | ||||
|         toCost = normaliseMixedAmount . costOfMixedAmount  | ||||
| 
 | ||||
|         maybecost = if valuationTypeIsCost ropts then costOfMixedAmount else id | ||||
|     showamt :: MixedAmount -> String | ||||
|     showamt | color_    = cshowMixedAmountOneLineWithoutPrice | ||||
|             | otherwise = showMixedAmountOneLineWithoutPrice | ||||
|  | ||||
| @ -31,7 +31,7 @@ | ||||
| 
 | ||||
| 
 | ||||
| # 1. Test --budget switch | ||||
| $ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget | ||||
| $ hledger -f- bal -D -b 2016-12-01 -e 2016-12-04 --budget | ||||
| Budget performance in 2016/12/01-2016/12/03: | ||||
| 
 | ||||
|                   ||           2016/12/01            2016/12/02            2016/12/03  | ||||
| @ -45,7 +45,7 @@ Budget performance in 2016/12/01-2016/12/03: | ||||
|                   ||    0 [            0]     0 [            0]     0 [            0]  | ||||
| 
 | ||||
| # 2. -E | ||||
| $ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget -E | ||||
| $ hledger -f- bal -D -b 2016-12-01 -e 2016-12-04 --budget -E | ||||
| Budget performance in 2016/12/01-2016/12/03: | ||||
| 
 | ||||
|                   ||           2016/12/01            2016/12/02            2016/12/03  | ||||
| @ -95,15 +95,15 @@ Budget performance in 2016/12/01-2016/12/03: | ||||
|     expenses:leisure  $15 | ||||
|     assets:cash | ||||
| 
 | ||||
| $ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget | ||||
| $ hledger -f- bal -D -b 2016-12-01 -e 2016-12-04 --budget | ||||
| Budget performance in 2016/12/01-2016/12/03: | ||||
| 
 | ||||
|                   ||                 2016/12/01                    2016/12/02                  2016/12/03  | ||||
| ==================++====================================================================================== | ||||
|  assets           ||       $-15 [  60% of $-25]          $-26 [ 104% of $-25]        $-51 [ 204% of $-25]  | ||||
|  assets:cash      ||       $-15 [  60% of $-25]          $-26 [ 104% of $-25]        $-51 [ 204% of $-25]  | ||||
|  expenses         ||        £10 [  60% of  $25]    $5, 20 CAD [ 104% of  $25]         $51 [ 204% of  $25]  | ||||
|  expenses:food    ||        £10 [ 150% of  $10]        20 CAD [ 210% of  $10]         $11 [ 110% of  $10]  | ||||
|  expenses         ||        £10 [          $25]    $5, 20 CAD [          $25]         $51 [ 204% of  $25]  | ||||
|  expenses:food    ||        £10 [          $10]        20 CAD [          $10]         $11 [ 110% of  $10]  | ||||
|  expenses:leisure ||          0 [   0% of  $15]            $5 [  33% of  $15]           0 [   0% of  $15]  | ||||
| ------------------++-------------------------------------------------------------------------------------- | ||||
|                   ||  $-15, £10 [            0]  $-21, 20 CAD [            0]           0 [            0]  | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user