Skip to content

Commit

Permalink
Merge pull request #60 from siowena/master
Browse files Browse the repository at this point in the history
Reports updated mostly for currency conversion, split where appropriate and ignore Duplicate Tx
  • Loading branch information
vomikan authored Dec 12, 2019
2 parents 9769114 + b237f28 commit e303885
Show file tree
Hide file tree
Showing 67 changed files with 1,761 additions and 965 deletions.
15 changes: 8 additions & 7 deletions AccountForecast/description.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Account Forecast Report using Repeating Transactions

Note: Requires at least one entry for account name in repeating transactions.

TODO:
1. Update account name in SQL (line 24).
2. Update account name in Template (line 12).
<h1>Account Forecast Report using Repeating Transactions</h1>
<p>Figures are displayed in the Currency of the Account selected.</p>
<p>Note: Requires at least one entry for Account in Repeating Transactions.</p>
<p>Setup:
<ol>
<li>Update Account name in SQL (line 25).</li>
</ol>
</p>
20 changes: 16 additions & 4 deletions AccountForecast/luacontent.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
local total = 0;
local prefix = '';
local suffix = '';
local forecast = {0,0,0,0,0,0}
local dpchar = '';
local grpsepchar = '';
local forecast = {0,0,0,0,0,0};
local period = 6;
local initialized = 0;
local repeatcode = 0;
local numrepeats = 0;
local accountname = '';

function is_leap_year(year)
local ly = 0;
Expand Down Expand Up @@ -52,7 +55,7 @@ end

