mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
amount/currency updates
This commit is contained in:
parent
2b696b8f0d
commit
23cb79e1f9
2
Entry.hs
2
Entry.hs
@ -25,7 +25,7 @@ data Entry = Entry {
|
|||||||
ecode :: String,
|
ecode :: String,
|
||||||
edescription :: String,
|
edescription :: String,
|
||||||
etransactions :: [Transaction]
|
etransactions :: [Transaction]
|
||||||
} deriving (Eq,Ord)
|
} deriving (Eq)
|
||||||
|
|
||||||
instance Show Entry where show = showEntry
|
instance Show Entry where show = showEntry
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ showTransactionsWithBalances [] _ = []
|
|||||||
showTransactionsWithBalances ts b =
|
showTransactionsWithBalances ts b =
|
||||||
unlines $ showTransactionsWithBalances' ts dummyt b
|
unlines $ showTransactionsWithBalances' ts dummyt b
|
||||||
where
|
where
|
||||||
dummyt = (Entry "" False "" "" [], Transaction "" (Amount "" 0))
|
dummyt = (Entry "" False "" "" [], Transaction "" (dollars 0))
|
||||||
showTransactionsWithBalances' [] _ _ = []
|
showTransactionsWithBalances' [] _ _ = []
|
||||||
showTransactionsWithBalances' (t:ts) tprev b =
|
showTransactionsWithBalances' (t:ts) tprev b =
|
||||||
(if (entry t /= (entry tprev))
|
(if (entry t /= (entry tprev))
|
||||||
|
4
Parse.hs
4
Parse.hs
@ -231,9 +231,9 @@ ledgeramount = try (do
|
|||||||
many1 spacenonewline
|
many1 spacenonewline
|
||||||
currency <- many (noneOf "-.0123456789\n") <?> "currency"
|
currency <- many (noneOf "-.0123456789\n") <?> "currency"
|
||||||
quantity <- many1 (oneOf "-.,0123456789") <?> "quantity"
|
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 (',' /=)
|
stripcommas = filter (',' /=)
|
||||||
|
|
||||||
|
6
TODO
6
TODO
@ -1,7 +1,11 @@
|
|||||||
|
fix up Amounts
|
||||||
|
allow flexible display by currency
|
||||||
|
allow parsing by currency
|
||||||
|
fix arithmetic
|
||||||
|
|
||||||
feature: read timelog files
|
feature: read timelog files
|
||||||
timelog parser
|
timelog parser
|
||||||
handle time amounts
|
handle time amounts
|
||||||
fix arithmetic
|
|
||||||
calculate time intervals
|
calculate time intervals
|
||||||
find datetime type
|
find datetime type
|
||||||
auto-generate missing clock-out
|
auto-generate missing clock-out
|
||||||
|
34
Tests.hs
34
Tests.hs
@ -13,7 +13,7 @@ import Utils
|
|||||||
|
|
||||||
transaction1_str = " expenses:food:dining $10.00\n"
|
transaction1_str = " expenses:food:dining $10.00\n"
|
||||||
|
|
||||||
transaction1 = Transaction "expenses:food:dining" (Amount "$" 10)
|
transaction1 = Transaction "expenses:food:dining" (dollars 10)
|
||||||
|
|
||||||
entry1_str = "\
|
entry1_str = "\
|
||||||
\2007/01/28 coopportunity\n\
|
\2007/01/28 coopportunity\n\
|
||||||
@ -23,8 +23,8 @@ entry1_str = "\
|
|||||||
|
|
||||||
entry1 =
|
entry1 =
|
||||||
(Entry "2007/01/28" False "" "coopportunity"
|
(Entry "2007/01/28" False "" "coopportunity"
|
||||||
[Transaction "expenses:food:groceries" (Amount "$" 47.18),
|
[Transaction "expenses:food:groceries" (Amount (getcurrency "$") 47.18),
|
||||||
Transaction "assets:checking" (Amount "$" (-47.18))])
|
Transaction "assets:checking" (Amount (getcurrency "$") (-47.18))])
|
||||||
|
|
||||||
entry2_str = "\
|
entry2_str = "\
|
||||||
\2007/01/27 * joes diner\n\
|
\2007/01/27 * joes diner\n\
|
||||||
@ -163,9 +163,9 @@ ledger7 = Ledger
|
|||||||
edate="2007/01/01", estatus=False, ecode="*", edescription="opening balance",
|
edate="2007/01/01", estatus=False, ecode="*", edescription="opening balance",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="assets:cash",
|
Transaction {taccount="assets:cash",
|
||||||
tamount=Amount {currency="$", quantity=4.82}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=4.82}},
|
||||||
Transaction {taccount="equity:opening balances",
|
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",
|
edate="2007/02/01", estatus=False, ecode="*", edescription="ayres suites",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="expenses:vacation",
|
Transaction {taccount="expenses:vacation",
|
||||||
tamount=Amount {currency="$", quantity=179.92}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=179.92}},
|
||||||
Transaction {taccount="assets:checking",
|
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",
|
edate="2007/01/02", estatus=False, ecode="*", edescription="auto transfer to savings",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="assets:saving",
|
Transaction {taccount="assets:saving",
|
||||||
tamount=Amount {currency="$", quantity=200}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=200}},
|
||||||
Transaction {taccount="assets:checking",
|
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",
|
edate="2007/01/03", estatus=False, ecode="*", edescription="poquito mas",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="expenses:food:dining",
|
Transaction {taccount="expenses:food:dining",
|
||||||
tamount=Amount {currency="$", quantity=4.82}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=4.82}},
|
||||||
Transaction {taccount="assets:cash",
|
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",
|
edate="2007/01/03", estatus=False, ecode="*", edescription="verizon",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="expenses:phone",
|
Transaction {taccount="expenses:phone",
|
||||||
tamount=Amount {currency="$", quantity=95.11}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=95.11}},
|
||||||
Transaction {taccount="assets:checking",
|
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",
|
edate="2007/01/03", estatus=False, ecode="*", edescription="discover",
|
||||||
etransactions=[
|
etransactions=[
|
||||||
Transaction {taccount="liabilities:credit cards:discover",
|
Transaction {taccount="liabilities:credit cards:discover",
|
||||||
tamount=Amount {currency="$", quantity=80}},
|
tamount=Amount {currency=(getcurrency "$"), quantity=80}},
|
||||||
Transaction {taccount="assets:checking",
|
Transaction {taccount="assets:checking",
|
||||||
tamount=Amount {currency="$", quantity=(-80)}}
|
tamount=Amount {currency=(getcurrency "$"), quantity=(-80)}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -274,7 +274,7 @@ test_ledgerentry =
|
|||||||
|
|
||||||
test_autofillEntry =
|
test_autofillEntry =
|
||||||
assertEqual'
|
assertEqual'
|
||||||
(Amount "$" (-47.18))
|
(Amount (getcurrency "$") (-47.18))
|
||||||
(tamount $ last $ etransactions $ autofillEntry entry1)
|
(tamount $ last $ etransactions $ autofillEntry entry1)
|
||||||
|
|
||||||
test_expandAccountNames =
|
test_expandAccountNames =
|
||||||
@ -294,7 +294,7 @@ test_ledgerAccountNames =
|
|||||||
props = mapM quickCheck
|
props = mapM quickCheck
|
||||||
[
|
[
|
||||||
parse' ledgertransaction transaction1_str `parseEquals`
|
parse' ledgertransaction transaction1_str `parseEquals`
|
||||||
(Transaction "expenses:food:dining" (Amount "$" 10))
|
(Transaction "expenses:food:dining" (Amount (getcurrency "$") 10))
|
||||||
,
|
,
|
||||||
ledgerAccountNames ledger7 ==
|
ledgerAccountNames ledger7 ==
|
||||||
["assets","assets:cash","assets:checking","assets:saving","equity",
|
["assets","assets:cash","assets:checking","assets:saving","equity",
|
||||||
|
@ -49,12 +49,11 @@ entriesFromTimeLogEntries [clockin,clockout] =
|
|||||||
intime = tdatetime clockin
|
intime = tdatetime clockin
|
||||||
indate = dateFrom $ tdatetime clockin
|
indate = dateFrom $ tdatetime clockin
|
||||||
outtime = tdatetime clockout
|
outtime = tdatetime clockout
|
||||||
amount = timeAmount $ 0 -- read $ outtime - intime
|
amount = hours 0 -- read $ outtime - intime
|
||||||
|
|
||||||
entriesFromTimeLogEntries many =
|
entriesFromTimeLogEntries many =
|
||||||
(entriesFromTimeLogEntries $ take 2 many) ++
|
(entriesFromTimeLogEntries $ take 2 many) ++
|
||||||
(entriesFromTimeLogEntries $ drop 2 many)
|
(entriesFromTimeLogEntries $ drop 2 many)
|
||||||
|
|
||||||
clockoutNowEntry = TimeLogEntry ' ' "" ""
|
clockoutNowEntry = TimeLogEntry ' ' "" ""
|
||||||
timeAmount = Amount "h"
|
|
||||||
dateFrom = id
|
dateFrom = id
|
||||||
|
@ -10,7 +10,7 @@ import Amount
|
|||||||
data Transaction = Transaction {
|
data Transaction = Transaction {
|
||||||
taccount :: AccountName,
|
taccount :: AccountName,
|
||||||
tamount :: Amount
|
tamount :: Amount
|
||||||
} deriving (Eq,Ord)
|
} deriving (Eq)
|
||||||
|
|
||||||
instance Show Transaction where show = showTransaction
|
instance Show Transaction where show = showTransaction
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ elideRight width s =
|
|||||||
autofillTransactions :: [Transaction] -> [Transaction]
|
autofillTransactions :: [Transaction] -> [Transaction]
|
||||||
autofillTransactions ts =
|
autofillTransactions ts =
|
||||||
let (ns, as) = partition isNormal 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
|
case (length as) of
|
||||||
0 -> ns
|
0 -> ns
|
||||||
1 -> ns ++ [balanceTransaction $ head as]
|
1 -> ns ++ [balanceTransaction $ head as]
|
||||||
|
Loading…
Reference in New Issue
Block a user