New stuff for report.

This commit is contained in:
James Cole 2017-12-10 08:56:20 +01:00
parent 089214709f
commit 2a87add745
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
8 changed files with 127 additions and 319 deletions

View File

@ -47,13 +47,14 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/ */
public function generate(): string public function generate(): string
{ {
$accountIds = join(',', $this->accounts->pluck('id')->toArray()); $accountIds = join(',', $this->accounts->pluck('id')->toArray());
$expenseIds = join(',', $this->expense->pluck('id')->toArray()); $expenseIds = join(',', $this->expense->pluck('id')->toArray());
$reportType = 'account'; $reportType = 'account';
$preferredPeriod = $this->preferredPeriod();
return view( return view(
'reports.account.report', 'reports.account.report',
compact('accountIds', 'reportType','expenseIds') compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod')
)->with('start', $this->start)->with('end', $this->end)->render(); )->with('start', $this->start)->with('end', $this->end)->render();
} }
@ -134,4 +135,12 @@ class MonthReportGenerator implements ReportGeneratorInterface
{ {
return $this; return $this;
} }
/**
* @return string
*/
protected function preferredPeriod(): string
{
return 'day';
}
} }

View File

@ -28,4 +28,11 @@ namespace FireflyIII\Generator\Report\Account;
class MultiYearReportGenerator extends MonthReportGenerator class MultiYearReportGenerator extends MonthReportGenerator
{ {
// Doesn't do anything different. // Doesn't do anything different.
/**
* @return string
*/
protected function preferredPeriod(): string {
return 'year';
}
} }

View File

@ -28,4 +28,11 @@ namespace FireflyIII\Generator\Report\Account;
class YearReportGenerator extends MonthReportGenerator class YearReportGenerator extends MonthReportGenerator
{ {
// Doesn't do anything different. // Doesn't do anything different.
/**
* @return string
*/
protected function preferredPeriod(): string {
return 'month';
}
} }

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Report;
use FireflyIII\Http\Controllers\Controller;
/**
* Class ExpenseController
*/
class ExpenseController extends Controller
{
}

8
public/js/ff/reports/account/all.js vendored Normal file
View File

@ -0,0 +1,8 @@
function loadAjaxPartial(holder, uri) {
"use strict";
$.get(uri).done(function (data) {
displayAjaxPartial(data, holder);
}).fail(function () {
failAjaxPartial(uri, holder);
});
}

21
public/js/ff/reports/account/month.js vendored Normal file
View File

@ -0,0 +1,21 @@
$(function () {
"use strict";
drawChart();
loadAjaxPartial('inOutAccounts', spentUri);
loadAjaxPartial('inOutPeriod', groupedUri);
loadAjaxPartial('inOutCategory', categoryUri);
loadAjaxPartial('inOutBudget', budgetUri);
loadAjaxPartial('topXexpense', expenseUri);
loadAjaxPartial('topXincome', incomeUri);
});
function drawChart() {
"use strict";
// month view:
// draw account chart
lineChart(mainUri, 'in-out-chart');
}

View File

