mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
Tweak reports.
This commit is contained in:
60
app/Http/Controllers/Report/BalanceController.php
Normal file
60
app/Http/Controllers/Report/BalanceController.php
Normal 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;
|
||||
}
|
||||
}
|
@@ -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 */
|
||||
@@ -210,9 +205,8 @@ class ReportController extends Controller
|
||||
*/
|
||||
private function createRepositories()
|
||||
{
|
||||
$this->helper = app(ReportHelperInterface::class);
|
||||
$this->budgetHelper = app(BudgetReportHelperInterface::class);
|
||||
$this->balanceHelper = app(BalanceReportHelperInterface::class);
|
||||
$this->helper = app(ReportHelperInterface::class);
|
||||
$this->budgetHelper = app(BudgetReportHelperInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,10 +220,9 @@ class ReportController extends Controller
|
||||
private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
// 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);
|
||||
$budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts);
|
||||
$bills = $this->helper->getBillReport($start, $end, $accounts);
|
||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||
|
||||
// and some id's, joined:
|
||||
$accountIds = join(',', $accounts->pluck('id')->toArray());
|
||||
@@ -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'
|
||||
)
|
||||
@@ -289,8 +281,8 @@ class ReportController extends Controller
|
||||
*/
|
||||
private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
|
||||
{
|
||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||
$budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts);
|
||||
$tags = $this->helper->tagReport($start, $end, $accounts);
|
||||
$budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts);
|
||||
|
||||
Session::flash('gaEventCategory', 'report');
|
||||
Session::flash('gaEventAction', 'year');
|
||||
|
@@ -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!');
|
||||
|
@@ -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>
|
||||
|
@@ -1,70 +1,62 @@
|
||||
<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">
|
||||
<!-- build balance report header -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">{{ 'budgets'|_ }}</th>
|
||||
{% for account in balance.getBalanceHeader.getAccounts %}
|
||||
<th><a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a></th>
|
||||
{% endfor %}
|
||||
<th>
|
||||
{{ 'leftInBudget'|_ }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<table class="table table-hover">
|
||||
<!-- build balance report header -->
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">{{ 'budgets'|_ }}</th>
|
||||
{% for account in balance.getBalanceHeader.getAccounts %}
|
||||
<th><a href="{{ route('accounts.show',account.id) }}">{{ account.name }}</a></th>
|
||||
{% endfor %}
|
||||
<th>
|
||||
{{ 'leftInBudget'|_ }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<!-- make rows -->
|
||||
{% for balanceLine in balance.getBalanceLines %}
|
||||
<tr>
|
||||
<!-- make rows -->
|
||||
{% for balanceLine in balance.getBalanceLines %}
|
||||
<tr>
|
||||
|
||||
{% if balanceLine.getBudget.id %}
|
||||
<td>
|
||||
<a href="{{ route('budgets.show',balanceLine.getBudget.id) }}">{{ balanceLine.getTitle }}</a>
|
||||
{% if balanceLine.getStartdate and balanceLine.getEnddate %}
|
||||
<span class="small"><br>
|
||||
{{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }}
|
||||
—
|
||||
{{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }}
|
||||
{% if balanceLine.getBudget.id %}
|
||||
<td>
|
||||
<a href="{{ route('budgets.show',balanceLine.getBudget.id) }}">{{ balanceLine.getTitle }}</a>
|
||||
{% if balanceLine.getStartdate and balanceLine.getEnddate %}
|
||||
<span class="small"><br>
|
||||
{{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }}
|
||||
—
|
||||
{{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }}
|
||||
</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 %}
|
||||
</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 %}
|
||||
<td>
|
||||
{% if balanceEntry.getSpent != 0 %}
|
||||
<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"
|
||||
data-account-id="{{ balanceEntry.getAccount.id }}"
|
||||
data-budget-id="{{ balanceLine.getBudget.id }}" data-role="{{ balanceLine.getRole }}"></i>
|
||||
{% for balanceEntry in balanceLine.getBalanceEntries %}
|
||||
<td>
|
||||
{% if balanceEntry.getSpent != 0 %}
|
||||
<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"
|
||||
data-account-id="{{ balanceEntry.getAccount.id }}"
|
||||
data-budget-id="{{ balanceLine.getBudget.id }}" data-role="{{ balanceLine.getRole }}"></i>
|
||||
|
||||
{% endif %}
|
||||
{% if balanceEntry.getLeft != 0 %}
|
||||
<span class="text-success">{{ (balanceEntry.getLeft)|formatAmountPlain }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td>
|
||||
{{ balanceLine.leftOfRepetition|formatAmount }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if balanceEntry.getLeft != 0 %}
|
||||
<span class="text-success">{{ (balanceEntry.getLeft)|formatAmountPlain }}</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<td>
|
||||
{{ balanceLine.leftOfRepetition|formatAmount }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
@@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user