function get_next_date(record, previousYear, previousMonth, previousDay)
local originalnumber = tonumber(record:get("NUMOCCURRENCES"));
-- Auto Execute User Acknowlegement required
-- Auto Execute User Acknowledgment required
if repeatcode >= 100 then
repeatcode = repeatcode - 100;
end
Expand Down Expand Up @@ -143,6 +146,9 @@ function handle_record(record)
total = record:get("Balance");
prefix = record:get("PFX_SYMBOL");
suffix = record:get("SFX_SYMBOL");
dpchar = record:get("DECIMAL_POINT");
grpsepchar = record:get("GROUP_SEPARATOR");
accountname = record:get("ACCOUNTNAME");
for i=1,period do
forecast[i] = total;
end
Expand Down Expand Up @@ -186,17 +192,23 @@ function complete(result)
else
data = data .. value .. ',';
end
result:set("Current_Total", prefix .. value .. suffix);
result:set("Current_Total", value);
for i=1,period do
value = string.format("%.2f", forecast[i]);
if tonumber(string.sub(value,-1)) == 0 and tonumber(string.sub(value,-2)) ~= 0 then
data = data .. '\'' .. value .. '\',';
else
data = data .. value .. ',';
end
result:set("Month" .. i .. "_Total", prefix .. value .. suffix);
result:set("Month" .. i .. "_Total", value);
local date = os.date("*t", os.time{year=curYear,month=curMonth+i,day=curDay});
result:set("Month" .. i .. "_Label", string.format("(%d-%02d-%02d)",date.year,date.month,date.day));
end
result:set('CHART_DATA', string.sub(data,1,-2) .. "]}]");
-- Override the base currency variables as the account may be in different currency
result:set('PFX_SYMBOL', prefix);
result:set('SFX_SYMBOL', suffix);
result:set('DECIMAL_POINT', dpchar);
result:set('GROUP_SEPARATOR', grpsepchar);
result:set('ACCOUNTNAME', accountname);
end
14 changes: 7 additions & 7 deletions AccountForecast/sqlcontent.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- TODO: Update account name in line 24.
select b.TRANSAMOUNT, b.REPEATS, b.NUMOCCURRENCES, b.NEXTOCCURRENCEDATE, c.PFX_SYMBOL, c.SFX_SYMBOL,
-- TODO: Update account name in line 25.
select b.TRANSAMOUNT, b.REPEATS, b.NUMOCCURRENCES, b.NEXTOCCURRENCEDATE, c.PFX_SYMBOL, c.SFX_SYMBOL, c.DECIMAL_POINT, c.GROUP_SEPARATOR,
(select a.INITIALBAL + total(t.TRANSAMOUNT)
from
(select ACCOUNTID, STATUS,
(case when TRANSCODE = 'Deposit' then TRANSAMOUNT else -TRANSAMOUNT end) as TRANSAMOUNT
from CHECKINGACCOUNT_V1
union all
select TOACCOUNTID, STATUS, TOTRANSAMOUNT
select TOACCOUNTID, STATUS, TOTRANSAMOUNT
from CHECKINGACCOUNT_V1
where TRANSCODE = 'Transfer') as t
where t.ACCOUNTID = a.ACCOUNTID
and t.STATUS <> 'V') as Balance
and t.STATUS NOT IN ('V','D')) as Balance, a.ACCOUNTNAME as ACCOUNTNAME
from
(select ACCOUNTID, STATUS, REPEATS, NUMOCCURRENCES, NEXTOCCURRENCEDATE,
(case when TRANSCODE = 'Deposit' then TRANSAMOUNT else -TRANSAMOUNT end) as TRANSAMOUNT
Expand All @@ -19,7 +19,7 @@ from
select TOACCOUNTID, STATUS, REPEATS, NUMOCCURRENCES, NEXTOCCURRENCEDATE, TOTRANSAMOUNT
from BILLSDEPOSITS_V1
where TRANSCODE = 'Transfer') as b
inner join ACCOUNTLIST_V1 as a on b.ACCOUNTID = a.ACCOUNTID
inner join ACCOUNTLIST_V1 as a on b.ACCOUNTID = a.ACCOUNTID
inner join CURRENCYFORMATS_V1 as c on c.CURRENCYID = a.CURRENCYID
where a.ACCOUNTNAME = 'Account1'
and b.STATUS <> 'V';
where b.STATUS NOT IN ('V','D')
and a.ACCOUNTNAME = 'Account1';
63 changes: 51 additions & 12 deletions AccountForecast/template.htt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!DOCTYPE HTML>
<!-- TODO: Update account name in line 12 -->
<html lang="en-US">
<head>
<meta charset="UTF-8" />
Expand All @@ -9,51 +8,51 @@
</head>
<body>
<div class="container">
<h3>Account Forecast Report (Account1)</h3>
<p><TMPL_VAR TODAY></p>
<h3>Account Forecast Report (<TMPL_VAR ACCOUNTNAME>)</h3>
<p>Report Date: <TMPL_VAR TODAY></p>
<div class="row">
<div class="col-xs-2"></div>
<div class="col-xs-8">
<table class="table-condensed">
<tr><td class="text-center"><canvas id="reportChart" width="600" height="300"></canvas></td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td><p class="small text-muted">All figures in Account's currency: <TMPL_VAR PFX_SYMBOL><TMPL_VAR SFX_SYMBOL></p></td></tr>
<tr><td><table class="table">
<thead>
<tr>
<th>Date</th>
<th class="text-right">Value</th>
<th class="text-right">Amount (<TMPL_VAR PFX_SYMBOL><TMPL_VAR SFX_SYMBOL>)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Current</td>
<td class="text-right"><TMPL_VAR Current_Total></td>
<td class="numberf text-right"><TMPL_VAR Current_Total></td>
</tr>
</tbody>
<tfoot>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>1 month <TMPL_VAR Month1_Label></td>
<td class="text-right"><TMPL_VAR Month1_Total></td>
<td class="numberf text-right"><TMPL_VAR Month1_Total></td>
</tr>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>2 months <TMPL_VAR Month2_Label></td>
<td class="text-right"><TMPL_VAR Month2_Total></td>
<td class="numberf text-right"><TMPL_VAR Month2_Total></td>
</tr>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>3 months <TMPL_VAR Month3_Label></td>
<td class="text-right"><TMPL_VAR Month3_Total></td>
<td class="numberf text-right"><TMPL_VAR Month3_Total></td>
</tr>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>4 months <TMPL_VAR Month4_Label></td>
<td class="text-right"><TMPL_VAR Month4_Total></td>
<td class="numberf text-right"><TMPL_VAR Month4_Total></td>
</tr>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>5 months <TMPL_VAR Month5_Label></td>
<td class="text-right"><TMPL_VAR Month5_Total></td>
<td class="numberf text-right"><TMPL_VAR Month5_Total></td>
</tr>
<tr style="background-color:rgba(255,0,0,0.5)">
<td>6 months <TMPL_VAR Month6_Label></td>
<td class="text-right"><TMPL_VAR Month6_Total></td>
<td class="numberf text-right"><TMPL_VAR Month6_Total></td>
</tr>
</tfoot>
</table></td></tr></table>
Expand All @@ -69,10 +68,50 @@
</div>
</div>
<script>
<!-- Chart -->
var data = {labels : ["Current","1 month","2 months","3 months","4 months","5 months","6 months"], <TMPL_VAR "CHART_DATA">}
var opt = {bezierCurve : false}
var ctx = document.getElementById("reportChart").getContext("2d");
var reportChart = new Chart(ctx).Line(data,opt);
</script>
<script>
<!-- Format numbers -->
function formatNumberWithSeparators(sn, grpchar) {
if (grpchar != "") {
return sn.toString().replace(/\B(?=(\d{3})+(?!\d))/g, grpchar);
}
else {
return sn;
}
}

function changeDecimalPoint(sn, dpchar) {
var dppos = sn.lastIndexOf(".");
if (dpchar != "") {
return (dppos > 0 ? sn.slice(0, dppos) + dpchar + sn.substr(dppos + 1) : sn);
}
else {
return sn;
}
}

function currency(sn, grpsep, dpt) {
var fn = parseFloat(sn);
return isNaN(fn) ? sn : formatNumberWithSeparators(changeDecimalPoint(fn.toFixed(2), dpt), grpsep);
}

