1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Model.Transaction where
7 import qualified Data.List
8 import qualified Data.Map.Strict as Data.Map
9 import Data.Text (Text)
10 import Data.Typeable ()
11 import Text.Parsec.Pos (SourcePos, initialPos)
13 import qualified Hcompta.Model.Date as Date
14 import Hcompta.Model.Date (Date)
15 import qualified Hcompta.Model.Transaction.Posting as Posting
16 import qualified Hcompta.Model.Transaction.Tag as Tag
18 -- * The 'Transaction' type
23 , comments_before :: [Comment]
24 , comments_after :: [Comment]
25 , dates :: (Date, [Date])
26 , description :: Description
27 , postings :: Posting.By_Account
28 , sourcepos :: SourcePos
31 } deriving (Data, Eq, Read, Show, Typeable)
34 type Comment = Posting.Comment
35 type Description = Text
41 , comments_before = []
43 , dates = (Date.nil, [])
45 , postings = Data.Map.empty
46 , sourcepos = initialPos ""
48 , tags = Data.Map.empty
51 -- * Types to submodules
53 type Posting = Posting.Posting
56 -- * The 'By_Date' mapping
59 = Data.Map.Map Date.UTC [Transaction]
61 -- ** Convenient constructors
63 -- | Return a tuple associating the given 'Transaction' with its 'Date'.
64 by_date :: Transaction -> (Date.UTC, Transaction)
65 by_date t = (Date.to_UTC $ fst $ dates t, t)
67 -- | Return a Data.'Data.Map.Map' associating the given 'Transaction's with their respective 'Date'.
68 from_List :: [Transaction] -> By_Date
70 Data.Map.fromListWith (++) . -- TODO: check order is preserved on equality, or flip (++)
71 Data.List.map (\t -> (Date.to_UTC $ fst $ dates t, [t]))