{-| All the basic data types, defined here for easy re-use. See "Main". -} module Types where import Utils import qualified Data.Map as Map -- | a date type Date = String -- | a date and time type DateTime = String -- | the currency of an Amount. Rates are currently hardcoded. data Currency = Currency { symbol :: String, rate :: Double -- ^ relative to the dollar.. 0 rates not supported yet } deriving (Eq,Show) -- | some amount of money, shares, or anything else. data Amount = Amount { currency :: Currency, quantity :: Double, precision :: Int -- ^ number of significant decimal places } deriving (Eq) -- | AccountNames are strings like assets:cash:petty, from which we derive -- the chart of accounts type AccountName = String -- | a transaction line within a ledger entry. data LedgerTransaction = LedgerTransaction { taccount :: AccountName, tamount :: Amount, tcomment :: String } deriving (Eq) -- | a ledger "modifier" entry. Currently ignored. data ModifierEntry = ModifierEntry { valueexpr :: String, m_transactions :: [LedgerTransaction] } deriving (Eq) -- | a ledger "periodic" entry. Currently ignored. data PeriodicEntry = PeriodicEntry { periodexpr :: String, p_transactions :: [LedgerTransaction] } deriving (Eq) -- | a regular ledger entry, containing two or more transactions which balance data LedgerEntry = LedgerEntry { edate :: Date, estatus :: Bool, ecode :: String, edescription :: String, ecomment :: String, etransactions :: [LedgerTransaction], epreceding_comment_lines :: String } deriving (Eq) -- | a parsed ledger file. We call it raw to distinguish from the cached -- version below. data RawLedger = RawLedger { modifier_entries :: [ModifierEntry], periodic_entries :: [PeriodicEntry], entries :: [LedgerEntry], final_comment_lines :: String } deriving (Eq) -- | a timelog entry in a timelog file (generated by timeclock.el) data TimeLogEntry = TimeLogEntry { tlcode :: Char, tldatetime :: DateTime, tlcomment :: String } deriving (Eq,Ord) -- | a parsed timelog file data TimeLog = TimeLog { timelog_entries :: [TimeLogEntry] } deriving (Eq) -- | optimisations: these types provide some caching and are easier to work with. -- A Transaction is a LedgerTransaction with some of its parent -- LedgerEntry's data attached. data Transaction = Transaction { entryno :: Int, date :: Date, description :: String, account :: AccountName, amount :: Amount } deriving (Eq) -- | an Account stores an account name, all transactions in the account -- (excluding subaccounts), and the total balance (including subaccounts). data Account = Account { aname :: AccountName, atransactions :: [Transaction], abalance :: Amount } -- | a raw ledger plus its tree of account names, a map from account names -- to Accounts, and the preferred precision. data Ledger = Ledger { rawledger :: RawLedger, accountnametree :: Tree AccountName, accounts :: Map.Map AccountName Account, lprecision :: Int }