1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Model.Transaction.Posting where
7 import qualified Data.Foldable
8 import qualified Data.List
9 import qualified Data.Map.Strict as Data.Map
10 import Data.Text (Text)
11 import Data.Typeable ()
12 import Text.Parsec.Pos (SourcePos, initialPos)
14 import qualified Hcompta.Model.Account as Account ()
15 import Hcompta.Model.Account (Account)
16 import qualified Hcompta.Model.Amount as Amount
17 import Hcompta.Model.Date (Date)
18 import qualified Hcompta.Model.Transaction.Tag as Tag
20 -- * The 'Posting' type
25 , amounts :: Amount.By_Unit
26 , comments :: [Comment]
28 , sourcepos :: SourcePos
32 } deriving (Data, Eq, Read, Show, Typeable)
36 instance Read SourcePos where
37 readsPrec _ s = [(initialPos s, "")]
42 | Type_Virtual_Balanced
43 deriving (Data, Eq, Read, Show, Typeable)
45 -- ** Convenient constructors
51 , amounts = Data.Map.empty
55 , sourcepos = initialPos ""
56 , tags = Data.Map.empty
57 , type_ = Type_Regular
60 -- * The 'By_Account' mapping
63 = Data.Map.Map Account [Posting]
65 -- ** Convenient constructors
67 -- | Return a tuple associating the given 'Posting' with its 'Account'.
68 by_account :: Posting -> (Account, Posting)
69 by_account posting = (account posting, posting)
71 -- | Return a Data.'Data.Map.Map' associating the given 'Posting's with their respective 'Account'.
72 from_List :: [Posting] -> By_Account
74 Data.Map.fromListWith (++) $
76 (\posting -> (account posting, [posting]))
81 -- | Return the 'Unit's in use within the given 'Posting's
83 :: Data.Foldable.Foldable m
91 (Data.Map.keys . amounts))