mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add more stuff to ajax controllers, making report controller simpler.
This commit is contained in:
parent
01de147900
commit
fe3f015171
@ -17,6 +17,7 @@ namespace FireflyIII\Http\Controllers\Report;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,9 +37,22 @@ class AccountController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function accountReport(Carbon $start, Carbon $end, Collection $accounts)
|
public function accountReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||||
{
|
{
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('account-report');
|
||||||
|
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$accountTasker = app(AccountTaskerInterface::class);
|
$accountTasker = app(AccountTaskerInterface::class);
|
||||||
$accountReport = $accountTasker->getAccountReport($start, $end, $accounts);
|
$accountReport = $accountTasker->getAccountReport($start, $end, $accounts);
|
||||||
|
|
||||||
return view('reports.partials.accounts', compact('accountReport'));
|
$result = view('reports.partials.accounts', compact('accountReport'))->render();
|
||||||
|
$cache->store($result);
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
app/Http/Controllers/Report/CategoryController.php
Normal file
59
app/Http/Controllers/Report/CategoryController.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CategoryController.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);
|
||||||
|
|
||||||
|
namespace FireflyIII\Http\Controllers\Report;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||||
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CategoryController
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Http\Controllers\Report
|
||||||
|
*/
|
||||||
|
class CategoryController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReportHelperInterface $helper
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function categoryReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||||
|
{
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('category-report');
|
||||||
|
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||||
|
if ($cache->has()) {
|
||||||
|
return $cache->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories = $helper->getCategoryReport($start, $end, $accounts);
|
||||||
|
|
||||||
|
$result = view('reports.partials.categories', compact('categories'))->render();
|
||||||
|
$cache->store($result);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,6 +17,7 @@ namespace FireflyIII\Http\Controllers\Report;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
|
use FireflyIII\Support\CacheProperties;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
@ -28,22 +29,38 @@ use Response;
|
|||||||
class InOutController extends Controller
|
class InOutController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ReportHelperInterface $helper
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
public function inOutReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
public function inOutReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||||
{
|
{
|
||||||
|
// chart properties for cache:
|
||||||
|
$cache = new CacheProperties;
|
||||||
|
$cache->addProperty($start);
|
||||||
|
$cache->addProperty($end);
|
||||||
|
$cache->addProperty('in-out-report');
|
||||||
|
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||||
|
if ($cache->has()) {
|
||||||
|
return Response::json($cache->get());
|
||||||
|
}
|
||||||
|
|
||||||
$incomes = $helper->getIncomeReport($start, $end, $accounts);
|
$incomes = $helper->getIncomeReport($start, $end, $accounts);
|
||||||
$expenses = $helper->getExpenseReport($start, $end, $accounts);
|
$expenses = $helper->getExpenseReport($start, $end, $accounts);
|
||||||
$incomeTopLength = 8;
|
|
||||||
$expenseTopLength = 8;
|
|
||||||
|
|
||||||
return Response::json(
|
$result = [
|
||||||
[
|
'income' => view('reports.partials.income', compact('incomes'))->render(),
|
||||||
'income' => view('reports.partials.income', compact('incomes', 'incomeTopLength'))->render(),
|
'expenses' => view('reports.partials.expenses', compact('expenses'))->render(),
|
||||||
'expenses' => view('reports.partials.expenses', compact('expenses', 'expenseTopLength'))->render(),
|
|
||||||
'incomes_expenses' => view('reports.partials.income-vs-expenses', compact('expenses', 'incomes'))->render(),
|
'incomes_expenses' => view('reports.partials.income-vs-expenses', compact('expenses', 'incomes'))->render(),
|
||||||
]
|
];
|
||||||
);
|
$cache->store($result);
|
||||||
|
|
||||||
|
return Response::json($result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -227,7 +227,6 @@ class ReportController extends Controller
|
|||||||
{
|
{
|
||||||
// get report stuff!
|
// get report stuff!
|
||||||
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts);
|
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts);
|
||||||
$categories = $this->helper->getCategoryReport($start, $end, $accounts);
|
|
||||||
$balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts);
|
$balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts);
|
||||||
$bills = $this->helper->getBillReport($start, $end, $accounts);
|
$bills = $this->helper->getBillReport($start, $end, $accounts);
|
||||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||||
@ -243,7 +242,6 @@ class ReportController extends Controller
|
|||||||
'tags',
|
'tags',
|
||||||
'incomes',
|
'incomes',
|
||||||
'budgets', 'balance',
|
'budgets', 'balance',
|
||||||
'categories',
|
|
||||||
'bills',
|
'bills',
|
||||||
'accountIds', 'reportType'
|
'accountIds', 'reportType'
|
||||||
)
|
)
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// find the little info buttons and respond to them.
|
|
||||||
$('.firefly-info-button').click(clickInfoButton);
|
|
||||||
|
|
||||||
// load the account report, which this report shows:
|
// load the account report, which this report shows:
|
||||||
loadAccountReport();
|
loadAccountReport();
|
||||||
@ -19,11 +18,20 @@ $(function () {
|
|||||||
// load income / expense / difference:
|
// load income / expense / difference:
|
||||||
loadInOutReport();
|
loadInOutReport();
|
||||||
|
|
||||||
|
// trigger info click
|
||||||
|
triggerInfoClick();
|
||||||
|
|
||||||
// trigger list length things:
|
// trigger list length things:
|
||||||
listLengthInitial();
|
listLengthInitial();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function triggerInfoClick() {
|
||||||
|
"use strict";
|
||||||
|
// find the little info buttons and respond to them.
|
||||||
|
$('.firefly-info-button').unbind('clicl').click(clickInfoButton);
|
||||||
|
}
|
||||||
|
|
||||||
function listLengthInitial() {
|
function listLengthInitial() {
|
||||||
"use strict";
|
"use strict";
|
||||||
$('.overListLength').hide();
|
$('.overListLength').hide();
|
||||||
@ -62,6 +70,7 @@ function placeInOutReport(data) {
|
|||||||
$('#expenseReport').removeClass('loading').html(data.expenses);
|
$('#expenseReport').removeClass('loading').html(data.expenses);
|
||||||
$('#incomeVsExpenseReport').removeClass('loading').html(data.incomes_expenses);
|
$('#incomeVsExpenseReport').removeClass('loading').html(data.incomes_expenses);
|
||||||
listLengthInitial();
|
listLengthInitial();
|
||||||
|
triggerInfoClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
function failInOutReport() {
|
function failInOutReport() {
|
||||||
|
@ -1,11 +1,32 @@
|
|||||||
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds , picker:true, minDate, year, month, columnChart, lineChart, stackedColumnChart */
|
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl */
|
||||||
|
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
drawChart();
|
drawChart();
|
||||||
|
|
||||||
|
loadCategoryReport();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function loadCategoryReport() {
|
||||||
|
"use strict";
|
||||||
|
console.log('Going to grab ' + categoryReportUrl);
|
||||||
|
$.get(categoryReportUrl).done(placeCategoryReport).fail(failCategoryReport);
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeCategoryReport(data) {
|
||||||
|
"use strict";
|
||||||
|
$('#categoryReport').removeClass('loading').html(data);
|
||||||
|
listLengthInitial();
|
||||||
|
triggerInfoClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
function failCategoryReport() {
|
||||||
|
"use strict";
|
||||||
|
console.log('Fail category report data!');
|
||||||
|
$('#categoryReport').removeClass('loading').addClass('general-chart-error');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function drawChart() {
|
function drawChart() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -39,9 +39,8 @@
|
|||||||
<!-- budgets -->
|
<!-- budgets -->
|
||||||
{% include 'reports/partials/budgets.twig' %}
|
{% include 'reports/partials/budgets.twig' %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4 col-md-4 col-sm-12">
|
<div class="col-lg-4 col-md-4 col-sm-12 loading" id="categoryReport">
|
||||||
<!-- categories -->
|
{# {% include 'reports/partials/categories.twig' %} #}
|
||||||
{% include 'reports/partials/categories.twig' %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -82,6 +81,7 @@
|
|||||||
<!-- some URL's -->
|
<!-- some URL's -->
|
||||||
var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||||
var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||||
|
var categoryReportUrl = '{{ route('reports.data.categoryReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>
|
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>
|
||||||
<script type="text/javascript" src="js/ff/reports/default/month.js"></script>
|
<script type="text/javascript" src="js/ff/reports/default/month.js"></script>
|
||||||
|
@ -12,7 +12,11 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for cat in categories.getCategories %}
|
{% for cat in categories.getCategories %}
|
||||||
|
{% if loop.index > listLength %}
|
||||||
|
<tr class="overListLength">
|
||||||
|
{% else %}
|
||||||
<tr>
|
<tr>
|
||||||
|
{% endif %}
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route('categories.show',cat.id) }}">{{ cat.name }}</a>
|
<a href="{{ route('categories.show',cat.id) }}">{{ cat.name }}</a>
|
||||||
</td>
|
</td>
|
||||||
@ -26,6 +30,14 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
|
{% if categories.getCategories.count > expenseTopLength %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" class="active">
|
||||||
|
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><em>{{ 'sum'|_ }}</em></td>
|
<td><em>{{ 'sum'|_ }}</em></td>
|
||||||
<td>{{ categories.getTotal|formatAmount }}</td>
|
<td>{{ categories.getTotal|formatAmount }}</td>
|
||||||
|
@ -329,6 +329,12 @@ Route::group(
|
|||||||
['uses' => 'Report\InOutController@inOutReport', 'as' => 'reports.data.inOutReport']
|
['uses' => 'Report\InOutController@inOutReport', 'as' => 'reports.data.inOutReport']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// category report:
|
||||||
|
Route::get(
|
||||||
|
'/reports/data/category-report/{start_date}/{end_date}/{accountList}',
|
||||||
|
['uses' => 'Report\CategoryController@categoryReport', 'as' => 'reports.data.categoryReport']
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rules Controller
|
* Rules Controller
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user