refactoring

This commit is contained in:
Simon Michael 2007-02-18 20:43:06 +00:00
parent 1524dffbe2
commit 6a55237836
4 changed files with 26 additions and 34 deletions

View File

@ -9,7 +9,8 @@ import EntryTransaction
import Ledger 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) type Account = (AccountName,[EntryTransaction],Amount)
aname (a,_,_) = a aname (a,_,_) = a
@ -17,28 +18,24 @@ atransactions (_,ts,_) = ts
abalance (_,_,b) = b abalance (_,_,b) = b
mkAccount :: Ledger -> AccountName -> Account 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 balanceInAccountNamed :: Ledger -> AccountName -> Amount
accountNameBalance l a = sumEntryTransactions (accountNameTransactions l a) balanceInAccountNamed l a =
sumEntryTransactions (transactionsInAccountNamed l a)
accountNameTransactions :: Ledger -> AccountName -> [EntryTransaction] aggregateBalanceInAccountNamed :: Ledger -> AccountName -> Amount
accountNameTransactions l a = ledgerTransactionsMatching (["^" ++ a ++ "(:.+)?$"], []) l aggregateBalanceInAccountNamed l a =
sumEntryTransactions (aggregateTransactionsInAccountNamed l a)
accountNameBalanceNoSubs :: Ledger -> AccountName -> Amount transactionsInAccountNamed :: Ledger -> AccountName -> [EntryTransaction]
accountNameBalanceNoSubs l a = sumEntryTransactions (accountNameTransactionsNoSubs l a) transactionsInAccountNamed l a =
ledgerTransactionsMatching (["^" ++ a ++ "$"], []) l
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
aggregateTransactionsInAccountNamed :: Ledger -> AccountName -> [EntryTransaction]
aggregateTransactionsInAccountNamed l a =
ledgerTransactionsMatching (["^" ++ a ++ "(:.+)?$"], []) l
-- a tree of Accounts -- a tree of Accounts

View File

@ -8,9 +8,9 @@ import Transaction
-- We convert Transactions into EntryTransactions, which are (entry, -- We convert Transactions into EntryTransactions, which are (entry,
-- transaction) pairs, since I couldn't easily just have transactions -- transaction) pairs, since I couldn't see how to easily have
-- reference their entry like in OO. These are referred to as just -- transactions reference their entry like in OO. These are referred to
-- "transactions" hereafter. -- as just "transactions" hereafter.
type EntryTransaction = (Entry,Transaction) type EntryTransaction = (Entry,Transaction)

View File

@ -1,16 +1,14 @@
-- data types & behaviours -- data types & behaviours
module Models ( module Models (
module Models,
module Account,
module Ledger,
module EntryTransaction,
module Transaction,
module Entry,
module AccountName,
module BasicTypes, module BasicTypes,
module AccountName,
module Entry,
module Transaction,
module EntryTransaction,
module Ledger,
module Account
) )
where where
import Utils
import BasicTypes import BasicTypes
import AccountName import AccountName
import Entry import Entry

5
TODO
View File

@ -1,10 +1,7 @@
cleanup/reorganize
Entry/Transaction/EntryTransaction
basic features basic features
handle mixed amounts and currencies
balance balance
elide boring accounts elide boring accounts
handle mixed amounts and currencies
print print
entry entry
-j and -J graph data output -j and -J graph data output