Skip to content

Firefly III: a personal finances manager

Clean up report code.

James Colebe201e811dbf
diff --git a/app/Http/Controllers/Report/OperationsController.php b/app/Http/Controllers/Report/OperationsController.php
index a30954ec7b..f1abe0b96e 100644
--- a/app/Http/Controllers/Report/OperationsController.php
+++ b/app/Http/Controllers/Report/OperationsController.php
@@ -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;
@@ -227,15 +229,22 @@ class OperationsController extends Controller
$name = $transaction->opposing_account_name;
if (!isset($expenses[$opposingId])) {
$expenses[$opposingId] = [
- 'id' => $opposingId,
- 'name' => $name,
- 'sum' => '0',
- 'count' => 0,
+ '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;
diff --git a/resources/views/reports/partials/expenses.twig b/resources/views/reports/partials/expenses.twig
deleted file mode 100644
index e1d7956087..0000000000
--- a/resources/views/reports/partials/expenses.twig
+++ /dev/null
@@ -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>
diff --git a/resources/views/reports/partials/income-expenses.twig b/resources/views/reports/partials/income-expenses.twig
new file mode 100644
index 0000000000..de978da6fc
--- /dev/null
+++ b/resources/views/reports/partials/income-expenses.twig
@@ -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>
diff --git a/resources/views/reports/partials/income.twig b/resources/views/reports/partials/income.twig
deleted file mode 100644
index be2e37dcd0..0000000000
--- a/resources/views/reports/partials/income.twig
+++ /dev/null
@@ -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>