Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides definitions for balances used as in accounting.
Synopsis
- data Balance (precision :: Nat) = Balance {
- balanceSide :: !Side
- balanceValue :: !(Quantity precision)
- balanceDebit :: KnownNat precision => Balance precision -> Maybe (Quantity precision)
- balanceCredit :: KnownNat precision => Balance precision -> Maybe (Quantity precision)
- updateBalance :: KnownNat precision => Balance precision -> Amount precision -> Balance precision
- amountFromBalance :: KnownNat precision => Balance precision -> Amount precision
- quantityFromBalance :: KnownNat precision => AccountKind -> Balance precision -> Quantity precision
- valueFromBalance :: KnownNat precision => AccountKind -> Balance precision -> Quantity precision
Documentation
data Balance (precision :: Nat) Source #
Data definition for balances.
This definition is similar to Amount
, however,
the value is allowed to be negative to reflect "Negative Balance" phenomenon.
See https://www.accountingtools.com/articles/what-is-a-negative-balance.html
Balance | |
|
Instances
Eq (Balance precision) Source # | |
KnownNat precision => Show (Balance precision) Source # | |
Generic (Balance precision) Source # | |
KnownNat precision => ToJSON (Balance precision) Source # | For normal balances:
For negative balances:
|
Defined in Haspara.Accounting.Balance | |
KnownNat precision => FromJSON (Balance precision) Source # |
For normal balances:
For negative balances:
|
type Rep (Balance precision) Source # | |
Defined in Haspara.Accounting.Balance type Rep (Balance precision) = D1 ('MetaData "Balance" "Haspara.Accounting.Balance" "haspara-0.0.0.4-91kyQ1gsJrx6JOOKY5ajCi" 'False) (C1 ('MetaCons "Balance" 'PrefixI 'True) (S1 ('MetaSel ('Just "balanceSide") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Side) :*: S1 ('MetaSel ('Just "balanceValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Quantity precision)))) |
balanceDebit :: KnownNat precision => Balance precision -> Maybe (Quantity precision) Source #
Returns the debit quantity, if any.
balanceCredit :: KnownNat precision => Balance precision -> Maybe (Quantity precision) Source #
Returns the credit quantity, if any.
updateBalance :: KnownNat precision => Balance precision -> Amount precision -> Balance precision Source #
Updates the balance with the given amount.
>>>
import Haspara.Accounting.Amount
>>>
import Haspara.Accounting.Side
>>>
import Refined.Unsafe
>>>
let balance = Balance SideDebit 42 :: Balance 2
>>>
balance
Balance {balanceSide = SideDebit, balanceValue = 42.00}>>>
let amountDebit = Amount SideDebit (unsafeRefine 10) :: Amount 2
>>>
amountDebit
Amount {amountSide = SideDebit, amountValue = Refined 10.00}>>>
let amountCredit = Amount SideCredit (unsafeRefine 10) :: Amount 2
>>>
amountCredit
Amount {amountSide = SideCredit, amountValue = Refined 10.00}>>>
updateBalance balance amountDebit
Balance {balanceSide = SideDebit, balanceValue = 52.00}>>>
updateBalance balance amountCredit
Balance {balanceSide = SideDebit, balanceValue = 32.00}
amountFromBalance :: KnownNat precision => Balance precision -> Amount precision Source #
Converts the balance to amount.
>>>
import Haspara.Accounting.Side
>>>
amountFromBalance (Balance SideDebit 42 :: Balance 2)
Amount {amountSide = SideDebit, amountValue = Refined 42.00}>>>
amountFromBalance (Balance SideDebit (-42) :: Balance 2)
Amount {amountSide = SideCredit, amountValue = Refined 42.00}>>>
amountFromBalance (Balance SideCredit 42 :: Balance 2)
Amount {amountSide = SideCredit, amountValue = Refined 42.00}>>>
amountFromBalance (Balance SideCredit (-42) :: Balance 2)
Amount {amountSide = SideDebit, amountValue = Refined 42.00}
quantityFromBalance :: KnownNat precision => AccountKind -> Balance precision -> Quantity precision Source #
Returns the quantity of the balance given the account kind.
See quantityFromAmount
for the meaning of quantity.
valueFromBalance :: KnownNat precision => AccountKind -> Balance precision -> Quantity precision Source #
Returns the value of the balance given the account kind.
See valueFromAmount
for the meaning of quantity.