mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up some report code.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
parent
6c8d594df7
commit
5e480eca36
@ -19,7 +19,6 @@ use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Response;
|
||||
|
||||
/**
|
||||
* Class InOutController
|
||||
@ -37,29 +36,83 @@ class InOutController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function inOutReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||
public function expenseReport(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('expense-report');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return Response::json($cache->get());
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$expenses = $helper->getExpenseReport($start, $end, $accounts);
|
||||
|
||||
$result = view('reports.partials.expenses', compact('expenses'))->render();
|
||||
$cache->store($result);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReportHelperInterface $helper
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function incExpReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('inc-exp-report');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$incomes = $helper->getIncomeReport($start, $end, $accounts);
|
||||
$expenses = $helper->getExpenseReport($start, $end, $accounts);
|
||||
|
||||
$result = [
|
||||
'income' => view('reports.partials.income', compact('incomes'))->render(),
|
||||
'expenses' => view('reports.partials.expenses', compact('expenses'))->render(),
|
||||
'incomes_expenses' => view('reports.partials.income-vs-expenses', compact('expenses', 'incomes'))->render(),
|
||||
];
|
||||
$result = view('reports.partials.income-vs-expenses', compact('expenses', 'incomes'))->render();
|
||||
$cache->store($result);
|
||||
|
||||
return Response::json($result);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReportHelperInterface $helper
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function incomeReport(ReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
$cache->addProperty('income-report');
|
||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$incomes = $helper->getIncomeReport($start, $end, $accounts);
|
||||
|
||||
$result = view('reports.partials.income', compact('incomes'))->render();
|
||||
$cache->store($result);
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, accountIds, inOutReportUrl, accountReportUrl */
|
||||
/* globals startDate, showOnlyTop, showFullList, endDate, reportType, expenseReportUri, accountIds, incExpReportUri,accountReportUri, incomeReportUri */
|
||||
/*
|
||||
* all.js
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
@ -13,23 +13,19 @@ $(function () {
|
||||
|
||||
|
||||
// load the account report, which this report shows:
|
||||
loadAccountReport();
|
||||
loadAjaxPartial('accountReport', accountReportUri);
|
||||
|
||||
// load income / expense / difference:
|
||||
loadInOutReport();
|
||||
|
||||
// trigger info click
|
||||
triggerInfoClick();
|
||||
|
||||
// trigger list length things:
|
||||
listLengthInitial();
|
||||
// load income and expense reports:
|
||||
loadAjaxPartial('incomeReport',incomeReportUri);
|
||||
loadAjaxPartial('expenseReport',expenseReportUri);
|
||||
loadAjaxPartial('incomeVsExpenseReport',incExpReportUri);
|
||||
|
||||
});
|
||||
|
||||
function triggerInfoClick() {
|
||||
"use strict";
|
||||
// find the little info buttons and respond to them.
|
||||
$('.firefly-info-button').unbind('clicl').click(clickInfoButton);
|
||||
$('.firefly-info-button').unbind('click').click(clickInfoButton);
|
||||
}
|
||||
|
||||
function listLengthInitial() {
|
||||
@ -58,44 +54,6 @@ function triggerList(e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function loadInOutReport() {
|
||||
"use strict";
|
||||
console.log('Going to grab ' + inOutReportUrl);
|
||||
$.get(inOutReportUrl).done(placeInOutReport).fail(failInOutReport);
|
||||
}
|
||||
|
||||
function placeInOutReport(data) {
|
||||
"use strict";
|
||||
$('#incomeReport').removeClass('loading').html(data.income);
|
||||
$('#expenseReport').removeClass('loading').html(data.expenses);
|
||||
$('#incomeVsExpenseReport').removeClass('loading').html(data.incomes_expenses);
|
||||
listLengthInitial();
|
||||
triggerInfoClick();
|
||||
}
|
||||
|
||||
function failInOutReport() {
|
||||
"use strict";
|
||||
console.log('Fail in/out report data!');
|
||||
$('#incomeReport').removeClass('loading').addClass('general-chart-error');
|
||||
$('#expenseReport').removeClass('loading').addClass('general-chart-error');
|
||||
$('#incomeVsExpenseReport').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
function loadAccountReport() {
|
||||
"use strict";
|
||||
$.get(accountReportUrl).done(placeAccountReport).fail(failAccountReport);
|
||||
}
|
||||
|
||||
function placeAccountReport(data) {
|
||||
"use strict";
|
||||
$('#accountReport').removeClass('loading').html(data);
|
||||
}
|
||||
|
||||
function failAccountReport(data) {
|
||||
"use strict";
|
||||
$('#accountReport').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
function clickInfoButton(e) {
|
||||
"use strict";
|
||||
// find all data tags, regardless of what they are:
|
||||
@ -125,8 +83,7 @@ function respondInfoButton(data) {
|
||||
"use strict";
|
||||
// remove wait cursor
|
||||
$('body').removeClass('waiting');
|
||||
$('#defaultModal').empty().html(data.html);
|
||||
$('#defaultModal').modal('show');
|
||||
$('#defaultModal').empty().html(data.html).modal('show');
|
||||
|
||||
}
|
||||
|
||||
@ -150,6 +107,12 @@ function displayAjaxPartial(data, holder) {
|
||||
|
||||
// find a sortable table and make it sortable:
|
||||
$.bootstrapSortable(true);
|
||||
|
||||
// find the info click things and respond to them:
|
||||
triggerInfoClick();
|
||||
|
||||
// trigger list thing
|
||||
listLengthInitial();
|
||||
}
|
||||
|
||||
function failAjaxPartial(uri, holder) {
|
||||
|
@ -1,74 +1,15 @@
|
||||
/* globals google, budgetReportUrl, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl, balanceReportUrl */
|
||||
/* globals google, categoryReportUri, budgetReportUri, balanceReportUri */
|
||||
|
||||
|
||||
$(function () {
|
||||
"use strict";
|
||||
drawChart();
|
||||
|
||||
loadCategoryReport();
|
||||
loadBalanceReport();
|
||||
loadBudgetReport();
|
||||
loadAjaxPartial('categoryReport', categoryReportUri);
|
||||
loadAjaxPartial('budgetReport', budgetReportUri);
|
||||
loadAjaxPartial('balanceReport',balanceReportUri);
|
||||
});
|
||||
|
||||
function loadCategoryReport() {
|
||||
"use strict";
|
||||
console.log('Going to grab ' + categoryReportUrl);
|
||||
$.get(categoryReportUrl).done(placeCategoryReport).fail(failCategoryReport);
|
||||
}
|
||||
|
||||
function loadBudgetReport() {
|
||||
"use strict";
|
||||
console.log('Going to grab ' + budgetReportUrl);
|
||||
$.get(budgetReportUrl).done(placeBudgetReport).fail(failBudgetReport);
|
||||
}
|
||||
|
||||
|
||||
function loadBalanceReport() {
|
||||
"use strict";
|
||||
console.log('Going to grab ' + categoryReportUrl);
|
||||
$.get(balanceReportUrl).done(placeBalanceReport).fail(failBalanceReport);
|
||||
}
|
||||
|
||||
function placeBudgetReport(data) {
|
||||
"use strict";
|
||||
$('#budgetReport').removeClass('loading').html(data);
|
||||
listLengthInitial();
|
||||
triggerInfoClick();
|
||||
}
|
||||
|
||||
function placeBalanceReport(data) {
|
||||
"use strict";
|
||||
$('#balanceReport').removeClass('loading').html(data);
|
||||
listLengthInitial();
|
||||
triggerInfoClick();
|
||||
}
|
||||
|
||||
function placeCategoryReport(data) {
|
||||
"use strict";
|
||||
$('#categoryReport').removeClass('loading').html(data);
|
||||
listLengthInitial();
|
||||
triggerInfoClick();
|
||||
}
|
||||
|
||||
function failBudgetReport() {
|
||||
"use strict";
|
||||
console.log('Fail budget report data!');
|
||||
$('#budgetReport').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
function failBalanceReport() {
|
||||
"use strict";
|
||||
console.log('Fail balance report data!');
|
||||
$('#balanceReport').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
function failCategoryReport() {
|
||||
"use strict";
|
||||
console.log('Fail category report data!');
|
||||
$('#categoryReport').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
|
||||
function drawChart() {
|
||||
"use strict";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* globals google, accountIds, budgetYearOverviewUrl */
|
||||
/* globals google, accountIds, budgetYearOverviewUri */
|
||||
|
||||
var chartDrawn;
|
||||
var budgetChart;
|
||||
@ -7,30 +7,9 @@ $(function () {
|
||||
chartDrawn = false;
|
||||
drawChart();
|
||||
|
||||
//
|
||||
loadBudgetOverview();
|
||||
loadAjaxPartial('budgetOverview',budgetYearOverviewUri);
|
||||
});
|
||||
|
||||
function loadBudgetOverview() {
|
||||
"use strict";
|
||||
console.log('Going to grab ' + budgetYearOverviewUrl);
|
||||
$.get(budgetYearOverviewUrl).done(placeBudgetOverview).fail(failBudgetOverview);
|
||||
}
|
||||
|
||||
function placeBudgetOverview(data) {
|
||||
"use strict";
|
||||
$('#budgetOverview').removeClass('loading').html(data);
|
||||
$('.budget-chart-activate').on('click', clickBudgetChart);
|
||||
}
|
||||
|
||||
function failBudgetOverview() {
|
||||
"use strict";
|
||||
console.log('Fail budget overview data!');
|
||||
$('#budgetOverview').removeClass('loading').addClass('general-chart-error');
|
||||
}
|
||||
|
||||
|
||||
|
||||
function drawChart() {
|
||||
"use strict";
|
||||
|
||||
|
@ -132,11 +132,14 @@
|
||||
var accountIds = '{{ accountIds }}';
|
||||
|
||||
<!-- some URL's -->
|
||||
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 categoryReportUrl = '{{ route('reports.data.categoryReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var balanceReportUrl = '{{ route('reports.data.balanceReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var budgetReportUrl = '{{ route('reports.data.budgetReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var accountReportUri = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var incomeReportUri = '{{ route('reports.data.incomeReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var expenseReportUri = '{{ route('reports.data.expenseReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var incExpReportUri = '{{ route('reports.data.incExpReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var categoryReportUri = '{{ route('reports.data.categoryReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var budgetReportUri = '{{ route('reports.data.budgetReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var balanceReportUri = '{{ route('reports.data.balanceReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
|
||||
</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>
|
||||
|
@ -123,9 +123,12 @@
|
||||
var accountIds = '{{ accountIds }}';
|
||||
|
||||
<!-- some URL's -->
|
||||
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 budgetYearOverviewUrl = '{{ route('reports.data.budgetYearOverview', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var accountReportUri = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var incomeReportUri = '{{ route('reports.data.incomeReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var expenseReportUri = '{{ route('reports.data.expenseReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
var incExpReportUri = '{{ route('reports.data.incExpReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
|
||||
var budgetYearOverviewUri = '{{ route('reports.data.budgetYearOverview', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}';
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="js/ff/reports/default/all.js"></script>
|
||||
|
@ -316,10 +316,20 @@ Route::group(
|
||||
['uses' => 'Report\AccountController@accountReport', 'as' => 'reports.data.accountReport']
|
||||
);
|
||||
|
||||
// income report
|
||||
// income and expenses report
|
||||
Route::get(
|
||||
'/reports/data/in-out-report/{start_date}/{end_date}/{accountList}',
|
||||
['uses' => 'Report\InOutController@inOutReport', 'as' => 'reports.data.inOutReport']
|
||||
'/reports/data/inc-exp-report/{start_date}/{end_date}/{accountList}',
|
||||
['uses' => 'Report\InOutController@incExpReport', 'as' => 'reports.data.incExpReport']
|
||||
);
|
||||
// (income report):
|
||||
Route::get(
|
||||
'/reports/data/income-report/{start_date}/{end_date}/{accountList}',
|
||||
['uses' => 'Report\InOutController@incomeReport', 'as' => 'reports.data.incomeReport']
|
||||
);
|
||||
// (expense report):
|
||||
Route::get(
|
||||
'/reports/data/expense-report/{start_date}/{end_date}/{accountList}',
|
||||
['uses' => 'Report\InOutController@expenseReport', 'as' => 'reports.data.expenseReport']
|
||||
);
|
||||
|
||||
// category report:
|
||||
|
Loading…
Reference in New Issue
Block a user