]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Format/Ledger/Journal.hs
Correction : calcul de la largeur des montants.
[comptalang.git] / lib / Hcompta / Format / Ledger / Journal.hs
1 {-# LANGUAGE DeriveDataTypeable #-}
2 module Hcompta.Format.Ledger.Journal where
3
4 import Data.Data
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 ()
11
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
16
17 data Journal
18 = Journal
19 { file :: FilePath
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)
28
29 nil :: Journal
30 nil =
31 Journal
32 { file = ""
33 , includes = []
34 , last_read_time = Time.posixSecondsToUTCTime 0
35 , transactions = Data.Map.empty
36 , unit_styles = Data.Map.empty
37 }
38
39 to_Model :: Journal -> Model.Journal
40 to_Model jour =
41 Model.Journal.Journal
42 { Model.Journal.transactions =
43 Data.Map.unionsWith (++) $
44 flatten transactions $ jour
45 }
46 where
47 flatten :: (Journal -> a) -> Journal -> [a]
48 flatten g j = g j:Data.List.concatMap (flatten g) (includes j)