Tweak reports.

This commit is contained in:
James Cole
2016-10-26 19:45:10 +02:00
parent 5db4f8512b
commit afdcfa8525
6 changed files with 160 additions and 82 deletions

View File

@@ -0,0 +1,60 @@
<?php
/**
* BalanceController.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\BalanceReportHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
/**
* Class BalanceController
*
* @package FireflyIII\Http\Controllers\Report
*/
class BalanceController extends Controller
{
/**
* @param BalanceReportHelperInterface $helper
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return string
*/
public function balanceReport(BalanceReportHelperInterface $helper, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('balance-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return $cache->get();
}
$balance = $helper->getBalanceReport($start, $end, $accounts);
$result = view('reports.partials.balance', compact('balance'))->render();
$cache->store($result);
return $result;
}
}

View File

@@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
@@ -38,10 +37,6 @@ use View;
*/
class ReportController extends Controller
{
/** @var BalanceReportHelperInterface */
protected $balanceHelper;
/** @var BudgetReportHelperInterface */
protected $budgetHelper;
/** @var ReportHelperInterface */
@@ -212,7 +207,6 @@ class ReportController extends Controller
{
$this->helper = app(ReportHelperInterface::class);
$this->budgetHelper = app(BudgetReportHelperInterface::class);
$this->balanceHelper = app(BalanceReportHelperInterface::class);
}
/**
@@ -227,7 +221,6 @@ class ReportController extends Controller
{
// get report stuff!
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts);
$balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts);
$bills = $this->helper->getBillReport($start, $end, $accounts);
$tags = $this->helper->tagReport($start, $end, $accounts);
@@ -238,10 +231,9 @@ class ReportController extends Controller
return view(
'reports.default.month',
compact(
'start', 'end', 'reportType',
'start', 'end',
'tags',
'incomes',
'budgets', 'balance',
'budgets',
'bills',
'accountIds', 'reportType'
)

View File

@@ -1,4 +1,4 @@
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl */
/* globals google, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl, balanceReportUrl */
$(function () {
@@ -6,6 +6,7 @@ $(function () {
drawChart();
loadCategoryReport();
loadBalanceReport();
});
function loadCategoryReport() {
@@ -14,6 +15,19 @@ function loadCategoryReport() {
$.get(categoryReportUrl).done(placeCategoryReport).fail(failCategoryReport);
}
function loadBalanceReport() {
"use strict";
console.log('Going to grab ' + categoryReportUrl);
$.get(balanceReportUrl).done(placeBalanceReport).fail(failBalanceReport);
}
function placeBalanceReport(data) {
"use strict";
$('#balanceReport').removeClass('loading').html(data);
listLengthInitial();
triggerInfoClick();
}
function placeCategoryReport(data) {
"use strict";
$('#categoryReport').removeClass('loading').html(data);
@@ -21,6 +35,12 @@ function placeCategoryReport(data) {
triggerInfoClick();
}
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!');

View File

@@ -87,7 +87,14 @@
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
{% include 'reports/partials/balance.twig' %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})</h3>
</div>
<div class="box-body table-responsive no-padding loading" id="balanceReport">
</div>
</div>
</div>
</div>
<div class="row">
@@ -119,6 +126,7 @@
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]) }}';
</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>

View File

@@ -1,9 +1,4 @@
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<table class="table table-hover">
<!-- build balance report header -->
<thead>
<tr>
@@ -64,7 +59,4 @@
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</table>

View File

@@ -335,6 +335,12 @@ Route::group(
['uses' => 'Report\CategoryController@categoryReport', 'as' => 'reports.data.categoryReport']
);
// balance report:
Route::get(
'/reports/data/balance-report/{start_date}/{end_date}/{accountList}',
['uses' => 'Report\BalanceController@balanceReport', 'as' => 'reports.data.balanceReport']
);
/**
* Rules Controller
*/