Budget report cleaned up and multi-currency.

This commit is contained in:
James Cole 2019-09-02 20:30:47 +02:00
parent 0fd7e4363d
commit 771cf73171
11 changed files with 487 additions and 348 deletions

View File

@ -185,6 +185,7 @@ class ChartJsGenerator implements GeneratorInterface
// make larger than 0 // make larger than 0
$chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$value); $chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$value);
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['labels'][] = $key; $chartData['labels'][] = $key;
++$index; ++$index;
} }

View File

@ -79,7 +79,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
->render(); ->render();
} catch (Throwable $e) { } catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage())); Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage()));
$result = 'Could not render report view.'; $result = sprintf('Could not render report view: %s', $e->getMessage());
} }
return $result; return $result;

View File

@ -1,4 +1,4 @@
<?php <?php /** @noinspection MoreThanThreeArgumentsInspection */
/** /**
* BudgetReportController.php * BudgetReportController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com * Copyright (c) 2017 thegrumpydictator@gmail.com
@ -24,12 +24,9 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface; use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Http\Controllers\AugumentData; use FireflyIII\Support\Http\Controllers\AugumentData;
use FireflyIII\Support\Http\Controllers\TransactionCalculation; use FireflyIII\Support\Http\Controllers\TransactionCalculation;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
@ -44,13 +41,12 @@ use Illuminate\Support\Collection;
class BudgetReportController extends Controller class BudgetReportController extends Controller
{ {
use AugumentData, TransactionCalculation; use AugumentData, TransactionCalculation;
/** @var BudgetLimitRepositoryInterface */
private $blRepository;
/** @var BudgetRepositoryInterface The budget repository */
private $budgetRepository;
/** @var GeneratorInterface Chart generation methods. */ /** @var GeneratorInterface Chart generation methods. */
private $generator; private $generator;
/** @var OperationsRepositoryInterface */
private $opsRepository;
/** /**
* BudgetReportController constructor. * BudgetReportController constructor.
* *
@ -61,78 +57,172 @@ class BudgetReportController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
$this->generator = app(GeneratorInterface::class); $this->generator = app(GeneratorInterface::class);
$this->budgetRepository = app(BudgetRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
return $next($request); return $next($request);
} }
); );
} }
/** /**
* Chart that groups expenses by the account. * Chart that groups the expenses by budget.
*
* TODO this chart is not multi-currency aware.
* *
* @param Collection $accounts * @param Collection $accounts
* @param Collection $budgets * @param Collection $budgets
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param string $others
* *
* @return JsonResponse * @return JsonResponse
*/ */
public function accountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse public function budgetExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): JsonResponse
{ {
/** @var MetaPieChartInterface $helper */ $result = [];
$helper = app(MetaPieChartInterface::class); $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$helper->setAccounts($accounts);
$helper->setBudgets($budgets); // loop expenses.
$helper->setStart($start); foreach ($spent as $currency) {
$helper->setEnd($end); foreach ($currency['budgets'] as $budget) {
$helper->setCollectOtherObjects(1 === (int)$others); $title = sprintf('%s (%s)', $budget['name'], $currency['currency_name']);
$chartData = $helper->generate('expense', 'account'); $result[$title] = $result[$title] ?? [
$data = $this->generator->pieChart($chartData); 'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
];
foreach ($budget['transaction_journals'] as $journal) {
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
}
}
}
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data); return response()->json($data);
} }
/** /**
* Chart that groups the expenses by budget. * Chart that groups the expenses by budget.
* *
* TODO this chart is not multi-currency aware. * @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
public function categoryExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): JsonResponse
{
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
// loop expenses.
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$result[$title] = $result[$title] ?? [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
];
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
}
}
}
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
/**
* Chart that groups expenses by the account.
* *
* @param Collection $accounts * @param Collection $accounts
* @param Collection $budgets * @param Collection $budgets
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param string $others
* *
* @return JsonResponse * @return JsonResponse
*/ */
public function budgetExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse public function destinationAccountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): JsonResponse
{ {
/** @var MetaPieChartInterface $helper */ $result = [];
$helper = app(MetaPieChartInterface::class); $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$helper->setAccounts($accounts);
$helper->setBudgets($budgets); // loop expenses.
$helper->setStart($start); foreach ($spent as $currency) {
$helper->setEnd($end); foreach ($currency['budgets'] as $budget) {
$helper->setCollectOtherObjects(1 === (int)$others);
$chartData = $helper->generate('expense', 'budget');
$data = $this->generator->pieChart($chartData); foreach ($budget['transaction_journals'] as $journal) {
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$result[$title] = $result[$title] ?? [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
];
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
}
}
}
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data); return response()->json($data);
} }
/** /**
* Main overview of a budget in the budget report. * Main overview of a budget in the budget report.
* *
* TODO this chart is not multi-currency aware. * @param Collection $accounts
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
public function mainChart(Collection $accounts, Budget $budget, Carbon $start, Carbon $end): JsonResponse
{
$chartData = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, new Collection([$budget]));
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
// loop expenses.
foreach ($spent as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf(
'%s (%s)', (string)trans('firefly.spent_in_specific_budget', ['budget' => $budget['name']]), $currency['currency_name']
),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
'currency_id' => $currency['currency_id'],
'entries' => $this->makeEntries($start, $end),
];
foreach ($currency['budgets'] as $currentBudget) {
foreach ($currentBudget['transaction_journals'] as $journal) {
$key = $journal['date']->formatLocalized($format);
$amount = app('steam')->positive($journal['amount']);
$chartData[$spentKey]['entries'][$key] = $chartData[$spentKey]['entries'][$key] ?? '0';
$chartData[$spentKey]['entries'][$key] = bcadd($chartData[$spentKey]['entries'][$key], $amount);
}
}
}
$data = $this->generator->multiSet($chartData);
return response()->json($data);
}
/**
* Chart that groups expenses by the account.
* *
* @param Collection $accounts * @param Collection $accounts
* @param Collection $budgets * @param Collection $budgets
@ -140,82 +230,56 @@ class BudgetReportController extends Controller
* @param Carbon $end * @param Carbon $end
* *
* @return JsonResponse * @return JsonResponse
*
*/ */
public function mainChart(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): JsonResponse public function sourceAccountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): JsonResponse
{ {
$cache = new CacheProperties; $result = [];
$cache->addProperty('chart.budget.report.main'); $spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$cache->addProperty($accounts);
$cache->addProperty($budgets);
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$function = app('navigation')->preferredEndOfPeriod($start, $end);
$chartData = [];
$currentStart = clone $start;
// prep chart data: // loop expenses.
foreach ($budgets as $budget) { foreach ($spent as $currency) {
$chartData[$budget->id] = [ foreach ($currency['budgets'] as $budget) {
'label' => (string)trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
$chartData[$budget->id . '-sum'] = [
'label' => (string)trans('firefly.sum_of_expenses_in_budget', ['budget' => $budget->name]),
'type' => 'line',
'fill' => false,
'yAxisID' => 'y-axis-1',
'entries' => [],
];
$chartData[$budget->id . '-left'] = [
'label' => (string)trans('firefly.left_in_budget_limit', ['budget' => $budget->name]),
'type' => 'bar',
'fill' => false,
'yAxisID' => 'y-axis-0',
'entries' => [],
];
}
$allBudgetLimits = $this->blRepository->getAllBudgetLimits($start, $end);
$sumOfExpenses = [];
$leftOfLimits = [];
while ($currentStart < $end) {
$currentEnd = clone $currentStart;
$currentEnd = $currentEnd->$function();
$expenses = $this->groupByBudget($this->getExpensesInBudgets($accounts, $budgets, $currentStart, $currentEnd));
$label = $currentStart->formatLocalized($format);
/** @var Budget $budget */
foreach ($budgets as $budget) {
// get budget limit(s) for this period):
$budgetLimits = $this->filterBudgetLimits($allBudgetLimits, $budget, $currentStart, $currentEnd);
$currentExpenses = $expenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = $sumOfExpenses[$budget->id] ?? '0';
$sumOfExpenses[$budget->id] = bcadd($currentExpenses, $sumOfExpenses[$budget->id]);
$chartData[$budget->id]['entries'][$label] = bcmul($currentExpenses, '-1');
$chartData[$budget->id . '-sum']['entries'][$label] = bcmul($sumOfExpenses[$budget->id], '-1');
if (count($budgetLimits) > 0) { foreach ($budget['transaction_journals'] as $journal) {
$budgetLimitId = $budgetLimits->first()->id; $title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$leftOfLimits[$budgetLimitId] = $leftOfLimits[$budgetLimitId] ?? (string)$budgetLimits->sum('amount'); $result[$title] = $result[$title] ?? [
$leftOfLimits[$budgetLimitId] = bcadd($leftOfLimits[$budgetLimitId], $currentExpenses); 'amount' => '0',
$chartData[$budget->id . '-left']['entries'][$label] = $leftOfLimits[$budgetLimitId]; 'currency_symbol' => $currency['currency_symbol'],
];
$amount = app('steam')->positive($journal['amount']);
$result[$title]['amount'] = bcadd($result[$title]['amount'], $amount);
} }
} }
/** @var Carbon $currentStart */
$currentStart = clone $currentEnd;
$currentStart->addDay();
} }
$data = $this->generator->multiSet($chartData); $data = $this->generator->multiCurrencyPieChart($result);
$cache->store($data);
return response()->json($data); return response()->json($data);
} }
/**
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
private function makeEntries(Carbon $start, Carbon $end): array
{
$return = [];
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$key = $currentStart->formatLocalized($format);
$return[$key] = '0';
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
return $return;
}
} }

View File

@ -148,6 +148,58 @@ class BudgetController extends Controller
return view('reports.budget.partials.accounts', compact('sums', 'report')); return view('reports.budget.partials.accounts', compact('sums', 'report'));
} }
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*/
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
// get all journals.
$opsRepository = app(OperationsRepositoryInterface::class);
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$result[$destinationId] = $result[$destinationId] ?? [
'transactions' => 0,
'sum' => '0',
'avg' => '0',
'avg_float' => 0,
'destination_account_name' => $journal['destination_account_name'],
'destination_account_id' => $journal['destination_account_id'],
'currency_id' => $currency['currency_id'],
'currency_name' => $currency['currency_name'],
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$destinationId]['transactions']++;
$result[$destinationId]['sum'] = bcadd($journal['amount'], $result[$destinationId]['sum']);
$result[$destinationId]['avg'] = bcdiv($result[$destinationId]['sum'], (string)$result[$destinationId]['transactions']);
$result[$destinationId]['avg_float'] = (float)$result[$destinationId]['avg'];
}
}
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'avg_float');
array_multisort($amounts, SORT_ASC, $result);
try {
$result = view('reports.budget.partials.avg-expenses', compact('result'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
}
return $result;
}
/** /**
* @param Collection $accounts * @param Collection $accounts
* @param Collection $budgets * @param Collection $budgets
@ -238,7 +290,6 @@ class BudgetController extends Controller
return $result; return $result;
} }
/** /**
* Show budget overview for a period. * Show budget overview for a period.
* *
@ -304,4 +355,52 @@ class BudgetController extends Controller
return $result; return $result;
} }
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*/
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
// get all journals.
$opsRepository = app(OperationsRepositoryInterface::class);
$spent = $opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$result[] = [
'description' => $journal['description'],
'transaction_group_id' => $journal['transaction_group_id'],
'amount_float' => (float)$journal['amount'],
'amount' => $journal['amount'],
'date' => $journal['date']->formatLocalized($this->monthAndDayFormat),
'destination_account_name' => $journal['destination_account_name'],
'destination_account_id' => $journal['destination_account_id'],
'currency_id' => $currency['currency_id'],
'currency_name' => $currency['currency_name'],
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
}
}
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'amount_float');
array_multisort($amounts, SORT_ASC, $result);
try {
$result = view('reports.budget.partials.top-expenses', compact('result'))->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
}
return $result;
}
} }

