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
|
|
|
{-
|
2007-07-04 06:50:29 +04:00
|
|
|
Here is the approximate module hierarchy. The early code defined types in
|
|
|
|
each module and so was strictly layered. Now, all data types have been
|
|
|
|
moved to the bottom. The modules are still used to group related
|
2007-07-04 13:34:30 +04:00
|
|
|
functions/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-04 13:51:37 +04:00
|
|
|
Transaction
|
|
|
|
LedgerFile
|
|
|
|
LedgerEntry
|
|
|
|
LedgerTransaction
|
2007-07-04 13:34:30 +04:00
|
|
|
AccountName
|
|
|
|
Amount
|
|
|
|
Currency
|
|
|
|
Types
|
|
|
|
Utils
|
|
|
|
|
2007-07-02 20:43:14 +04:00
|
|
|
-}
|
2007-02-16 12:00:17 +03:00
|
|
|
|
2007-07-11 10:58:47 +04:00
|
|
|
-- account and description-matching patterns
|
|
|
|
type FilterPatterns = (Maybe Regex, Maybe Regex)
|
|
|
|
|
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,
|
2007-07-04 06:50:29 +04:00
|
|
|
rate :: Double -- relative to the dollar.. 0 rates not supported yet
|
2007-07-02 20:43:14 +04:00
|
|
|
} 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)
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- AccountNames are strings like "assets:cash:petty", from which we derive
|
|
|
|
-- the chart of accounts
|
2007-07-02 20:43:14 +04:00
|
|
|
type AccountName = String
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- a line item in a ledger entry
|
2007-07-04 13:51:37 +04:00
|
|
|
data LedgerTransaction = LedgerTransaction {
|
2007-07-02 20:43:14 +04:00
|
|
|
taccount :: AccountName,
|
2007-07-04 16:05:54 +04:00
|
|
|
tamount :: Amount,
|
|
|
|
tcomment :: String
|
2007-07-02 20:43:14 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
|
|
|
-- a ledger entry, with two or more balanced transactions
|
2007-07-04 13:51:37 +04:00
|
|
|
data LedgerEntry = LedgerEntry {
|
2007-07-02 20:43:14 +04:00
|
|
|
edate :: Date,
|
2007-07-04 14:59:29 +04:00
|
|
|
estatus :: Bool,
|
2007-07-02 20:43:14 +04:00
|
|
|
ecode :: String,
|
|
|
|
edescription :: String,
|
2007-07-04 16:05:54 +04:00
|
|
|
ecomment :: String,
|
2008-06-28 08:44:33 +04:00
|
|
|
etransactions :: [LedgerTransaction],
|
|
|
|
epreceding_comment_lines :: String
|
2007-07-02 20:43:14 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- an automated ledger entry
|
2007-07-02 20:43:14 +04:00
|
|
|
data ModifierEntry = ModifierEntry {
|
|
|
|
valueexpr :: String,
|
2007-07-04 13:51:37 +04:00
|
|
|
m_transactions :: [LedgerTransaction]
|
2007-07-02 20:43:14 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- a periodic ledger entry
|
2007-07-02 20:43:14 +04:00
|
|
|
data PeriodicEntry = PeriodicEntry {
|
|
|
|
periodexpr :: String,
|
2007-07-04 13:51:37 +04:00
|
|
|
p_transactions :: [LedgerTransaction]
|
2007-07-02 20:43:14 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-04 06:50:29 +04:00
|
|
|
-- we also parse timeclock.el timelogs
|
2007-07-02 20:43:14 +04:00
|
|
|
data TimeLogEntry = TimeLogEntry {
|
2007-07-04 16:05:54 +04:00
|
|
|
tlcode :: Char,
|
|
|
|
tldatetime :: DateTime,
|
|
|
|
tlcomment :: String
|
2007-07-02 20:43:14 +04:00
|
|
|
} 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-04 13:51:37 +04:00
|
|
|
data LedgerFile = LedgerFile {
|
2007-07-02 22:57:37 +04:00
|
|
|
modifier_entries :: [ModifierEntry],
|
|
|
|
periodic_entries :: [PeriodicEntry],
|
2008-06-28 08:44:33 +04:00
|
|
|
entries :: [LedgerEntry],
|
|
|
|
final_comment_lines :: String
|
2007-07-02 22:57:37 +04:00
|
|
|
} deriving (Eq)
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- we flatten LedgerEntries and LedgerTransactions into Transactions,
|
|
|
|
-- which are simpler to query at the cost of some data duplication
|
|
|
|
data Transaction = Transaction {
|
2007-07-04 16:40:26 +04:00
|
|
|
entryno :: Int,
|
2007-07-04 14:59:29 +04:00
|
|
|
date :: Date,
|
|
|
|
description :: String,
|
|
|
|
account :: AccountName,
|
|
|
|
amount :: Amount
|
|
|
|
} deriving (Eq)
|
2007-07-02 20:43:14 +04:00
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- cached information for a particular account
|
2007-07-02 20:43:14 +04:00
|
|
|
data Account = Account {
|
|
|
|
aname :: AccountName,
|
2007-07-04 13:51:37 +04:00
|
|
|
atransactions :: [Transaction], -- excludes sub-accounts
|
2007-07-04 14:59:29 +04:00
|
|
|
abalance :: Amount -- includes sub-accounts
|
2007-07-02 20:43:14 +04:00
|
|
|
}
|
|
|
|
|
2007-07-04 14:59:29 +04:00
|
|
|
-- a ledger with account information cached for faster queries
|
2007-07-02 23:15:39 +04:00
|
|
|
data Ledger = Ledger {
|
2007-07-11 10:58:47 +04:00
|
|
|
rawledger :: LedgerFile,
|
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
|
|
|
}
|
|
|
|
|