mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 19:01:39 +00:00
Rename method, remove 0.
This commit is contained in:
@@ -344,7 +344,7 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
|
||||
private function collectBalances(): void
|
||||
{
|
||||
$this->balances = Steam::finalAccountsBalanceOptimized($this->collection, $this->getDate(), $this->primaryCurrency, $this->convertToPrimary);
|
||||
$this->balances = Steam::accountsBalancesOptimized($this->collection, $this->getDate(), $this->primaryCurrency, $this->convertToPrimary);
|
||||
}
|
||||
|
||||
public function setDate(?Carbon $date): void
|
||||
|
@@ -37,7 +37,6 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use ValueError;
|
||||
|
||||
use function Safe\parse_url;
|
||||
use function Safe\preg_replace;
|
||||
|
||||
@@ -65,10 +64,10 @@ class Steam
|
||||
// Log::debug(sprintf('Trying bcround("%s",%d)', $number, $precision));
|
||||
if (str_contains($number, '.')) {
|
||||
if ('-' !== $number[0]) {
|
||||
return bcadd($number, '0.'.str_repeat('0', $precision).'5', $precision);
|
||||
return bcadd($number, '0.' . str_repeat('0', $precision) . '5', $precision);
|
||||
}
|
||||
|
||||
return bcsub($number, '0.'.str_repeat('0', $precision).'5', $precision);
|
||||
return bcsub($number, '0.' . str_repeat('0', $precision) . '5', $precision);
|
||||
}
|
||||
|
||||
return $number;
|
||||
@@ -265,8 +264,7 @@ class Steam
|
||||
'transactions.transaction_currency_id',
|
||||
DB::raw('SUM(transactions.amount) AS sum_of_day'),
|
||||
]
|
||||
)
|
||||
;
|
||||
);
|
||||
|
||||
$currentBalance = $startBalance;
|
||||
$converter = new ExchangeRateConverter();
|
||||
@@ -319,7 +317,7 @@ class Steam
|
||||
return $balances;
|
||||
}
|
||||
|
||||
public function finalAccountsBalanceOptimized(Collection $accounts, Carbon $date, ?TransactionCurrency $primary = null, ?bool $convertToPrimary = null): array
|
||||
public function accountsBalancesOptimized(Collection $accounts, Carbon $date, ?TransactionCurrency $primary = null, ?bool $convertToPrimary = null): array
|
||||
{
|
||||
$result = [];
|
||||
$convertToPrimary ??= Amount::convertToPrimary();
|
||||
@@ -331,8 +329,7 @@ class Steam
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d H:i:s'))
|
||||
->get(['transactions.account_id', 'transaction_currencies.code', 'transactions.amount'])->toArray()
|
||||
;
|
||||
->get(['transactions.account_id', 'transaction_currencies.code', 'transactions.amount'])->toArray();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
@@ -436,8 +433,7 @@ class Steam
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', '=', 'transactions.transaction_currency_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d H:i:s'))
|
||||
->get(['transaction_currencies.code', 'transactions.amount'])->toArray()
|
||||
;
|
||||
->get(['transaction_currencies.code', 'transactions.amount'])->toArray();
|
||||
$others = $this->groupAndSumTransactions($array, 'code', 'amount');
|
||||
// Log::debug('All balances are (joined)', $others);
|
||||
// if there is no request to convert, take this as "balance" and "pc_balance".
|
||||
@@ -769,7 +765,10 @@ class Steam
|
||||
|
||||
/** @var AccountMeta $item */
|
||||
foreach ($result as $item) {
|
||||
$accountPreferences[(int)$item->account_id] = (int)$item->data;
|
||||
$integer = (int)$item->data;
|
||||
if (0 !== $integer) {
|
||||
$accountPreferences[(int)$item->account_id] = $integer;
|
||||
}
|
||||
}
|
||||
// collect those currencies.
|
||||
$set = TransactionCurrency::whereIn('id', $accountPreferences)->get();
|
||||
@@ -786,11 +785,11 @@ class Steam
|
||||
$currencies[$currencyId] ??= $account->meta['currency'];
|
||||
$accountCurrencies[$accountId] = $account->meta['currency'];
|
||||
}
|
||||
if (!$currencyPresent && !array_key_exists($account->id, $accountPreferences)) {
|
||||
if (!$currencyPresent && !array_key_exists($accountId, $accountPreferences)) {
|
||||
$accountCurrencies[$accountId] = $primary;
|
||||
}
|
||||
if (!$currencyPresent && array_key_exists($account->id, $accountPreferences)) {
|
||||
$accountCurrencies[$account->id] = $currencies[$accountPreferences[$account->id]];
|
||||
if (!$currencyPresent && array_key_exists($accountId, $accountPreferences)) {
|
||||
$accountCurrencies[$accountId] = $currencies[$accountPreferences[$account->id]];
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user