From 6a552378365c5a6bc011eea308cd4f47c73ca986 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 18 Feb 2007 20:43:06 +0000 Subject: [PATCH] refactoring --- Account.hs | 35 ++++++++++++++++------------------- EntryTransaction.hs | 6 +++--- Models.hs | 14 ++++++-------- TODO | 5 +---- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/Account.hs b/Account.hs index 1b9e50582..730f4cd68 100644 --- a/Account.hs +++ b/Account.hs @@ -9,7 +9,8 @@ import EntryTransaction import Ledger --- an Account caches an account's name, balance and transactions for convenience +-- an Account caches an account's name, balance (including sub-accounts) +-- and transactions (not including sub-accounts) type Account = (AccountName,[EntryTransaction],Amount) aname (a,_,_) = a @@ -17,28 +18,24 @@ atransactions (_,ts,_) = ts abalance (_,_,b) = b mkAccount :: Ledger -> AccountName -> Account -mkAccount l a = (a, accountNameTransactionsNoSubs l a, accountNameBalance l a) +mkAccount l a = + (a, transactionsInAccountNamed l a, aggregateBalanceInAccountNamed l a) -accountNameBalance :: Ledger -> AccountName -> Amount -accountNameBalance l a = sumEntryTransactions (accountNameTransactions l a) +balanceInAccountNamed :: Ledger -> AccountName -> Amount +balanceInAccountNamed l a = + sumEntryTransactions (transactionsInAccountNamed l a) -accountNameTransactions :: Ledger -> AccountName -> [EntryTransaction] -accountNameTransactions l a = ledgerTransactionsMatching (["^" ++ a ++ "(:.+)?$"], []) l +aggregateBalanceInAccountNamed :: Ledger -> AccountName -> Amount +aggregateBalanceInAccountNamed l a = + sumEntryTransactions (aggregateTransactionsInAccountNamed l a) -accountNameBalanceNoSubs :: Ledger -> AccountName -> Amount -accountNameBalanceNoSubs l a = sumEntryTransactions (accountNameTransactionsNoSubs l a) - -accountNameTransactionsNoSubs :: Ledger -> AccountName -> [EntryTransaction] -accountNameTransactionsNoSubs l a = ledgerTransactionsMatching (["^" ++ a ++ "$"], []) l - --- showAccountNamesWithBalances :: [(AccountName,String)] -> Ledger -> String --- showAccountNamesWithBalances as l = --- unlines $ map (showAccountNameAndBalance l) as - --- showAccountNameAndBalance :: Ledger -> (AccountName, String) -> String --- showAccountNameAndBalance l (a, adisplay) = --- printf "%20s %s" (showBalance $ accountBalance l a) adisplay +transactionsInAccountNamed :: Ledger -> AccountName -> [EntryTransaction] +transactionsInAccountNamed l a = + ledgerTransactionsMatching (["^" ++ a ++ "$"], []) l +aggregateTransactionsInAccountNamed :: Ledger -> AccountName -> [EntryTransaction] +aggregateTransactionsInAccountNamed l a = + ledgerTransactionsMatching (["^" ++ a ++ "(:.+)?$"], []) l -- a tree of Accounts diff --git a/EntryTransaction.hs b/EntryTransaction.hs index 53248538c..7d2ee8025 100644 --- a/EntryTransaction.hs +++ b/EntryTransaction.hs @@ -8,9 +8,9 @@ import Transaction -- We convert Transactions into EntryTransactions, which are (entry, --- transaction) pairs, since I couldn't easily just have transactions --- reference their entry like in OO. These are referred to as just --- "transactions" hereafter. +-- transaction) pairs, since I couldn't see how to easily have +-- transactions reference their entry like in OO. These are referred to +-- as just "transactions" hereafter. type EntryTransaction = (Entry,Transaction) diff --git a/Models.hs b/Models.hs index fb12bd372..bc7d301ea 100644 --- a/Models.hs +++ b/Models.hs @@ -1,16 +1,14 @@ -- data types & behaviours module Models ( - module Models, - module Account, - module Ledger, - module EntryTransaction, - module Transaction, - module Entry, - module AccountName, module BasicTypes, + module AccountName, + module Entry, + module Transaction, + module EntryTransaction, + module Ledger, + module Account ) where -import Utils import BasicTypes import AccountName import Entry diff --git a/TODO b/TODO index 2223cf79b..f092fba88 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,7 @@ -cleanup/reorganize - Entry/Transaction/EntryTransaction - basic features - handle mixed amounts and currencies balance elide boring accounts + handle mixed amounts and currencies print entry -j and -J graph data output