mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Clean up several endpoints with complex code.
This commit is contained in:
@@ -33,6 +33,7 @@ use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\Report\Summarizer\TransactionSummarizer;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -222,10 +223,6 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
$subset = $repository->getAccountsByType(config('firefly.valid_liabilities'));
|
||||
$selection = new Collection();
|
||||
|
||||
// default currency information for native stuff.
|
||||
$convertToNative = Amount::convertToNative($this->user);
|
||||
$default = Amount::getDefaultCurrency();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($subset as $account) {
|
||||
if ('credit' === $repository->getMetaValue($account, 'liability_direction')) {
|
||||
@@ -258,55 +255,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
if (null !== $currency) {
|
||||
Log::debug('STOP looking for transactions in the foreign currency.');
|
||||
}
|
||||
$array = [];
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
// TODO same as in category::sumexpenses
|
||||
$amount = '0';
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyName = $journal['currency_name'];
|
||||
$currencySymbol = $journal['currency_symbol'];
|
||||
$currencyCode = $journal['currency_code'];
|
||||
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||
if ($convertToNative) {
|
||||
$useNative = $default->id !== (int) $journal['currency_id'];
|
||||
$amount = Amount::getAmountFromJournal($journal);
|
||||
if ($useNative) {
|
||||
Log::debug(sprintf('Journal #%d switches to native amount (original is %s)', $journal['transaction_journal_id'], $journal['currency_code']));
|
||||
$currencyId = $default->id;
|
||||
$currencyName = $default->name;
|
||||
$currencySymbol = $default->symbol;
|
||||
$currencyCode = $default->code;
|
||||
$currencyDecimalPlaces = $default->decimal_places;
|
||||
}
|
||||
}
|
||||
if (!$convertToNative) {
|
||||
$amount = $journal['amount'];
|
||||
// if the amount is not in $currency (but should be), use the foreign_amount if that one is correct.
|
||||
// otherwise, ignore the transaction all together.
|
||||
if (null !== $currency && $currencyId !== $currency->id && $currency->id === (int) $journal['foreign_currency_id']) {
|
||||
Log::debug(sprintf('Journal #%d switches to foreign amount because it matches native.', $journal['transaction_journal_id']));
|
||||
$amount = $journal['foreign_amount'];
|
||||
$currencyId = (int) $journal['foreign_currency_id'];
|
||||
$currencyName = $journal['foreign_currency_name'];
|
||||
$currencySymbol = $journal['foreign_currency_symbol'];
|
||||
$currencyCode = $journal['foreign_currency_code'];
|
||||
$currencyDecimalPlaces = $journal['foreign_currency_decimal_places'];
|
||||
}
|
||||
}
|
||||
$array[$currencyId] ??= [
|
||||
'sum' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $currencyName,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'currency_code' => $currencyCode,
|
||||
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||
];
|
||||
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($amount));
|
||||
Log::debug(sprintf('Journal #%d adds amount %s %s', $journal['transaction_journal_id'], $currencyCode, $amount));
|
||||
}
|
||||
Log::debug('End of sumExpenses.', $array);
|
||||
|
||||
return $array;
|
||||
$summarizer = new TransactionSummarizer($this->user);
|
||||
return $summarizer->groupByCurrencyId($journals);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user