This renames RawTransaction -> Posting and Entry -> LedgerTransaction, plus a bunch more cleanups for consistency. So while ledger 3 has transactions containing postings, and so do we when speaking to users, internally we call ledger 3's transactions LedgerTransaction, and we keep our old Transaction type as well, because it's useful and used all over the place. To review: - ledger 2 had Entrys containing Transactions. - hledger 0.4 had Entrys containing RawTransactions, and Transactions which are a RawTransaction with its parent Entry's info added. Transactions are what we most work with when reporting and are ubiquitous in the code and docs. - ledger 3 has Transactions containing Postings. - hledger 0.5 now has LedgerTransactions containing Postings, with Transactions kept as before (a Posting plus it's parent's info). These could be named PartialTransactions or TransactionPostings, but it gets too verbose and obscure for devs and users.
		
			
				
	
	
		
			36 lines
		
	
	
		
			998 B
		
	
	
	
		
			Haskell
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			998 B
		
	
	
	
		
			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
 | |
| 
 | |
| hasAmount :: Posting -> Bool
 | |
| hasAmount = (/= missingamt) . pamount
 |