Simplified report code.

This commit is contained in:
James Cole
2015-05-16 13:06:38 +02:00
parent bec58a1ee6
commit bdff275672
11 changed files with 1183 additions and 723 deletions

View File

@@ -1,218 +1,241 @@
{% extends "./layout/default.twig" %}
{% block content %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date, shared) }}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, start, shared) }}
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-long-arrow-right fa-fw"></i>
Income
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-line-chart"></i>
{{ 'accountBalances'|_ }}
</div>
<div class="panel-body">
<div id="account-balances-chart"></div>
</div>
</div>
<table class="table table-bordered">
{% set sum = 0 %}
{% for entry in income %}
{% set sum = sum + entry.queryAmount %}
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-fw fa-credit-card"></i>
{{ 'accountBalances'|_ }}
</div>
<table class="table table-bordered table-striped">
<tr>
<th>{{ 'account'|_ }}</th>
<th>{{ 'balanceStartOfMonth'|_ }}</th>
<th>{{ 'balanceEndOfMonth'|_ }}</th>
<th>{{ 'difference'|_ }}</th>
</tr>
{% for account in accounts %}
<tr>
<td><a href="{{route('accounts.show',account.id)}}">{{ account.name }}</a></td>
<td>{{ account.startBalance|formatAmount }}</td>
<td>{{ account.endBalance|formatAmount }}</td>
<td>
<a href="{{ route('transactions.show',entry.id) }}" title="{{ entry.description }}">{{ entry.description }}</a>
</td>
<td>
{% if entry.type == 'Withdrawal' %}
<span class="text-danger">{{entry.queryAmount|formatAmountPlain}}</span>
{% endif %}
{% if entry.type == 'Deposit' %}
<span class="text-success">{{entry.queryAmount|formatAmountPlain}}</span>
{% endif %}
{% if entry.type == 'Transfer' %}
<span class="text-info">{{entry.queryAmount|formatAmountPlain}}</span>
{% endif %}
</td>
<td>
{{entry.date.format('j F Y')}}
</td>
<td>
<a href="{{route('accounts.show',entry.account_id)}}">{{ entry.name }}</a>
{{ (account.startBalance - account.endBalance)|formatAmount }}
</td>
</tr>
{% endfor %}
{% if displaySum %}
</table>
</div>
<!-- income vs expenses -->
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-fw fa-exchange"></i>
{{ 'incomeVsExpenses'|_ }}
</div>
<table class="table table-bordered table-striped">
<tr>
<td>{{ 'in'|_ }}</td>
<td>{{ totalIncome|formatAmount }}</td>
</tr>
<tr>
<td>{{ 'out'|_ }}</td>
<td><span class="text-danger">{{ (totalExpense * -1)|formatAmountPlain }}</span></td>
</tr>
<tr>
<td>{{ 'difference'|_ }}</td>
<td>{{ (totalIncome + totalExpense)|formatAmount }}</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- income -->
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-long-arrow-right fa-fw"></i>
{{ 'income'|_ }} ({{ trans('firefly.topX',{number: incomeTopLength}) }})
</div>
<table class="table">
{% for id,row in incomes %}
{% if loop.index > incomeTopLength %}
<tr class="collapse out incomesCollapsed">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',id) }}" title="{{ row.name }}">{{ row.name }}</a>
{% if row.count > 1 %}
<br /><small>{{ row.count }} {{ 'transactions'|_|lower }}</small>
{% endif %}
</td>
<td>{{ row.amount|formatAmount }}</td>
</tr>
{% endfor %}
{% if incomes|length > incomeTopLength %}
<tr>
<td><em>Sum</em></td>
<td colspan="3">{{ sum|formatAmount }}</td>
<td colspan="2" class="active">
<a href="#" id="showIncomes">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td>{{ totalIncome|formatAmount }}</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- expenses -->
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-long-arrow-left fa-fw"></i>
{{ 'expenses'|_ }} ({{ trans('firefly.topX',{number: expenseTopLength}) }})
</div>
<table class="table">
{% set sum =0 %}
{% for row in expenses %}
{% if loop.index > expenseTopLength %}
<tr class="collapse out expenseCollapsed">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',row.id) }}">{{ row.name }}</a>
{% if row.count > 1 %}
<br /><small>{{ row.count }} {{ 'transactions'|_|lower }}</small>
{% endif %}
</td>
<td><span class="text-danger">{{ (row.amount*-1)|formatAmountPlain }}</span></td>
</tr>
{% set sum = sum + row.amount %}
{% endfor %}
{% if expenses|length > expenseTopLength %}
<tr>
<td colspan="2" class="active">
<a href="#" id="showExpenses">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td><span class="text-danger">{{ (sum * -1)|formatAmountPlain }}</span></td>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-tasks fa-fw"></i>
{{ 'budgets'|_ }}
</div>
<table class="table table-bordered">
<tr>
<th>{{ 'budget'|_ }}</th>
<th>{{ 'date'|_ }}</th>
<th>{{ 'budgeted'|_ }}</th>
<th>{{ 'spent'|_ }}</th>
<th>{{ 'left'|_ }}</th>
<th>{{ 'overspent'|_ }}</th>
</tr>
{% for data in budgets %}
<tr>
<td>
{% if data[0] %}
<a href="{{route('budgets.show',data[0].id)}}">{{ data[0].name }}</a>
{% else %}
<em>{{ 'noBudget'|_ }}</em>
{% endif %}
</td>
<td>
{% if data[1] %}
{{ data[1].startdate.formatLocalized(monthAndDayFormat) }}
{% endif %}
</td>
<td>
{% if data[1] %}
{{ data[1].amount|formatAmount }}
{% else %}
{{ 0|formatAmount }}
{% endif %}
</td>
<td>
{% if data[3] != 0 %}
{{ data[3]|formatAmount }}
{% endif %}
</td>
<td>
{% if data[2] != 0 %}
{{ data[2]|formatAmount }}
{% endif %}
</td>
<td>
{% if data[4] != 0 %}
<span class="text-danger">{{ data[4]|formatAmountPlain }}</span>
{% endif %}
</td>
</tr>
{% endfor %}
<tr>
<td colspan="2"><em>{{ 'sum'|_ }}</em></td>
<td>{{ budgetSums.budgeted|formatAmount }}</td>
<td>{{ budgetSums.spent|formatAmount }}</td>
<td>{{ budgetSums.left|formatAmount }}</td>
<td><span class="text-danger">{{ budgetSums.overspent|formatAmountPlain }}</span></td>
</tr>
</table>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-long-arrow-left fa-fw"></i>
Expenses (top 10)
</div>
<table class="table table-bordered">
{% set sum = 0 %}
{% for id,expense in expenses %}
{% set sum = sum + expense.queryAmount %}
<tr>
{% if id > 0 %}
<td><a href="{{route('accounts.show',id)}}">{{ expense.name }}</a></td>
{% else %}
<td><em>{{ expense.name }}</em></td>
{% endif %}
<td><span class="text-danger">{{ expense.queryAmount|formatAmountPlain }}</span></td>
</tr>
{% endfor %}
<tr>
<td><em>Sum</em></td>
<td><span class="text-danger">{{ sum|formatAmountPlain }}</span></td>
</tr>
</table>
</div>
</div>
<div class="col-lg-3 col-md-4 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-exchange fa-fw"></i>
Sums
</div>
{% set totalIn = 0 %}
{% for entry in income %}
{% set totalIn = totalIn + entry.queryAmount %}
{% endfor %}
<table class="table table-bordered">
<tr>
<td>In</td>
<td>{{ totalIn|formatAmount }}</td>
</tr>
<tr>
<td>Out</td>
<td><span class="text-danger">{{ sum|formatAmountPlain }}</span></td>
</tr>
<tr>
<td>Difference</td>
<td>{{ (totalIn - sum)|formatAmount }}</td>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-tasks fa-fw"></i>
Budgets
</div>
<table class="table table-bordered">
<tr>
<th>Budget</th>
<th>Envelope</th>
<th>Spent</th>
<th>Left</th>
</tr>
{% set sumSpent = 0 %}
{% set sumEnvelope = 0 %}
{% set sumLeft = 0 %}
{% for id,budget in budgets %}
{% set sumSpent = sumSpent + budget.spent %}
{% set sumEnvelope = sumEnvelope + budget.queryAmount %}
{% set sumLeft = sumLeft + budget.queryAmount + budget.spent %}
<!-- only display when relevant: -->
{% if budget.queryAmount != 0 or budget.spent != 0 %}
<tr>
<td>
{% if id > 0 %}
<a href="{{route('budgets.show',id)}}">{{ budget.name }}</a>
{% else %}
<em>{{ budget.name }}</em>
{% endif %}
</td>
<td>{{ budget.queryAmount|formatAmount }}</td>
<td><span class="text-danger">{{ (budget.spent*-1)|formatAmountPlain }}</span></td>
<td>{{ (budget.queryAmount + budget.spent)|formatAmount }}</td>
</tr>
{% endif %}
{% endfor %}
<tr>
<td><em>Sum</em></td>
<td>{{ sumEnvelope|formatAmount }}</td>
<td>{{ sumSpent|formatAmount }}</td>
<td>{{ sumLeft|formatAmount }}</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-bar-chart fa-fw"></i>
Categories
{{ 'categories'|_ }}
</div>
<table class="table table-bordered">
<tr>
<th>Category</th>
<th>Spent</th>
<th>{{ 'categories'|_ }}</th>
<th>{{ 'spent'|_ }}</th>
</tr>
{% set sum = 0 %}
{% for id,category in categories %}
{% set sum = sum + category.queryAmount %}
<tr>
<td>
{% if id > 0 %}
<a href="{{route('categories.show',id)}}">{{ category.name }}</a>
{% else %}
<em>{{ category.name }}</em>
{% endif %}
</td>
<td><span class="text-danger">{{ (category.queryAmount * -1)|formatAmountPlain }}</span></td>
</tr>
{% for data in categories %}
{% if data[1] > 0 %}
<tr>
<td>
<a href="{{route('categories.show',data[0].id)}}">{{ data[0].name }}</a>
</td>
<td><span class="text-danger">{{ (data[1])|formatAmountPlain }}</span></td>
</tr>
{% endif %}
{% endfor %}
<tr>
<td><em>Sum</em></td>
<td><span class="text-danger">{{ (sum * -1)|formatAmountPlain }}</span></td>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-fw fa-credit-card"></i>
Accounts
</div>
<table class="table table-bordered table-striped">
<tr>
<th>Account</th>
<th>Start of month</th>
<th>Current balance</th>
<th>Spent</th>
<th>Earned</th>
</tr>
{% for account in accounts %}
<tr>
<td><a href="{{route('accounts.show',account.id)}}">{{ account.name }}</a></td>
<td>{{ account.startBalance|formatAmount }}</td>
<td>{{ account.endBalance|formatAmount }}</td>
<td>
{% if account.startBalance - account.endBalance > 0 %}
<span class="text-danger">{{ (account.startBalance - account.endBalance)|formatAmountPlain }}</span>
{% endif %}
</td>
<td>
{% if account.startBalance - account.endBalance < 0 %}
<span class="text-success">{{ ((account.startBalance - account.endBalance)*-1)|formatAmountPlain }}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
<div class="row">
@@ -220,27 +243,31 @@
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-sort-amount-asc fa-fw"></i>
Budgets
{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})
</div>
<table class="table table-bordered table-striped">
<tr>
<th colspan="2">Budgets</th>
<th colspan="2">{{ 'budgets'|_ }}</th>
{% for account in accounts %}
{% if not account.hide %}
<th><a href="{{route('accounts.show',account.id)}}">{{ account.name }}</a></th>
{% endif %}
<th><a href="{{route('accounts.show',account.id)}}">{{ account.name }}</a></th>
{% endfor %}
<th colspan="2">
Left in budget
{{ 'leftInBudget'|_ }}
</th>
</tr>
{% for id,budget in budgets %}
<tr>
<td>{{ budget.name }}</td>
<td>{{ budget.queryAmount|formatAmount }}</td>
{% set spent = 0 %}
{% for account in accounts %}
{% if not account.hide %}
{% for data in budgets %}
{% if data[0] %}
<tr>
<td>{{ data[0].name }}</td>
<td>
{% if data[1] %}
{{ data[1].amount|formatAmount }}
{% else %}
{{ 0|formatAmount }}
{% endif %}
</td>
{% set spent = 0 %}
{% for account in accounts %}
{% if account.budgetInformation[id] %}
<td>
{% if id == 0 %}
@@ -255,14 +282,20 @@
{% else %}
<td>{{ 0|formatAmount }}</td>
{% endif %}
{% endif %}
{% endfor %}
<td>{{ (budget.queryAmount + budget.spent)|formatAmount }}</td>
<td>{{ (budget.queryAmount + spent)|formatAmount }}</td>
</tr>
{% endfor %}
<td>
{% if data[1] %}
{{ (data[1].amount - data[3])|formatAmount }}
{% else %}
{{ (0 - data[3])|formatAmount }}
{% endif %}
</td>
<td>{{ data[2]|formatAmount }}</td>
</tr>
{% endif %}
{% endfor %}
<tr>
<td colspan="2">Balanced by transfers</td>
<td colspan="2">{{ 'balancedByTransfersAndTags'|_ }}</td>
{% for account in accounts %}
{% if not account.hide %}
<td>
@@ -273,7 +306,7 @@
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Left unbalanced</td>
<td colspan="2">{{ 'leftUnbalanced'|_ }}</td>
{% for account in accounts %}
{% if not account.hide %}
@@ -293,7 +326,7 @@
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2"><em>Sum</em></td>
<td colspan="2"><em>{{ 'sum'|_ }}</em></td>
{% for account in accounts %}
{% if not account.hide %}
<td>{{ accountAmounts[account.id]|formatAmount }}</td>
@@ -302,7 +335,7 @@
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Expected balance</td>
<td colspan="2">{{ 'expectedBalance'|_ }}</td>
{% for account in accounts %}
{% if not account.hide %}
<td>{{ (account.startBalance + accountAmounts[account.id])|formatAmount }}</td>
@@ -320,7 +353,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-calendar-o fa-fw"></i>
Bills
{{ 'bills'|_ }}
</div>
<div class="panel-body">Body</div>
</div>
@@ -331,7 +364,7 @@
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-fw fa-folder-o"></i>
Outside of budgets
{{ 'outsideOfBudgets'|_ }}
</div>
<div class="panel-body">Body</div>
</div>
@@ -339,5 +372,16 @@
</div>
{% endblock %}
{% block scripts %}
<script type="text/javascript">
var shared = {% if shared %}'/shared'{% else %}''{% endif %};
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.
var expenseRestShow = false; // starts hidden.
var showTheRest = '{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}';
var hideTheRest = '{{ trans('firefly.hideTheRest',{number:incomeTopLength}) }}';
var showTheRestExpense = '{{ trans('firefly.showTheRest',{number:expenseTopLength}) }}';
var hideTheRestExpense = '{{ trans('firefly.hideTheRest',{number:expenseTopLength}) }}';
</script>
<script type="text/javascript" src="js/reports.js"></script>
{% endblock %}

