Skip to content

Firefly III: a personal finances manager

Fixed various currency displays.

James Cole5329e026dcb8
diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php
index 0b12e60fe0..d02815963a 100644
--- a/app/Generator/Report/Audit/MonthReportGenerator.php
+++ b/app/Generator/Report/Audit/MonthReportGenerator.php
@@ -19,6 +19,7 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
+use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Steam;
@@ -147,6 +148,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
private function getAuditReport(Account $account, Carbon $date): array
{
+ /** @var CurrencyRepositoryInterface $currencyRepos */
+ $currencyRepos = app(CurrencyRepositoryInterface::class);
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -155,15 +158,21 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals = $journals->reverse();
$dayBeforeBalance = Steam::balance($account, $date);
$startBalance = $dayBeforeBalance;
-
+ $currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
/** @var Transaction $journal */
foreach ($journals as $transaction) {
$transaction->before = $startBalance;
- $transactionAmount = $transaction->transaction_amount;
- $newBalance = bcadd($startBalance, $transactionAmount);
- $transaction->after = $newBalance;
- $startBalance = $newBalance;
+ $transactionAmount = $transaction->transaction_amount;
+
+ if ($currency->id === $transaction->foreign_currency_id) {
+ $transactionAmount = $transaction->transaction_foreign_amount;
+ }
+
+ $newBalance = bcadd($startBalance, $transactionAmount);
+ $transaction->after = $newBalance;
+ $startBalance = $newBalance;
+ $transaction->currency = $currency;
}
/*
diff --git a/app/Helpers/Collector/JournalCollector.php b/app/Helpers/Collector/JournalCollector.php
index 2fbc389eab..7edc9a5164 100644
--- a/app/Helpers/Collector/JournalCollector.php
+++ b/app/Helpers/Collector/JournalCollector.php
@@ -72,11 +72,14 @@ class JournalCollector implements JournalCollectorInterface
'transactions.transaction_journal_id',
'transactions.amount as transaction_amount',
+
+ 'transactions.transaction_currency_id as transaction_currency_id',
'transaction_currencies.code as transaction_currency_code',
'transaction_currencies.symbol as transaction_currency_symbol',
'transaction_currencies.decimal_places as transaction_currency_dp',
'transactions.foreign_amount as transaction_foreign_amount',
+ 'transactions.foreign_currency_id as foreign_currency_id',
'foreign_currencies.code as foreign_currency_code',
'foreign_currencies.symbol as foreign_currency_symbol',
'foreign_currencies.decimal_places as foreign_currency_dp',
diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php
index ba7011f902..db267e4401 100644
--- a/app/Support/Twig/AmountFormat.php
+++ b/app/Support/Twig/AmountFormat.php
@@ -52,6 +52,7 @@ class AmountFormat extends Twig_Extension
$this->formatDestinationBefore(),
$this->formatSourceAfter(),
$this->formatSourceBefore(),
+ $this->formatAmountByCurrency(),
];
}
@@ -107,6 +108,23 @@ class AmountFormat extends Twig_Extension
);
}
+ /**
+ * Will format the amount by the currency related to the given account.
+ *
+ * @return Twig_SimpleFunction
+ */
+ protected function formatAmountByCurrency(): Twig_SimpleFunction
+ {
+ return new Twig_SimpleFunction(
+ 'formatAmountByCurrency', function (TransactionCurrency $currency, string $amount, bool $coloured = true): string {
+
+ return app('amount')->formatAnything($currency, $amount, $coloured);
+
+
+ }, ['is_safe' => ['html']]
+ );
+ }
+
/**
* @return Twig_SimpleFilter
*/
diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig
index 40da0b960c..41f430b756 100644
--- a/resources/views/accounts/show.twig
+++ b/resources/views/accounts/show.twig
@@ -119,13 +119,13 @@
{% if period.spent != 0 %}
<tr>
<td style="width:33%;">{{ 'spent'|_ }}</td>
- <td style="text-align: right;">{{ period.spent|formatAmount }}</td>
+ <td style="text-align: right;">{{ formatAmountByCurrency(currency, period.spent) }}</td>
</tr>
{% endif %}
{% if period.earned != 0 %}
<tr>
<td style="width: 33%;">{{ 'earned'|_ }}</td>
- <td style="text-align: right;">{{ period.earned|formatAmount }}</td>
+ <td style="text-align: right;">{{ formatAmountByCurrency(currency, period.earned) }}</td>
</tr>
{% endif %}
</table>
diff --git a/resources/views/reports/audit/report.twig b/resources/views/reports/audit/report.twig
index 01444e9212..0a4b8b4e52 100644
--- a/resources/views/reports/audit/report.twig
+++ b/resources/views/reports/audit/report.twig
@@ -59,7 +59,7 @@
account_name: account.name,
url: url,
end: auditData[account.id].end,
- balance: auditData[account.id].endBalance|formatAmount
+ balance: formatAmountByAccount(account,auditData[account.id].endBalance)
})|raw }}
</p>
{% include 'reports.partials.journals-audit' with {'journals': auditData[account.id].journals,'account':account} %}
@@ -69,7 +69,7 @@
account_name: account.name,
url: url,
end: auditData[account.id].dayBefore,
- balance: auditData[account.id].dayBeforeBalance|formatAmount
+ balance: formatAmountByAccount(account, auditData[account.id].dayBeforeBalance)
})|raw }}
</p>
</div>
diff --git a/resources/views/reports/partials/journals-audit.twig b/resources/views/reports/partials/journals-audit.twig
index 4f0f794f96..d5da12c69f 100644
--- a/resources/views/reports/partials/journals-audit.twig
+++ b/resources/views/reports/partials/journals-audit.twig
@@ -57,11 +57,11 @@
{% endif %}
</a>
</td>
- <td class="hide-balance_before" style="text-align: right;">{{ transaction.before|formatAmount }}</td>
+ <td class="hide-balance_before" style="text-align: right;">{{ formatAmountByCurrency(transaction.currency, transaction.before) }}</td>
<td class="hide-amount" style="text-align: right;">
{{ transactionAmount(transaction) }}
</td>
- <td class="hide-balance_after" style="text-align: right;">{{ transaction.after|formatAmount }}</td>
+ <td class="hide-balance_after" style="text-align: right;">{{ formatAmountByCurrency(transaction.currency, transaction.after) }}</td>
<td class="hide-date">{{ transaction.date.formatLocalized(monthAndDayFormat) }}</td>
<td class="hide-book_date">