haspara-0.0.0.2: A library providing definitions to work with monetary values.
Safe HaskellNone
LanguageHaskell2010

Haspara.Accounting.Event

Description

This module provides definitions for economic events.

/Note: The concept is not YET REA-compatible although we want to achieve it at some point/.

Synopsis

Documentation

data Event o (s :: Nat) Source #

Type encoding of an economic increment/decrement event.

The event explicitly carries the date and quantity information along with a parameterized, arbitrary object providing the source of the event.

>>> :set -XDataKinds
>>> let date = read "2021-01-01"
>>> let oid = 1 :: Int
>>> let qty = $$(Refined.refineTH 42) :: UnsignedQuantity 2
>>> let event = EventDecrement date oid qty
>>> let json = Data.Aeson.encode event
>>> json
"{\"qty\":42.0,\"type\":\"DECREMENT\",\"obj\":1,\"date\":\"2021-01-01\"}"
>>> Data.Aeson.decode @(Event Int 2) json
Just (EventDecrement 2021-01-01 1 (Refined 42.00))
>>> Data.Aeson.decode json == Just event
True

Instances

Instances details
Eq o => Eq (Event o s) Source # 
Instance details

Defined in Haspara.Accounting.Event

Methods

(==) :: Event o s -> Event o s -> Bool #

(/=) :: Event o s -> Event o s -> Bool #

Ord o => Ord (Event o s) Source # 
Instance details

Defined in Haspara.Accounting.Event

Methods

compare :: Event o s -> Event o s -> Ordering #

(<) :: Event o s -> Event o s -> Bool #

(<=) :: Event o s -> Event o s -> Bool #

(>) :: Event o s -> Event o s -> Bool #

(>=) :: Event o s -> Event o s -> Bool #

max :: Event o s -> Event o s -> Event o s #

min :: Event o s -> Event o s -> Event o s #

(Show o, KnownNat s) => Show (Event o s) Source # 
Instance details

Defined in Haspara.Accounting.Event

Methods

showsPrec :: Int -> Event o s -> ShowS #

show :: Event o s -> String #

showList :: [Event o s] -> ShowS #

(ToJSON o, KnownNat s) => ToJSON (Event o s) Source # 
Instance details

Defined in Haspara.Accounting.Event

Methods

toJSON :: Event o s -> Value #

toEncoding :: Event o s -> Encoding #

toJSONList :: [Event o s] -> Value #

toEncodingList :: [Event o s] -> Encoding #

(FromJSON o, KnownNat s) => FromJSON (Event o s) Source # 
Instance details

Defined in Haspara.Accounting.Event

Methods

parseJSON :: Value -> Parser (Event o s) #

parseJSONList :: Value -> Parser [Event o s] #

eventDate :: KnownNat s => Event o s -> Day Source #

Returns the date of the event.

eventObject :: KnownNat s => Event o s -> o Source #

Returns the source object of the event.

negateEvent :: KnownNat s => Event o s -> Event o s Source #

Negates the event.

mkEvent Source #

Arguments

:: MonadError String m 
=> KnownNat s 
=> Day

Date of the event.

-> o

Source object of the event.

-> Quantity s

Quantity of the event.

-> m (Event o s) 

Smart constuctor for Event values.