hledger/Transaction.hs

36 lines
1014 B
Haskell
Raw Normal View History

module Transaction
where
import Utils
2007-07-02 18:54:36 +04:00
import Types
import AccountName
2007-03-12 10:58:11 +03:00
import Amount
instance Show Transaction where show = showTransaction
showTransaction :: Transaction -> String
showTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t)
where
showaccountname = printf "%-22s" . elideRight 22
showamount = printf "%11s" . showAmountRoundedOrZero
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
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