mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix some charts.
This commit is contained in:
parent
cacc58ee0c
commit
f7d6a4c6f9
@ -215,19 +215,18 @@ class AccountController extends Controller
|
|||||||
$budgetIds = [];
|
$budgetIds = [];
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$currencyName = $journal['currency_name'];
|
$budgetId = (int)$journal['budget_id'];
|
||||||
$budgetId = (int)$journal['budget_id'];
|
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
|
||||||
$combi = $budgetId . $currencyName;
|
$budgetIds[] = $budgetId;
|
||||||
$budgetIds[] = $budgetId;
|
if (!isset($result[$key])) {
|
||||||
if (!isset($result[$combi])) {
|
$result[$key] = [
|
||||||
$result[$combi] = [
|
|
||||||
'total' => '0',
|
'total' => '0',
|
||||||
'budget_id' => $budgetId,
|
'budget_id' => $budgetId,
|
||||||
'currency' => $currencyName,
|
'currency_name' => $journal['currency_name'],
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = $this->getBudgetNames($budgetIds);
|
$names = $this->getBudgetNames($budgetIds);
|
||||||
@ -235,7 +234,7 @@ class AccountController extends Controller
|
|||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$budgetId = $row['budget_id'];
|
$budgetId = $row['budget_id'];
|
||||||
$name = $names[$budgetId];
|
$name = $names[$budgetId];
|
||||||
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency']]);
|
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
|
||||||
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +277,7 @@ class AccountController extends Controller
|
|||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('chart.account.expense-category');
|
$cache->addProperty('chart.account.expense-category');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
@ -287,31 +286,26 @@ class AccountController extends Controller
|
|||||||
$journals = $collector->getExtractedJournals();
|
$journals = $collector->getExtractedJournals();
|
||||||
$result = [];
|
$result = [];
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
$categoryIds = [];
|
|
||||||
|
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$currencyName = $journal['currency_name'];
|
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
|
||||||
$categoryId = $journal['category_id'];
|
if (!isset($result[$key])) {
|
||||||
$combi = $categoryId . $currencyName;
|
$result[$key] = [
|
||||||
$categoryIds[] = $categoryId;
|
|
||||||
if (!isset($result[$combi])) {
|
|
||||||
$result[$combi] = [
|
|
||||||
'total' => '0',
|
'total' => '0',
|
||||||
'category_id' => $categoryId,
|
'category_id' => (int)$journal['category_id'],
|
||||||
'currency' => $currencyName,
|
'currency_name' => $journal['currency_name'],
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
|
||||||
}
|
}
|
||||||
|
$names = $this->getCategoryNames(array_keys($result));
|
||||||
$names = $this->getCategoryNames($categoryIds);
|
|
||||||
|
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$categoryId = $row['category_id'];
|
$categoryId = $row['category_id'];
|
||||||
$name = $names[$categoryId] ?? '(unknown)';
|
$name = $names[$categoryId] ?? '(unknown)';
|
||||||
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency']]);
|
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
|
||||||
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,29 +385,25 @@ class AccountController extends Controller
|
|||||||
$journals = $collector->getExtractedJournals();
|
$journals = $collector->getExtractedJournals();
|
||||||
$result = [];
|
$result = [];
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
$categoryIds = [];
|
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($journals as $journal) {
|
foreach ($journals as $journal) {
|
||||||
$categoryId = $journal['category_id'];
|
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
|
||||||
$currencyName = $journal['currency_name'];
|
if (!isset($result[$key])) {
|
||||||
$combi = $categoryId . $currencyName;
|
$result[$key] = [
|
||||||
$categoryIds[] = $categoryId;
|
|
||||||
if (!isset($result[$combi])) {
|
|
||||||
$result[$combi] = [
|
|
||||||
'total' => '0',
|
'total' => '0',
|
||||||
'category_id' => $categoryId,
|
'category_id' => $journal['category_id'],
|
||||||
'currency' => $currencyName,
|
'currency_name' => $journal['currency_name'],
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$names = $this->getCategoryNames($categoryIds);
|
$names = $this->getCategoryNames(array_keys($result));
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$categoryId = $row['category_id'];
|
$categoryId = $row['category_id'];
|
||||||
$name = $names[$categoryId] ?? '(unknown)';
|
$name = $names[$categoryId] ?? '(unknown)';
|
||||||
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency']]);
|
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
|
||||||
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol']];
|
||||||
}
|
}
|
||||||
$data = $this->generator->multiCurrencyPieChart($chartData);
|
$data = $this->generator->multiCurrencyPieChart($chartData);
|
||||||
|
Loading…
Reference in New Issue
Block a user