Correction : CLI.Command.Journal : tri par date même si plusieurs journaux.
authorJulien Moutinho <julm+hcompta@autogeree.net>
Fri, 10 Jul 2015 00:10:58 +0000 (02:10 +0200)
committerJulien Moutinho <julm+hcompta@autogeree.net>
Tue, 21 Jul 2015 09:31:00 +0000 (11:31 +0200)
cli/Hcompta/CLI/Command/Journal.hs

index fe8ec8559c44c2434e37a83a5dc8e90019390b7e..af92adffcb8283be13a70e4dd4bf8792ef617926 100644 (file)
@@ -10,6 +10,9 @@ import           Prelude hiding (foldr)
 import           Control.Monad.IO.Class (liftIO)
 import           Control.Monad.Trans.Except (runExceptT)
 import qualified Data.Either
+import           Data.Functor.Compose (Compose(..))
+import qualified Data.List
+import qualified Data.Map.Strict as Data.Map
 import           Data.Foldable (foldr)
 import           System.Console.GetOpt
                  ( ArgDescr(..)
@@ -116,15 +119,22 @@ run context args = do
                let transactions =
                        foldr
                         (Ledger.Journal.fold
-                                (flip (foldr
-                                        (flip (foldr
-                                                (\tr ->
-                                                       case Filter.test (ctx_transaction_filter ctx) tr of
-                                                        False -> id
-                                                        True  -> (:) tr
-                                                ))))
-                                . Ledger.journal_transactions))
-                        []
+                                (\j ->
+                                       let ts = Ledger.journal_transactions j in
+                                       Data.Map.unionWith (++) $
+                                       case ctx_transaction_filter ctx of
+                                        Filter.Any -> ts
+                                        _ ->
+                                               Data.Map.mapMaybe
+                                                (\lt ->
+                                                       case Data.List.filter
+                                                        (Filter.test (ctx_transaction_filter ctx)) lt of
+                                                        [] -> Nothing
+                                                        l -> Just l
+                                                )
+                                                ts
+                                ))
+                        Data.Map.empty
                         journals
                Ledger.Write.put sty IO.stdout $ do
-               Ledger.Write.transactions transactions
+               Ledger.Write.transactions (Compose transactions)