View File

@ -211,7 +211,7 @@ class OperationsRepository implements OperationsRepositoryInterface
if (null === $budgets || (null !== $budgets && 0 === $budgets->count())) { if (null === $budgets || (null !== $budgets && 0 === $budgets->count())) {
$collector->setBudgets($this->getBudgets()); $collector->setBudgets($this->getBudgets());
} }
$collector->withBudgetInformation(); $collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];
@ -248,9 +248,15 @@ class OperationsRepository implements OperationsRepositoryInterface
$array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = [ $array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = [
'amount' => app('steam')->negative($journal['amount']), 'amount' => app('steam')->negative($journal['amount']),
'source_account_id' => $journal['source_account_id'], 'destination_account_id' => $journal['destination_account_id'],
'date' => $journal['date'], 'destination_account_name' => $journal['destination_account_name'],
'source_account_id' => $journal['source_account_id'],
'source_account_name' => $journal['source_account_name'],
'category_name' => $journal['category_name'],
'description' => $journal['description'],
'transaction_group_id' => $journal['transaction_group_id'],
'date' => $journal['date'],
]; ];
} }

View File

@ -18,8 +18,6 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>. * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** global: budgetExpenseUri, accountExpenseUri, mainUri */
$(function () { $(function () {
"use strict"; "use strict";
drawChart(); drawChart();
@ -28,14 +26,9 @@ $(function () {
loadAjaxPartial('budgetsHolder', budgetsUri); loadAjaxPartial('budgetsHolder', budgetsUri);
loadAjaxPartial('accountPerbudgetHolder', accountPerBudgetUri); loadAjaxPartial('accountPerbudgetHolder', accountPerBudgetUri);
loadAjaxPartial('topExpensesHolder', topExpensesUri);
loadAjaxPartial('avgExpensesHolder', avgExpensesUri);
$('#budgets-out-pie-chart-checked').on('change', function () {
redrawPieChart('budgets-out-pie-chart', budgetExpenseUri);
});
$('#accounts-out-pie-chart-checked').on('change', function () {
redrawPieChart('accounts-out-pie-chart', accountExpenseUri);
});
}); });
@ -43,27 +36,21 @@ $(function () {
function drawChart() { function drawChart() {
"use strict"; "use strict";
// month view: $.each($('.main_budget_canvas'), function (i, v) {
doubleYNonStackedChart(mainUri, 'in-out-chart'); var canvas = $(v);
columnChart(canvas.data('url'), canvas.attr('id'));
});
// draw pie chart of income, depending on "show other transactions too": // draw pie chart of income, depending on "show other transactions too":
redrawPieChart('budgets-out-pie-chart', budgetExpenseUri); redrawPieChart('budgets-out-pie-chart', budgetExpenseUri);
redrawPieChart('accounts-out-pie-chart', accountExpenseUri); redrawPieChart('categories-out-pie-chart', categoryExpenseUri);
redrawPieChart('source-accounts-pie-chart', sourceExpenseUri);
redrawPieChart('dest-accounts-pie-chart', destinationExpenseUri);
} }
function redrawPieChart(container, uri) { function redrawPieChart(container, uri) {
"use strict"; "use strict";
var checkbox = $('#' + container + '-checked'); multiCurrencyPieChart(uri, container);
var others = '0';
// check if box is checked:
if (checkbox.prop('checked')) {
others = '1';
}
uri = uri.replace('OTHERS', others);
pieChart(uri, container);
} }

View File

@ -888,6 +888,11 @@ return [
'cannot_change_amount_reconciled' => 'You can\'t change the amount of reconciled transactions.', 'cannot_change_amount_reconciled' => 'You can\'t change the amount of reconciled transactions.',
'no_budget' => '(no budget)', 'no_budget' => '(no budget)',
'account_per_budget' => 'Account per budget', 'account_per_budget' => 'Account per budget',
'all_other_budgets' => '(all other budgets)',
'all_other_accounts' => '(all other accounts)',
'expense_per_source_account' => 'Expenses per source account',
'expense_per_destination_account' => 'Expenses per destination account',
'average_spending_per_destination' => 'Average expense per destination account',
'no_budget_squared' => '(no budget)', 'no_budget_squared' => '(no budget)',
'perm-delete-many' => 'Deleting many items in one go can be very disruptive. Please be cautious. You can delete part of a split transaction from this page, so take care.', 'perm-delete-many' => 'Deleting many items in one go can be very disruptive. Please be cautious. You can delete part of a split transaction from this page, so take care.',
'mass_deleted_transactions_success' => 'Deleted :amount transaction(s).', 'mass_deleted_transactions_success' => 'Deleted :amount transaction(s).',

View File

@ -8,7 +8,6 @@
<div class="row"> <div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
{# spent in these budgets per account, per currency.#}
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'accounts'|_ }}</h3> <h3 class="box-title">{{ 'accounts'|_ }}</h3>
@ -51,213 +50,100 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
{% if budgets.count > 1 %} <div class="col-lg-6 col-md-6">
<div class="col-lg-4 col-md-6"> <div class="box">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expense_per_budget'|_ }}</h3>
</div>
<div class="box-body">
<div style="width:100%;margin:0 auto;">
<canvas id="budgets-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
</div>
<label style="font-weight:normal;">
<input type="checkbox" id="budgets-out-pie-chart-checked">
<small>{{ 'include_expense_not_in_budget'|_ }}</small>
</label>
</div>
</div>
</div>
{% endif %}
<div class="col-lg-4 col-md-6">
<div class="box" id="pieCharts">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'expense_per_account'|_ }}</h3> <h3 class="box-title">{{ 'expense_per_budget'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<div style="width:100%;margin:0 auto;"> <div style="width:100%;margin:0 auto;">
<canvas id="accounts-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas> <canvas id="budgets-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
</div> </div>
<label style="font-weight:normal;">
<input type="checkbox" id="accounts-out-pie-chart-checked">
<small>{{ 'include_expense_not_in_account'|_ }}</small>
</label>
</div> </div>
</div> </div>
</div> </div>
</div> <div class="col-lg-6 col-md-6">
<div class="box">
<div class="row">
<div class="col-lg-12">
<div class="box" id="incomeAndExpensesChart">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'income_and_expenses'|_ }}</h3> <h3 class="box-title">{{ 'expense_per_category'|_ }}</h3>
</div> </div>
<div class="box-body"> <div class="box-body">
{# <div style="width:100%;margin:0 auto;">
Here be a chart with the budget limits as well if relevant.<br> <canvas id="categories-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
amount spent vs budget limit reps<br> </div>
over the entire period the amount spent would rise and the budget limit rep would be like a heart beat jumping up and down<br>
needs to be two axes to work<br>#}
<canvas id="in-out-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
{% if averageExpenses|length > 0 %} <div class="col-lg-6 col-md-6">
<div class="col-lg-6"> <div class="box">
<div class="box"> <div class="box-header with-border">
<div class="box-header with-border"> <h3 class="box-title">{{ 'expense_per_source_account'|_ }}</h3>
<h3 class="box-title">{{ 'average_spending_per_account'|_ }}</h3> </div>
<div class="box-body">
<div style="width:100%;margin:0 auto;">
<canvas id="source-accounts-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
</div> </div>
<div class="box-body table-responsive no-padding">
</div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
{#
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'spent_average'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'total'|_ }}</th>
<th data-defaultsign="_19">{{ 'transaction_count'|_ }}</th>
</tr>
</thead>
<tbody>
{% set totalCount = 0 %}
{% set totalSum = 0 %}
{% for row in averageExpenses %}
{% set totalCount = totalCount+ row.count %}
{% set totalSum = totalSum + row.sum %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-value="{{ row.name }}">
<a href="{{ route('accounts.show', row.id) }}">{{ row.name }}</a>
</td>
<td data-value="{{ row.average }}" style="text-align: right;">
{{ row.average|formatAmount }}
</td>
<td data-value="{{ row.sum }}" style="text-align: right;">
{{ row.sum|formatAmount }}
</td>
<td data-value="{{ row.count }}">
{{ row.count }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if averageExpenses|length > listLength %}
<tr>
<td colspan="4" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td colspan="2">
{{ 'sum'|_ }}
</td>
<td style="text-align:right">{{ totalSum|formatAmount }}</td>
<td>{{ totalCount }}</td>
</tr>
</tfoot>
</table>
</div>
#}
</div> </div>
</div> </div>
{% endif %} </div>
{% if topExpenses|length > 0 %} <div class="col-lg-6 col-md-6">
<div class="col-lg-6"> <div class="box">
<div class="box-header with-border">
<div class="box"> <h3 class="box-title">{{ 'expense_per_destination_account'|_ }}</h3>
<div class="box-header with-border"> </div>
<h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3> <div class="box-body">
<div style="width:100%;margin:0 auto;">
<canvas id="dest-accounts-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
</div> </div>
<div class="box-body table-responsive no-padding">
</div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
{#
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsort="disabled">{{ 'description'|_ }}</th>
<th data-defaultsign="month">{{ 'date'|_ }}</th>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'amount'|_ }}</th>
</tr>
</thead>
<tbody>
{% set totalSum = 0 %}
{% for row in topExpenses %}
{% set totalSum = totalSum + row.amount %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-sortable="false">
<a href="{{ route('transactions.show', row.transaction_group_id) }}">
{% if row.group_title|length > 0 %}
{{ row.group_title }} ({{ row.description }})
{% else %}
{{ row.description }}
{% endif %}
</a>
</td>
<td data-value="{{ row.date.format('Y-m-d') }}">
{{ row.date.formatLocalized(monthAndDayFormat) }}
</td>
<td data-value="{{ row.destination_account_name }}">
<a href="{{ route('accounts.show', row.destination_account_id) }}">
{{ row.destination_account_name }}
</a>
</td>
<td data-value="{{ row.amount }}" style="text-align: right;">
{{ formatAmountBySymbol(row.amount, row.currency_symbol, row.currency_decimal_places) }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if topExpenses|length > listLength %}
<tr>
<td colspan="4" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
<tr>
<td colspan="3">
{{ 'sum'|_ }}
</td>
<td style="text-align:right">{{ totalSum|formatAmount }}</td>
</tr>
</tfoot>
</table>
</div>
#}
</div> </div>
</div> </div>
{% endif %} </div>
</div>
{% for budget in budgets %}
<div class="row">
<div class="col-lg-12">
<div class="box main_budget_chart">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expenses'|_ }} ({{ budget.name }})</h3>
</div>
<div class="box-body">
<canvas class="main_budget_canvas" data-url="{{ route('chart.budget.main', [accountIds, budget.id, start.format('Ymd'), end.format('Ymd')]) }}" id="in-out-chart-{{ budget.id }}" style="width:100%;height:400px;" height="400" width="100%"></canvas>
</div>
</div>
</div>
</div>
{% endfor %}
<div class="row">
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'average_spending_per_destination'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding" id="avgExpensesHolder">
</div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
</div>
<div class="box-body table-responsive no-padding" id="topExpensesHolder">
</div>
{# loading indicator #}
<div class="overlay">
<i class="fa fa-refresh fa-spin"></i>
</div>
</div>
</div>
</div> </div>
{% endblock %} {% endblock %}
@ -277,13 +163,16 @@
// html block URI's: // html block URI's:
var accountsUri = '{{ route('report-data.budget.accounts', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}'; var accountsUri = '{{ route('report-data.budget.accounts', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var budgetsUri = '{{ route('report-data.budget.budgets', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}'; var budgetsUri = '{{ route('report-data.budget.budgets', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var accountPerBudgetUri = '{{ route('report-data.budget.account-per-budget', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}'; var accountPerBudgetUri = '{{ route('report-data.budget.account-per-budget', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var avgExpensesUri = '{{ route('report-data.budget.avg-expenses', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var topExpensesUri = '{{ route('report-data.budget.top-expenses', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
// chart uri's // chart uri's
var budgetExpenseUri = '{{ route('chart.budget.budget-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; var budgetExpenseUri = '{{ route('chart.budget.budget-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var accountExpenseUri = '{{ route('chart.budget.account-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; var categoryExpenseUri = '{{ route('chart.budget.category-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var mainUri = '{{ route('chart.budget.main', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}'; var sourceExpenseUri = '{{ route('chart.budget.source-account-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
var destinationExpenseUri = '{{ route('chart.budget.destination-account-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
</script> </script>

View File

@ -0,0 +1,46 @@
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'spent_average'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'total'|_ }}</th>
<th data-defaultsign="_19">{{ 'transaction_count'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in result %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-sortable="false">
<a href="{{ route('accounts.show', row.destination_account_id) }}">
{{ row.destination_account_name }}
</a>
</td>
<td data-value="{{ row.avg }}" style="text-align: right;">
{{ formatAmountBySymbol(row.avg, row.currency_symbol, row.currency_decimal_places) }}
</td>
<td data-value="{{ row.sum }}" style="text-align: right;">
{{ formatAmountBySymbol(row.sum, row.currency_symbol, row.currency_decimal_places) }}
</td>
<td data-value="{{ row.transactions }}">
{{ row.transactions }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if result|length > listLength %}
<tr>
<td colspan="4" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
</tfoot>
</table>

View File

@ -0,0 +1,48 @@
<table class="table table-hover sortable">
<thead>
<tr>
<th data-defaultsort="disabled">{{ 'description'|_ }}</th>
<th data-defaultsign="month">{{ 'date'|_ }}</th>
<th data-defaultsign="az">{{ 'account'|_ }}</th>
<th data-defaultsign="_19" style="text-align: right;">{{ 'amount'|_ }}</th>
</tr>
</thead>
<tbody>
{% for row in result %}
{% if loop.index > listLength %}
<tr class="overListLength">
{% else %}
<tr>
{% endif %}
<td data-sortable="false">
<a href="{{ route('transactions.show', row.transaction_group_id) }}">
{{ row.description }}
</a>
</td>
<td data-sortable="false">
{{ row.date }}
</td>
<td data-sortable="false">
<a href="{{ route('accounts.show', row.destination_account_id) }}">
{{ row.destination_account_name }}
</a>
</td>
<td data-value="{{ row.amount }}" style="text-align: right;">
{{ formatAmountBySymbol(row.amount, row.currency_symbol, row.currency_decimal_places) }}
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if result|length > listLength %}
<tr>
<td colspan="4" class="active">
<a href="#" class="listLengthTrigger">{{ trans('firefly.show_full_list',{number:incomeTopLength}) }}</a>
</td>
</tr>
{% endif %}
</tfoot>
</table>

View File

@ -367,19 +367,11 @@ Route::group(
Route::get('expense-expense/{budget}/{budgetLimit?}', ['uses' => 'BudgetController@expenseExpense', 'as' => 'expense-expense']); Route::get('expense-expense/{budget}/{budgetLimit?}', ['uses' => 'BudgetController@expenseExpense', 'as' => 'expense-expense']);
// these charts are used in reports (category reports): // these charts are used in reports (category reports):
Route::get( Route::get('category/expense/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetReportController@categoryExpense', 'as' => 'category-expense']);
'budget/expense/{accountList}/{budgetList}/{start_date}/{end_date}/{others}', Route::get('budget/expense/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetReportController@budgetExpense', 'as' => 'budget-expense']);
['uses' => 'BudgetReportController@budgetExpense', 'as' => 'budget-expense'] Route::get('source-account/expense/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetReportController@sourceAccountExpense', 'as' => 'source-account-expense']);
); Route::get('destination-account/expense/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetReportController@destinationAccountExpense', 'as' => 'destination-account-expense']);
Route::get( Route::get('operations/{accountList}/{budget}/{start_date}/{end_date}', ['uses' => 'BudgetReportController@mainChart', 'as' => 'main']);
'account/expense/{accountList}/{budgetList}/{start_date}/{end_date}/{others}',
['uses' => 'BudgetReportController@accountExpense', 'as' => 'account-expense']
);
Route::get(
'operations/{accountList}/{budgetList}/{start_date}/{end_date}',
['uses' => 'BudgetReportController@mainChart', 'as' => 'main']
);
} }
); );
@ -401,19 +393,19 @@ Route::group(
// these charts are used in reports (category reports): // these charts are used in reports (category reports):
Route::get( Route::get(
'category/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', 'category/income/{accountList}/{categoryList}/{start_date}/{end_date}',
['uses' => 'CategoryReportController@categoryIncome', 'as' => 'category-income'] ['uses' => 'CategoryReportController@categoryIncome', 'as' => 'category-income']
); );
Route::get( Route::get(
'category/expense/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', 'category/expense/{accountList}/{categoryList}/{start_date}/{end_date}',
['uses' => 'CategoryReportController@categoryExpense', 'as' => 'category-expense'] ['uses' => 'CategoryReportController@categoryExpense', 'as' => 'category-expense']
); );
Route::get( Route::get(
'account/income/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', 'account/income/{accountList}/{categoryList}/{start_date}/{end_date}',
['uses' => 'CategoryReportController@accountIncome', 'as' => 'account-income'] ['uses' => 'CategoryReportController@accountIncome', 'as' => 'account-income']
); );
Route::get( Route::get(
'account/expense/{accountList}/{categoryList}/{start_date}/{end_date}/{others}', 'account/expense/{accountList}/{categoryList}/{start_date}/{end_date}',
['uses' => 'CategoryReportController@accountExpense', 'as' => 'account-expense'] ['uses' => 'CategoryReportController@accountExpense', 'as' => 'account-expense']
); );
@ -433,19 +425,19 @@ Route::group(
// these charts are used in reports (tag reports): // these charts are used in reports (tag reports):
Route::get( Route::get(
'tag/income/{accountList}/{tagList}/{start_date}/{end_date}/{others}', 'tag/income/{accountList}/{tagList}/{start_date}/{end_date}',
['uses' => 'TagReportController@tagIncome', 'as' => 'tag-income'] ['uses' => 'TagReportController@tagIncome', 'as' => 'tag-income']
); );
Route::get( Route::get(
'tag/expense/{accountList}/{tagList}/{start_date}/{end_date}/{others}', 'tag/expense/{accountList}/{tagList}/{start_date}/{end_date}',
['uses' => 'TagReportController@tagExpense', 'as' => 'tag-expense'] ['uses' => 'TagReportController@tagExpense', 'as' => 'tag-expense']
); );
Route::get( Route::get(
'account/income/{accountList}/{tagList}/{start_date}/{end_date}/{others}', 'account/income/{accountList}/{tagList}/{start_date}/{end_date}',
['uses' => 'TagReportController@accountIncome', 'as' => 'account-income'] ['uses' => 'TagReportController@accountIncome', 'as' => 'account-income']
); );
Route::get( Route::get(
'account/expense/{accountList}/{tagList}/{start_date}/{end_date}/{others}', 'account/expense/{accountList}/{tagList}/{start_date}/{end_date}',
['uses' => 'TagReportController@accountExpense', 'as' => 'account-expense'] ['uses' => 'TagReportController@accountExpense', 'as' => 'account-expense']
); );
@ -815,6 +807,8 @@ Route::group(
Route::get('accounts/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@accounts', 'as' => 'accounts']); Route::get('accounts/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@accounts', 'as' => 'accounts']);
Route::get('budgets/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@budgets', 'as' => 'budgets']); Route::get('budgets/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@budgets', 'as' => 'budgets']);
Route::get('account-per-budget/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@accountPerBudget', 'as' => 'account-per-budget']); Route::get('account-per-budget/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@accountPerBudget', 'as' => 'account-per-budget']);
Route::get('top-expenses/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@topExpenses', 'as' => 'top-expenses']);
Route::get('avg-expenses/{accountList}/{budgetList}/{start_date}/{end_date}', ['uses' => 'BudgetController@avgExpenses', 'as' => 'avg-expenses']);
} }
); );