mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
refactoring
This commit is contained in:
parent
1524dffbe2
commit
6a55237836
35
Account.hs
35
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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
14
Models.hs
14
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
|
||||
|
Loading…
Reference in New Issue
Block a user