View File

@@ -1,6 +1,6 @@
{% extends "./layout/default.twig" %}
{% block content %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date, shared) }}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, start, shared) }}
<div class="row">
<div class="col-lg-10 col-md-8 col-sm-12">
@@ -41,7 +41,7 @@
<th>{{ 'balanceStartOfYear'|_ }}</th>
<th>{{ 'difference'|_ }}</th>
</tr>
{% for account in accounts %}
{% for account in accounts.getAccounts %}
<tr>
<td>
<a href="{{ route('accounts.show',account.id) }}" title="{{ account.name }}">{{ account.name }}</a>
@@ -53,9 +53,9 @@
{% endfor %}
<tr>
<td><em>Sum of sums</em></td>
<td>{{ accountsSums.start|formatAmount }}</td>
<td>{{ accountsSums.end|formatAmount }}</td>
<td>{{ accountsSums.diff|formatAmount }}</td>
<td>{{ accounts.getStart|formatAmount }}</td>
<td>{{ accounts.getEnd|formatAmount }}</td>
<td>{{ accounts.getDifference|formatAmount }}</td>
</tr>
</table>
</div>
@@ -88,22 +88,22 @@
{{ 'income'|_ }} ({{ trans('firefly.topX',{number: incomeTopLength}) }})
</div>
<table class="table">
{% for id,row in incomes %}
{% for income in incomes.getIncomes %}
{% if loop.index > incomeTopLength %}
<tr class="collapse out incomesCollapsed">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',id) }}" title="{{ row.name }}">{{ row.name }}</a>
{% if row.count > 1 %}
<br /><small>{{ row.count }} {{ 'transactions'|_|lower }}</small>
<a href="{{ route('accounts.show',income.id) }}" title="{{ income.name }}">{{ income.name }}</a>
{% if income.count > 1 %}
<br /><small>{{ income.count }} {{ 'transactions'|_|lower }}</small>
{% endif %}
</td>
<td>{{ row.amount|formatAmount }}</td>
<td>{{ income.amount|formatAmount }}</td>
</tr>
{% endfor %}
{% if incomes|length > incomeTopLength %}
{% if incomes.getIncomes|length > incomeTopLength %}
<tr>
<td colspan="2" class="active">
<a href="#" id="showIncomes">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
@@ -112,7 +112,7 @@
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td>{{ totalIncome|formatAmount }}</td>
<td>{{ incomes.getTotal|formatAmount }}</td>
</tr>
</table>
</div>
@@ -124,24 +124,22 @@
{{ 'expenses'|_ }} ({{ trans('firefly.topX',{number: expenseTopLength}) }})
</div>
<table class="table">
{% set sum =0 %}
{% for row in expenses %}
{% for expense in expenses.getExpenses %}
{% if loop.index > expenseTopLength %}
<tr class="collapse out expenseCollapsed">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',row.id) }}">{{ row.name }}</a>
{% if row.count > 1 %}
<br /><small>{{ row.count }} {{ 'transactions'|_|lower }}</small>
<a href="{{ route('accounts.show',expense.id) }}">{{ expense.name }}</a>
{% if expense.count > 1 %}
<br /><small>{{ expense.count }} {{ 'transactions'|_|lower }}</small>
{% endif %}
</td>
<td><span class="text-danger">{{ (row.amount*-1)|formatAmountPlain }}</span></td>
<td><span class="text-danger">{{ (expense.amount*-1)|formatAmountPlain }}</span></td>
</tr>
{% set sum = sum + row.amount %}
{% endfor %}
{% if expenses|length > expenseTopLength %}
{% if expenses.getExpenses|length > expenseTopLength %}
<tr>
<td colspan="2" class="active">
<a href="#" id="showExpenses">{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}</a>
@@ -150,7 +148,7 @@
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td><span class="text-danger">{{ (sum * -1)|formatAmountPlain }}</span></td>
<td><span class="text-danger">{{ (expenses.getTotal * -1)|formatAmountPlain }}</span></td>
</tr>
</table>
</div>
@@ -191,7 +189,7 @@
<script type="text/javascript" src="js/gcharts.js"></script>
<script type="text/javascript">
var year = '{{date.year}}';
var year = '{{start.year}}';
var shared = {% if shared %}'/shared'{% else %}''{% endif %};
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};