2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
module EntryTransaction
|
|
|
|
where
|
|
|
|
import Utils
|
2007-07-02 18:54:36 +04:00
|
|
|
import Types
|
2007-07-03 03:41:07 +04:00
|
|
|
import AccountName
|
2007-02-16 12:00:17 +03:00
|
|
|
import Entry
|
|
|
|
import Transaction
|
2007-03-12 10:58:11 +03:00
|
|
|
import Amount
|
2007-07-02 20:43:14 +04:00
|
|
|
import Currency
|
2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
entry (e,t) = e
|
|
|
|
transaction (e,t) = t
|
|
|
|
date (e,t) = edate e
|
|
|
|
status (e,t) = estatus e
|
|
|
|
code (e,t) = ecode e
|
|
|
|
description (e,t) = edescription e
|
|
|
|
account (e,t) = taccount t
|
|
|
|
amount (e,t) = tamount t
|
|
|
|
|
|
|
|
flattenEntry :: Entry -> [EntryTransaction]
|
|
|
|
flattenEntry e = [(e,t) | t <- etransactions e]
|
|
|
|
|
2007-07-03 03:41:07 +04:00
|
|
|
accountNamesFromTransactions :: [EntryTransaction] -> [AccountName]
|
|
|
|
accountNamesFromTransactions ts = nub $ map account ts
|
|
|
|
|
2007-02-16 12:00:17 +03:00
|
|
|
entryTransactionsFrom :: [Entry] -> [EntryTransaction]
|
|
|
|
entryTransactionsFrom es = concat $ map flattenEntry es
|
|
|
|
|
|
|
|
sumEntryTransactions :: [EntryTransaction] -> Amount
|
|
|
|
sumEntryTransactions ets =
|
|
|
|
sumTransactions $ map transaction ets
|
|
|
|
|
2007-07-03 12:46:39 +04:00
|
|
|
matchTransactionAccount :: Regex -> EntryTransaction -> Bool
|
|
|
|
matchTransactionAccount r t =
|
|
|
|
case matchRegex r (account t) of
|
2007-02-16 12:00:17 +03:00
|
|
|
Nothing -> False
|
|
|
|
otherwise -> True
|
|
|
|
|
2007-07-03 12:46:39 +04:00
|
|
|
matchTransactionDescription :: Regex -> EntryTransaction -> Bool
|
|
|
|
matchTransactionDescription r t =
|
|
|
|
case matchRegex r (description t) of
|
2007-02-16 12:00:17 +03:00
|
|
|
Nothing -> False
|
|
|
|
otherwise -> True
|
|
|
|
|
|
|
|
showTransactionsWithBalances :: [EntryTransaction] -> Amount -> String
|
|
|
|
showTransactionsWithBalances [] _ = []
|
|
|
|
showTransactionsWithBalances ts b =
|
|
|
|
unlines $ showTransactionsWithBalances' ts dummyt b
|
|
|
|
where
|
2007-03-12 20:53:39 +03:00
|
|
|
dummyt = (Entry "" False "" "" [], Transaction "" (dollars 0))
|
2007-02-16 12:00:17 +03:00
|
|
|
showTransactionsWithBalances' [] _ _ = []
|
|
|
|
showTransactionsWithBalances' (t:ts) tprev b =
|
|
|
|
(if (entry t /= (entry tprev))
|
|
|
|
then [showTransactionDescriptionAndBalance t b']
|
|
|
|
else [showTransactionAndBalance t b'])
|
|
|
|
++ (showTransactionsWithBalances' ts t b')
|
|
|
|
where b' = b + (amount t)
|
|
|
|
|
|
|
|
showTransactionDescriptionAndBalance :: EntryTransaction -> Amount -> String
|
|
|
|
showTransactionDescriptionAndBalance t b =
|
|
|
|
(showEntry $ entry t) ++ (showTransaction $ transaction t) ++ (showBalance b)
|
|
|
|
|
|
|
|
showTransactionAndBalance :: EntryTransaction -> Amount -> String
|
|
|
|
showTransactionAndBalance t b =
|
|
|
|
(replicate 32 ' ') ++ (showTransaction $ transaction t) ++ (showBalance b)
|
|
|
|
|
|
|
|
showBalance :: Amount -> String
|
2007-02-20 03:21:57 +03:00
|
|
|
showBalance b = printf " %12s" (showAmountRoundedOrZero b)
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-03 03:41:07 +04:00
|
|
|
transactionsWithAccountName :: AccountName -> [EntryTransaction] -> [EntryTransaction]
|
|
|
|
transactionsWithAccountName a ts = [t | t <- ts, account t == a]
|
|
|
|
|
|
|
|
transactionsWithOrBelowAccountName :: AccountName -> [EntryTransaction] -> [EntryTransaction]
|
|
|
|
transactionsWithOrBelowAccountName a ts =
|
|
|
|
[t | t <- ts, account t == a || a `isAccountNamePrefixOf` (account t)]
|
|
|
|
|