var NegValue = 0;
var elements = document.getElementsByClassName("numberf");
if (elements) {
for (var i = 0; i < elements.length; i++) {
NegValue = (elements[i].innerHTML.indexOf("-") > -1) ? 1 : 0;
elements[i].innerHTML = currency(elements[i].innerHTML, (elements[i].hasAttribute("data-grpsep") ? elements[i].getAttribute("data-grpsep") : "<TMPL_VAR GROUP_SEPARATOR>"), (elements[i].hasAttribute("data-decpt") ? elements[i].getAttribute("data-decpt") : "<TMPL_VAR DECIMAL_POINT>")).trim();
if (NegValue) {
elements[i].style.color = "#ff0000";
}
elements[i].style.textAlign = 'right';
}
}
</script>
</body>
</html>
5 changes: 4 additions & 1 deletion AccountSummary/description.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Checking and Term Account Summary Report
Checking and Term Account Summary Report

Setup:
1. Edit SQL line 35 for the account types required
8 changes: 3 additions & 5 deletions AccountSummary/luacontent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ local count = 0;
local colors = {"#FF6666", "#FFB266", "#FFFF66", "#B2FF66", "#66FF66", "#66FFB2", "#66FFFF", "#66B2FF", "#6666FF", "#B266FF", "#FF66FF", "#FF66B2"};

function handle_record(record)
local bal = string.format("%.2f", record:get('Balance'));
local base = bal * record:get("BASECONVRATE");
record:set("Balance", record:get('PFX_SYMBOL') .. bal .. record:get('SFX_SYMBOL'));
record:set("Base", base);
local base = record:get('BALANCE') * record:get("CURRVALUE");
record:set("BASE", base);
total = total + base;
local color = colors[1 + (count % #colors)];
data = data .. '{value:' .. string.format("%.2f", base) .. ',color:"' .. color .. '"},';
Expand All @@ -18,4 +16,4 @@ end
function complete(result)
result:set("Total", total);
result:set('CHART_DATA', string.sub(data,1,-2));
end
end
56 changes: 39 additions & 17 deletions AccountSummary/sqlcontent.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
select a.ACCOUNTNAME, c.BASECONVRATE, c.PFX_SYMBOL, c.SFX_SYMBOL,
(select a.INITIALBAL + total(t.TRANSAMOUNT)
from
(select ACCOUNTID, STATUS,
(case when TRANSCODE = 'Deposit' then TRANSAMOUNT else -TRANSAMOUNT end) as TRANSAMOUNT
from CHECKINGACCOUNT_V1
union all
select TOACCOUNTID, STATUS, TOTRANSAMOUNT
from CHECKINGACCOUNT_V1
where TRANSCODE = 'Transfer') as t
where t.ACCOUNTID = a.ACCOUNTID
and t.STATUS <> 'V') as Balance
from ACCOUNTLIST_V1 as a
inner join CURRENCYFORMATS_V1 as c on c.CURRENCYID = a.CURRENCYID
where a.ACCOUNTTYPE in ('Checking', 'Term') and a.STATUS = 'Open'
group by a.ACCOUNTNAME
order by a.ACCOUNTNAME asc;
/* Setup: edit line 35 for the account types required */
SELECT a.ACCOUNTNAME,
IFNULL(CH.CURRVALUE, c.BASECONVRATE) AS CURRVALUE,-- Only use ch.currvalue for v13 DB
c.PFX_SYMBOL,
c.SFX_SYMBOL,
c.DECIMAL_POINT,
c.GROUP_SEPARATOR,
(
SELECT a.INITIALBAL + total(t.TRANSAMOUNT)
FROM (
SELECT c1.ACCOUNTID,
(CASE WHEN c1.TRANSCODE = 'Deposit' THEN c1.TRANSAMOUNT ELSE -c1.TRANSAMOUNT END) AS TRANSAMOUNT
FROM CHECKINGACCOUNT_V1 AS c1
WHERE c1.STATUS NOT IN ('D', 'V')
UNION ALL
SELECT c2.TOACCOUNTID,
c2.TOTRANSAMOUNT
FROM CHECKINGACCOUNT_V1 AS c2
WHERE c2.TRANSCODE = 'Transfer' AND
c2.STATUS NOT IN ('D', 'V')
)
AS t
WHERE t.ACCOUNTID = a.ACCOUNTID
)
AS BALANCE
FROM ACCOUNTLIST_V1 AS a
INNER JOIN
CURRENCYFORMATS_V1 AS c ON c.CURRENCYID = a.CURRENCYID
LEFT JOIN
CURRENCYHISTORY_V1 AS CH ON CH.CURRENCYID = c.CURRENCYID AND
CH.CURRDATE = (
SELECT MAX(CRHST.CURRDATE)
FROM CURRENCYHISTORY_V1 AS CRHST
WHERE CRHST.CURRENCYID = c.CURRENCYID
)
WHERE a.ACCOUNTTYPE IN ('Checking', 'Term') AND
a.STATUS = 'Open'
GROUP BY a.ACCOUNTNAME
ORDER BY a.ACCOUNTNAME ASC;
Loading

0 comments on commit e303885

Please sign in to comment.