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.Equilibre' type
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])
17 (\Journal{Journal.transactions} ->
21 let bal = Balance.transaction tr Balance.nil
22 let eq = Balance.equilibre bal
23 if Balance.is_equilibrable eq