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-11-22 20:21:49 +03:00
|
|
|
nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction
|
2008-11-08 23:25:51 +03: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) =
|
2008-11-22 12:07:04 +03:00
|
|
|
concatTopPadded [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
|
|
|
|
(bracket,width) = case ttype of
|
|
|
|
BalancedVirtualTransaction -> (\s -> "["++s++"]", 20)
|
|
|
|
VirtualTransaction -> (\s -> "("++s++")", 20)
|
|
|
|
otherwise -> (id,22)
|
2008-11-22 12:07:04 +03:00
|
|
|
showamount = padleft 12 . showMixedAmountOrZero
|
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-19 00:29:42 +04:00
|
|
|
hasAmount = (/= missingamt) . tamount
|