1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-12-27 16:02:27 -05:00
moneygo/reports/monthly_cash_flow.lua

27 lines
710 B
Lua
Raw Normal View History

2017-07-07 20:53:22 -04:00
function generate()
year = date.now().year
2017-07-07 20:53:22 -04:00
accounts = get_accounts()
t = tabulation.new(12)
t:title(year .. " Monthly Cash Flow")
series = t:series("Income minus expenses")
2017-07-07 20:53:22 -04:00
for month=1,12 do
begin_date = date.new(year, month, 1)
end_date = date.new(year, month+1, 1)
2017-07-07 20:53:22 -04:00
t:label(month, tostring(begin_date))
cash_flow = 0
2017-07-07 20:53:22 -04:00
for id, acct in pairs(accounts) do
if acct.type == account.Expense or acct.type == account.Income then
balance = acct:balance(begin_date, end_date)
cash_flow = cash_flow - balance.amount
end
end
series:value(month, cash_flow)
end
2017-07-07 20:53:22 -04:00
return t
2017-07-07 20:53:22 -04:00
end