Account chart can display multiple currencies.

This commit is contained in:
James Cole 2017-04-15 17:26:03 +02:00
parent c7984d4363
commit 209a907c61
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 15 additions and 5 deletions

View File

@ -81,6 +81,9 @@ class ChartJsGenerator implements GeneratorInterface
if (isset($set['fill'])) {
$currentSet['fill'] = $set['fill'];
}
if (isset($set['currency_symbol'])) {
$currentSet['currency_symbol'] = $set['currency_symbol'];
}
$chartData['datasets'][] = $currentSet;
}

View File

@ -26,6 +26,7 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Log;
@ -501,11 +502,16 @@ class AccountController extends Controller
}
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$chartData = [];
foreach ($accounts as $account) {
$currency = $repository->find(intval($account->getMeta('currency_id')));
$currentSet = [
'label' => $account->name,
'entries' => [],
'label' => $account->name,
'currency_symbol' => $currency->symbol,
'entries' => [],
];
$currentStart = clone $start;
$range = Steam::balanceInRange($account, $start, clone $end);

View File

@ -42,7 +42,8 @@ var defaultChartOptions = {
callbacks: {
label: function (tooltipItem, data) {
"use strict";
return data.datasets[tooltipItem.datasetIndex].label + ': ' + accounting.formatMoney(tooltipItem.yLabel);
return data.datasets[tooltipItem.datasetIndex].label + ': ' +
accounting.formatMoney(tooltipItem.yLabel, data.datasets[tooltipItem.datasetIndex].currency_symbol);
}
}
}

View File

@ -91,7 +91,7 @@ function doubleYChart(URI, container) {
"use strict";
var colorData = true;
var options = defaultChartOptions;
var options = $.extend(true, {}, defaultChartOptions);
options.scales.yAxes = [
// y axis 0:
{
@ -141,7 +141,7 @@ function doubleYNonStackedChart(URI, container) {
"use strict";
var colorData = true;
var options = defaultChartOptions;
var options = $.extend(true, {}, defaultChartOptions);
options.scales.yAxes = [
// y axis 0:
{