mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Make budget chart multi-currency
This commit is contained in:
@@ -238,18 +238,22 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
// group by asset account ID:
|
// group by asset account ID:
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$assetId = (int)$journal['source_account_id'];
|
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
|
||||||
$result[$assetId] = $result[$assetId] ?? [
|
$result[$key] = $result[$key] ?? [
|
||||||
'amount' => '0',
|
'amount' => '0',
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
];
|
];
|
||||||
$result[$assetId]['amount'] = bcadd($journal['amount'], $result[$assetId]['amount']);
|
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = $this->getAccountNames(array_keys($result));
|
$names = $this->getAccountNames(array_keys($result));
|
||||||
foreach ($result as $assetId => $info) {
|
foreach ($result as $combinedId => $info) {
|
||||||
$chartData[$names[$assetId]]
|
$parts = explode('-', $combinedId);
|
||||||
= [
|
$assetId = (int)$parts[0];
|
||||||
|
$title = sprintf('%s (%s)', $names[$assetId], $info['currency_name']);
|
||||||
|
$chartData[$title]
|
||||||
|
= [
|
||||||
'amount' => $info['amount'],
|
'amount' => $info['amount'],
|
||||||
'currency_symbol' => $info['currency_symbol'],
|
'currency_symbol' => $info['currency_symbol'],
|
||||||
];
|
];
|
||||||
@@ -298,17 +302,21 @@ class BudgetController extends Controller
|
|||||||
$result = [];
|
$result = [];
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$categoryId = (int)$journal['category_id'];
|
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
|
||||||
$result[$categoryId] = $result[$categoryId] ?? [
|
$result[$key] = $result[$key] ?? [
|
||||||
'amount' => '0',
|
'amount' => '0',
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
];
|
];
|
||||||
$result[$categoryId]['amount'] = bcadd($journal['amount'], $result[$categoryId]['amount']);
|
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = $this->getCategoryNames(array_keys($result));
|
$names = $this->getCategoryNames(array_keys($result));
|
||||||
foreach ($result as $categoryId => $info) {
|
foreach ($result as $combinedId => $info) {
|
||||||
$chartData[$names[$categoryId]] = [
|
$parts = explode('-', $combinedId);
|
||||||
|
$categoryId = (int)$parts[0];
|
||||||
|
$title = sprintf('%s (%s)', $names[$categoryId], $info['currency_name']);
|
||||||
|
$chartData[$title] = [
|
||||||
'amount' => $info['amount'],
|
'amount' => $info['amount'],
|
||||||
'currency_symbol' => $info['currency_symbol'],
|
'currency_symbol' => $info['currency_symbol'],
|
||||||
];
|
];
|
||||||
@@ -359,18 +367,22 @@ class BudgetController extends Controller
|
|||||||
$chartData = [];
|
$chartData = [];
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$opposingId = (int)$journal['destination_account_id'];
|
$key = sprintf('%d-%d', $journal['destination_account_id'], $journal['currency_id']);
|
||||||
$result[$opposingId] = $result[$opposingId] ?? [
|
$result[$key] = $result[$key] ?? [
|
||||||
'amount' => '0',
|
'amount' => '0',
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
];
|
];
|
||||||
$result[$opposingId]['amount'] = bcadd($journal['amount'], $result[$opposingId]['amount']);
|
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = $this->getAccountNames(array_keys($result));
|
$names = $this->getAccountNames(array_keys($result));
|
||||||
foreach ($result as $opposingId => $info) {
|
foreach ($result as $combinedId => $info) {
|
||||||
$name = $names[$opposingId] ?? 'no name';
|
$parts = explode('-', $combinedId);
|
||||||
$chartData[$name] = [
|
$opposingId = (int)$parts[0];
|
||||||
|
$name = $names[$opposingId] ?? 'no name';
|
||||||
|
$title = sprintf('%s (%s)', $name, $info['currency_name']);
|
||||||
|
$chartData[$title] = [
|
||||||
'amount' => $info['amount'],
|
'amount' => $info['amount'],
|
||||||
'currency_symbol' => $info['currency_symbol'],
|
'currency_symbol' => $info['currency_symbol'],
|
||||||
];
|
];
|
||||||
|
|||||||
12
public/v1/js/ff/budgets/show.js
vendored
12
public/v1/js/ff/budgets/show.js
vendored
@@ -24,14 +24,14 @@ $(function () {
|
|||||||
"use strict";
|
"use strict";
|
||||||
if (budgetLimitID > 0) {
|
if (budgetLimitID > 0) {
|
||||||
otherCurrencyLineChart(budgetChartUri, 'budgetOverview', currencySymbol);
|
otherCurrencyLineChart(budgetChartUri, 'budgetOverview', currencySymbol);
|
||||||
pieChart(expenseCategoryUri, 'budget-cat-out');
|
multiCurrencyPieChart(expenseCategoryUri, 'budget-cat-out');
|
||||||
pieChart(expenseAssetUri, 'budget-asset-out');
|
multiCurrencyPieChart(expenseAssetUri, 'budget-asset-out');
|
||||||
pieChart(expenseExpenseUri, 'budget-expense-out');
|
multiCurrencyPieChart(expenseExpenseUri, 'budget-expense-out');
|
||||||
}
|
}
|
||||||
if (budgetLimitID === 0) {
|
if (budgetLimitID === 0) {
|
||||||
columnChart(budgetChartUri, 'budgetOverview');
|
columnChart(budgetChartUri, 'budgetOverview');
|
||||||
pieChart(expenseCategoryUri, 'budget-cat-out');
|
multiCurrencyPieChart(expenseCategoryUri, 'budget-cat-out');
|
||||||
pieChart(expenseAssetUri, 'budget-asset-out');
|
multiCurrencyPieChart(expenseAssetUri, 'budget-asset-out');
|
||||||
pieChart(expenseExpenseUri, 'budget-expense-out');
|
multiCurrencyPieChart(expenseExpenseUri, 'budget-expense-out');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user