1 {-# LANGUAGE NamedFieldPuns #-}
2 module Hcompta.Format.Ledger.Balance where
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
11 -- * The 'Balance.Deviation' type
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])
19 (\Journal{Journal.transactions} ->
23 let bal = Balance.transaction tr Balance.nil
24 let dev = Balance.deviation bal
25 if Balance.is_equilibrium_inferrable dev