Safe Haskell | None |
---|
Containers for entries.
This module is the key guardian of the core principle of
double-entry accounting, which is that debits and credits must
always balance. An Ent
is a container for an Entry
. An Entry
holds a DrCr
and an Amount
which, in turn, holds a Commodity
and a Qty
. For a given Commodity
in a particular transaction,
the sum of the debits must always be equal to the sum of the
credits.
In addition to the Entry
, the Ent
holds information about
whether the particular Entry
it holds is inferred or not. An Ent
is inferred
if the user did not supply the entry, but Penny was
able to deduce its Entry
because proper entries were supplied for
all the other postings in the transaction. The Ent
also holds
arbitrary metadata--which will typically be other information about
the particular posting, such as the payee, account, etc.
A collection of Ent
is an Ents
. This module will only create an
Ent
as part of an Ents
(though you can later separate the Ent
from its other Ents
if you like.) In any given Ents
, all of the
Ent
collectively have a zero balance.
This module also contains type synonyms used to represent a Posting, which is an Ent bundled with its sibling Ents, and a Transaction.
- data Ent m
- entry :: Ent m -> Either (Entry QtyRep) (Entry Qty)
- meta :: Ent m -> m
- inferred :: Ent m -> Bool
- data Ents m
- unEnts :: Ents m -> [Ent m]
- tupleEnts :: Ents m -> (Ent m, Ent m, [Ent m])
- mapEnts :: (Ent a -> b) -> Ents a -> Ents b
- traverseEnts :: Applicative f => (Ent a -> f b) -> Ents a -> f (Ents b)
- ents :: [(Maybe (Either (Entry QtyRep) (Entry Qty)), m)] -> Maybe (Ents m)
- rEnts :: Commodity -> DrCr -> (Either QtyRep Qty, m) -> [(Either QtyRep Qty, m)] -> m -> Ents m
- headEnt :: Ents m -> Ent m
- tailEnts :: Ents m -> (Ent m, [Ent m])
- newtype Posting = Posting {
- unPosting :: (TopLineData, Ents PostingData)
- newtype Transaction = Transaction {}
- transactionToPostings :: Transaction -> [Posting]
- views :: Ents m -> [Ents m]
- unrollSnd :: (a, [b]) -> [(a, b)]
Ent
Information about an entry, along with whether it is inferred and its metadata.
entry :: Ent m -> Either (Entry QtyRep) (Entry Qty)Source
The entry from an Ent. If the Ent is inferred--that is, if the user did not supply an entry for it and Penny was able to infer the entry--this will be a Right with the inferred Entry.
Ents
tupleEnts :: Ents m -> (Ent m, Ent m, [Ent m])Source
Every Ents alwas contains at least two ents, and possibly additional ones.
mapEnts :: (Ent a -> b) -> Ents a -> Ents bSource
Alter the metadata Ents, while examining the Ents themselves. If you only want to change the metadata and you don't need to examine the other contents of the Ent, use the Functor instance. You cannot change non-metadata aspects of the Ent.
traverseEnts :: Applicative f => (Ent a -> f b) -> Ents a -> f (Ents b)Source
Alter the metadata of Ents while examing their contents. If you do not need to examine their contents, use the Traversable instance.
ents :: [(Maybe (Either (Entry QtyRep) (Entry Qty)), m)] -> Maybe (Ents m)Source
Creates an Ents
. At most, one of the Maybe Entry can be Nothing
and this function will infer the remaining Entry. This function
fails if it cannot create a balanced Ents.
headEnt :: Ents m -> Ent mSource
Get information from the head posting in the View, which is the one you are most likely interested in. This never fails, as every Ents has at least two postings.
Postings and transactions
In a Posting, the Ent yielded by headEnt
will be the posting of
interest. The other sibling postings are also available for
inspection.
newtype Transaction Source
A Transaction and a Posting are identical on the inside, but they have different semantic meanings so they are wrapped in newtypes.
transactionToPostings :: Transaction -> [Posting]Source
Splits a Transaction into Postings.