Fixed various currency displays.

This commit is contained in:
James Cole
2017-06-06 07:18:09 +02:00
parent a7412e43b3
commit 5329e026dc
6 changed files with 41 additions and 11 deletions

View File

@@ -19,6 +19,7 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Steam; use Steam;
@@ -147,6 +148,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/ */
private function getAuditReport(Account $account, Carbon $date): array private function getAuditReport(Account $account, Carbon $date): array
{ {
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -155,15 +158,21 @@ class MonthReportGenerator implements ReportGeneratorInterface
$journals = $journals->reverse(); $journals = $journals->reverse();
$dayBeforeBalance = Steam::balance($account, $date); $dayBeforeBalance = Steam::balance($account, $date);
$startBalance = $dayBeforeBalance; $startBalance = $dayBeforeBalance;
$currency = $currencyRepos->find(intval($account->getMeta('currency_id')));
/** @var Transaction $journal */ /** @var Transaction $journal */
foreach ($journals as $transaction) { foreach ($journals as $transaction) {
$transaction->before = $startBalance; $transaction->before = $startBalance;
$transactionAmount = $transaction->transaction_amount; $transactionAmount = $transaction->transaction_amount;
if ($currency->id === $transaction->foreign_currency_id) {
$transactionAmount = $transaction->transaction_foreign_amount;
}
$newBalance = bcadd($startBalance, $transactionAmount); $newBalance = bcadd($startBalance, $transactionAmount);
$transaction->after = $newBalance; $transaction->after = $newBalance;
$startBalance = $newBalance; $startBalance = $newBalance;
$transaction->currency = $currency;
} }
/* /*

View File

@@ -72,11 +72,14 @@ class JournalCollector implements JournalCollectorInterface
'transactions.transaction_journal_id', 'transactions.transaction_journal_id',
'transactions.amount as transaction_amount', 'transactions.amount as transaction_amount',
'transactions.transaction_currency_id as transaction_currency_id',
'transaction_currencies.code as transaction_currency_code', 'transaction_currencies.code as transaction_currency_code',
'transaction_currencies.symbol as transaction_currency_symbol', 'transaction_currencies.symbol as transaction_currency_symbol',
'transaction_currencies.decimal_places as transaction_currency_dp', 'transaction_currencies.decimal_places as transaction_currency_dp',
'transactions.foreign_amount as transaction_foreign_amount', 'transactions.foreign_amount as transaction_foreign_amount',
'transactions.foreign_currency_id as foreign_currency_id',
'foreign_currencies.code as foreign_currency_code', 'foreign_currencies.code as foreign_currency_code',
'foreign_currencies.symbol as foreign_currency_symbol', 'foreign_currencies.symbol as foreign_currency_symbol',
'foreign_currencies.decimal_places as foreign_currency_dp', 'foreign_currencies.decimal_places as foreign_currency_dp',

View File

@@ -52,6 +52,7 @@ class AmountFormat extends Twig_Extension
$this->formatDestinationBefore(), $this->formatDestinationBefore(),
$this->formatSourceAfter(), $this->formatSourceAfter(),
$this->formatSourceBefore(), $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 * @return Twig_SimpleFilter
*/ */

View File

@@ -119,13 +119,13 @@
{% if period.spent != 0 %} {% if period.spent != 0 %}
<tr> <tr>
<td style="width:33%;">{{ 'spent'|_ }}</td> <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> </tr>
{% endif %} {% endif %}
{% if period.earned != 0 %} {% if period.earned != 0 %}
<tr> <tr>
<td style="width: 33%;">{{ 'earned'|_ }}</td> <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> </tr>
{% endif %} {% endif %}
</table> </table>

View File

@@ -59,7 +59,7 @@
account_name: account.name, account_name: account.name,
url: url, url: url,
end: auditData[account.id].end, end: auditData[account.id].end,
balance: auditData[account.id].endBalance|formatAmount balance: formatAmountByAccount(account,auditData[account.id].endBalance)
})|raw }} })|raw }}
</p> </p>
{% include 'reports.partials.journals-audit' with {'journals': auditData[account.id].journals,'account':account} %} {% include 'reports.partials.journals-audit' with {'journals': auditData[account.id].journals,'account':account} %}
@@ -69,7 +69,7 @@
account_name: account.name, account_name: account.name,
url: url, url: url,
end: auditData[account.id].dayBefore, end: auditData[account.id].dayBefore,
balance: auditData[account.id].dayBeforeBalance|formatAmount balance: formatAmountByAccount(account, auditData[account.id].dayBeforeBalance)
})|raw }} })|raw }}
</p> </p>
</div> </div>

View File

@@ -57,11 +57,11 @@
{% endif %} {% endif %}
</a> </a>
</td> </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;"> <td class="hide-amount" style="text-align: right;">
{{ transactionAmount(transaction) }} {{ transactionAmount(transaction) }}
</td> </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-date">{{ transaction.date.formatLocalized(monthAndDayFormat) }}</td>
<td class="hide-book_date"> <td class="hide-book_date">