haspara-0.0.0.8: A library providing definitions to work with monetary values.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Haspara.Accounting.Side

Description

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

Documentation

data Side Source #

Data definition for encoding the debit/credit indicator.

Constructors

SideDebit 
SideCredit 

Instances

Instances details
FromJSON Side Source #

FromJSON instance for Side.

>>> :set -XOverloadedStrings
>>> Aeson.eitherDecode "\"db\"" :: Either String Side
Right SideDebit
>>> Aeson.eitherDecode "\"cr\"" :: Either String Side
Right SideCredit
>>> Aeson.eitherDecode "\"hebele\"" :: Either String Side
Left "Error in $: Unkown side indicator: \"hebele\". Expecting one of \"db\" or \"cr\""
Instance details

Defined in Haspara.Accounting.Side

ToJSON Side Source #

ToJSON instance for Side.

>>> Aeson.encode SideDebit
"\"db\""
>>> Aeson.encode SideCredit
"\"cr\""
>>> Aeson.decode (Aeson.encode SideDebit) == Just SideDebit
True
>>> Aeson.decode (Aeson.encode SideCredit) == Just SideCredit
True
Instance details

Defined in Haspara.Accounting.Side

Show Side Source # 
Instance details

Defined in Haspara.Accounting.Side

Methods

showsPrec :: Int -> Side -> ShowS #

show :: Side -> String #

showList :: [Side] -> ShowS #

Eq Side Source # 
Instance details

Defined in Haspara.Accounting.Side

Methods

(==) :: Side -> Side -> Bool #

(/=) :: Side -> Side -> Bool #

Ord Side Source # 
Instance details

Defined in Haspara.Accounting.Side

Methods

compare :: Side -> Side -> Ordering #

(<) :: Side -> Side -> Bool #

(<=) :: Side -> Side -> Bool #

(>) :: Side -> Side -> Bool #

(>=) :: Side -> Side -> Bool #

max :: Side -> Side -> Side #

min :: Side -> Side -> Side #

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 accountDebitCredit
AssetIncreaseDecrease
LiabilityDecreaseIncrease
Equity/CapitalDecreaseIncrease
Income/RevenueDecreaseIncrease
ExpenseCostDividendIncreaseDecrease
>>> :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 AccountNormal BalanceNegative Balance
AssetDebitCredit
LiabilityCreditDebit
EquityCreditDebit
RevenueCreditDebit
ExpenseDebitCredit