diff --git a/Ledger.hs b/Ledger.hs index 33f6a1aa9..4256f67fc 100644 --- a/Ledger.hs +++ b/Ledger.hs @@ -1,5 +1,10 @@ {-| + +The Ledger package allows parsing and querying of ledger files. +It generally provides a compatible subset of C++ ledger's functionality. + -} + module Ledger ( module Ledger.Types, module Ledger.Currency, diff --git a/Ledger/Account.hs b/Ledger/Account.hs index 4b365fd6b..81e4ae09e 100644 --- a/Ledger/Account.hs +++ b/Ledger/Account.hs @@ -1,3 +1,11 @@ +{-| + +An 'Account' stores an account name, all transactions in the account +(excluding any subaccounts), and the total balance (including any +subaccounts). + +-} + module Ledger.Account where import Ledger.Utils diff --git a/Ledger/AccountName.hs b/Ledger/AccountName.hs index a85c97bc6..ef40c0cf8 100644 --- a/Ledger/AccountName.hs +++ b/Ledger/AccountName.hs @@ -1,3 +1,10 @@ +{-| + +'AccountName's are strings like @assets:cash:petty@. +From a set of these we derive the account hierarchy. + +-} + module Ledger.AccountName where import Ledger.Utils @@ -49,8 +56,8 @@ subAccountNamesFrom accts a = filter (`isSubAccountNameOf` a) accts -- | We could almost get by with just the AccountName manipulations -- above, but we need smarter structures to eg display the account -- tree with boring accounts elided. This converts a list of --- AccountNames to a tree (later we will convert that to a tree of --- Accounts.) +-- AccountName to a tree (later we will convert that to a tree of +-- 'Account'.) accountNameTreeFrom_props = [ accountNameTreeFrom ["a"] == Node "top" [Node "a" []], diff --git a/Ledger/Amount.hs b/Ledger/Amount.hs index cdf39fd31..132a2f22a 100644 --- a/Ledger/Amount.hs +++ b/Ledger/Amount.hs @@ -1,5 +1,7 @@ {-| -A simple amount is a currency, quantity pair: +An 'Amount' is some quantity of money, shares, or anything else. + +A simple amount is a currency, quantity pair (where currency can be anything): @ $1 @@ -7,11 +9,11 @@ A simple amount is a currency, quantity pair: EUR 3.44 GOOG 500 1.5h - 90m + 90apples 0 @ -A mixed amount is one or more simple amounts: +A mixed amount (not yet implemented) is one or more simple amounts: @ $50, EUR 3, AAPL 500 diff --git a/Ledger/Currency.hs b/Ledger/Currency.hs index 3284e627d..55a6607dd 100644 --- a/Ledger/Currency.hs +++ b/Ledger/Currency.hs @@ -1,3 +1,10 @@ +{-| + +A 'Currency' is a symbol and a conversion rate relative to the +dollar. Currency symbols are parsed from the ledger file, rates are +currently hard-coded. + +-} module Ledger.Currency where import qualified Data.Map as Map diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index 35b94f451..e9dea4efc 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -1,3 +1,10 @@ +{-| + +A 'Ledger' stores, for efficiency, a 'RawLedger' plus its tree of account +names, a map from account names to 'Account's, and the display precision. + +-} + module Ledger.Ledger where import qualified Data.Map as Map diff --git a/Ledger/LedgerEntry.hs b/Ledger/LedgerEntry.hs index 937c95096..a0a88ba72 100644 --- a/Ledger/LedgerEntry.hs +++ b/Ledger/LedgerEntry.hs @@ -1,3 +1,10 @@ +{-| + +A 'LedgerEntry' represents a normal entry in the ledger file. It contains +two or more 'RawTransaction's which balance. + +-} + module Ledger.LedgerEntry where import Ledger.Utils diff --git a/Ledger/RawLedger.hs b/Ledger/RawLedger.hs index 89eac41b5..91d930464 100644 --- a/Ledger/RawLedger.hs +++ b/Ledger/RawLedger.hs @@ -1,3 +1,10 @@ +{-| + +A 'RawLedger' is a parsed ledger file. We call it raw to distinguish from +the cached 'Ledger'. + +-} + module Ledger.RawLedger where import qualified Data.Map as Map diff --git a/Ledger/RawTransaction.hs b/Ledger/RawTransaction.hs index aa01f3dc4..c285e7ae3 100644 --- a/Ledger/RawTransaction.hs +++ b/Ledger/RawTransaction.hs @@ -1,3 +1,10 @@ +{-| + +A 'RawTransaction' represents a single transaction line within a ledger +entry. We call it raw to distinguish from the cached 'Transaction'. + +-} + module Ledger.RawTransaction where import Ledger.Utils diff --git a/Ledger/TimeLog.hs b/Ledger/TimeLog.hs index 669bf60c5..7d6545f43 100644 --- a/Ledger/TimeLog.hs +++ b/Ledger/TimeLog.hs @@ -1,3 +1,10 @@ +{-| + +A 'TimeLog' is a parsed timelog file (generated by timeclock.el). +It contains zero or more 'TimeLogEntry's. + +-} + module Ledger.TimeLog where import Ledger.Utils diff --git a/Ledger/Transaction.hs b/Ledger/Transaction.hs index 901a9aa0f..4eb8713dd 100644 --- a/Ledger/Transaction.hs +++ b/Ledger/Transaction.hs @@ -1,3 +1,10 @@ +{-| + +A 'Transaction' is a 'RawTransaction' with its parent 'LedgerEntry' \'s +date and description attached, for easier querying. + +-} + module Ledger.Transaction where import Ledger.Utils @@ -13,7 +20,9 @@ instance Show Transaction where show (Transaction eno d desc a amt) = unwords [d,desc,a,show amt] --- | we use the entry number e to remember the grouping of txns +-- | Convert a 'LedgerEntry' to two or more 'Transaction's. An id number +-- is attached to the transactions to preserve their grouping - it should +-- be unique per entry. flattenEntry :: (LedgerEntry, Int) -> [Transaction] flattenEntry (LedgerEntry d _ _ desc _ ts _, e) = [Transaction e d desc (taccount t) (tamount t) | t <- ts] diff --git a/Ledger/Types.hs b/Ledger/Types.hs index 03f401d42..d52f694b7 100644 --- a/Ledger/Types.hs +++ b/Ledger/Types.hs @@ -1,36 +1,32 @@ -{-| +{-| + All the main data types, defined here to avoid import cycles. +See the corresponding modules for documentation. + -} + module Ledger.Types where import Ledger.Utils import qualified Data.Map as Map --- | a date type Date = String --- | a date and time type DateTime = String --- | the currency of an Amount. data Currency = Currency { symbol :: String, - rate :: Double -- ^ relative to the dollar (rates are currently hardcoded) + rate :: Double } 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 single transaction line within a ledger entry. We call it raw to --- distinguish from the cached 'Transaction'. data RawTransaction = RawTransaction { taccount :: AccountName, tamount :: Amount, @@ -49,7 +45,6 @@ data PeriodicEntry = PeriodicEntry { p_transactions :: [RawTransaction] } deriving (Eq) --- | a regular ledger entry, containing two or more transactions which balance data LedgerEntry = LedgerEntry { edate :: Date, estatus :: Bool, @@ -60,8 +55,6 @@ data LedgerEntry = LedgerEntry { epreceding_comment_lines :: String } deriving (Eq) --- | a parsed ledger file. We call it raw to distinguish from the cached --- 'Ledger'. data RawLedger = RawLedger { modifier_entries :: [ModifierEntry], periodic_entries :: [PeriodicEntry], @@ -69,22 +62,16 @@ data RawLedger = RawLedger { 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 RawTransaction with some of its parent --- LedgerEntry's data attached. data Transaction = Transaction { entryno :: Int, date :: Date, @@ -93,16 +80,12 @@ data Transaction = Transaction { 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, diff --git a/Ledger/Utils.hs b/Ledger/Utils.hs index b0f6a5469..9bb60f464 100644 --- a/Ledger/Utils.hs +++ b/Ledger/Utils.hs @@ -1,4 +1,9 @@ --- standard always-available imports and utilities +{-| + +Standard always-available imports and utilities. + +-} + module Ledger.Utils ( module Ledger.Utils, module Char, diff --git a/Options.hs b/Options.hs index df149cb6e..e1ccd6826 100644 --- a/Options.hs +++ b/Options.hs @@ -93,7 +93,7 @@ wildcard :: Regex wildcard = mkRegex ".*" -- | parse the user's specified ledger file and do some action with it --- (or report a parse error) +-- (or report a parse error). This function makes the whole thing go. parseLedgerAndDo :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO () parseLedgerAndDo opts pats cmd = do path <- ledgerFilePath opts