]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Format/Ledger/Balance.hs
Modif : CLI.Command.Balance : meilleur affichage
[comptalang.git] / lib / Hcompta / Format / Ledger / Balance.hs
1 {-# LANGUAGE NamedFieldPuns #-}
2 module Hcompta.Format.Ledger.Balance where
3
4 import Hcompta.Model (Transaction)
5 import qualified Hcompta.Calc.Balance as Balance
6 import qualified Hcompta.Format.Ledger.Journal as Journal
7 import Hcompta.Format.Ledger.Journal (Journal(..))
8 import qualified Hcompta.Lib.Foldable as Lib.Foldable
9
10 -- * The 'Balance.Equilibre' type
11
12 -- | Return the first 'Transaction' (if any) which does not respect 'Balance.is_equilibrable'
13 -- with the path of 'Journal's leading to that 'Transaction'.
14 equilibre :: Journal -> Maybe ((Transaction, Balance.Equilibre), [Journal])
15 equilibre =
16 Journal.find
17 (\Journal{Journal.transactions} ->
18 Lib.Foldable.find
19 (Lib.Foldable.find
20 (\tr -> do
21 let bal = Balance.transaction tr Balance.nil
22 let eq = Balance.equilibre bal
23 if Balance.is_equilibrable eq
24 then Nothing
25 else Just (tr, eq)
26 )
27 )
28 transactions
29 )