Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module provides definitions for and functions to work with Debit/Credit dichotomy which is essential to double-entry bookkeeping.
In our concept, we refer to this dichotomy as Side (materialized via Side
sum-type) which is either Debit (materialized via SideDebit
nullary data
constructor) or Dredit (materialized via SideCredit
nullary data
constructor).
This module provides FromJSON
and ToJSON
instances for Side
as well. Following accounting conventions, we chose the JSON value for
Debit as "db"
, and for Credit as "cr"
.
Synopsis
- data Side
- otherSide :: Side -> Side
- sideByAccountKind :: KnownNat precision => AccountKind -> Quantity precision -> Side
- normalSideByAccountKind :: AccountKind -> Side
Documentation
Data definition for encoding the debit/credit indicator.
Instances
FromJSON Side Source # |
|
ToJSON Side Source # |
|
Defined in Haspara.Accounting.Side | |
Show Side Source # | |
Eq Side Source # | |
Ord Side Source # | |
otherSide :: Side -> Side Source #
Gives the other side.
>>>
otherSide SideDebit
SideCredit>>>
otherSide SideCredit
SideDebit
sideByAccountKind :: KnownNat precision => AccountKind -> Quantity precision -> Side Source #
Computes the Side
by the given AccountKind
and the sign of the given
Quantity
.
The sign of the Quantity
is indeed a proxy for whether the event of the
Quantity
is an increment (+1
) or decrement (-1
) event.
0
quantities are considered to originate from an increment event. So far,
this seems to be a safe assumption that gives us totality in the context of
this function.
Note the following mapping as a guide:
Kind of account | Debit | Credit |
Asset | Increase | Decrease |
Liability | Decrease | Increase |
Equity/Capital | Decrease | Increase |
Income/Revenue | Decrease | Increase |
ExpenseCostDividend | Increase | Decrease |
>>>
:set -XDataKinds
>>>
import Haspara.Quantity
>>>
let decrement = mkQuantity (-0.42) :: Quantity 2
>>>
let nocrement = mkQuantity 0 :: Quantity 2
>>>
let increment = mkQuantity 0.42 :: Quantity 2
>>>
fmap (sideByAccountKind AccountKindAsset) [decrement, nocrement, increment]
[SideCredit,SideDebit,SideDebit]>>>
fmap (sideByAccountKind AccountKindLiability) [decrement, nocrement, increment]
[SideDebit,SideCredit,SideCredit]>>>
fmap (sideByAccountKind AccountKindEquity) [decrement, nocrement, increment]
[SideDebit,SideCredit,SideCredit]>>>
fmap (sideByAccountKind AccountKindRevenue) [decrement, nocrement, increment]
[SideDebit,SideCredit,SideCredit]>>>
fmap (sideByAccountKind AccountKindExpense) [decrement, nocrement, increment]
[SideCredit,SideDebit,SideDebit]
normalSideByAccountKind :: AccountKind -> Side Source #
Returns the "normal" side for a given AccountKind
.
Note the following mapping as a guide:
Kind of Account | Normal Balance | Negative Balance |
Asset | Debit | Credit |
Liability | Credit | Debit |
Equity | Credit | Debit |
Revenue | Credit | Debit |
Expense | Debit | Credit |