@ -22,12 +22,12 @@
</div> </div>
</div> </div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12" id="inOutPeriod"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'in_out_accounts_period'|_ }}</h3> <h3 class="box-title">{{ ('in_out_accounts_period_'~preferredPeriod)|_ }}</h3>
</div> </div>
<div class="box-body table-responsive no-padding"> <div class="box-body table-responsive no-padding" id="inOutPeriod">
{# loading indicator #} {# loading indicator #}
<div class="overlay"> <div class="overlay">
<i class="fa fa-refresh fa-spin"></i> <i class="fa fa-refresh fa-spin"></i>
@ -89,7 +89,7 @@
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3> <h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
</div> </div>
<div class="box-body table-responsive no-padding" id="topXExpense"> <div class="box-body table-responsive no-padding" id="topXexpense">
{# loading indicator #} {# loading indicator #}
<div class="overlay"> <div class="overlay">
<i class="fa fa-refresh fa-spin"></i> <i class="fa fa-refresh fa-spin"></i>
@ -112,297 +112,6 @@
</div> </div>
</div> </div>
</div> </div>
{#
<div class="row">
{% if categories.count > 1 %}
<div class="col-lg-2 col-md-3">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'income_per_category'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="categories-in-pie-chart" style="margin:0 auto;" height="150" width="150"></canvas>
<label style="font-weight:normal;">
<input type="checkbox" id="categories-in-pie-chart-checked">
<small>{{ 'include_income_not_in_category'|_ }}</small>
</label>
</div>
</div>
</div>
<div class="col-lg-2 col-md-3">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expense_per_category'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="categories-out-pie-chart" style="margin:0 auto;" height="150" width="150"></canvas>
<label style="font-weight:normal;">
<input type="checkbox" id="categories-out-pie-chart-checked">
<small>{{ 'include_expense_not_in_category'|_ }}</small>
</label>
</div>
</div>
</div>
{% endif %}
<div class="col-lg-2 col-md-3" id="pieCharts">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'income_per_account'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="accounts-in-pie-chart" style="margin:0 auto;" height="150" width="150"></canvas>
<label style="font-weight:normal;">
<input type="checkbox" id="accounts-in-pie-chart-checked">
<small>{{ 'include_income_not_in_account'|_ }}</small>
</label>
</div>
</div>
</div>
<div class="col-lg-2 col-md-3">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expense_per_account'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="accounts-out-pie-chart" style="margin:0 auto;" height="150" width="150"></canvas>
<label style="font-weight:normal;">
<input type="checkbox" id="accounts-out-pie-chart-checked">
<small>{{ 'include_expense_not_in_account'|_ }}</small>
</label>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="box" id="incomeAndExpensesChart">
<div class="box-header with-border">
<h3 class="box-title">{{ 'income_and_expenses'|_ }}</h3>
</div>
<div class="box-body">
<canvas id="in-out-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
</div>
</div>
</div>
</div>
<div class="row">
{% if averageExpenses|length > 0 %}
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'average_spending_per_account'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'spent_average'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'total'|_ }}</th>
<th data-defaultsign="_19">{{ 'transaction_count'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in averageExpenses %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-value="{{ row.name }}">
<a href="{{ route('accounts.show', row.id) }}">{{ row.name }}</a>
</td>
<td data-value="{{ row.average }}" style="text-align: right;">
{{ row.average|formatAmount }}
</td>
<td data-value="{{ row.sum }}" style="text-align: right;">
{{ row.sum|formatAmount }}
</td>
<td data-value="{{ row.count }}">
{{ row.count }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if averageExpenses|length > listLength %}
<tr>
<td colspan="4" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
</tfoot>
</table>
</div>
</div>
</div>
{% endif %}
{% if topExpenses.count > 0 %}
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
</div>
<div class="box-body">
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsort="disabled">{{ 'description'|_ }}</th>
<th data-defaultsign="month">{{ 'date'|_ }}</th>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'amount'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in topExpenses %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-sortable="false">
<a href="{{ route('transactions.show', row.journal_id) }}">
{% if row.transaction_description|length > 0 %}
{{ row.transaction_description }} ({{ row.description }})
{% else %}
{{ row.description }}
{% endif %}
</a>
</td>
<td data-value="{{ row.date.format('Y-m-d') }}">
{{ row.date.formatLocalized(monthAndDayFormat) }}
</td>
<td data-value="{{ row.opposing_account_name }}">
<a href="{{ route('accounts.show', row.opposing_account_id) }}">
{{ row.opposing_account_name }}
</a>
</td>
<td data-value="{{ row.transaction_amount }}" style="text-align: right;">
{{ row.transaction_amount|formatAmount }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if topExpenses|length > listLength %}
<tr>
<td colspan="3" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
</tfoot>
</table>
</div>
</div>
</div>
{% endif %}
</div>
<div class="row">
{% if averageIncome|length > 0 %}
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'average_income_per_account'|_ }}</h3>
</div>
<div class="box-body">
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19">{{ 'income_average'|_ }}</th>
<th data-defaultsign="_19">{{ 'total'|_ }}</th>
<th data-defaultsign="_19">{{ 'transaction_count'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in averageIncome %}
<tr>
<td data-value="{{ row.name }}">
<a href="{{ route('accounts.show', row.id) }}">{{ row.name }}</a>
</td>
<td data-value="{{ row.average }}">
{{ row.average|formatAmount }}
</td>
<td data-value="{{ row.sum }}">
{{ row.sum|formatAmount }}
</td>
<td data-value="{{ row.count }}">
{{ row.count }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endif %}
<div class="col-lg-6">
{% if topIncome.count > 0 %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
</div>
<div class="box-body">
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsort="disabled">{{ 'description'|_ }}</th>
<th data-defaultsign="month">{{ 'date'|_ }}</th>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19">{{ 'amount'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in topIncome %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td>
<a href="{{ route('transactions.show', row.journal_id) }}">
{% if row.transaction_description|length > 0 %}
{{ row.transaction_description }} ({{ row.description }})
{% else %}
{{ row.description }}
{% endif %}
</a>
</td>
<td data-value="{{ row.date.format('Y-m-d H-i-s') }}">
{{ row.date.formatLocalized(monthAndDayFormat) }}
</td>
<td data-value="{{ row.opposing_account_name }}">
<a href="{{ route('accounts.show', row.opposing_account_id) }}">
{{ row.opposing_account_name }}
</a>
</td>
<td data-value="{{ row.transaction_amount }}">
{{ row.transaction_amount|formatAmount }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if topIncome.count > listLength %}
<tr>
<td colspan="3" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
</tfoot>
</table>
</div>
</div>
{% endif %}
</div>
</div>
#}
{% endblock %} {% endblock %}
@ -417,19 +126,24 @@
var startDate = '{{ start.format('Ymd') }}'; var startDate = '{{ start.format('Ymd') }}';
var endDate = '{{ end.format('Ymd') }}'; var endDate = '{{ end.format('Ymd') }}';
var accountIds = '{{ accountIds }}'; var accountIds = '{{ accountIds }}';
var categoryIds = '{{ categoryIds }}'; var expenseIds = '{{ expenseIds }}';
// chart uri's // chart uri's
var categoryIncomeUri = '{{ route('chart.category.category-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; var mainUri = '{{ route('chart.expense.main', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var categoryExpenseUri = '{{ route('chart.category.category-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}';
var accountIncomeUri = '{{ route('chart.category.account-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; // boxes with stuff:
var accountExpenseUri = '{{ route('chart.category.account-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; var spentUri = '{{ route('report-data.expense.spent', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var mainUri = '{{ route('chart.category.main', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd')]) }}'; var groupedUri = '{{ route('report-data.expense.spent-grouped', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var categoryUri = '{{ route('report-data.expense.category', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var budgetUri = '{{ route('report-data.expense.budget', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseUri = '{{ route('report-data.expense.expenses', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
var incomeUri = '{{ route('report-data.expense.income', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}';
</script> </script>
<script type="text/javascript" src="js/ff/reports/category/all.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="js/ff/reports/account/all.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/ff/reports/category/month.js?v={{ FF_VERSION }}"></script> <script type="text/javascript" src="js/ff/reports/account/month.js?v={{ FF_VERSION }}"></script>
{% endblock %} {% endblock %}

View File

@ -1,14 +1,4 @@
<?php <?php
/**
* web.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1); declare(strict_types=1);
@ -95,7 +85,9 @@ Route::group(
// reconcile routes: // reconcile routes:
Route::get('reconcile/{account}/index/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@reconcile', 'as' => 'reconcile']); Route::get('reconcile/{account}/index/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@reconcile', 'as' => 'reconcile']);
Route::get('reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@transactions', 'as' => 'reconcile.transactions']); Route::get(
'reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@transactions', 'as' => 'reconcile.transactions']
);
Route::get('reconcile/{account}/overview/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@overview', 'as' => 'reconcile.overview']); Route::get('reconcile/{account}/overview/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@overview', 'as' => 'reconcile.overview']);
Route::post('reconcile/{account}/submit/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@submit', 'as' => 'reconcile.submit']); Route::post('reconcile/{account}/submit/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@submit', 'as' => 'reconcile.submit']);
@ -224,7 +216,7 @@ Route::group(
); );
/** /**
* Chart\Account Controller * Chart\Account Controller (default report)
*/ */
Route::group( Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/account', 'as' => 'chart.account.'], function () { ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/account', 'as' => 'chart.account.'], function () {
@ -246,6 +238,7 @@ Route::group(
} }
); );
/** /**
* Chart\Bill Controller * Chart\Bill Controller
*/ */
@ -374,6 +367,19 @@ Route::group(
} }
); );
/**
* Chart\Expense Controller (for expense/revenue report).
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/expense', 'as' => 'chart.expense.'], function () {
Route::get(
'operations/{accountList}/{expenseList}/{start_date}/{end_date}',
['uses' => 'ExpenseReportController@mainChart', 'as' => 'main']
);
}
);
/** /**
* Chart\PiggyBank Controller * Chart\PiggyBank Controller
*/ */
@ -582,6 +588,27 @@ Route::group(
} }
); );
/**
* Report Data Expense / Revenue Account Controller
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Report', 'prefix' => 'report-data/expense', 'as' => 'report-data.expense.'], function () {
// spent per period / spent grouped
Route::get('spent/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spent', 'as' => 'spent']);
Route::get('spent-grouped/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spentGrouped', 'as' => 'spent-grouped']);
// per category && per budget
Route::get('category/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@category', 'as' => 'category']);
Route::get('budget/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@budget', 'as' => 'budget']);
//expense earned top X
Route::get('expenses/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topX', 'as' => 'expenses']);
Route::get('income/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topXPeriod', 'as' => 'income']);
}
);
/** /**
* Report Data Income/Expenses Controller (called financial operations) * Report Data Income/Expenses Controller (called financial operations)
*/ */