Support register --invert option to negate amounts
This commit is contained in:
		
							parent
							
								
									98d7c073c7
								
							
						
					
					
						commit
						161ca660dc
					
				| @ -116,7 +116,8 @@ matchedPostingsBeforeAndDuring opts q j (DateSpan mstart mend) = | |||||||
|   where |   where | ||||||
|     beforestartq = dbg1 "beforestartq" $ dateqtype $ DateSpan Nothing mstart |     beforestartq = dbg1 "beforestartq" $ dateqtype $ DateSpan Nothing mstart | ||||||
|     beforeandduringps = |     beforeandduringps = | ||||||
|       dbg1 "ps4" $ sortBy (comparing sortdate) $                               -- sort postings by date or date2 |       dbg1 "ps5" $ sortBy (comparing sortdate) $                               -- sort postings by date or date2 | ||||||
|  |       dbg1 "ps4" $ (if invert_ opts then map negatePostingAmount else id) $    -- with --invert, invert amounts | ||||||
|       dbg1 "ps3" $ map (filterPostingAmount symq) $                            -- remove amount parts which the query's cur: terms would exclude |       dbg1 "ps3" $ map (filterPostingAmount symq) $                            -- remove amount parts which the query's cur: terms would exclude | ||||||
|       dbg1 "ps2" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings |       dbg1 "ps2" $ (if related_ opts then concatMap relatedPostings else id) $ -- with -r, replace each with its sibling postings | ||||||
|       dbg1 "ps1" $ filter (beforeandduringq `matchesPosting`) $                -- filter postings by the query, with no start date or depth limit |       dbg1 "ps1" $ filter (beforeandduringq `matchesPosting`) $                -- filter postings by the query, with no start date or depth limit | ||||||
| @ -135,6 +136,9 @@ matchedPostingsBeforeAndDuring opts q j (DateSpan mstart mend) = | |||||||
|       where |       where | ||||||
|         dateq = dbg1 "dateq" $ filterQuery queryIsDateOrDate2 $ dbg1 "q" q  -- XXX confused by multiple date:/date2: ? |         dateq = dbg1 "dateq" $ filterQuery queryIsDateOrDate2 $ dbg1 "q" q  -- XXX confused by multiple date:/date2: ? | ||||||
| 
 | 
 | ||||||
|  | negatePostingAmount :: Posting -> Posting | ||||||
|  | negatePostingAmount p = p { pamount = negate $ pamount p } | ||||||
|  | 
 | ||||||
| -- | Generate postings report line items from a list of postings or (with | -- | Generate postings report line items from a list of postings or (with | ||||||
| -- non-Nothing dates attached) summary postings. | -- non-Nothing dates attached) summary postings. | ||||||
| postingsReportItems :: [(Posting,Maybe Day)] -> (Posting,Maybe Day) -> WhichDate -> Int -> MixedAmount -> (Int -> MixedAmount -> MixedAmount -> MixedAmount) -> Int -> [PostingsReportItem] | postingsReportItems :: [(Posting,Maybe Day)] -> (Posting,Maybe Day) -> WhichDate -> Int -> MixedAmount -> (Int -> MixedAmount -> MixedAmount -> MixedAmount) -> Int -> [PostingsReportItem] | ||||||
|  | |||||||
| @ -36,6 +36,7 @@ registermode = hledgerCommandMode | |||||||
|   ,flagNone ["average","A"] (setboolopt "average") |   ,flagNone ["average","A"] (setboolopt "average") | ||||||
|      "show running average of posting amounts instead of total (implies --empty)" |      "show running average of posting amounts instead of total (implies --empty)" | ||||||
|   ,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead" |   ,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead" | ||||||
|  |   ,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign" | ||||||
|   ,flagReq  ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N" |   ,flagReq  ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N" | ||||||
|      ("set output width (default: " ++ |      ("set output width (default: " ++ | ||||||
| #ifdef mingw32_HOST_OS | #ifdef mingw32_HOST_OS | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user