diff --git a/Entry.hs b/Entry.hs index cfe9d4be7..c0156c123 100644 --- a/Entry.hs +++ b/Entry.hs @@ -25,7 +25,7 @@ data Entry = Entry { ecode :: String, edescription :: String, etransactions :: [Transaction] - } deriving (Eq,Ord) + } deriving (Eq) instance Show Entry where show = showEntry diff --git a/EntryTransaction.hs b/EntryTransaction.hs index 55a69507e..b69c0518c 100644 --- a/EntryTransaction.hs +++ b/EntryTransaction.hs @@ -51,7 +51,7 @@ showTransactionsWithBalances [] _ = [] showTransactionsWithBalances ts b = unlines $ showTransactionsWithBalances' ts dummyt b where - dummyt = (Entry "" False "" "" [], Transaction "" (Amount "" 0)) + dummyt = (Entry "" False "" "" [], Transaction "" (dollars 0)) showTransactionsWithBalances' [] _ _ = [] showTransactionsWithBalances' (t:ts) tprev b = (if (entry t /= (entry tprev)) diff --git a/Parse.hs b/Parse.hs index 19cefaddb..ff8734b6d 100644 --- a/Parse.hs +++ b/Parse.hs @@ -231,9 +231,9 @@ ledgeramount = try (do many1 spacenonewline currency <- many (noneOf "-.0123456789\n") "currency" quantity <- many1 (oneOf "-.,0123456789") "quantity" - return (Amount currency (read $ stripcommas quantity)) + return (Amount (getcurrency currency) (read $ stripcommas quantity)) ) <|> - return (Amount "AUTO" 0) + return (Amount (Currency "AUTO" 0) 0) stripcommas = filter (',' /=) diff --git a/TODO b/TODO index 654b72b83..0d97cdc87 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,11 @@ +fix up Amounts + allow flexible display by currency + allow parsing by currency + fix arithmetic + feature: read timelog files timelog parser handle time amounts - fix arithmetic calculate time intervals find datetime type auto-generate missing clock-out diff --git a/Tests.hs b/Tests.hs index 3e0de2602..67fbe00ac 100644 --- a/Tests.hs +++ b/Tests.hs @@ -13,7 +13,7 @@ import Utils transaction1_str = " expenses:food:dining $10.00\n" -transaction1 = Transaction "expenses:food:dining" (Amount "$" 10) +transaction1 = Transaction "expenses:food:dining" (dollars 10) entry1_str = "\ \2007/01/28 coopportunity\n\ @@ -23,8 +23,8 @@ entry1_str = "\ entry1 = (Entry "2007/01/28" False "" "coopportunity" - [Transaction "expenses:food:groceries" (Amount "$" 47.18), - Transaction "assets:checking" (Amount "$" (-47.18))]) + [Transaction "expenses:food:groceries" (Amount (getcurrency "$") 47.18), + Transaction "assets:checking" (Amount (getcurrency "$") (-47.18))]) entry2_str = "\ \2007/01/27 * joes diner\n\ @@ -163,9 +163,9 @@ ledger7 = Ledger edate="2007/01/01", estatus=False, ecode="*", edescription="opening balance", etransactions=[ Transaction {taccount="assets:cash", - tamount=Amount {currency="$", quantity=4.82}}, + tamount=Amount {currency=(getcurrency "$"), quantity=4.82}}, Transaction {taccount="equity:opening balances", - tamount=Amount {currency="$", quantity=(-4.82)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-4.82)}} ] } , @@ -173,9 +173,9 @@ ledger7 = Ledger edate="2007/02/01", estatus=False, ecode="*", edescription="ayres suites", etransactions=[ Transaction {taccount="expenses:vacation", - tamount=Amount {currency="$", quantity=179.92}}, + tamount=Amount {currency=(getcurrency "$"), quantity=179.92}}, Transaction {taccount="assets:checking", - tamount=Amount {currency="$", quantity=(-179.92)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-179.92)}} ] } , @@ -183,9 +183,9 @@ ledger7 = Ledger edate="2007/01/02", estatus=False, ecode="*", edescription="auto transfer to savings", etransactions=[ Transaction {taccount="assets:saving", - tamount=Amount {currency="$", quantity=200}}, + tamount=Amount {currency=(getcurrency "$"), quantity=200}}, Transaction {taccount="assets:checking", - tamount=Amount {currency="$", quantity=(-200)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-200)}} ] } , @@ -193,9 +193,9 @@ ledger7 = Ledger edate="2007/01/03", estatus=False, ecode="*", edescription="poquito mas", etransactions=[ Transaction {taccount="expenses:food:dining", - tamount=Amount {currency="$", quantity=4.82}}, + tamount=Amount {currency=(getcurrency "$"), quantity=4.82}}, Transaction {taccount="assets:cash", - tamount=Amount {currency="$", quantity=(-4.82)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-4.82)}} ] } , @@ -203,9 +203,9 @@ ledger7 = Ledger edate="2007/01/03", estatus=False, ecode="*", edescription="verizon", etransactions=[ Transaction {taccount="expenses:phone", - tamount=Amount {currency="$", quantity=95.11}}, + tamount=Amount {currency=(getcurrency "$"), quantity=95.11}}, Transaction {taccount="assets:checking", - tamount=Amount {currency="$", quantity=(-95.11)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-95.11)}} ] } , @@ -213,9 +213,9 @@ ledger7 = Ledger edate="2007/01/03", estatus=False, ecode="*", edescription="discover", etransactions=[ Transaction {taccount="liabilities:credit cards:discover", - tamount=Amount {currency="$", quantity=80}}, + tamount=Amount {currency=(getcurrency "$"), quantity=80}}, Transaction {taccount="assets:checking", - tamount=Amount {currency="$", quantity=(-80)}} + tamount=Amount {currency=(getcurrency "$"), quantity=(-80)}} ] } ] @@ -274,7 +274,7 @@ test_ledgerentry = test_autofillEntry = assertEqual' - (Amount "$" (-47.18)) + (Amount (getcurrency "$") (-47.18)) (tamount $ last $ etransactions $ autofillEntry entry1) test_expandAccountNames = @@ -294,7 +294,7 @@ test_ledgerAccountNames = props = mapM quickCheck [ parse' ledgertransaction transaction1_str `parseEquals` - (Transaction "expenses:food:dining" (Amount "$" 10)) + (Transaction "expenses:food:dining" (Amount (getcurrency "$") 10)) , ledgerAccountNames ledger7 == ["assets","assets:cash","assets:checking","assets:saving","equity", diff --git a/TimeLog.hs b/TimeLog.hs index 6b9732a5c..97ba910e0 100644 --- a/TimeLog.hs +++ b/TimeLog.hs @@ -49,12 +49,11 @@ entriesFromTimeLogEntries [clockin,clockout] = intime = tdatetime clockin indate = dateFrom $ tdatetime clockin outtime = tdatetime clockout - amount = timeAmount $ 0 -- read $ outtime - intime + amount = hours 0 -- read $ outtime - intime entriesFromTimeLogEntries many = (entriesFromTimeLogEntries $ take 2 many) ++ (entriesFromTimeLogEntries $ drop 2 many) clockoutNowEntry = TimeLogEntry ' ' "" "" -timeAmount = Amount "h" dateFrom = id diff --git a/Transaction.hs b/Transaction.hs index dd0c66323..6e9896d6d 100644 --- a/Transaction.hs +++ b/Transaction.hs @@ -10,7 +10,7 @@ import Amount data Transaction = Transaction { taccount :: AccountName, tamount :: Amount - } deriving (Eq,Ord) + } deriving (Eq) instance Show Transaction where show = showTransaction @@ -26,7 +26,7 @@ elideRight width s = autofillTransactions :: [Transaction] -> [Transaction] autofillTransactions ts = let (ns, as) = partition isNormal ts - where isNormal t = (currency $ tamount t) /= "AUTO" in + where isNormal t = (symbol $ currency $ tamount t) /= "AUTO" in case (length as) of 0 -> ns 1 -> ns ++ [balanceTransaction $ head as]