Clean up report code.

This commit is contained in:
James Cole 2016-12-27 15:31:17 +01:00
parent d520849ce1
commit be201e811d
4 changed files with 72 additions and 90 deletions

View File

@ -48,8 +48,9 @@ class OperationsController extends Controller
if ($cache->has()) {
return $cache->get();
}
$expenses = $this->getExpenseReport($start, $end, $accounts);
$result = view('reports.partials.expenses', compact('expenses'))->render();
$entries = $this->getExpenseReport($start, $end, $accounts);
$type = 'expense-entry';
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
$cache->store($result);
return $result;
@ -74,9 +75,10 @@ class OperationsController extends Controller
if ($cache->has()) {
return $cache->get();
}
$income = $this->getIncomeReport($start, $end, $accounts);
$entries = $this->getIncomeReport($start, $end, $accounts);
$type = 'income-entry';
$result = view('reports.partials.income-expenses', compact('entries', 'type'))->render();
$result = view('reports.partials.income', compact('income'))->render();
$cache->store($result);
return $result;
@ -230,12 +232,19 @@ class OperationsController extends Controller
'id' => $opposingId,
'name' => $name,
'sum' => '0',
'average' => '0',
'count' => 0,
];
}
$expenses[$opposingId]['sum'] = bcadd($expenses[$opposingId]['sum'], $transaction->transaction_amount);
$expenses[$opposingId]['count']++;
}
// do averages:
foreach ($expenses as $key => $entry) {
if ($expenses[$key]['count'] > 1) {
$expenses[$key]['average'] = bcdiv($expenses[$key]['sum'], strval($expenses[$key]['count']));
}
}
return $expenses;

View File

@ -1,41 +0,0 @@
<table class="table table-hover">
<tbody>
{% set sum = 0 %}
{% for expense in expenses %}
{% set sum = sum + expense.sum %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',expense.id) }}">{{ expense.name }}</a>
{% if expense.count > 1 %}
<br/>
<small>
{{ expense.count }} {{ 'transactions'|_|lower }}
<i class="fa fa-fw text-muted fa-info-circle firefly-info-button" data-location="expense-entry"
data-account-id="{{ expense.id }}"></i>
</small>
{% endif %}
</td>
<td>
{{ (expense.sum)|formatAmount }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if expenses|length > listLength %}
<tr>
<td colspan="2" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td>{{ (sum)|formatAmount }}</td>
</tr>
</tfoot>
</table>

View File

@ -0,0 +1,55 @@
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ 'name'|_ }}</th>
<th data-defaultsign="_19">{{ 'total'|_ }}</th>
<th data-defaultsign="_19" class="hidden-xs">{{ 'average'|_ }}</th>
</tr>
</thead>
<tbody>
{% set sum = 0 %}
{% for entry in entries %}
{% set sum = sum + entry.sum %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-value="{{ entry.name }}">
<a href="{{ route('accounts.show',entry.id) }}">{{ entry.name }}</a>
{% if entry.count > 1 %}
<br/>
<small>
{{ entry.count }} {{ 'transactions'|_|lower }}
<i class="fa fa-fw text-muted fa-info-circle firefly-info-button" data-location="{{ type }}"
data-account-id="{{ entry.id }}"></i>
</small>
{% endif %}
</td>
<td data-value="{{ entry.sum }}">
{{ (entry.sum)|formatAmount }}
</td>
<td class="hidden-xs" data-value="{{ entry.average }}">
{% if entry.count > 1 %}
{{ entry.average|formatAmount }}
{% else %}
&mdash;
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if entries|length > listLength %}
<tr>
<td colspan="3" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td>{{ (sum)|formatAmount }}</td>
</tr>
</tfoot>
</table>

View File

@ -1,41 +0,0 @@
<table class="table table-hover">
<tbody>
{% set sum = 0 %}
{% for row in income %}
{% set sum = sum + row.sum %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('accounts.show',row.id) }}" title="{{ row.name }}">{{ row.name }}</a>
{% if row.count > 1 %}
<br/>
<small>
{{ row.count }} {{ 'transactions'|_|lower }}
<i class="fa fa-fw text-muted fa-info-circle firefly-info-button" data-location="income-entry"
data-account-id="{{ row.id }}"></i>
</small>
{% endif %}
</td>
<td>{{ row.sum|formatAmount }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if income|length > listLength %}
<tr>
<td colspan="2" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{ number:listLength } ) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td><em>{{ 'sum'|_ }}</em></td>
<td>{{ sum|formatAmount }}</td>
</tr>
</tfoot>
</table>