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

Haspara.Accounting.Event

Synopsis

Documentation

data Event o (s :: Nat) Source #

Encoding of an increment/decrement event.

>>> :set -XDataKinds
>>> import Refined
>>> let date = read "2021-01-01"
>>> let oid = 1 :: Int
>>> let qty = $$(refineTH 42) :: UnsignedQuantity 2
>>> let event = EventDecrement date oid qty
>>> let json = Aeson.encode event
>>> json
"{\"qty\":42.0,\"obj\":1,\"date\":\"2021-01-01\",\"type\":\"DECREMENT\"}"
>>> Aeson.decode json :: Maybe (Event Int 2)
Just (EventDecrement 2021-01-01 1 (Refined 42.00))
>>> 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] #

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

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

mkEvent :: (MonadError String m, KnownNat s) => Date -> o -> Quantity s -> m (Event o s) Source #