mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed various currency displays.
This commit is contained in:
parent
a7412e43b3
commit
5329e026dc
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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">
|
||||
|
Loading…
Reference in New Issue
Block a user