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