mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Add multi-currency for budget chart
This commit is contained in:
@@ -114,6 +114,8 @@ class BudgetController extends Controller
|
|||||||
$rows = [];
|
$rows = [];
|
||||||
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
|
$spent = $this->opsRepository->listExpenses($start, $end, null, new Collection([$budget]));
|
||||||
$expenses = $this->processExpenses($budget->id, $spent, $start, $end);
|
$expenses = $this->processExpenses($budget->id, $spent, $start, $end);
|
||||||
|
$converter = new ExchangeRateConverter();
|
||||||
|
$currencies = [$this->primaryCurrency->id => $this->primaryCurrency,];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int $currencyId
|
* @var int $currencyId
|
||||||
@@ -122,6 +124,13 @@ class BudgetController extends Controller
|
|||||||
foreach ($expenses as $currencyId => $row) {
|
foreach ($expenses as $currencyId => $row) {
|
||||||
// budgeted, left and overspent are now 0.
|
// budgeted, left and overspent are now 0.
|
||||||
$limit = $this->filterLimit($currencyId, $limits);
|
$limit = $this->filterLimit($currencyId, $limits);
|
||||||
|
|
||||||
|
// primary currency entries
|
||||||
|
$row['pc_budgeted'] = '0';
|
||||||
|
$row['pc_spent'] = '0';
|
||||||
|
$row['pc_left'] = '0';
|
||||||
|
$row['pc_overspent'] = '0';
|
||||||
|
|
||||||
if (null !== $limit) {
|
if (null !== $limit) {
|
||||||
$row['budgeted'] = $limit->amount;
|
$row['budgeted'] = $limit->amount;
|
||||||
$row['left'] = bcsub($row['budgeted'], bcmul($row['spent'], '-1'));
|
$row['left'] = bcsub($row['budgeted'], bcmul($row['spent'], '-1'));
|
||||||
@@ -129,6 +138,21 @@ class BudgetController extends Controller
|
|||||||
$row['left'] = 1 === bccomp($row['left'], '0') ? $row['left'] : '0';
|
$row['left'] = 1 === bccomp($row['left'], '0') ? $row['left'] : '0';
|
||||||
$row['overspent'] = 1 === bccomp($row['overspent'], '0') ? $row['overspent'] : '0';
|
$row['overspent'] = 1 === bccomp($row['overspent'], '0') ? $row['overspent'] : '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert data if necessary.
|
||||||
|
if (true === $this->convertToPrimary && $currencyId !== $this->primaryCurrency->id) {
|
||||||
|
$currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
|
||||||
|
$row['pc_budgeted'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['budgeted']);
|
||||||
|
$row['pc_spent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['spent']);
|
||||||
|
$row['pc_left'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['left']);
|
||||||
|
$row['pc_overspent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['overspent']);
|
||||||
|
}
|
||||||
|
if (true === $this->convertToPrimary && $currencyId === $this->primaryCurrency->id) {
|
||||||
|
$row['pc_budgeted'] = $row['budgeted'];
|
||||||
|
$row['pc_spent'] = $row['spent'];
|
||||||
|
$row['pc_left'] = $row['left'];
|
||||||
|
$row['pc_overspent'] = $row['overspent'];
|
||||||
|
}
|
||||||
$rows[] = $row;
|
$rows[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,9 +169,16 @@ class BudgetController extends Controller
|
|||||||
$current = [
|
$current = [
|
||||||
'label' => $budget->name,
|
'label' => $budget->name,
|
||||||
'currency_id' => (string)$row['currency_id'],
|
'currency_id' => (string)$row['currency_id'],
|
||||||
'currency_code' => $row['currency_code'],
|
|
||||||
'currency_name' => $row['currency_name'],
|
'currency_name' => $row['currency_name'],
|
||||||
|
'currency_code' => $row['currency_code'],
|
||||||
'currency_decimal_places' => $row['currency_decimal_places'],
|
'currency_decimal_places' => $row['currency_decimal_places'],
|
||||||
|
|
||||||
|
'primary_currency_id' => (string)$this->primaryCurrency->id,
|
||||||
|
'primary_currency_name' => $this->primaryCurrency->name,
|
||||||
|
'primary_currency_code' => $this->primaryCurrency->code,
|
||||||
|
'primary_currency_symbol' => $this->primaryCurrency->symbol,
|
||||||
|
'primary_currency_decimal_places' => $this->primaryCurrency->decimal_places,
|
||||||
|
|
||||||
'period' => null,
|
'period' => null,
|
||||||
'date' => $row['start'],
|
'date' => $row['start'],
|
||||||
'start_date' => $row['start'],
|
'start_date' => $row['start'],
|
||||||
@@ -161,7 +192,10 @@ class BudgetController extends Controller
|
|||||||
'overspent' => $row['overspent'],
|
'overspent' => $row['overspent'],
|
||||||
],
|
],
|
||||||
'pc_entries' => [
|
'pc_entries' => [
|
||||||
|
'budgeted' => $row['pc_budgeted'],
|
||||||
|
'spent' => '0',
|
||||||
|
'left' => '0',
|
||||||
|
'overspent' => '0',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$return[] = $current;
|
$return[] = $current;
|
||||||
|
Reference in New Issue
Block a user