Simplify bill overview.

This commit is contained in:
James Cole 2019-08-16 21:21:38 +02:00
parent a32df0066e
commit 5a2998c80e
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
16 changed files with 209 additions and 50 deletions

View File

@ -24,7 +24,6 @@ namespace FireflyIII\Generator\Report\Standard;
use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use Illuminate\Support\Collection;
use Log;
use Throwable;
@ -50,17 +49,11 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
public function generate(): string
{
/** @var ReportHelperInterface $helper */
$helper = app(ReportHelperInterface::class);
$bills = $helper->getBillReport($this->start, $this->end, $this->accounts);
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
$reportType = 'default';
try {
return view(
'reports.default.month',
compact('bills', 'accountIds', 'reportType')
)->with('start', $this->start)->with('end', $this->end)->render();
return view('reports.default.month', compact('accountIds', 'reportType'))->with('start', $this->start)->with('end', $this->end)->render();
} catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.default.month: %s', $e->getMessage()));
$result = 'Could not render report view.';

View File

@ -66,20 +66,61 @@ class ReportHelper implements ReportHelperInterface
*
* Excludes bills which have not had a payment on the mentioned accounts.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return BillCollection
* @return array
*/
public function getBillReport(Carbon $start, Carbon $end, Collection $accounts): BillCollection
public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array
{
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$bills = $repository->getBillsForAccounts($accounts);
$report = [
'bills' => [],
];
/** @var Bill $bill */
foreach ($bills as $bill) {
$expectedDates = $repository->getPayDatesInRange($bill, $start, $end);
$billId = $bill->id;
$currency = $bill->transactionCurrency;
$current = [
'id' => $bill->id,
'name' => $bill->name,
'active' => $bill->active,
'amount_min' => $bill->amount_min,
'amount_max' => $bill->amount_max,
'currency_id' => $bill->transaction_currency_id,
'currency_code' => $currency->code,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'expected_dates' => $expectedDates->toArray(),
'paid_moments' => [],
];
/** @var Carbon $start */
foreach ($expectedDates as $expectedStart) {
$expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null);
// is paid in this period maybe?
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($expectedStart, $expectedEnd)->setBill($bill);
$current['paid_moments'][] = $collector->getExtractedJournals();
}
// append to report:
$report['bills'][$billId] = $current;
}
return $report;
echo '<pre>';
print_r($report);
exit;
$collection = new BillCollection;
$collection->setStartDate($start);

View File

@ -41,9 +41,9 @@ interface ReportHelperInterface
* @param Carbon $end
* @param Collection $accounts
*
* @return BillCollection
* @return array
*/
public function getBillReport(Carbon $start, Carbon $end, Collection $accounts): BillCollection;
public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array;
/**
* Generate a list of months.

View File

@ -54,7 +54,7 @@ class BalanceController extends Controller
$cache->addProperty('balance-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
$helper = app(BalanceReportHelperInterface::class);
$report = $helper->getBalanceReport($accounts, $start, $end);

View File

@ -0,0 +1,73 @@
<?php
/**
* BillController.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
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;
use Log;
use Throwable;
/**
* Class BillController
*/
class BillController extends Controller
{
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*/
public function overview(Collection $accounts, Carbon $start, Carbon $end)
{ // chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('bill-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
}
/** @var ReportHelperInterface $helper */
$helper = app(ReportHelperInterface::class);
$report = $helper->getBillReport($accounts, $start, $end);
// try {
$result = view('reports.partials.bills', compact('report'))->render();
// @codeCoverageIgnoreStart
// } catch (Throwable $e) {
// Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
// $result = 'Could not render view.';
// }
// @codeCoverageIgnoreEnd
$cache->store($result);
return $result;
}
}

View File

