mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-20 02:37:12 +03:00
42 lines
1.1 KiB
Haskell
42 lines
1.1 KiB
Haskell
{-|
|
|
|
|
A 'Posting' represents a single transaction line within a ledger
|
|
entry. We call it raw to distinguish from the cached 'Transaction'.
|
|
|
|
-}
|
|
|
|
module Ledger.Posting
|
|
where
|
|
import Ledger.Utils
|
|
import Ledger.Types
|
|
import Ledger.Amount
|
|
import Ledger.AccountName
|
|
|
|
|
|
instance Show Posting where show = showPosting
|
|
|
|
nullrawposting = Posting False "" nullmixedamt "" RegularPosting
|
|
|
|
showPosting :: Posting -> String
|
|
showPosting (Posting s a amt _ ttype) =
|
|
concatTopPadded [showaccountname a ++ " ", showamount amt]
|
|
where
|
|
showaccountname = printf "%-22s" . bracket . elideAccountName width
|
|
(bracket,width) = case ttype of
|
|
BalancedVirtualPosting -> (\s -> "["++s++"]", 20)
|
|
VirtualPosting -> (\s -> "("++s++")", 20)
|
|
otherwise -> (id,22)
|
|
showamount = padleft 12 . showMixedAmountOrZero
|
|
|
|
isReal :: Posting -> Bool
|
|
isReal p = ptype p == RegularPosting
|
|
|
|
isVirtual :: Posting -> Bool
|
|
isVirtual p = ptype p == VirtualPosting
|
|
|
|
isBalancedVirtual :: Posting -> Bool
|
|
isBalancedVirtual p = ptype p == BalancedVirtualPosting
|
|
|
|
hasAmount :: Posting -> Bool
|
|
hasAmount = (/= missingamt) . pamount
|