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 Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
use FireflyIII\Helpers\Report\BudgetReportHelperInterface; use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -38,10 +37,6 @@ use View;
*/ */
class ReportController extends Controller class ReportController extends Controller
{ {
/** @var BalanceReportHelperInterface */
protected $balanceHelper;
/** @var BudgetReportHelperInterface */ /** @var BudgetReportHelperInterface */
protected $budgetHelper; protected $budgetHelper;
/** @var ReportHelperInterface */ /** @var ReportHelperInterface */
@@ -210,9 +205,8 @@ class ReportController extends Controller
*/ */
private function createRepositories() private function createRepositories()
{ {
$this->helper = app(ReportHelperInterface::class); $this->helper = app(ReportHelperInterface::class);
$this->budgetHelper = app(BudgetReportHelperInterface::class); $this->budgetHelper = app(BudgetReportHelperInterface::class);
$this->balanceHelper = app(BalanceReportHelperInterface::class);
} }
/** /**
@@ -226,10 +220,9 @@ class ReportController extends Controller
private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts) private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{ {
// get report stuff! // get report stuff!
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts); $budgets = $this->budgetHelper->getBudgetReport($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);
// and some id's, joined: // and some id's, joined:
$accountIds = join(',', $accounts->pluck('id')->toArray()); $accountIds = join(',', $accounts->pluck('id')->toArray());
@@ -238,10 +231,9 @@ class ReportController extends Controller
return view( return view(
'reports.default.month', 'reports.default.month',
compact( compact(
'start', 'end', 'reportType', 'start', 'end',
'tags', 'tags',
'incomes', 'budgets',
'budgets', 'balance',
'bills', 'bills',
'accountIds', 'reportType' 'accountIds', 'reportType'
) )
@@ -289,8 +281,8 @@ class ReportController extends Controller
*/ */
private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts) private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{ {
$tags = $this->helper->tagReport($start, $end, $accounts); $tags = $this->helper->tagReport($start, $end, $accounts);
$budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts); $budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts);
Session::flash('gaEventCategory', 'report'); Session::flash('gaEventCategory', 'report');
Session::flash('gaEventAction', 'year'); Session::flash('gaEventAction', 'year');

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 () { $(function () {
@@ -6,6 +6,7 @@ $(function () {
drawChart(); drawChart();
loadCategoryReport(); loadCategoryReport();
loadBalanceReport();
}); });
function loadCategoryReport() { function loadCategoryReport() {
@@ -14,6 +15,19 @@ function loadCategoryReport() {
$.get(categoryReportUrl).done(placeCategoryReport).fail(failCategoryReport); $.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) { function placeCategoryReport(data) {
"use strict"; "use strict";
$('#categoryReport').removeClass('loading').html(data); $('#categoryReport').removeClass('loading').html(data);
@@ -21,6 +35,12 @@ function placeCategoryReport(data) {
triggerInfoClick(); triggerInfoClick();
} }
function failBalanceReport() {
"use strict";
console.log('Fail balance report data!');
$('#balanceReport').removeClass('loading').addClass('general-chart-error');
}
function failCategoryReport() { function failCategoryReport() {
"use strict"; "use strict";
console.log('Fail category report data!'); console.log('Fail category report data!');

View File

@@ -87,7 +87,14 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12"> <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> </div>
<div class="row"> <div class="row">
@@ -119,6 +126,7 @@
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]) }}'; 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>
<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>

View File

@@ -1,70 +1,62 @@
<div class="box"> <table class="table table-hover">
<div class="box-header with-border"> <!-- build balance report header -->
<h3 class="box-title">{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})</h3> <thead>
</div> <tr>
<div class="box-body table-responsive no-padding"> <th colspan="2">{{ 'budgets'|_ }}</th>
<table class="table table-hover"> {% for account in balance.getBalanceHeader.getAccounts %}
<!-- build balance report header --> <th><a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a></th>
<thead> {% endfor %}
<tr> <th>
<th colspan="2">{{ 'budgets'|_ }}</th> {{ 'leftInBudget'|_ }}
{% for account in balance.getBalanceHeader.getAccounts %} </th>
<th><a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a></th> </tr>
{% endfor %} </thead>
<th> <tbody>
{{ 'leftInBudget'|_ }}
</th>
</tr>
</thead>
<tbody>
<!-- make rows --> <!-- make rows -->
{% for balanceLine in balance.getBalanceLines %} {% for balanceLine in balance.getBalanceLines %}
<tr> <tr>
{% if balanceLine.getBudget.id %} {% if balanceLine.getBudget.id %}
<td> <td>
<a href="{{ route('budgets.show',balanceLine.getBudget.id) }}">{{ balanceLine.getTitle }}</a> <a href="{{ route('budgets.show',balanceLine.getBudget.id) }}">{{ balanceLine.getTitle }}</a>
{% if balanceLine.getStartdate and balanceLine.getEnddate %} {% if balanceLine.getStartdate and balanceLine.getEnddate %}
<span class="small"><br> <span class="small"><br>
{{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }} {{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }}
&mdash; &mdash;
{{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }} {{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }}
</span> </span>
{% endif %}
</td>
<td>
{% if(balanceLine.getBudget.amount) %}
{{ balanceLine.getBudget.amount|formatAmount }}
{% else %}
{{ '0'|formatAmount }}
{% endif %}
</td>
{% else %}
<td colspan="2">{{ balanceLine.getTitle }}</td>
{% endif %} {% endif %}
</td>
<td>
{% if(balanceLine.getBudget.amount) %}
{{ balanceLine.getBudget.amount|formatAmount }}
{% else %}
{{ '0'|formatAmount }}
{% endif %}
</td>
{% else %}
<td colspan="2">{{ balanceLine.getTitle }}</td>
{% endif %}
{% for balanceEntry in balanceLine.getBalanceEntries %} {% for balanceEntry in balanceLine.getBalanceEntries %}
<td> <td>
{% if balanceEntry.getSpent != 0 %} {% if balanceEntry.getSpent != 0 %}
<span class="text-danger">{{ (balanceEntry.getSpent)|formatAmountPlain }}</span> <span class="text-danger">{{ (balanceEntry.getSpent)|formatAmountPlain }}</span>
<i class="fa fa-fw text-muted fa-info-circle firefly-info-button" data-location="balance-amount" <i class="fa fa-fw text-muted fa-info-circle firefly-info-button" data-location="balance-amount"
data-account-id="{{ balanceEntry.getAccount.id }}" data-account-id="{{ balanceEntry.getAccount.id }}"
data-budget-id="{{ balanceLine.getBudget.id }}" data-role="{{ balanceLine.getRole }}"></i> data-budget-id="{{ balanceLine.getBudget.id }}" data-role="{{ balanceLine.getRole }}"></i>
{% endif %} {% endif %}
{% if balanceEntry.getLeft != 0 %} {% if balanceEntry.getLeft != 0 %}
<span class="text-success">{{ (balanceEntry.getLeft)|formatAmountPlain }}</span> <span class="text-success">{{ (balanceEntry.getLeft)|formatAmountPlain }}</span>
{% endif %} {% endif %}
</td> </td>
{% endfor %}
<td>
{{ balanceLine.leftOfRepetition|formatAmount }}
</td>
</tr>
{% endfor %} {% endfor %}
</tbody> <td>
</table> {{ balanceLine.leftOfRepetition|formatAmount }}
</div> </td>
</tr>
</div> {% endfor %}
</tbody>
</table>

View File

@@ -335,6 +335,12 @@ Route::group(
['uses' => 'Report\CategoryController@categoryReport', 'as' => 'reports.data.categoryReport'] ['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 * Rules Controller
*/ */