hledger/Ledger/RawTransaction.hs

36 lines
1.1 KiB
Haskell
Raw Normal View History

{-|
A 'RawTransaction' represents a single transaction line within a ledger
entry. We call it raw to distinguish from the cached 'Transaction'.
-}
module Ledger.RawTransaction
where
import Ledger.Utils
2008-10-03 04:12:59 +04:00
import Ledger.Types
import Ledger.Amount
2008-10-15 23:14:34 +04:00
import Ledger.AccountName
instance Show RawTransaction where show = showRawTransaction
2008-11-22 20:21:49 +03:00
nullrawtxn = RawTransaction "" nullmixedamt "" RegularTransaction
2008-11-08 23:25:51 +03:00
showRawTransaction :: RawTransaction -> String
showRawTransaction (RawTransaction a amt _ ttype) =
2008-11-22 12:07:04 +03:00
concatTopPadded [showaccountname a ++ " ", showamount amt]
where
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
isReal :: RawTransaction -> Bool
isReal t = rttype t == RegularTransaction
hasAmount :: RawTransaction -> Bool
2008-10-19 00:29:42 +04:00
hasAmount = (/= missingamt) . tamount