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
-- 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

View File

@ -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)

View File

@ -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

5
TODO
View File

@ -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