1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-25 23:23:21 -05:00

reports: Add initial monthly_expenses

This commit is contained in:
Aaron Lindsay 2017-02-11 09:27:34 -05:00
parent 55d0e718c8
commit d2b98c3d4b
2 changed files with 49 additions and 8 deletions

View File

@ -0,0 +1,49 @@
function account_series_map(accounts, report)
map = {}
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
all_handled = true
for id, acct in pairs(accounts) do
if not map[id] then
all_handled = false
if not acct.parent then
map[id] = report:series(acct.name)
elseif map[acct.parent.accountid] then
map[id] = map[acct.parent.accountid]:series(acct.name)
end
end
end
if all_handled then
return map
end
end
error("Accounts nested more than 100 levels deep")
end
function generate()
year = date.now().year
account_type = account.Expense
accounts = get_accounts()
r = report.new(12)
series_map = account_series_map(accounts, r)
for month=1,12 do
balance = nil
begin_date = date.new(year, month, 1)
end_date = date.new(year, month+1, 1)
r:label(month, tostring(begin_date))
for id, acct in pairs(accounts) do
series = series_map[id]
if acct.type == account_type then
balance = acct:balance(begin_date, end_date)
series:value(month, balance.amount)
end
end
end
return r
end

View File

@ -1,8 +0,0 @@
accounts = get_accounts()
for id, account in pairs(accounts) do
print(account, account.security)
a = account:balance(date.new("2015-12-01"), date.new("2017-12-01"))
b = account:balance(date.new("2015-06-01"), date.new("2015-12-01"))
print(a, b, a+b, account:balance())
end