Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains the internal type and functions not to be
used directly as most of them are unsafe, meaning that they allow
actions that violate double-entry contraints or actions
on accounts other than the current body's accounts (via
UNSAFE_AccountN
).
Therefore, do not use this module directly, use HAX.Bookkeeping instead.
- type AccountNumber = Int
- type AssetName = String
- type EntityName = String
- data FullAccountName = FAN {
- fEntity :: EntityName
- fAccount :: String
- swapFAN :: FullAccountName -> FullAccountName
- data AccountName
- type AccountsMap = Map FullAccountName AccountNumber
- sortedAccountNames :: AccountsMap -> [FullAccountName]
- internalAccountNumber :: FullAccountName -> AccountsMap -> AccountNumber
- type Posting = (AccountName, Amount)
- type InternalPosting = (AccountNumber, Amount)
- data Tx = UNSAFE_Tx {
- tComment :: Comment
- tPostings :: [InternalPosting]
- data BalancingTx = BalancingTx {
- txComment :: Comment
- txRemains :: AccountName
- txPostings :: [Posting]
- balanceTx :: Monoid w => BalancingTx -> Acc s l w Tx
- data LogEntry
- type EntityLogEntry = (EntityName, LogEntry)
- type LedgerIndex = (ADate, AccountNumber)
- type LedgerBounds = (LedgerIndex, LedgerIndex)
- class Ledger l where
- data LedgerRW = UNSAFE_Ledger {}
- data FixedLedger = FixedLedger {}
- data FullLedger = FullLedger {}
- data Environment body ledger = Env {
- eLedger :: ledger
- eAccounts :: AccountsMap
- eDate :: ADate
- eBody :: body
- eName :: Maybe EntityName
- type Acc body ledger writer = RWST (Environment body ledger) writer () IO
- type AccountingRW body = Acc body LedgerRW ()
- type AccountingReadOnly body = Acc body FixedLedger (AccountingRW body ())
- class (Monoid w, Ledger l) => AccPair l w
- type AmountRW body = AccountingRW body Amount
- type AmountA body l w = Acc body l w Amount
- fixed :: AccountingReadOnly s a -> AccountingRW s a
- ledgerBounds :: (Monoid w, Ledger l) => Acc s l w (LedgerIndex, LedgerIndex)
- readEntryForNumber :: (Monoid w, Ledger l) => AccountNumber -> Acc s l w (Amount, [EntityLogEntry])
- accountsNumbers :: (Monoid w, Ledger l) => Acc s l w [AccountNumber]
- timeInterval :: (Monoid w, Ledger l) => Acc s l w (ADate, ADate)
- accountNumber :: Monoid w => AccountName -> Acc s l w AccountNumber
- nameErr :: MonadReader (Environment body ledger) m => [Char] -> m EntityName
- readEntryForName :: (Monoid w, Ledger l) => AccountName -> Acc s l w (Amount, [EntityLogEntry])
- uNSAFE_at :: Monoid w => ADate -> Acc s l w a -> Acc s l w a
- uNSAFE_addToBalance :: InternalPosting -> AccountingRW s ()
- uNSAFE_carryOver :: AccountingRW s ()
Account Names and Numbers
type AccountNumber = Int Source #
type EntityName = String Source #
data FullAccountName Source #
uniquely identifying name used to lookup the account numbers
FAN | |
|
data AccountName Source #
this type is used to make functions taking AccountNames
polymorphic.
AccountN String | account for the current entity. Only these accounts should be accessible in accounting actions |
UNSAFE_AccountN FullAccountName | full account for internal use only |
Eq AccountName Source # | |
Ord AccountName Source # | |
Show AccountName Source # | |
IsString AccountName Source # |
|
PrintfArg AccountName Source # | |
type AccountsMap = Map FullAccountName AccountNumber Source #
The map from FullAccountName
s to AccountNumber
s used
internally to address the efficient Ledger
array storage
sortedAccountNames :: AccountsMap -> [FullAccountName] Source #
Extract accounts names order by their internal account numbers
internalAccountNumber :: FullAccountName -> AccountsMap -> AccountNumber Source #
extract the AccountNumber
for a FullAccountName
from an AccountsMap
Postings and Transactions
type Posting = (AccountName, Amount) Source #
type InternalPosting = (AccountNumber, Amount) Source #
A transaction that is already balanced. Such an object can only
be built from BalancingTx
using balanceTx
and is never needed
as function input. This format is used to log the transactions in
the Ledger
's LogEntry
.
UNSAFE_Tx | |
|
data BalancingTx Source #
A transaction involving only accounts relative to a body, and that is self balancing through the use of an account for the remains
BalancingTx | |
|
balanceTx :: Monoid w => BalancingTx -> Acc s l w Tx Source #
Balance a BalancingTx
and prepend the entitiyName to the
comment. This is only used internally
The Ledger
Information that is logged while the ledger is built
type EntityLogEntry = (EntityName, LogEntry) Source #
type LedgerIndex = (ADate, AccountNumber) Source #
type LedgerBounds = (LedgerIndex, LedgerIndex) Source #
This class defines what a Ledger
is:
lBounds :: l -> IO LedgerBounds Source #
it has bounds
lReadEntry :: LedgerIndex -> l -> IO (Amount, [EntityLogEntry]) Source #
single entries for a given account and date consisting of the account balance and the log entries for that date can be read.
lAccountHistory :: (ADate, ADate) -> (ADate -> LedgerIndex) -> l -> IO [Amount] Source #
the account history can be read
lFix :: l -> IO FixedLedger Source #
it can be fixed into an immutable type
lunsafeFix :: l -> IO FixedLedger Source #
fix withou making a copy. This is has to be safe to use, if the mutable version is never modified after the freeze operation.
LedgerRW
implements a writable (within the IO monad) Ledger
.
The total balance is always zero and no transactions that depend on
future values are allowed. This is guaranteed, by not exporting
UNSAFE_Ledger and instead, the ledger is only changed using the
exported safe functions. E.g. tx
, fromTo
, ...
UNSAFE_Ledger | |
|
data FixedLedger Source #
This type implements the Ledger in immutable form, suitable as the main result of the whole program or for accounting accounts that are garantueed to not change the ledger.
data FullLedger Source #
Accounting Environment
data Environment body ledger Source #
Represents the environment an accounting action is run on.
Env | |
|
Monoid w => Eq (AmountA s l w) Source # | |
Monoid w => Fractional (AmountA s l w) Source # | |
Monoid w => Num (AmountA s l w) Source # | Allows to use soll "Cash" + 4 :: AmountA s l |
Monoid w => Ord (AmountA s l w) Source # | Allows to use min ( "Cash") (balanceAt date "Cash") :: AmountA s l |
Accounting Actions
type Acc body ledger writer = RWST (Environment body ledger) writer () IO Source #
The Accounting Monad
This monad is a stack of Reader Writer and IO monad.
Actions from this monad can read an immutable environment. This
environment however, contains references to mutable arrays (see
LedgerRW
), which can be modified through IO actions lifted into
this monad into this
monad.
The body
type variable will contain the type of the Body
the
current accounting action is concerned with.
type AccountingRW body = Acc body LedgerRW () Source #
A specializations for read-write accounting actions with no (i.e. trivial '()') writer output
type AccountingReadOnly body = Acc body FixedLedger (AccountingRW body ()) Source #
A specialization for read-only actions. These actions can however
produce read-write actions as output via the Writer
Monad. This
is used in fixed
.
class (Monoid w, Ledger l) => AccPair l w Source #
Short-cut class used in type signatures involving Acc
and its derivatives
type AmountRW body = AccountingRW body Amount Source #
type synonym for an accounting action that has an amount as result
fixed :: AccountingReadOnly s a -> AccountingRW s a Source #
run a read only action and its genrated read-write output within a general accounting action and pass on its result.
Internal Helper Functions
ledgerBounds :: (Monoid w, Ledger l) => Acc s l w (LedgerIndex, LedgerIndex) Source #
readEntryForNumber :: (Monoid w, Ledger l) => AccountNumber -> Acc s l w (Amount, [EntityLogEntry]) Source #
accountsNumbers :: (Monoid w, Ledger l) => Acc s l w [AccountNumber] Source #
accountNumber :: Monoid w => AccountName -> Acc s l w AccountNumber Source #
nameErr :: MonadReader (Environment body ledger) m => [Char] -> m EntityName Source #
Tries to get the eName
of the current entity and throws an
error if it is Nothing.
readEntryForName :: (Monoid w, Ledger l) => AccountName -> Acc s l w (Amount, [EntityLogEntry]) Source #
Internal UNSAFE Functions
uNSAFE_at :: Monoid w => ADate -> Acc s l w a -> Acc s l w a Source #
perform an accounting action at any date
uNSAFE_addToBalance :: InternalPosting -> AccountingRW s () Source #
uNSAFE_carryOver :: AccountingRW s () Source #
add last month's balances to previous month's. This is performed once for every time step in generate