lib: transaction, [v]post*, balassert* constructors, for tests etc.
This commit is contained in:
parent
115643a024
commit
ca565795ad
@ -15,9 +15,16 @@ module Hledger.Data.Posting (
|
|||||||
nullposting,
|
nullposting,
|
||||||
posting,
|
posting,
|
||||||
post,
|
post,
|
||||||
|
vpost,
|
||||||
|
post',
|
||||||
|
vpost',
|
||||||
nullsourcepos,
|
nullsourcepos,
|
||||||
nullassertion,
|
nullassertion,
|
||||||
assertion,
|
assertion,
|
||||||
|
balassert,
|
||||||
|
balassertTot,
|
||||||
|
balassertParInc,
|
||||||
|
balassertTotInc,
|
||||||
-- * operations
|
-- * operations
|
||||||
originalPosting,
|
originalPosting,
|
||||||
postingStatus,
|
postingStatus,
|
||||||
@ -95,8 +102,23 @@ nullposting = Posting
|
|||||||
}
|
}
|
||||||
posting = nullposting
|
posting = nullposting
|
||||||
|
|
||||||
|
-- constructors
|
||||||
|
|
||||||
|
-- | Make a posting to an account.
|
||||||
post :: AccountName -> Amount -> Posting
|
post :: AccountName -> Amount -> Posting
|
||||||
post acct amt = posting {paccount=acct, pamount=Mixed [amt]}
|
post acc amt = posting {paccount=acc, pamount=Mixed [amt]}
|
||||||
|
|
||||||
|
-- | Make a virtual (unbalanced) posting to an account.
|
||||||
|
vpost :: AccountName -> Amount -> Posting
|
||||||
|
vpost acc amt = (post acc amt){ptype=VirtualPosting}
|
||||||
|
|
||||||
|
-- | Make a posting to an account, maybe with a balance assertion.
|
||||||
|
post' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting
|
||||||
|
post' acc amt ass = posting {paccount=acc, pamount=Mixed [amt], pbalanceassertion=ass}
|
||||||
|
|
||||||
|
-- | Make a virtual (unbalanced) posting to an account, maybe with a balance assertion.
|
||||||
|
vpost' :: AccountName -> Amount -> Maybe BalanceAssertion -> Posting
|
||||||
|
vpost' acc amt ass = (post' acc amt ass){ptype=VirtualPosting, pbalanceassertion=ass}
|
||||||
|
|
||||||
nullsourcepos :: GenericSourcePos
|
nullsourcepos :: GenericSourcePos
|
||||||
nullsourcepos = JournalSourcePos "" (1,1)
|
nullsourcepos = JournalSourcePos "" (1,1)
|
||||||
@ -110,6 +132,22 @@ nullassertion = BalanceAssertion
|
|||||||
}
|
}
|
||||||
assertion = nullassertion
|
assertion = nullassertion
|
||||||
|
|
||||||
|
-- | Make a partial, exclusive balance assertion.
|
||||||
|
balassert :: Amount -> Maybe BalanceAssertion
|
||||||
|
balassert amt = Just $ nullassertion{baamount=amt}
|
||||||
|
|
||||||
|
-- | Make a total, exclusive balance assertion.
|
||||||
|
balassertTot :: Amount -> Maybe BalanceAssertion
|
||||||
|
balassertTot amt = Just $ nullassertion{baamount=amt, batotal=True}
|
||||||
|
|
||||||
|
-- | Make a partial, inclusive balance assertion.
|
||||||
|
balassertParInc :: Amount -> Maybe BalanceAssertion
|
||||||
|
balassertParInc amt = Just $ nullassertion{baamount=amt, bainclusive=True}
|
||||||
|
|
||||||
|
-- | Make a total, inclusive balance assertion.
|
||||||
|
balassertTotInc :: Amount -> Maybe BalanceAssertion
|
||||||
|
balassertTotInc amt = Just $ nullassertion{baamount=amt, batotal=True, bainclusive=True}
|
||||||
|
|
||||||
-- Get the original posting, if any.
|
-- Get the original posting, if any.
|
||||||
originalPosting :: Posting -> Posting
|
originalPosting :: Posting -> Posting
|
||||||
originalPosting p = fromMaybe p $ poriginal p
|
originalPosting p = fromMaybe p $ poriginal p
|
||||||
|
|||||||
@ -16,6 +16,7 @@ tags.
|
|||||||
module Hledger.Data.Transaction (
|
module Hledger.Data.Transaction (
|
||||||
-- * Transaction
|
-- * Transaction
|
||||||
nulltransaction,
|
nulltransaction,
|
||||||
|
transaction,
|
||||||
txnTieKnot,
|
txnTieKnot,
|
||||||
txnUntieKnot,
|
txnUntieKnot,
|
||||||
-- * operations
|
-- * operations
|
||||||
@ -95,6 +96,10 @@ nulltransaction = Transaction {
|
|||||||
tprecedingcomment=""
|
tprecedingcomment=""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Make a simple transaction with the given date and postings.
|
||||||
|
transaction :: String -> [Posting] -> Transaction
|
||||||
|
transaction datestr ps = txnTieKnot $ nulltransaction{tdate=parsedate datestr, tpostings=ps}
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Render a journal transaction as text in the style of Ledger's print command.
|
Render a journal transaction as text in the style of Ledger's print command.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user