Support register --invert option to negate amounts

This commit is contained in:
Jakob Schöttl 2019-02-09 15:31:43 +01:00 committed by Simon Michael
parent 98d7c073c7
commit 161ca660dc
2 changed files with 6 additions and 1 deletions

View File

@ -116,7 +116,8 @@ matchedPostingsBeforeAndDuring opts q j (DateSpan mstart mend) =
where
beforestartq = dbg1 "beforestartq" $ dateqtype $ DateSpan Nothing mstart
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 "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
@ -135,6 +136,9 @@ matchedPostingsBeforeAndDuring opts q j (DateSpan mstart mend) =
where
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
-- non-Nothing dates attached) summary postings.
postingsReportItems :: [(Posting,Maybe Day)] -> (Posting,Maybe Day) -> WhichDate -> Int -> MixedAmount -> (Int -> MixedAmount -> MixedAmount -> MixedAmount) -> Int -> [PostingsReportItem]

View File

@ -36,6 +36,7 @@ registermode = hledgerCommandMode
,flagNone ["average","A"] (setboolopt "average")
"show running average of posting amounts instead of total (implies --empty)"
,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"
("set output width (default: " ++
#ifdef mingw32_HOST_OS