mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-26 15:42:27 -05:00
Add more sample reports
Also switch tabs to spaces in existing sample reports
This commit is contained in:
parent
f213e1061c
commit
8f884f7a69
42
reports/asset_allocation.lua
Normal file
42
reports/asset_allocation.lua
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
function generate()
|
||||||
|
accounts = get_accounts()
|
||||||
|
securities = get_securities()
|
||||||
|
default_currency = get_default_currency()
|
||||||
|
series_map = {}
|
||||||
|
totals_map = {}
|
||||||
|
|
||||||
|
t = tabulation.new(1)
|
||||||
|
t:title("Current Asset Allocation")
|
||||||
|
|
||||||
|
t:label(1, "Assets")
|
||||||
|
|
||||||
|
for id, security in pairs(securities) do
|
||||||
|
totals_map[id] = 0
|
||||||
|
series_map[id] = t:series(tostring(security))
|
||||||
|
end
|
||||||
|
|
||||||
|
for id, acct in pairs(accounts) do
|
||||||
|
if acct.type == account.Asset or acct.type == account.Investment or acct.type == account.Bank or acct.type == account.Cash then
|
||||||
|
balance = acct:balance()
|
||||||
|
multiplier = 1
|
||||||
|
if acct.security ~= default_currency and balance.amount ~= 0 then
|
||||||
|
price = acct.security:closestprice(default_currency, date.now())
|
||||||
|
if price == nil then
|
||||||
|
--[[
|
||||||
|
-- This should contain code to warn the user that their report is missing some information
|
||||||
|
--]]
|
||||||
|
multiplier = 0
|
||||||
|
else
|
||||||
|
multiplier = price.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
totals_map[acct.security.SecurityId] = balance.amount * multiplier + totals_map[acct.security.SecurityId]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for id, series in pairs(series_map) do
|
||||||
|
series:value(1, totals_map[id])
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
@ -1,26 +1,26 @@
|
|||||||
function generate()
|
function generate()
|
||||||
year = date.now().year
|
year = date.now().year
|
||||||
|
|
||||||
accounts = get_accounts()
|
accounts = get_accounts()
|
||||||
t = tabulation.new(12)
|
t = tabulation.new(12)
|
||||||
t:title(year .. " Monthly Cash Flow")
|
t:title(year .. " Monthly Cash Flow")
|
||||||
series = t:series("Income minus expenses")
|
series = t:series("Income minus expenses")
|
||||||
|
|
||||||
for month=1,12 do
|
for month=1,12 do
|
||||||
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)
|
||||||
|
|
||||||
t:label(month, tostring(begin_date))
|
t:label(month, tostring(begin_date))
|
||||||
cash_flow = 0
|
cash_flow = 0
|
||||||
|
|
||||||
for id, acct in pairs(accounts) do
|
for id, acct in pairs(accounts) do
|
||||||
if acct.type == account.Expense or acct.type == account.Income then
|
if acct.type == account.Expense or acct.type == account.Income then
|
||||||
balance = acct:balance(begin_date, end_date)
|
balance = acct:balance(begin_date, end_date)
|
||||||
cash_flow = cash_flow - balance.amount
|
cash_flow = cash_flow - balance.amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
series:value(month, cash_flow)
|
series:value(month, cash_flow)
|
||||||
end
|
end
|
||||||
|
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
function account_series_map(accounts, tabulation)
|
function account_series_map(accounts, tabulation)
|
||||||
map = {}
|
map = {}
|
||||||
|
|
||||||
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
|
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
|
||||||
all_handled = true
|
all_handled = true
|
||||||
for id, acct in pairs(accounts) do
|
for id, acct in pairs(accounts) do
|
||||||
if not map[id] then
|
if not map[id] then
|
||||||
all_handled = false
|
all_handled = false
|
||||||
if not acct.parent then
|
if not acct.parent then
|
||||||
map[id] = tabulation:series(acct.name)
|
map[id] = tabulation:series(acct.name)
|
||||||
elseif map[acct.parent.accountid] then
|
elseif map[acct.parent.accountid] then
|
||||||
map[id] = map[acct.parent.accountid]:series(acct.name)
|
map[id] = map[acct.parent.accountid]:series(acct.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if all_handled then
|
if all_handled then
|
||||||
return map
|
return map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
error("Accounts nested (at least) 100 levels deep")
|
error("Accounts nested (at least) 100 levels deep")
|
||||||
end
|
end
|
||||||
|
|
||||||
function generate()
|
function generate()
|
||||||
year = date.now().year
|
year = date.now().year
|
||||||
account_type = account.Expense
|
account_type = account.Expense
|
||||||
|
|
||||||
accounts = get_accounts()
|
accounts = get_accounts()
|
||||||
t = tabulation.new(12)
|
t = tabulation.new(12)
|
||||||
t:title(year .. " Monthly Expenses")
|
t:title(year .. " Monthly Expenses")
|
||||||
series_map = account_series_map(accounts, t)
|
series_map = account_series_map(accounts, t)
|
||||||
|
|
||||||
for month=1,12 do
|
for month=1,12 do
|
||||||
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)
|
||||||
|
|
||||||
t:label(month, tostring(begin_date))
|
t:label(month, tostring(begin_date))
|
||||||
|
|
||||||
for id, acct in pairs(accounts) do
|
for id, acct in pairs(accounts) do
|
||||||
series = series_map[id]
|
series = series_map[id]
|
||||||
if acct.type == account_type then
|
if acct.type == account_type then
|
||||||
balance = acct:balance(begin_date, end_date)
|
balance = acct:balance(begin_date, end_date)
|
||||||
series:value(month, balance.amount)
|
series:value(month, balance.amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
60
reports/monthly_net_worth.lua
Normal file
60
reports/monthly_net_worth.lua
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
function account_series_map(accounts, tabulation)
|
||||||
|
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] = tabulation: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
|
||||||
|
|
||||||
|
accounts = get_accounts()
|
||||||
|
t = tabulation.new(12)
|
||||||
|
t:title(year .. " Monthly Net Worth")
|
||||||
|
series_map = account_series_map(accounts, t)
|
||||||
|
default_currency = get_default_currency()
|
||||||
|
|
||||||
|
for month=1,12 do
|
||||||
|
end_date = date.new(year, month+1, 1)
|
||||||
|
|
||||||
|
t:label(month, tostring(end_date))
|
||||||
|
|
||||||
|
for id, acct in pairs(accounts) do
|
||||||
|
series = series_map[id]
|
||||||
|
if acct.type ~= account.Expense and acct.type ~= account.Income and acct.type ~= account.Trading then
|
||||||
|
balance = acct:balance(end_date)
|
||||||
|
multiplier = 1
|
||||||
|
if acct.security ~= default_currency and balance.amount ~= 0 then
|
||||||
|
price = acct.security:closestprice(default_currency, end_date)
|
||||||
|
if price == nil then
|
||||||
|
--[[
|
||||||
|
-- This should contain code to warn the user that their report is missing some information
|
||||||
|
--]]
|
||||||
|
multiplier = 0
|
||||||
|
else
|
||||||
|
multiplier = price.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
series:value(month, balance.amount * multiplier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
61
reports/monthly_net_worth_change.lua
Normal file
61
reports/monthly_net_worth_change.lua
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
function account_series_map(accounts, tabulation)
|
||||||
|
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] = tabulation: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
|
||||||
|
|
||||||
|
accounts = get_accounts()
|
||||||
|
t = tabulation.new(12)
|
||||||
|
t:title(year .. " Monthly Net Worth")
|
||||||
|
series_map = account_series_map(accounts, t)
|
||||||
|
default_currency = get_default_currency()
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
for id, acct in pairs(accounts) do
|
||||||
|
series = series_map[id]
|
||||||
|
if acct.type ~= account.Expense and acct.type ~= account.Income and acct.type ~= account.Trading then
|
||||||
|
balance = acct:balance(begin_date, end_date)
|
||||||
|
multiplier = 1
|
||||||
|
if acct.security ~= default_currency then
|
||||||
|
price = acct.security:closestprice(default_currency, end_date)
|
||||||
|
if price == nil then
|
||||||
|
--[[
|
||||||
|
-- This should contain code to warn the user that their report is missing some information
|
||||||
|
--]]
|
||||||
|
multiplier = 0
|
||||||
|
else
|
||||||
|
multiplier = price.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
series:value(month, balance.amount * multiplier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
60
reports/quarterly_net_worth.lua
Normal file
60
reports/quarterly_net_worth.lua
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
function account_series_map(accounts, tabulation)
|
||||||
|
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] = tabulation: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-4
|
||||||
|
|
||||||
|
accounts = get_accounts()
|
||||||
|
t = tabulation.new(20)
|
||||||
|
t:title(year .. "-" .. date.now().year .. " Quarterly Net Worth")
|
||||||
|
series_map = account_series_map(accounts, t:series("Net Worth"))
|
||||||
|
default_currency = get_default_currency()
|
||||||
|
|
||||||
|
for month=1,20 do
|
||||||
|
end_date = date.new(year, month*3-2, 1)
|
||||||
|
|
||||||
|
t:label(month, tostring(end_date))
|
||||||
|
|
||||||
|
for id, acct in pairs(accounts) do
|
||||||
|
series = series_map[id]
|
||||||
|
if acct.type ~= account.Expense and acct.type ~= account.Income and acct.type ~= account.Trading then
|
||||||
|
balance = acct:balance(end_date)
|
||||||
|
multiplier = 1
|
||||||
|
if acct.security ~= default_currency then
|
||||||
|
price = acct.security:closestprice(default_currency, end_date)
|
||||||
|
if price == nil then
|
||||||
|
--[[
|
||||||
|
-- This should contain code to warn the user that their report is missing some information
|
||||||
|
--]]
|
||||||
|
multiplier = 0
|
||||||
|
else
|
||||||
|
multiplier = price.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
series:value(month, balance.amount * multiplier)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return t
|
||||||
|
end
|
@ -1,47 +1,47 @@
|
|||||||
function account_series_map(accounts, tabulation)
|
function account_series_map(accounts, tabulation)
|
||||||
map = {}
|
map = {}
|
||||||
|
|
||||||
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
|
for i=1,100 do -- we're not messing with accounts more than 100 levels deep
|
||||||
all_handled = true
|
all_handled = true
|
||||||
for id, acct in pairs(accounts) do
|
for id, acct in pairs(accounts) do
|
||||||
if not map[id] then
|
if not map[id] then
|
||||||
all_handled = false
|
all_handled = false
|
||||||
if not acct.parent then
|
if not acct.parent then
|
||||||
map[id] = tabulation:series(acct.name)
|
map[id] = tabulation:series(acct.name)
|
||||||
elseif map[acct.parent.accountid] then
|
elseif map[acct.parent.accountid] then
|
||||||
map[id] = map[acct.parent.accountid]:series(acct.name)
|
map[id] = map[acct.parent.accountid]:series(acct.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if all_handled then
|
if all_handled then
|
||||||
return map
|
return map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
error("Accounts nested (at least) 100 levels deep")
|
error("Accounts nested (at least) 100 levels deep")
|
||||||
end
|
end
|
||||||
|
|
||||||
function generate()
|
function generate()
|
||||||
year = date.now().year
|
year = date.now().year
|
||||||
account_type = account.Income
|
account_type = account.Income
|
||||||
|
|
||||||
accounts = get_accounts()
|
accounts = get_accounts()
|
||||||
t = tabulation.new(1)
|
t = tabulation.new(1)
|
||||||
t:title(year .. " Income")
|
t:title(year .. " Income")
|
||||||
series_map = account_series_map(accounts, t)
|
series_map = account_series_map(accounts, t)
|
||||||
|
|
||||||
begin_date = date.new(year, 1, 1)
|
begin_date = date.new(year, 1, 1)
|
||||||
end_date = date.new(year+1, 1, 1)
|
end_date = date.new(year+1, 1, 1)
|
||||||
|
|
||||||
t:label(1, year .. " Income")
|
t:label(1, year .. " Income")
|
||||||
|
|
||||||
for id, acct in pairs(accounts) do
|
for id, acct in pairs(accounts) do
|
||||||
series = series_map[id]
|
series = series_map[id]
|
||||||
if acct.type == account_type then
|
if acct.type == account_type then
|
||||||
balance = acct:balance(begin_date, end_date)
|
balance = acct:balance(begin_date, end_date)
|
||||||
series:value(1, balance.amount)
|
series:value(1, balance.amount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user