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

Haspara.Accounting.Posting

Synopsis

Documentation

newtype Posting a o (s :: Nat) Source #

Type encoding for a posting.

>>> :set -XDataKinds
>>> import Haspara.Accounting
>>> import Refined
>>> import qualified Data.Aeson as Aeson
>>> import qualified Data.List.NonEmpty as NE
>>> let date = read "2021-01-01"
>>> let oid = 1 :: Int
>>> let qty = $$(refineTH 42) :: UnsignedQuantity 2
>>> let event = EventDecrement date oid qty
>>> let account = Account AccountKindAsset ("Cash" :: String, 1 ::Int)
>>> let posting =  Posting . NE.fromList $ [(event, account)]
>>> let json = Aeson.encode posting
>>> json
"[[{\"qty\":42.0,\"obj\":1,\"date\":\"2021-01-01\",\"type\":\"DECREMENT\"},{\"kind\":\"ASSET\",\"object\":[\"Cash\",1]}]]"
>>> Aeson.decode json :: Maybe (Posting (String, Int) Int 2)
Just (Posting ((EventDecrement 2021-01-01 1 (Refined 42.00),Account {accountKind = AccountKindAsset, accountObject = ("Cash",1)}) :| []))
>>> Aeson.decode json == Just posting
True

Constructors

Posting (NonEmpty (Event o s, Account a)) 

Instances

Instances details
(Eq o, Eq a) => Eq (Posting a o s) Source # 
Instance details

Defined in Haspara.Accounting.Posting

Methods

(==) :: Posting a o s -> Posting a o s -> Bool #

(/=) :: Posting a o s -> Posting a o s -> Bool #

(Ord o, Ord a) => Ord (Posting a o s) Source # 
Instance details

Defined in Haspara.Accounting.Posting

Methods

compare :: Posting a o s -> Posting a o s -> Ordering #

(<) :: Posting a o s -> Posting a o s -> Bool #

(<=) :: Posting a o s -> Posting a o s -> Bool #

(>) :: Posting a o s -> Posting a o s -> Bool #

(>=) :: Posting a o s -> Posting a o s -> Bool #

max :: Posting a o s -> Posting a o s -> Posting a o s #

min :: Posting a o s -> Posting a o s -> Posting a o s #

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

Defined in Haspara.Accounting.Posting

Methods

showsPrec :: Int -> Posting a o s -> ShowS #

show :: Posting a o s -> String #

showList :: [Posting a o s] -> ShowS #

Generic (Posting a o s) Source # 
Instance details

Defined in Haspara.Accounting.Posting

Associated Types

type Rep (Posting a o s) :: Type -> Type #

Methods

from :: Posting a o s -> Rep (Posting a o s) x #

to :: Rep (Posting a o s) x -> Posting a o s #

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

Defined in Haspara.Accounting.Posting

Methods

toJSON :: Posting a o s -> Value #

toEncoding :: Posting a o s -> Encoding #

toJSONList :: [Posting a o s] -> Value #

toEncodingList :: [Posting a o s] -> Encoding #

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

Defined in Haspara.Accounting.Posting

Methods

parseJSON :: Value -> Parser (Posting a o s) #

parseJSONList :: Value -> Parser [Posting a o s] #

type Rep (Posting a o s) Source # 
Instance details

Defined in Haspara.Accounting.Posting

type Rep (Posting a o s) = D1 ('MetaData "Posting" "Haspara.Accounting.Posting" "haspara-0.0.0.1-GIZpgp6So3jGG6B29GnUaf" 'True) (C1 ('MetaCons "Posting" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty (Event o s, Account a)))))

postingEvents :: KnownNat s => Posting a o s -> [o] Source #

post :: KnownNat s => Posting a o s -> [(Account a, Entry o s)] Source #