web: show proper Y-values in register chart (fixes #122)
This commit is contained in:
		
							parent
							
								
									191ed1b92a
								
							
						
					
					
						commit
						fd8de9558e
					
				| @ -34,6 +34,7 @@ module Hledger.Reports ( | |||||||
|   TransactionsReport, |   TransactionsReport, | ||||||
|   TransactionsReportItem, |   TransactionsReportItem, | ||||||
|   triDate, |   triDate, | ||||||
|  |   triBalance, | ||||||
|   triSimpleBalance, |   triSimpleBalance, | ||||||
|   transactionsReportByCommodity, |   transactionsReportByCommodity, | ||||||
|   journalTransactionsReport, |   journalTransactionsReport, | ||||||
| @ -437,6 +438,7 @@ type TransactionsReportItem = (Transaction -- the corresponding transaction | |||||||
| 
 | 
 | ||||||
| triDate (t,_,_,_,_,_) = tdate t | triDate (t,_,_,_,_,_) = tdate t | ||||||
| triAmount (_,_,_,_,a,_) = a | triAmount (_,_,_,_,a,_) = a | ||||||
|  | triBalance (_,_,_,_,_,a) = a | ||||||
| triSimpleBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0" | triSimpleBalance (_,_,_,_,_,Mixed a) = case a of [] -> "0" | ||||||
|                                                  (Amount{aquantity=q}):_ -> show q |                                                  (Amount{aquantity=q}):_ -> show q | ||||||
| 
 | 
 | ||||||
| @ -449,26 +451,35 @@ transactionsReportByCommodity tr = | |||||||
|     transactionsReportCommodities (_,items) = |     transactionsReportCommodities (_,items) = | ||||||
|       nub $ sort $ map acommodity $ concatMap (amounts . triAmount) items |       nub $ sort $ map acommodity $ concatMap (amounts . triAmount) items | ||||||
| 
 | 
 | ||||||
| -- Remove transaction report items and item amount components that | -- Remove transaction report items and item amount (and running | ||||||
| -- don't involve the specified commodity. Other item fields like the | -- balance amount) components that don't involve the specified | ||||||
| -- running balance and the transaction are left unchanged. | -- commodity. Other item fields such as the transaction are left unchanged. | ||||||
| filterTransactionsReportByCommodity :: Commodity -> TransactionsReport -> TransactionsReport | filterTransactionsReportByCommodity :: Commodity -> TransactionsReport -> TransactionsReport | ||||||
| filterTransactionsReportByCommodity c (label,items) = | filterTransactionsReportByCommodity c (label,items) = | ||||||
|   (label, fixTransactionsReportItemBalances $ concat [filterTransactionsReportItemByCommodity c i | i <- items]) |   (label, fixTransactionsReportItemBalances $ concat [filterTransactionsReportItemByCommodity c i | i <- items]) | ||||||
|   where |   where | ||||||
|     filterTransactionsReportItemByCommodity c (t,t2,s,o,Mixed as,bal) |     filterTransactionsReportItemByCommodity c (t,t2,s,o,a,bal) | ||||||
|       | c `elem` cs = [item'] |       | c `elem` cs = [item'] | ||||||
|       | otherwise   = [] |       | otherwise   = [] | ||||||
|       where |       where | ||||||
|         cs = map acommodity as |         cs = map acommodity as | ||||||
|         item' = (t,t2,s,o,Mixed as',bal) |         item' = (t,t2,s,o,a',bal) | ||||||
|         as' = filter ((==c).acommodity) as |         a' = filterMixedAmountByCommodity c a | ||||||
|     fixTransactionsReportItemBalances is = reverse $ go nullmixedamt $ reverse is | 
 | ||||||
|  |     fixTransactionsReportItemBalances [] = [] | ||||||
|  |     fixTransactionsReportItemBalances [i] = [i] | ||||||
|  |     fixTransactionsReportItemBalances items = reverse $ i:(go startbal is) | ||||||
|       where |       where | ||||||
|  |         i:is = reverse items | ||||||
|  |         startbal = filterMixedAmountByCommodity c $ triBalance i | ||||||
|         go _ [] = [] |         go _ [] = [] | ||||||
|         go bal ((t,t2,s,o,amt,_):is) = (t,t2,s,o,amt,bal'):go bal' is |         go bal ((t,t2,s,o,amt,_):is) = (t,t2,s,o,amt,bal'):go bal' is | ||||||
|           where bal' = bal + amt |           where bal' = bal + amt | ||||||
| 
 | 
 | ||||||
|  | -- | Filter out all but the specified commodity from this amount. | ||||||
|  | filterMixedAmountByCommodity :: Commodity -> MixedAmount -> MixedAmount | ||||||
|  | filterMixedAmountByCommodity c (Mixed as) = Mixed $ filter ((==c). acommodity) as | ||||||
|  | 
 | ||||||
| -- | Select transactions from the whole journal for a transactions report, | -- | Select transactions from the whole journal for a transactions report, | ||||||
| -- with no \"current\" account. The end result is similar to | -- with no \"current\" account. The end result is similar to | ||||||
| -- "postingsReport" except it uses queries and transaction-based report | -- "postingsReport" except it uses queries and transaction-based report | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user