1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Format.Ledger.Journal where
5 import qualified Data.List
6 import qualified Data.Map.Strict as Data.Map
7 import Data.Map.Strict (Map)
8 import qualified Data.Time.Clock as Time
9 import qualified Data.Time.Clock.POSIX as Time
10 import Data.Typeable ()
12 import qualified Hcompta.Model as Model
13 import qualified Hcompta.Model.Amount as Amount
14 import qualified Hcompta.Model.Journal as Model.Journal
15 import qualified Hcompta.Model.Transaction as Transaction
20 , includes :: [Journal]
21 -- , historical_prices :: [Amount.Price.Historical]
22 , last_read_time :: Time.UTCTime
23 , transactions :: Transaction.By_Date
24 -- , transaction_periodics :: [Transaction.Periodic]
25 -- , transaction_modifiers :: [Transaction.Modifier]
26 , unit_styles :: Map Amount.Unit Amount.Style
27 } deriving (Data, Eq, Read, Show, Typeable)
34 , last_read_time = Time.posixSecondsToUTCTime 0
35 , transactions = Data.Map.empty
36 , unit_styles = Data.Map.empty
39 to_Model :: Journal -> Model.Journal
42 { Model.Journal.transactions =
43 Data.Map.unionsWith (++) $
44 flatten transactions $ jour
47 flatten :: (Journal -> a) -> Journal -> [a]
48 flatten g j = g j:Data.List.concatMap (flatten g) (includes j)