lib: +postingNegate
This commit is contained in:
parent
0dca0911f3
commit
bbb06209e7
@ -63,6 +63,7 @@ module Hledger.Data.Posting (
|
|||||||
|
|
||||||
-- * arithmetic
|
-- * arithmetic
|
||||||
sumPostings,
|
sumPostings,
|
||||||
|
postingNegate,
|
||||||
postingNegateMainAmount,
|
postingNegateMainAmount,
|
||||||
-- * rendering
|
-- * rendering
|
||||||
showPosting,
|
showPosting,
|
||||||
@ -381,6 +382,13 @@ accountNamesFromPostings = S.toList . S.fromList . map paccount
|
|||||||
sumPostings :: [Posting] -> MixedAmount
|
sumPostings :: [Posting] -> MixedAmount
|
||||||
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
|
sumPostings = foldl' (\amt p -> maPlus amt $ pamount p) nullmixedamt
|
||||||
|
|
||||||
|
-- | Negate the posting's main amount and balance assertion amount if any.
|
||||||
|
postingNegate :: Posting -> Posting
|
||||||
|
postingNegate p@Posting{pamount=a, pbalanceassertion=mb} =
|
||||||
|
p{pamount=negate a, pbalanceassertion=fmap balanceAssertionNegate mb}
|
||||||
|
where
|
||||||
|
balanceAssertionNegate b@BalanceAssertion{baamount=ba} = b{baamount=negate ba}
|
||||||
|
|
||||||
-- | Negate the posting's main amount but not the balance assertion amount.
|
-- | Negate the posting's main amount but not the balance assertion amount.
|
||||||
postingNegateMainAmount :: Posting -> Posting
|
postingNegateMainAmount :: Posting -> Posting
|
||||||
postingNegateMainAmount p@Posting{pamount=a} = p{pamount=negate a}
|
postingNegateMainAmount p@Posting{pamount=a} = p{pamount=negate a}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user