From 951d56f7fe6c1a9fafe32361d67ad5e5876ceb86 Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Fri, 7 Jul 2017 20:53:22 -0400 Subject: [PATCH] Add monthly cash flow example report --- docs/lua_reports.md | 2 ++ reports/monthly_cash_flow.lua | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 reports/monthly_cash_flow.lua diff --git a/docs/lua_reports.md b/docs/lua_reports.md index e025954..4898111 100644 --- a/docs/lua_reports.md +++ b/docs/lua_reports.md @@ -42,6 +42,8 @@ function generate() end ``` +More examples can be found in the reports/ directory in the MoneyGo source tree. + ## Basic Operation The lua code behind a report *must* contain a `generate()` function which takes diff --git a/reports/monthly_cash_flow.lua b/reports/monthly_cash_flow.lua new file mode 100644 index 0000000..08697a7 --- /dev/null +++ b/reports/monthly_cash_flow.lua @@ -0,0 +1,26 @@ +function generate() + year = date.now().year + + accounts = get_accounts() + t = tabulation.new(12) + t:title(year .. " Monthly Cash Flow") + series = t:series("Income minus expenses") + + for month=1,12 do + begin_date = date.new(year, month, 1) + end_date = date.new(year, month+1, 1) + + t:label(month, tostring(begin_date)) + cash_flow = 0 + + 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 + + return t +end