mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 14:12:15 +00:00
Code cleanup in AccountForm.
This commit is contained in:
@@ -55,31 +55,25 @@ class Steam
|
||||
$cache->addProperty('balance');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
//return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
//
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||
$currency = $repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
|
||||
// use system default currency:
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
$currencyId = $currency->id;
|
||||
}
|
||||
// first part: get all balances in own currency:
|
||||
$nativeBalance = (string)$account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
->where('transactions.transaction_currency_id', $currencyId)
|
||||
->where('transactions.transaction_currency_id', $currency->id)
|
||||
->sum('transactions.amount');
|
||||
|
||||
// get all balances in foreign currency:
|
||||
$foreignBalance = (string)$account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d'))
|
||||
->where('transactions.foreign_currency_id', $currencyId)
|
||||
->where('transactions.transaction_currency_id', '!=', $currencyId)
|
||||
->where('transactions.foreign_currency_id', $currency->id)
|
||||
->where('transactions.transaction_currency_id', '!=', $currency->id)
|
||||
->sum('transactions.foreign_amount');
|
||||
|
||||
$balance = bcadd($nativeBalance, $foreignBalance);
|
||||
|
||||
Reference in New Issue
Block a user