2008-10-03 06:04:15 +04:00
|
|
|
{-|
|
|
|
|
|
|
|
|
A 'RawTransaction' represents a single transaction line within a ledger
|
|
|
|
entry. We call it raw to distinguish from the cached 'Transaction'.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2008-10-03 04:40:06 +04:00
|
|
|
module Ledger.RawTransaction
|
2007-07-04 13:51:37 +04:00
|
|
|
where
|
2008-10-03 04:05:16 +04:00
|
|
|
import Ledger.Utils
|
2008-10-03 04:12:59 +04:00
|
|
|
import Ledger.Types
|
2008-10-03 04:40:06 +04:00
|
|
|
import Ledger.Amount
|
2008-10-15 23:14:34 +04:00
|
|
|
import Ledger.AccountName
|
2007-07-04 13:51:37 +04:00
|
|
|
|
|
|
|
|
2008-10-16 10:00:46 +04:00
|
|
|
instance Show RawTransaction where show = showRawTransaction
|
2007-07-04 13:51:37 +04:00
|
|
|
|
2008-10-16 10:00:46 +04:00
|
|
|
showRawTransaction :: RawTransaction -> String
|
2008-10-16 10:12:40 +04:00
|
|
|
showRawTransaction (RawTransaction a amt _ ttype) =
|
|
|
|
showaccountname a ++ " " ++ (showamount amt)
|
2007-07-04 13:51:37 +04:00
|
|
|
where
|
2008-10-16 10:12:40 +04:00
|
|
|
showaccountname = printf "%-22s" . bracket . elideAccountName width
|
2008-10-18 12:39:08 +04:00
|
|
|
showamount = printf "%12s" . showMixedAmountOrZero
|
2008-10-16 10:12:40 +04:00
|
|
|
(bracket,width) = case ttype of
|
|
|
|
BalancedVirtualTransaction -> (\s -> "["++s++"]", 20)
|
|
|
|
VirtualTransaction -> (\s -> "("++s++")", 20)
|
|
|
|
otherwise -> (id,22)
|
2007-07-04 13:51:37 +04:00
|
|
|
|
2008-10-16 10:52:35 +04:00
|
|
|
isReal :: RawTransaction -> Bool
|
|
|
|
isReal t = rttype t == RegularTransaction
|
|
|
|
|
|
|
|
hasAmount :: RawTransaction -> Bool
|
2008-10-18 12:39:08 +04:00
|
|
|
hasAmount = (/= autoamt) . tamount
|