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

Add years_income.lua report

This commit is contained in:
Aaron Lindsay 2017-02-22 08:26:21 -05:00
parent db7a60b292
commit 4536db030e
2 changed files with 48 additions and 2 deletions

View File

@ -18,7 +18,7 @@ function account_series_map(accounts, report)
end end
end end
error("Accounts nested more than 100 levels deep") error("Accounts nested (at least) 100 levels deep")
end end
function generate() function generate()
@ -31,7 +31,6 @@ function generate()
series_map = account_series_map(accounts, r) series_map = account_series_map(accounts, r)
for month=1,12 do for month=1,12 do
balance = nil
begin_date = date.new(year, month, 1) begin_date = date.new(year, month, 1)
end_date = date.new(year, month+1, 1) end_date = date.new(year, month+1, 1)

47
reports/years_income.lua Normal file
View File

@ -0,0 +1,47 @@
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 (at least) 100 levels deep")
end
function generate()
year = date.now().year
account_type = account.Income
accounts = get_accounts()
r = report.new(1)
r:title(year .. " Income")
series_map = account_series_map(accounts, r)
begin_date = date.new(year, 1, 1)
end_date = date.new(year+1, 1, 1)
r:label(1, year .. " Income")
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(1, balance.amount)
end
end
return r
end