2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
module Transaction
|
|
|
|
where
|
|
|
|
import Utils
|
2007-07-02 18:54:36 +04:00
|
|
|
import Types
|
2007-02-18 21:12:02 +03:00
|
|
|
import AccountName
|
2007-03-12 10:58:11 +03:00
|
|
|
import Amount
|
2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
|
|
|
|
instance Show Transaction where show = showTransaction
|
|
|
|
|
2007-07-04 05:38:56 +04:00
|
|
|
showTransaction :: Transaction -> String
|
|
|
|
showTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t)
|
|
|
|
where
|
|
|
|
showaccountname = printf "%-22s" . elideRight 22
|
|
|
|
showamount = printf "%11s" . showAmountRoundedOrZero
|
2007-02-16 12:00:17 +03:00
|
|
|
|
|
|
|
elideRight width s =
|
|
|
|
case length s > width of
|
|
|
|
True -> take (width - 2) s ++ ".."
|
|
|
|
False -> s
|
|
|
|
|
|
|
|
autofillTransactions :: [Transaction] -> [Transaction]
|
|
|
|
autofillTransactions ts =
|
|
|
|
let (ns, as) = partition isNormal ts
|
2007-03-12 20:53:39 +03:00
|
|
|
where isNormal t = (symbol $ currency $ tamount t) /= "AUTO" in
|
2007-02-16 12:00:17 +03:00
|
|
|
case (length as) of
|
|
|
|
0 -> ns
|
|
|
|
1 -> ns ++ [balanceTransaction $ head as]
|
|
|
|
where balanceTransaction t = t{tamount = -(sumTransactions ns)}
|
|
|
|
otherwise -> error "too many blank transactions in this entry"
|
|
|
|
|
|
|
|
sumTransactions :: [Transaction] -> Amount
|
2007-07-03 12:46:39 +04:00
|
|
|
sumTransactions = sum . map tamount
|
2007-02-16 12:00:17 +03:00
|
|
|
|