diff --git a/Account.hs b/Account.hs index c5a090cf9..c65d9d288 100644 --- a/Account.hs +++ b/Account.hs @@ -5,7 +5,7 @@ import Types import AccountName import Amount import LedgerEntry -import LedgerTransaction +import RawTransaction import Transaction diff --git a/Ledger.hs b/Ledger.hs index 85dad880e..f50d8780c 100644 --- a/Ledger.hs +++ b/Ledger.hs @@ -73,7 +73,7 @@ filterLedgerEntries (acctpat,descpat) (RawLedger ms ps es f) = where filteredentries :: [LedgerEntry] filteredentries = (filter matchdesc $ filter (any matchtxn . etransactions) es) - matchtxn :: LedgerTransaction -> Bool + matchtxn :: RawTransaction -> Bool matchtxn t = case matchRegex acctpat (taccount t) of Nothing -> False otherwise -> True diff --git a/LedgerEntry.hs b/LedgerEntry.hs index accbb14b8..c0bd6361d 100644 --- a/LedgerEntry.hs +++ b/LedgerEntry.hs @@ -2,7 +2,7 @@ module LedgerEntry where import Utils import Types -import LedgerTransaction +import RawTransaction import Amount diff --git a/Models.hs b/Models.hs index 72a8d6f78..4d1943f41 100644 --- a/Models.hs +++ b/Models.hs @@ -1,10 +1,13 @@ -{-| all data types & behaviours -} +{-| +This module makes it easier to import all the hledger "models", +the main data types and their "methods". +-} module Models ( module Types, module Currency, module Amount, module AccountName, - module LedgerTransaction, + module RawTransaction, module LedgerEntry, module TimeLog, module Transaction, @@ -19,7 +22,7 @@ import Types import Currency import Amount import AccountName -import LedgerTransaction +import RawTransaction import LedgerEntry import TimeLog import Transaction diff --git a/Parse.hs b/Parse.hs index 2dfbb66df..36c815c0a 100644 --- a/Parse.hs +++ b/Parse.hs @@ -248,10 +248,10 @@ ledgerstatus = try (do { char '*'; many1 spacenonewline; return True } ) <|> ret ledgercode :: Parser String ledgercode = try (do { char '('; code <- anyChar `manyTill` char ')'; many1 spacenonewline; return code } ) <|> return "" -ledgertransactions :: Parser [LedgerTransaction] +ledgertransactions :: Parser [RawTransaction] ledgertransactions = (ledgertransaction "transaction") `manyTill` (do {newline "blank line"; return ()} <|> eof) -ledgertransaction :: Parser LedgerTransaction +ledgertransaction :: Parser RawTransaction ledgertransaction = do many1 spacenonewline account <- ledgeraccount @@ -259,7 +259,7 @@ ledgertransaction = do many spacenonewline comment <- ledgercomment restofline - return (LedgerTransaction account amount comment) + return (RawTransaction account amount comment) -- | account names may have single spaces in them, and are terminated by two or more spaces ledgeraccount :: Parser String diff --git a/LedgerTransaction.hs b/RawTransaction.hs similarity index 64% rename from LedgerTransaction.hs rename to RawTransaction.hs index 0c8d92c4c..585fead49 100644 --- a/LedgerTransaction.hs +++ b/RawTransaction.hs @@ -1,4 +1,4 @@ -module LedgerTransaction +module RawTransaction where import Utils import Types @@ -6,9 +6,9 @@ import AccountName import Amount -instance Show LedgerTransaction where show = showLedgerTransaction +instance Show RawTransaction where show = showLedgerTransaction -showLedgerTransaction :: LedgerTransaction -> String +showLedgerTransaction :: RawTransaction -> String showLedgerTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t) where showaccountname = printf "%-22s" . elideRight 22 @@ -19,7 +19,7 @@ elideRight width s = True -> take (width - 2) s ++ ".." False -> s -autofillTransactions :: [LedgerTransaction] -> [LedgerTransaction] +autofillTransactions :: [RawTransaction] -> [RawTransaction] autofillTransactions ts = case (length blanks) of 0 -> ts @@ -30,8 +30,8 @@ autofillTransactions ts = isnormal t = (symbol $ currency $ tamount t) /= "AUTO" balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)} -sumLedgerTransactions :: [LedgerTransaction] -> Amount +sumLedgerTransactions :: [RawTransaction] -> Amount sumLedgerTransactions = sum . map tamount -ledgerTransactionSetPrecision :: Int -> LedgerTransaction -> LedgerTransaction -ledgerTransactionSetPrecision p (LedgerTransaction a amt c) = LedgerTransaction a amt{precision=p} c +ledgerTransactionSetPrecision :: Int -> RawTransaction -> RawTransaction +ledgerTransactionSetPrecision p (RawTransaction a amt c) = RawTransaction a amt{precision=p} c diff --git a/Tests.hs b/Tests.hs index 5c65f2b7b..e945c156e 100644 --- a/Tests.hs +++ b/Tests.hs @@ -59,7 +59,7 @@ assertParseEqual expected parsed = transaction1_str = " expenses:food:dining $10.00\n" -transaction1 = LedgerTransaction "expenses:food:dining" (dollars 10) "" +transaction1 = RawTransaction "expenses:food:dining" (dollars 10) "" entry1_str = "\ \2007/01/28 coopportunity\n\ @@ -69,8 +69,8 @@ entry1_str = "\ entry1 = (LedgerEntry "2007/01/28" False "" "coopportunity" "" - [LedgerTransaction "expenses:food:groceries" (Amount (getcurrency "$") 47.18 2) "", - LedgerTransaction "assets:checking" (Amount (getcurrency "$") (-47.18) 2) ""] "") + [RawTransaction "expenses:food:groceries" (Amount (getcurrency "$") 47.18 2) "", + RawTransaction "assets:checking" (Amount (getcurrency "$") (-47.18) 2) ""] "") entry2_str = "\ \2007/01/27 * joes diner\n\ @@ -207,10 +207,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/01/01", estatus=False, ecode="*", edescription="opening balance", ecomment="", etransactions=[ - LedgerTransaction {taccount="assets:cash", + RawTransaction {taccount="assets:cash", tamount=Amount {currency=(getcurrency "$"), quantity=4.82, precision=2}, tcomment=""}, - LedgerTransaction {taccount="equity:opening balances", + RawTransaction {taccount="equity:opening balances", tamount=Amount {currency=(getcurrency "$"), quantity=(-4.82), precision=2}, tcomment=""} ], @@ -220,10 +220,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/02/01", estatus=False, ecode="*", edescription="ayres suites", ecomment="", etransactions=[ - LedgerTransaction {taccount="expenses:vacation", + RawTransaction {taccount="expenses:vacation", tamount=Amount {currency=(getcurrency "$"), quantity=179.92, precision=2}, tcomment=""}, - LedgerTransaction {taccount="assets:checking", + RawTransaction {taccount="assets:checking", tamount=Amount {currency=(getcurrency "$"), quantity=(-179.92), precision=2}, tcomment=""} ], @@ -233,10 +233,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/01/02", estatus=False, ecode="*", edescription="auto transfer to savings", ecomment="", etransactions=[ - LedgerTransaction {taccount="assets:saving", + RawTransaction {taccount="assets:saving", tamount=Amount {currency=(getcurrency "$"), quantity=200, precision=2}, tcomment=""}, - LedgerTransaction {taccount="assets:checking", + RawTransaction {taccount="assets:checking", tamount=Amount {currency=(getcurrency "$"), quantity=(-200), precision=2}, tcomment=""} ], @@ -246,10 +246,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/01/03", estatus=False, ecode="*", edescription="poquito mas", ecomment="", etransactions=[ - LedgerTransaction {taccount="expenses:food:dining", + RawTransaction {taccount="expenses:food:dining", tamount=Amount {currency=(getcurrency "$"), quantity=4.82, precision=2}, tcomment=""}, - LedgerTransaction {taccount="assets:cash", + RawTransaction {taccount="assets:cash", tamount=Amount {currency=(getcurrency "$"), quantity=(-4.82), precision=2}, tcomment=""} ], @@ -259,10 +259,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/01/03", estatus=False, ecode="*", edescription="verizon", ecomment="", etransactions=[ - LedgerTransaction {taccount="expenses:phone", + RawTransaction {taccount="expenses:phone", tamount=Amount {currency=(getcurrency "$"), quantity=95.11, precision=2}, tcomment=""}, - LedgerTransaction {taccount="assets:checking", + RawTransaction {taccount="assets:checking", tamount=Amount {currency=(getcurrency "$"), quantity=(-95.11), precision=2}, tcomment=""} ], @@ -272,10 +272,10 @@ ledger7 = RawLedger LedgerEntry { edate="2007/01/03", estatus=False, ecode="*", edescription="discover", ecomment="", etransactions=[ - LedgerTransaction {taccount="liabilities:credit cards:discover", + RawTransaction {taccount="liabilities:credit cards:discover", tamount=Amount {currency=(getcurrency "$"), quantity=80, precision=2}, tcomment=""}, - LedgerTransaction {taccount="assets:checking", + RawTransaction {taccount="assets:checking", tamount=Amount {currency=(getcurrency "$"), quantity=(-80), precision=2}, tcomment=""} ], diff --git a/TimeLog.hs b/TimeLog.hs index e97ad0177..ce3f91c4e 100644 --- a/TimeLog.hs +++ b/TimeLog.hs @@ -4,7 +4,7 @@ import Utils import Types import Currency import Amount -import LedgerTransaction +import RawTransaction import LedgerEntry import RawLedger @@ -32,8 +32,8 @@ entriesFromTimeLogEntries [clockin,clockout] = edescription = accountname, ecomment = "", etransactions = [ - LedgerTransaction accountname amount "", - LedgerTransaction "TIME" (-amount) "" + RawTransaction accountname amount "", + RawTransaction "TIME" (-amount) "" ], epreceding_comment_lines=""} ] diff --git a/Transaction.hs b/Transaction.hs index 43da64b9b..a3105bd81 100644 --- a/Transaction.hs +++ b/Transaction.hs @@ -4,7 +4,7 @@ import Utils import Types import AccountName import LedgerEntry -import LedgerTransaction +import RawTransaction import Amount import Currency @@ -48,11 +48,11 @@ showTransactionsWithBalances ts b = showTransactionDescriptionAndBalance :: Transaction -> Amount -> String showTransactionDescriptionAndBalance t b = (showEntryDescription $ LedgerEntry (date t) False "" (description t) "" [] "") - ++ (showLedgerTransaction $ LedgerTransaction (account t) (amount t) "") ++ (showBalance b) + ++ (showLedgerTransaction $ RawTransaction (account t) (amount t) "") ++ (showBalance b) showTransactionAndBalance :: Transaction -> Amount -> String showTransactionAndBalance t b = - (replicate 32 ' ') ++ (showLedgerTransaction $ LedgerTransaction (account t) (amount t) "") ++ (showBalance b) + (replicate 32 ' ') ++ (showLedgerTransaction $ RawTransaction (account t) (amount t) "") ++ (showBalance b) showBalance :: Amount -> String showBalance b = printf " %12s" (showAmountRoundedOrZero b) diff --git a/Types.hs b/Types.hs index 4af2264b1..c7989be94 100644 --- a/Types.hs +++ b/Types.hs @@ -29,8 +29,9 @@ data Amount = Amount { -- the chart of accounts type AccountName = String --- | a transaction line within a ledger entry. -data LedgerTransaction = LedgerTransaction { +-- | 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, tcomment :: String @@ -39,13 +40,13 @@ data LedgerTransaction = LedgerTransaction { -- | a ledger "modifier" entry. Currently ignored. data ModifierEntry = ModifierEntry { valueexpr :: String, - m_transactions :: [LedgerTransaction] + m_transactions :: [RawTransaction] } deriving (Eq) -- | a ledger "periodic" entry. Currently ignored. data PeriodicEntry = PeriodicEntry { periodexpr :: String, - p_transactions :: [LedgerTransaction] + p_transactions :: [RawTransaction] } deriving (Eq) -- | a regular ledger entry, containing two or more transactions which balance @@ -55,12 +56,12 @@ data LedgerEntry = LedgerEntry { ecode :: String, edescription :: String, ecomment :: String, - etransactions :: [LedgerTransaction], + etransactions :: [RawTransaction], epreceding_comment_lines :: String } deriving (Eq) -- | a parsed ledger file. We call it raw to distinguish from the cached --- version below. +-- 'Ledger'. data RawLedger = RawLedger { modifier_entries :: [ModifierEntry], periodic_entries :: [PeriodicEntry], @@ -81,7 +82,8 @@ data TimeLog = TimeLog { } deriving (Eq) -- | optimisations: these types provide some caching and are easier to work with. --- A Transaction is a LedgerTransaction with some of its parent +-- +-- A Transaction is a RawTransaction with some of its parent -- LedgerEntry's data attached. data Transaction = Transaction { entryno :: Int, diff --git a/hledger.hs b/hledger.hs index eaba0ab4e..ac53b09b0 100644 --- a/hledger.hs +++ b/hledger.hs @@ -28,7 +28,7 @@ hledger ("Main") "Transaction" "RawLedger" "LedgerEntry" - "LedgerTransaction" + "RawTransaction" "AccountName" "Amount" "Currency"