clarify Types

This commit is contained in:
Simon Michael 2008-10-02 22:33:32 +00:00
parent f4b4fc98fe
commit e2a753a36d

View File

@ -6,34 +6,49 @@ where
import Utils import Utils
import qualified Data.Map as Map import qualified Data.Map as Map
-- | a date
type Date = String type Date = String
-- | a date and time
type DateTime = String type DateTime = String
-- | the currency of an Amount. Rates are currently hardcoded.
data Currency = Currency { data Currency = Currency {
symbol :: String, symbol :: String,
rate :: Double -- relative to the dollar.. 0 rates not supported yet rate :: Double -- ^ relative to the dollar.. 0 rates not supported yet
} deriving (Eq,Show) } deriving (Eq,Show)
-- | some amount of money, time, stock, oranges, or whatever. -- | some amount of money, shares, or anything else.
data Amount = Amount { data Amount = Amount {
currency :: Currency, currency :: Currency,
quantity :: Double, quantity :: Double,
precision :: Int -- number of significant decimal places precision :: Int -- ^ number of significant decimal places
} deriving (Eq) } deriving (Eq)
-- | AccountNames are strings like assets:cash:petty, from which we derive -- | AccountNames are strings like assets:cash:petty, from which we derive
-- the chart of accounts -- the chart of accounts
type AccountName = String type AccountName = String
-- | a line item in a ledger entry -- | a transaction line within a ledger entry.
data LedgerTransaction = LedgerTransaction { data LedgerTransaction = LedgerTransaction {
taccount :: AccountName, taccount :: AccountName,
tamount :: Amount, tamount :: Amount,
tcomment :: String tcomment :: String
} deriving (Eq) } deriving (Eq)
-- | a ledger entry, containing two or more balanced transactions -- | 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 { data LedgerEntry = LedgerEntry {
edate :: Date, edate :: Date,
estatus :: Bool, estatus :: Bool,
@ -44,19 +59,16 @@ data LedgerEntry = LedgerEntry {
epreceding_comment_lines :: String epreceding_comment_lines :: String
} deriving (Eq) } deriving (Eq)
-- | an automated ledger entry -- | a parsed ledger file. We call it raw to distinguish from the cached
data ModifierEntry = ModifierEntry { -- version below.
valueexpr :: String, data RawLedger = RawLedger {
m_transactions :: [LedgerTransaction] modifier_entries :: [ModifierEntry],
periodic_entries :: [PeriodicEntry],
entries :: [LedgerEntry],
final_comment_lines :: String
} deriving (Eq) } deriving (Eq)
-- | a periodic ledger entry -- | a timelog entry in a timelog file (generated by timeclock.el)
data PeriodicEntry = PeriodicEntry {
periodexpr :: String,
p_transactions :: [LedgerTransaction]
} deriving (Eq)
-- | a timelog entry (we also parse timeclock.el timelogs)
data TimeLogEntry = TimeLogEntry { data TimeLogEntry = TimeLogEntry {
tlcode :: Char, tlcode :: Char,
tldatetime :: DateTime, tldatetime :: DateTime,
@ -68,16 +80,9 @@ data TimeLog = TimeLog {
timelog_entries :: [TimeLogEntry] timelog_entries :: [TimeLogEntry]
} deriving (Eq) } deriving (Eq)
-- | a parsed ledger file -- | optimisations: these types provide some caching and are easier to work with.
data RawLedger = RawLedger { -- A Transaction is a LedgerTransaction with some of its parent
modifier_entries :: [ModifierEntry], -- LedgerEntry's data attached.
periodic_entries :: [PeriodicEntry],
entries :: [LedgerEntry],
final_comment_lines :: String
} deriving (Eq)
-- | we flatten LedgerEntries and LedgerTransactions into Transactions,
-- which are simpler to query at the cost of some data duplication
data Transaction = Transaction { data Transaction = Transaction {
entryno :: Int, entryno :: Int,
date :: Date, date :: Date,
@ -86,14 +91,16 @@ data Transaction = Transaction {
amount :: Amount amount :: Amount
} deriving (Eq) } deriving (Eq)
-- | cached information for a particular account -- | an Account stores an account name, all transactions in the account
-- (excluding subaccounts), and the total balance (including subaccounts).
data Account = Account { data Account = Account {
aname :: AccountName, -- ^ the account name aname :: AccountName,
atransactions :: [Transaction], -- ^ the transactions, excluding sub-accounts atransactions :: [Transaction],
abalance :: Amount -- ^ the total balance, including sub-accounts abalance :: Amount
} }
-- | a ledger with account information cached for faster queries -- | a raw ledger plus its tree of account names, a map from account names
-- to Accounts, and the preferred precision.
data Ledger = Ledger { data Ledger = Ledger {
rawledger :: RawLedger, rawledger :: RawLedger,
accountnametree :: Tree AccountName, accountnametree :: Tree AccountName,