2007-07-02 22:57:37 +04:00
|
|
|
module Types
|
2007-02-16 12:00:17 +03:00
|
|
|
where
|
|
|
|
import Utils
|
2007-07-02 22:57:37 +04:00
|
|
|
import qualified Data.Map as Map
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-02 20:43:14 +04:00
|
|
|
{-
|
|
|
|
|
|
|
|
First, here is the module hierarchy. The initial implementation defined
|
2007-07-02 20:55:29 +04:00
|
|
|
types in each module and was strictly layered. Now, all types have been
|
2007-07-02 20:43:14 +04:00
|
|
|
moved to the bottom, with modules still used to group related functions
|
2007-07-02 20:55:29 +04:00
|
|
|
(aka methods - make overview to list those).
|
2007-07-02 20:43:14 +04:00
|
|
|
|
|
|
|
hledger
|
|
|
|
Options
|
|
|
|
Tests
|
|
|
|
Parse
|
|
|
|
Models
|
|
|
|
TimeLog
|
|
|
|
TimeLogEntry
|
2007-07-02 23:15:39 +04:00
|
|
|
Ledger
|
2007-07-02 22:57:37 +04:00
|
|
|
Account
|
2007-07-02 23:15:39 +04:00
|
|
|
RawLedger
|
2007-07-02 22:57:37 +04:00
|
|
|
EntryTransaction
|
|
|
|
Entry
|
|
|
|
Transaction
|
|
|
|
AccountName
|
|
|
|
Amount
|
|
|
|
Currency
|
|
|
|
Types
|
|
|
|
Utils
|
2007-07-02 20:43:14 +04:00
|
|
|
|
|
|
|
-}
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-03-12 03:13:53 +03:00
|
|
|
type Date = String
|
2007-07-02 20:43:14 +04:00
|
|
|
|
2007-03-12 03:13:53 +03:00
|
|
|
type DateTime = String
|
2007-07-02 20:43:14 +04:00
|
|
|
|
|
|
|
data Currency = Currency {
|
|
|
|
symbol :: String,
|
|
|
|
rate :: Double -- relative to the dollar
|
|
|
|
} deriving (Eq,Show)
|
|
|
|
|
|
|
|
-- some amount of money, time, stock, oranges, etc.
|
|
|
|
data Amount = Amount {
|
|
|
|
currency :: Currency,
|
2007-07-04 05:38:56 +04:00
|
|
|
quantity :: Double,
|
|
|
|
precision :: Int -- number of significant decimal places
|
2007-07-02 20:43:14 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
-- AccountNames are strings like "assets:cash:petty"; from these we build
|
|
|
|
-- the chart of accounts, which should be a simple hierarchy.
|
|
|
|
type AccountName = String
|
|
|
|
|
|
|
|
-- a flow of an amount to an account
|
|
|
|
data Transaction = Transaction {
|
|
|
|
taccount :: AccountName,
|
|
|
|
tamount :: Amount
|
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
-- cleared ?
|
|
|
|
type EntryStatus = Bool
|
|
|
|
|
|
|
|
-- a ledger entry, with two or more balanced transactions
|
|
|
|
data Entry = Entry {
|
|
|
|
edate :: Date,
|
|
|
|
estatus :: EntryStatus,
|
|
|
|
ecode :: String,
|
|
|
|
edescription :: String,
|
|
|
|
etransactions :: [Transaction]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
-- an "automated" entry (see = in ledger manual)
|
|
|
|
data ModifierEntry = ModifierEntry {
|
|
|
|
valueexpr :: String,
|
|
|
|
m_transactions :: [Transaction]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
-- a periodic entry (see ~ in ledger manual)
|
|
|
|
data PeriodicEntry = PeriodicEntry {
|
|
|
|
periodexpr :: String,
|
|
|
|
p_transactions :: [Transaction]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-02 22:57:37 +04:00
|
|
|
-- we also parse timeclock.el's timelogs (as a ledger)
|
2007-07-02 20:43:14 +04:00
|
|
|
data TimeLogEntry = TimeLogEntry {
|
|
|
|
tcode :: Char,
|
|
|
|
tdatetime :: DateTime,
|
|
|
|
tcomment :: String
|
|
|
|
} deriving (Eq,Ord)
|
|
|
|
|
|
|
|
data TimeLog = TimeLog {
|
|
|
|
timelog_entries :: [TimeLogEntry]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-02 22:57:37 +04:00
|
|
|
-- a parsed ledger file
|
2007-07-02 23:15:39 +04:00
|
|
|
data RawLedger = RawLedger {
|
2007-07-02 22:57:37 +04:00
|
|
|
modifier_entries :: [ModifierEntry],
|
|
|
|
periodic_entries :: [PeriodicEntry],
|
|
|
|
entries :: [Entry]
|
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-02 20:43:14 +04:00
|
|
|
-- We convert Transactions into EntryTransactions, which are (entry,
|
|
|
|
-- transaction) pairs, since I couldn't see how to have transactions
|
|
|
|
-- reference their entry like in OO. These are referred to as just
|
|
|
|
-- "transactions" in modules above EntryTransaction.
|
|
|
|
type EntryTransaction = (Entry,Transaction)
|
|
|
|
|
2007-07-02 23:15:39 +04:00
|
|
|
-- all information for a particular account, derived from a RawLedger
|
2007-07-02 20:43:14 +04:00
|
|
|
data Account = Account {
|
|
|
|
aname :: AccountName,
|
|
|
|
atransactions :: [EntryTransaction], -- excludes sub-accounts
|
|
|
|
abalance :: Amount -- includes sub-accounts
|
|
|
|
}
|
|
|
|
|
2007-07-02 22:57:37 +04:00
|
|
|
-- a ledger with account info cached for faster queries
|
2007-07-02 23:15:39 +04:00
|
|
|
data Ledger = Ledger {
|
|
|
|
rawledger :: RawLedger,
|
2007-07-03 03:41:07 +04:00
|
|
|
accountnametree :: Tree AccountName,
|
2007-07-04 05:38:56 +04:00
|
|
|
accounts :: Map.Map AccountName Account,
|
|
|
|
lprecision :: Int
|
2007-07-02 22:57:37 +04:00
|
|
|
}
|
|
|
|
|