diff options
author | Nicolas Vigier <boklm@mageia.org> | 2013-05-20 16:42:49 +0000 |
---|---|---|
committer | Nicolas Vigier <boklm@mageia.org> | 2013-05-20 16:42:49 +0000 |
commit | a07404806a3dad6ca2758229b3c4e79978e2f660 (patch) | |
tree | c0d720b649f920f06c7b4115cbdd917c93763da3 | |
parent | e724d2cd95c6a305ec60193d3ce28cb1d7a17c17 (diff) | |
download | mgatres-a07404806a3dad6ca2758229b3c4e79978e2f660.tar mgatres-a07404806a3dad6ca2758229b3c4e79978e2f660.tar.gz mgatres-a07404806a3dad6ca2758229b3c4e79978e2f660.tar.bz2 mgatres-a07404806a3dad6ca2758229b3c4e79978e2f660.tar.xz mgatres-a07404806a3dad6ca2758229b3c4e79978e2f660.zip |
Add categories graphs
git-svn-id: svn+ssh://svn.mageia.org/svn/soft/mga-treasurer/trunk@8342 5b7c3c08-40e5-403b-9995-ace06908e4af
-rw-r--r-- | NEWS | 1 | ||||
-rwxr-xr-x | mktreasurer | 5 | ||||
-rw-r--r-- | tmpl/index.html | 80 | ||||
-rw-r--r-- | tmpl/transactions_by_year.html | 80 |
4 files changed, 162 insertions, 4 deletions
@@ -1,6 +1,7 @@ - add donations graphs - add accounts history graphs +- add categories graphs Version 0.3 diff --git a/mktreasurer b/mktreasurer index 1f1614b..f13b531 100755 --- a/mktreasurer +++ b/mktreasurer @@ -162,6 +162,11 @@ sub transactions_infos { foreach my $tra (@{$y->{transactions}}) { next unless $tra->{ca}; $y->{ca_balance}->{$tra->{ca}} += $tra->{amount}; + if ($tra->{amount} > 0) { + $y->{ca_revenues}->{$tra->{ca}} += $tra->{amount}; + } else { + $y->{ca_expenses}->{$tra->{ca}} -= $tra->{amount}; + } } $y->{start_balance} = $start_balance ? $start_balance : new Math::BigFloat 0; $y->{end_balance} = $y->{balance} + new Math::BigFloat $y->{start_balance}; diff --git a/tmpl/index.html b/tmpl/index.html index d6862bc..f04135a 100644 --- a/tmpl/index.html +++ b/tmpl/index.html @@ -38,9 +38,85 @@ <h2>Expenses and revenues by category</h2> + [%- + SET ca_expenses = []; + SET ca_expenses_names = []; + SET ca_revenues = []; + SET ca_revenues_names = []; + + FOREACH ca IN transactions.by_ca.keys.sort; + IF transactions.by_ca.$ca.expenses != 0; + ca_expenses.push(ca); + ca_expenses_names.push(transactions.by_ca.$ca.c_name); + END; + IF transactions.by_ca.$ca.revenues != 0; + ca_revenues.push(ca); + ca_revenues_names.push(transactions.by_ca.$ca.c_name); + END; + END; + -%] + + <h3>Expenses</h3> + [% IF ca_expenses.size > 1 %] + <canvas id="expenses_ca_bar_chart" height="300" width="[% 80 + ca_expenses.size * 65 %]"></canvas> + + <script> + + var barChartDataExpenses = { + labels : ["[% ca_expenses_names.join('","') %]"], + datasets : [ + { + fillColor : "#e51b1b", + strokeColor : "#f11111", + data: [ + [%- FOR ca IN ca_expenses -%] + [%- transactions.by_ca.$ca.expenses -%] + [%- IF ! loop.last() -%],[%- END -%] + [%- END %]] + } + ] + + } + + var myLine = new Chart(document.getElementById("expenses_ca_bar_chart").getContext("2d")).Bar(barChartDataExpenses); + + </script> + [% END %] + <ul> + [%- FOR ca IN ca_expenses %] + <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_ca.$ca.expenses %] Euros</li> + [%- END -%] + </ul> + + <h3>Revenues</h3> + [% IF ca_revenues.size > 1 %] + <canvas id="revenues_ca_bar_chart" height="300" width="[% 80 + ca_revenues.size * 65 %]"></canvas> + + <script> + + var barChartDataRevenues = { + labels : ["[% ca_revenues_names.join('","') %]"], + datasets : [ + { + fillColor : "#151f79", + strokeColor : "#101333", + data: [ + [%- FOR ca IN ca_revenues -%] + [%- transactions.by_ca.$ca.revenues -%] + [%- IF ! loop.last() -%],[%- END -%] + [%- END %]] + } + ] + + } + + var myLine = new Chart(document.getElementById("revenues_ca_bar_chart").getContext("2d")).Bar(barChartDataRevenues); + + </script> + [% END %] <ul> - [%- FOR ca IN transactions.by_ca.keys.sort %] - <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_ca.$ca.balance %] Euros</li> + [%- FOR ca IN ca_revenues %] + <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_ca.$ca.revenues %] Euros</li> [%- END -%] </ul> diff --git a/tmpl/transactions_by_year.html b/tmpl/transactions_by_year.html index 08e9c60..b363c72 100644 --- a/tmpl/transactions_by_year.html +++ b/tmpl/transactions_by_year.html @@ -22,11 +22,87 @@ </li> </ul> <h2>By category</h2> + + [%- + SET ca_expenses = []; + SET ca_expenses_names = []; + SET ca_revenues = []; + SET ca_revenues_names = []; + + IF transactions.by_year.$year.ca_revenues; + FOREACH ca IN transactions.by_year.$year.ca_revenues.keys; + ca_revenues.push(ca); + ca_revenues_names.push(transactions.by_ca.$ca.c_name); + END; + END; + IF transactions.by_year.$year.ca_expenses; + FOREACH ca IN transactions.by_year.$year.ca_expenses.keys; + ca_expenses.push(ca); + ca_expenses_names.push(transactions.by_ca.$ca.c_name); + END; + END; + -%] + <h3>Expenses</h3> + [% IF ca_expenses.size > 1 %] + <canvas id="expenses_ca_bar_chart" height="300" width="[% 80 + ca_expenses.size * 65 %]"></canvas> + + <script> + + var barChartDataExpenses = { + labels : ["[% ca_expenses_names.join('","') %]"], + datasets : [ + { + fillColor : "#e51b1b", + strokeColor : "#f11111", + data: [ + [%- FOR ca IN ca_expenses -%] + [%- transactions.by_year.$year.ca_expenses.$ca -%] + [%- IF ! loop.last() -%],[%- END -%] + [%- END %]] + } + ] + } + + var myLine = new Chart(document.getElementById("expenses_ca_bar_chart").getContext("2d")).Bar(barChartDataExpenses); + + </script> + [% END %] + <ul> + [%- FOR ca IN ca_expenses %] + <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_year.$year.ca_expenses.$ca %] Euros</li> + [%- END -%] + </ul> + + <h3>Revenues</h3> + [% IF ca_revenues.size > 1 %] + <canvas id="revenues_ca_bar_chart" height="300" width="[% 80 + ca_revenues.size * 65 %]"></canvas> + + <script> + var barChartDataRevenues = { + labels : ["[% ca_revenues_names.join('","') %]"], + datasets : [ + { + fillColor : "#151f79", + strokeColor : "#101333", + data: [ + [%- FOR ca IN ca_revenues -%] + [%- transactions.by_year.$year.ca_revenues.$ca -%] + [%- IF ! loop.last() -%],[%- END -%] + [%- END %]] + } + ] + } + + var myLine = new Chart(document.getElementById("revenues_ca_bar_chart").getContext("2d")).Bar(barChartDataRevenues); + + </script> + [% END %] <ul> - [% FOR ca IN transactions.by_year.$year.ca_balance.keys %] - <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_year.$year.ca_balance.$ca %] Euros</b></li> + [%- FOR ca IN ca_revenues %] + <li><b><a href="c_[% ca %].html">[% transactions.by_ca.$ca.c_name %]</a></b>: [% transactions.by_year.$year.ca_revenues.$ca %] Euros</li> [%- END -%] </ul> + <h2>Monthly reports</h2> <canvas id="accounts_history_bar_chart" height="250" width="[% 80 + transactions.by_year.$year.months.size * 65 %]"></canvas> |