1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 {-# LANGUAGE MultiParamTypeClasses #-}
6 {-# LANGUAGE NamedFieldPuns #-}
7 {-# LANGUAGE OverloadedStrings #-}
8 {-# LANGUAGE ScopedTypeVariables #-}
9 {-# LANGUAGE TupleSections #-}
10 {-# LANGUAGE TypeFamilies #-}
11 {-# LANGUAGE UndecidableSuperClasses #-}
12 module Hcompta.Transaction where
14 import Control.DeepSeq (NFData)
17 import Data.Function (($), (.), const)
18 import Data.Map.Strict (Map)
19 import Data.Monoid (Monoid(..))
20 import qualified Data.MonoTraversable as MT
22 import Data.Text (Text)
23 import Data.Typeable ()
24 import Text.Show (Show)
25 import Data.Tuple (fst, snd)
28 import Hcompta.Date (Date)
29 import Hcompta.Lib.Consable (Consable(..))
30 import Hcompta.Posting
34 -- * Class 'Transaction'
40 -- * Class 'Transactions'
41 class Transaction (MT.Element ts) => Transactions ts
44 -- * Class 'Transaction'
46 ( Date (Transaction_Date t)
47 , Postings (Transaction_Postings t)
48 ) => Transaction t where
49 type Transaction_Date t
50 type Transaction_Postings t
51 type Transaction_Wording t
52 transaction_date :: t -> Transaction_Date t
53 transaction_postings :: t -> Transaction_Postings t
54 transaction_wording :: t -> Transaction_Wording t
55 -- transaction_tags :: t -> Transaction_Tags
60 ) => Transaction (date, ps) where
61 type Transaction_Date (date, ps) = date
62 type Transaction_Postings (date, ps) = ps
63 type Transaction_Wording (date, ps) = ()
64 transaction_date = fst
65 transaction_postings = snd
66 transaction_wording = const ()
67 -- transaction_tags = const mempty
69 -- * Class 'Transactions'
70 class Transaction (Transactions_Transaction ts) => Transactions ts where
71 type Transactions_Transaction ts
74 Transactions [t] where
75 type Transactions_Transaction [t] = t
78 Transactions (Map date ts) where
79 type Transactions_Transaction (Map date ts) = Transactions_Transaction ts
82 -- ** Type 'Description'
84 type Description = Text
86 -- * Type 'Transaction_Anchor'
87 newtype Transaction_Anchor
88 = Transaction_Anchor Anchor
89 deriving (Data, Eq, NFData, Ord, Show, Typeable)
90 newtype Transaction_Anchors
91 = Transaction_Anchors Anchors
92 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
94 instance Consable Anchor Transaction_Anchors where
95 mcons a (Transaction_Anchors anchors) =
96 Transaction_Anchors $ mcons a anchors
98 transaction_anchor :: Anchor_Path -> Transaction_Anchor
99 transaction_anchor = Transaction_Anchor . anchor
101 -- | Return the given 'Transaction_Anchors'
102 -- with the given 'Transaction_Anchor' incorporated.
103 transaction_anchor_cons :: Transaction_Anchor -> Transaction_Anchors -> Transaction_Anchors
104 transaction_anchor_cons (Transaction_Anchor t) (Transaction_Anchors ts) =
105 Transaction_Anchors $ anchor_cons t ts
107 -- * Type 'Transaction_Tag'
109 newtype Transaction_Tag
110 = Transaction_Tag Tag
111 deriving (Data, Eq, NFData, Ord, Show, Typeable)
112 newtype Transaction_Tags
113 = Transaction_Tags Tags
114 deriving (Data, Eq, Monoid, NFData, Show, Typeable)
116 instance Consable Tag Transaction_Tags where
117 mcons t (Transaction_Tags tags) =
118 Transaction_Tags $ mcons t tags
120 transaction_tag :: Tag_Path -> Tag_Value -> Transaction_Tag
121 transaction_tag p v = Transaction_Tag $ tag p v
123 -- | Return the given 'Transaction_Tags' with the given 'Transaction_Tag' incorporated.
124 transaction_tag_cons :: Transaction_Tag -> Transaction_Tags -> Transaction_Tags
125 transaction_tag_cons (Transaction_Tag t) (Transaction_Tags ts) =
126 Transaction_Tags $ tag_cons t ts