cli: Commands.Aregister: implement --invert option
This commit is contained in:
parent
fa3676df7d
commit
1a9bfcf5be
@ -58,8 +58,9 @@ module Hledger.Data.Posting (
|
||||
conversionPostingTagName,
|
||||
costPostingTagName,
|
||||
|
||||
-- * arithmetic
|
||||
-- * arithmetic
|
||||
sumPostings,
|
||||
negatePostingAmount,
|
||||
-- * rendering
|
||||
showPosting,
|
||||
showPostingLines,
|
||||
@ -387,6 +388,10 @@ accountNamesFromPostings = S.toList . S.fromList . map paccount
|
||||
sumPostings :: [Posting] -> MixedAmount
|
||||
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
|
||||
|
||||
-- | Negate amount in a posting.
|
||||
negatePostingAmount :: Posting -> Posting
|
||||
negatePostingAmount = postingTransformAmount negate
|
||||
|
||||
-- | Strip all prices from a Posting.
|
||||
postingStripCosts :: Posting -> Posting
|
||||
postingStripCosts = postingTransformAmount mixedAmountStripCosts
|
||||
|
||||
@ -162,6 +162,7 @@ accountTransactionsReport rspec@ReportSpec{_rsReportOpts=ropts} j thisacctq = it
|
||||
. traceAtWith 5 (("ts4:\n"++).pshowTransactions.map snd)
|
||||
. sortBy (comparing (Down . fst) <> comparing (Down . tindex . snd))
|
||||
. map (\t -> (transactionRegisterDate wd reportq thisacctq t, t))
|
||||
. map (if invert_ ropts then (\t -> t{tpostings = map negatePostingAmount $ tpostings t}) else id)
|
||||
$ jtxns acctJournal
|
||||
|
||||
pshowTransactions :: [Transaction] -> String
|
||||
|
||||
@ -249,9 +249,6 @@ summarisePostingsInDateSpan spn@(DateSpan b e) wd mdepth showempty ps
|
||||
bal = if isclipped a then aibalance else aebalance
|
||||
isclipped a' = maybe False (accountNameLevel a' >=) mdepth
|
||||
|
||||
negatePostingAmount :: Posting -> Posting
|
||||
negatePostingAmount = postingTransformAmount negate
|
||||
|
||||
|
||||
-- tests
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ aregistermode = 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"
|
||||
,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
||||
,flagNone ["no-header"] (setboolopt "no-header")
|
||||
"omit header row in table output"
|
||||
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N"
|
||||
|
||||
@ -12,6 +12,7 @@ Flags:
|
||||
balance.
|
||||
--no-elide don't show only 2 commodities per amount
|
||||
--cumulative show running total from report start date
|
||||
--invert display all amounts with reversed sign
|
||||
--no-header omit header row in table output
|
||||
-w --width=N set output width (default: terminal width or
|
||||
$COLUMNS). -wN,M sets description width as well.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user