@ -57,17 +57,17 @@ class BudgetController extends Controller
$cache->addProperty('budget-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
$helper = app(BudgetReportHelperInterface::class);
$budgets = $helper->getBudgetReport($start, $end, $accounts);
//try {
try {
$result = view('reports.partials.budgets', compact('budgets'))->render();
// @codeCoverageIgnoreStart
// } catch (Throwable $e) {
// Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
// $result = 'Could not render view.';
// }
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
$result = 'Could not render view.';
}
// @codeCoverageIgnoreEnd
$cache->store($result);

View File

@ -164,7 +164,7 @@ class CategoryController extends Controller
$cache->addProperty('category-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
/** @var CategoryRepositoryInterface $repository */

View File

@ -253,7 +253,7 @@ class ExpenseController extends Controller
$cache->addProperty($accounts->pluck('id')->toArray());
$cache->addProperty($expense->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
$combined = $this->combineAccounts($expense);
$all = new Collection;
@ -305,7 +305,7 @@ class ExpenseController extends Controller
$cache->addProperty($accounts->pluck('id')->toArray());
$cache->addProperty($expense->pluck('id')->toArray());
if ($cache->has()) {
//return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
$combined = $this->combineAccounts($expense);
$all = new Collection;

View File

@ -238,8 +238,8 @@ class ReportController extends Controller
trans(
'firefly.report_default',
[
'start' => $start->formatLocalized($this->monthFormat),
'end' => $end->formatLocalized($this->monthFormat),
'start' => $start->formatLocalized($this->monthAndDayFormat),
'end' => $end->formatLocalized($this->monthAndDayFormat),
]
)
);

View File

@ -192,13 +192,13 @@ class BillRepository implements BillRepositoryInterface
$set = $this->user->bills()
->leftJoin(
'transaction_journals',
function (JoinClause $join) {
static function (JoinClause $join) {
$join->on('transaction_journals.bill_id', '=', 'bills.id')->whereNull('transaction_journals.deleted_at');
}
)
->leftJoin(
'transactions',
function (JoinClause $join) {
static function (JoinClause $join) {
$join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', '<', 0);
}
)

View File

@ -31,5 +31,6 @@ $(function () {
loadAjaxPartial('incomeReport', incomeReportUri);
loadAjaxPartial('expenseReport', expenseReportUri);
loadAjaxPartial('incomeVsExpenseReport', incExpReportUri);
loadAjaxPartial('billReport', billReportUri);
});

View File

@ -255,5 +255,7 @@ return [
'withdrawal_destination_id' => 'Destination account',
'deposit_source_id' => 'Source account',
'expected_on' => 'Expected on',
'paid' => 'Paid',
];

View File

@ -102,8 +102,7 @@
<div class="box-header with-border">
<h3 class="box-title">{{ 'categories'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding" id="categoryReport">
</div>
<div class="box-body table-responsive no-padding" id="categoryReport"></div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
@ -111,11 +110,6 @@
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
@ -134,10 +128,19 @@
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
{% include 'reports/partials/bills' %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'bills'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding" id="billReport"></div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
</div>
</div>
</div>
{#{% include 'reports/partials/bills' %}#}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="v1/css/bootstrap-sortable.css?v={{ FF_VERSION }}" type="text/css" media="all"/>
@ -166,6 +169,7 @@
var incomeReportUri = '{{ route('report-data.operations.income', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseReportUri = '{{ route('report-data.operations.expenses', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var incExpReportUri = '{{ route('report-data.operations.operations', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var billReportUri = '{{ route('report-data.bills.overview', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
// uri's for charts:
var accountChartUri = '{{ route('chart.account.report', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';

View File

@ -20,10 +20,15 @@
</td>
{% for account in report.accounts %}
{% if budget.spent[account.id] %}
<td style="text-align: right;">
{{ formatAmountBySymbol(budget.spent[account.id].spent, budget.spent[account.id].currency_symbol, budget.spent[account.id].currency_decimal_places) }}
</td>
<td style="text-align: right;">
{{ formatAmountBySymbol(budget.spent[account.id].spent, budget.spent[account.id].currency_symbol, budget.spent[account.id].currency_decimal_places) }}
</td>
{% else %}
{% if report.accounts[account.id].sum != 0 %}
<td>&nbsp;</td>
{% endif %}
{% endif %}
{% endfor %}
<td style="text-align: right;">
{% for sum in report.sums[budget.budget_id] %}

View File

@ -1,19 +1,51 @@
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'bills'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ trans('form.name') }}</th>
<th data-defaultsign="_19" class="hidden-xs" style="text-align: right;">{{ trans('form.amount_min') }}</th>
<th data-defaultsign="_19" class="hidden-xs" style="text-align: right;">{{ trans('form.amount_max') }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ trans('form.amount') }}</th>
<th data-defaultsign="_19" class="hidden-xs" style="text-align: right;">{{ trans('form.under') }}</th>
<th data-defaultsign="_19">{{ trans('form.expected_on') }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ trans('form.paid') }}</th>
</tr>
</thead>
<tbody>
{% for bill in report.bills %}
{% if bill.expected_dates|length > 0 and bill.paid_moments|length > 0 and bill.active %}
<tr>
<td>
<a href="{{ route('bills.show',bill.id) }}">{{ bill.name }}</a>
</td>
<td style="text-align:right;">
{{ formatAmountBySymbol(bill.amount_min, bill.currency_symbol, bill.currency_decimal_places) }}
</td>
<td style="text-align:right;">
{{ formatAmountBySymbol(bill.amount_max, bill.currency_symbol, bill.currency_decimal_places) }}
</td>
<td>
{% for date in bill.expected_dates %}
{{ date.formatLocalized(monthAndDayFormat) }}<br/>
{% endfor %}
</td>
<td style="text-align:right;">
{% set hitCount = 0 %}
{% for journals in bill.paid_moments %}
{% for journal in journals %}
{% set hitCount = hitCount+1 %}
<a title="{{ journal.date.formatLocalized(monthAndDayFormat) }}"
href="{{ route('transactions.show', [journal.transaction_group_id]) }}">{{ journal.description }}</a>,
{{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places) }}
<br/>
{% endfor %}
{% endfor %}
{% if hitCount == 0 %}
<em>{{ 'notCharged'|_ }}</em>
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
{% for line in bills.getBills %}
<tr>
<td data-value="{{ line.getBill.name }}">
@ -50,5 +82,3 @@
{% endfor %}
</tbody>
</table>
</div>
</div>

View File

@ -701,6 +701,16 @@ Route::group(
}
);
/**
* Report Data Bill Controller
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Report', 'prefix' => 'report-data/bill', 'as' => 'report-data.bills.'],
static function () {
Route::get('overview/{accountList}/{start_date}/{end_date}', ['uses' => 'BillController@overview', 'as' => 'overview']);
}
);
/**
* Report Data Expense / Revenue Account Controller
*/