]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Format/Ledger/Balance.hs
Ajout : Lib.Foldable : tests.
[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.Deviation' type
11
12 -- | Return the first 'Transaction' (if any) whose 'Posting's
13 -- do not sum to a 'Balance' respecting 'Balance.is_inferrable',
14 -- with the path of 'Journal's leading to that 'Transaction'.
15 check_equilibrium :: Journal -> Maybe ((Transaction, Balance.Deviation), [Journal])
16 check_equilibrium =
17 Journal.find
18 (\Journal{Journal.transactions} ->
19 Lib.Foldable.find
20 (Lib.Foldable.find
21 (\tr -> do
22 let bal = Balance.transaction tr Balance.nil
23 let dev = Balance.deviation bal
24 if Balance.is_equilibrium_inferrable dev
25 then Nothing
26 else Just (tr, dev)
27 )
28 )
29 transactions
30 )