40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Haskell
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Haskell
		
	
	
	
	
	
| {-|
 | |
| 
 | |
| A 'RawLedger' is a parsed ledger file. We call it raw to distinguish from
 | |
| the cached 'Ledger'.
 | |
| 
 | |
| -}
 | |
| 
 | |
| module Ledger.RawLedger
 | |
| where
 | |
| import Ledger.Utils
 | |
| import Ledger.Types
 | |
| import Ledger.AccountName
 | |
| import Ledger.Entry
 | |
| import Ledger.Transaction
 | |
| 
 | |
| 
 | |
| instance Show RawLedger where
 | |
|     show l = printf "RawLedger with %d entries, %d accounts: %s"
 | |
|              ((length $ entries l) +
 | |
|               (length $ modifier_entries l) +
 | |
|               (length $ periodic_entries l))
 | |
|              (length accounts)
 | |
|              (show accounts)
 | |
|              where accounts = flatten $ rawLedgerAccountNameTree l
 | |
| 
 | |
| rawLedgerTransactions :: RawLedger -> [Transaction]
 | |
| rawLedgerTransactions = txns . entries
 | |
|     where
 | |
|       txns :: [Entry] -> [Transaction]
 | |
|       txns es = concat $ map flattenEntry $ zip es (iterate (+1) 1)
 | |
| 
 | |
| rawLedgerAccountNamesUsed :: RawLedger -> [AccountName]
 | |
| rawLedgerAccountNamesUsed = accountNamesFromTransactions . rawLedgerTransactions
 | |
| 
 | |
| rawLedgerAccountNames :: RawLedger -> [AccountName]
 | |
| rawLedgerAccountNames = sort . expandAccountNames . rawLedgerAccountNamesUsed
 | |
| 
 | |
| rawLedgerAccountNameTree :: RawLedger -> Tree AccountName
 | |
| rawLedgerAccountNameTree l = accountNameTreeFrom $ rawLedgerAccountNames l
 |