{-# OPTIONS_GHC -fno-warn-orphans #-} module Hcompta.LCC.Balance where import Data.Function (flip) import Data.Functor ((<$>)) import Data.Map.Strict (Map) -- import Data.Foldable (Foldable(..)) import qualified Hcompta as H import Hcompta.LCC.Amount import Hcompta.LCC.Account import Hcompta.LCC.Posting import Hcompta.LCC.Transaction import Hcompta.LCC.Journal import Hcompta.LCC.Compta {- import Data.Functor.Compose import Data.Function ((.)) -} import qualified Data.MonoTraversable as MT type Balance = H.Balance NameAccount Unit (H.Polarized Quantity) type BalByAccount = H.BalByAccount NameAccount Unit (H.Polarized Quantity) type BalByUnit = H.BalByUnit NameAccount Unit (H.Polarized Quantity) type DeviationByUnit = H.DeviationByUnit NameAccount Unit (H.Polarized Quantity) instance H.Sumable Balance (Account, Amounts) where bal += (Account acct, Amounts amts) = bal H.+= (acct, H.polarize <$> amts) instance H.Sumable Balance Posting where bal += p = bal H.+= (posting_account p, posting_amounts p) instance H.Sumable Balance Postings where bal += Postings ps = MT.ofoldr (flip (H.+=)) bal ps instance H.Sumable Balance Transaction where bal += t = bal H.+= transaction_postings t instance H.Sumable Balance a => H.Sumable Balance (Journal a) where bal += j = bal H.+= journal_content j instance H.Sumable Balance a => H.Sumable Balance (Journals a) where bal += Journals js = MT.ofoldr (flip (H.+=)) bal js instance H.Sumable Balance a => H.Sumable Balance (Compta src ss a) where bal += c = bal H.+= compta_journals c instance H.Sumable Balance (Map Date [Transaction]) where bal += m = MT.ofoldr (flip (H.+=)) bal m type Balanceable = H.Sumable Balance balance :: Balanceable a => a -> Balance balance = H.sum {- consBal :: Posting -> Balance -> Balance consBal = H.consBal -- type instance H.Postings H.:@ Transaction = Postings -- instance H.Get (H.Balance_Amounts Unit Quantity) [Transaction] where -- get = transaction_postings balancePosting :: Posting -> Balance -> Balance balancePosting = H.consBal balanceTransaction :: Transaction -> Balance -> Balance balanceTransaction = H.balance . transaction_postings balancePostings :: Postings -> Balance -> Balance balancePostings = H.balance balanceTransactions :: [Transaction] -> Balance -> Balance balanceTransactions = flip $ foldr H.balance balance :: Journal [Transaction] -> Balance -> Balance balance = flip $ MT.ofoldr $ flip $ foldr H.balance -- (Get (Balance_Account acct_sect) post, Get (Balance_Amounts unit qty) post, Addable qty, Ord acct_sect, Ord unit) => post -> Balance acct_sect unit qty -> Balance acct_sect unit qty -- balance_postings :: (post ~ Element posts, MonoFoldable posts, Get (Balance_Account acct_sect) post, Get (Balance_Amounts unit qty) post, Addable qty, Ord acct_sect, Ord unit) => posts -> Balance acct_sect unit qty -> Balance acct_sect unit qty --}