1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 module Hcompta.Model.Transaction.Posting where
6 import qualified Data.Foldable
7 import qualified Data.List
8 import qualified Data.Map
10 import Data.Typeable ()
12 import qualified Hcompta.Model.Account as Account
13 import Hcompta.Model.Account (Account)
14 import qualified Hcompta.Model.Amount as Amount
15 import Hcompta.Model.Amount (Amount)
16 import qualified Hcompta.Model.Date as Date
17 import Hcompta.Model.Date (Date)
18 import qualified Hcompta.Model.Transaction.Tag as Tag
19 import Hcompta.Model.Transaction.Tag (Tag)
21 -- * The 'Posting' type
26 , amounts :: Amount.By_Unit
33 } deriving (Data, Eq, Read, Show, Typeable)
38 | Type_Virtual_Balanced
39 deriving (Data, Eq, Read, Show, Typeable)
41 -- ** Convenient constructors
47 , amounts = Data.Map.empty
52 , tags = Data.Map.empty
53 , type_ = Type_Regular
56 -- * The 'By_Account' mapping
59 = Map Account [Posting]
61 -- ** Convenient constructors
63 -- | Return a tuple associating the given posting with its account.
64 by_account :: Posting -> (Account, Posting)
65 by_account posting = (account posting, posting)
67 -- | Return a 'Data.Map.Map' associating the given 'Posting's with their respective 'Unit'.
68 from_List :: [Posting] -> By_Account
70 Data.Map.fromListWith (++) $
72 (\posting -> (account posting, [posting]))
77 -- | Return the units in use within the given postings
79 :: Data.Foldable.Foldable m
87 (Data.Map.keys . amounts))