]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Format/Ledger/Balance.hs
Ajout : CLI.Lib.Shakespeare.Leijen : et demain L’Internationale...
[comptalang.git] / lib / Hcompta / Format / Ledger / Balance.hs
1 {-# LANGUAGE NamedFieldPuns #-}
2 module Hcompta.Format.Ledger.Balance where
3
4 {-
5 import Hcompta.Model (Transaction)
6 import qualified Hcompta.Calc.Balance as Balance
7 import qualified Hcompta.Format.Ledger.Journal as Journal
8 import Hcompta.Format.Ledger.Journal (Journal(..))
9 import qualified Hcompta.Lib.Foldable as Lib.Foldable
10
11 -- * The 'Balance.Deviation' type
12
13 -- | Return the first 'Transaction' (if any) whose 'Posting's
14 -- do not sum to a 'Balance' respecting 'Balance.is_inferrable',
15 -- with the path of 'Journal's leading to that 'Transaction'.
16 check_equilibrium :: Journal -> Maybe ((Transaction, Balance.Deviation), [Journal])
17 check_equilibrium =
18 Journal.find
19 (\Journal{Journal.transactions} ->
20 Lib.Foldable.find
21 (Lib.Foldable.find
22 (\tr -> do
23 let bal = Balance.transaction tr Balance.nil
24 let dev = Balance.deviation bal
25 if Balance.is_equilibrium_inferrable dev
26 then Nothing
27 else Just (tr, dev)
28 )
29 )
30 transactions
31 )
32 -}