mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Optimize currency search.
This commit is contained in:
@@ -28,5 +28,5 @@ parameters:
|
|||||||
|
|
||||||
# The level 8 is the highest level. original was 5
|
# The level 8 is the highest level. original was 5
|
||||||
# 7 is more than enough, higher just leaves NULL things.
|
# 7 is more than enough, higher just leaves NULL things.
|
||||||
level: 8
|
level: 7
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Http\Api\CleansChartData;
|
use FireflyIII\Support\Http\Api\CleansChartData;
|
||||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||||
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
||||||
@@ -143,7 +144,7 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
// convert data if necessary.
|
// convert data if necessary.
|
||||||
if (true === $this->convertToPrimary && $currencyId !== $this->primaryCurrency->id) {
|
if (true === $this->convertToPrimary && $currencyId !== $this->primaryCurrency->id) {
|
||||||
$currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
|
$currencies[$currencyId] ??= Amount::getTransactionCurrencyById($currencyId);
|
||||||
$row['pc_budgeted'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['budgeted']);
|
$row['pc_budgeted'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['budgeted']);
|
||||||
$row['pc_spent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['spent']);
|
$row['pc_spent'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['spent']);
|
||||||
$row['pc_left'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['left']);
|
$row['pc_left'] = $converter->convert($currencies[$currencyId], $this->primaryCurrency, $start, $row['left']);
|
||||||
@@ -231,7 +232,7 @@ class BudgetController extends Controller
|
|||||||
* @var array $block
|
* @var array $block
|
||||||
*/
|
*/
|
||||||
foreach ($spent as $currencyId => $block) {
|
foreach ($spent as $currencyId => $block) {
|
||||||
$this->currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
|
$this->currencies[$currencyId] ??= Amount::getTransactionCurrencyById($currencyId);
|
||||||
$return[$currencyId] ??= [
|
$return[$currencyId] ??= [
|
||||||
'currency_id' => (string)$currencyId,
|
'currency_id' => (string)$currencyId,
|
||||||
'currency_code' => $block['currency_code'],
|
'currency_code' => $block['currency_code'],
|
||||||
|
@@ -33,6 +33,7 @@ use FireflyIII\Enums\UserRoleEnum;
|
|||||||
use FireflyIII\Models\CurrencyExchangeRate;
|
use FireflyIII\Models\CurrencyExchangeRate;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;
|
use FireflyIII\Repositories\ExchangeRate\ExchangeRateRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
use FireflyIII\Support\Http\Api\ValidatesUserGroupTrait;
|
||||||
use FireflyIII\Transformers\ExchangeRateTransformer;
|
use FireflyIII\Transformers\ExchangeRateTransformer;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@@ -98,7 +99,7 @@ class StoreController extends Controller
|
|||||||
$from = $request->getFromCurrency();
|
$from = $request->getFromCurrency();
|
||||||
$collection = new Collection();
|
$collection = new Collection();
|
||||||
foreach ($data['rates'] as $key => $rate) {
|
foreach ($data['rates'] as $key => $rate) {
|
||||||
$to = TransactionCurrency::where('code', $key)->first();
|
$to = Amount::getTransactionCurrencyByCode($key);
|
||||||
if (null === $to) {
|
if (null === $to) {
|
||||||
continue; // should not happen.
|
continue; // should not happen.
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
|
namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
@@ -48,7 +49,7 @@ class StoreByDateRequest extends FormRequest
|
|||||||
|
|
||||||
public function getFromCurrency(): TransactionCurrency
|
public function getFromCurrency(): TransactionCurrency
|
||||||
{
|
{
|
||||||
return TransactionCurrency::where('code', $this->get('from'))->first();
|
return Amount::getTransactionCurrencyByCode((string) $this->get('from'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +84,7 @@ class StoreByDateRequest extends FormRequest
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$to = TransactionCurrency::where('code', $key)->first();
|
$to = Amount::getTransactionCurrencyByCode((string) $key);
|
||||||
if (null === $to) {
|
if (null === $to) {
|
||||||
$validator->errors()->add(sprintf('rates.%s', $key), trans('validation.invalid_currency_code', ['code' => $key]));
|
$validator->errors()->add(sprintf('rates.%s', $key), trans('validation.invalid_currency_code', ['code' => $key]));
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Requests\Models\CurrencyExchangeRate;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Request\ChecksLogin;
|
use FireflyIII\Support\Request\ChecksLogin;
|
||||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
@@ -42,7 +43,7 @@ class StoreRequest extends FormRequest
|
|||||||
|
|
||||||
public function getFromCurrency(): TransactionCurrency
|
public function getFromCurrency(): TransactionCurrency
|
||||||
{
|
{
|
||||||
return TransactionCurrency::where('code', $this->get('from'))->first();
|
return Amount::getTransactionCurrencyByCode((string) $this->get('from'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRate(): string
|
public function getRate(): string
|
||||||
@@ -52,7 +53,7 @@ class StoreRequest extends FormRequest
|
|||||||
|
|
||||||
public function getToCurrency(): TransactionCurrency
|
public function getToCurrency(): TransactionCurrency
|
||||||
{
|
{
|
||||||
return TransactionCurrency::where('code', $this->get('to'))->first();
|
return Amount::getTransactionCurrencyByCode((string) $this->get('to'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Api\V1\Requests\Models\PiggyBank;
|
namespace FireflyIII\Api\V1\Requests\Models\PiggyBank;
|
||||||
|
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
@@ -135,13 +136,13 @@ class StoreRequest extends FormRequest
|
|||||||
private function getCurrencyFromData(Validator $validator, array $data): ?TransactionCurrency
|
private function getCurrencyFromData(Validator $validator, array $data): ?TransactionCurrency
|
||||||
{
|
{
|
||||||
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
|
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
|
||||||
$currency = TransactionCurrency::whereCode($data['transaction_currency_code'])->first();
|
$currency = Amount::getTransactionCurrencyByCode((string) $data['transaction_currency_code']);
|
||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (array_key_exists('transaction_currency_id', $data) && '' !== (string) $data['transaction_currency_id']) {
|
if (array_key_exists('transaction_currency_id', $data) && '' !== (string) $data['transaction_currency_id']) {
|
||||||
$currency = TransactionCurrency::find((int) $data['transaction_currency_id']);
|
$currency = Amount::getTransactionCurrencyById((int) $data['transaction_currency_id']);
|
||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
@@ -25,9 +25,11 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Console\Commands\Upgrade;
|
namespace FireflyIII\Console\Commands\Upgrade;
|
||||||
|
|
||||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -117,9 +119,9 @@ class UpgradesCurrencyPreferences extends Command
|
|||||||
|
|
||||||
// set the default currency for the user and for the group:
|
// set the default currency for the user and for the group:
|
||||||
$preference = $this->getPreference($user);
|
$preference = $this->getPreference($user);
|
||||||
$primaryCurrency = TransactionCurrency::where('code', $preference)->first();
|
try {
|
||||||
if (null === $primaryCurrency) {
|
$primaryCurrency = Amount::getTransactionCurrencyByCode($preference);
|
||||||
// get EUR
|
} catch (FireflyException) {
|
||||||
$primaryCurrency = TransactionCurrency::where('code', 'EUR')->first();
|
$primaryCurrency = TransactionCurrency::where('code', 'EUR')->first();
|
||||||
}
|
}
|
||||||
$user->currencies()->updateExistingPivot($primaryCurrency->id, ['user_default' => true]);
|
$user->currencies()->updateExistingPivot($primaryCurrency->id, ['user_default' => true]);
|
||||||
|
@@ -27,6 +27,7 @@ namespace FireflyIII\Factory;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TransactionCurrencyFactory
|
* Class TransactionCurrencyFactory
|
||||||
@@ -48,7 +49,7 @@ class TransactionCurrencyFactory
|
|||||||
if (1 === $count) {
|
if (1 === $count) {
|
||||||
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
|
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
|
||||||
$old->forceDelete();
|
$old->forceDelete();
|
||||||
app('log')->warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
|
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -64,8 +65,8 @@ class TransactionCurrencyFactory
|
|||||||
);
|
);
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
$result = null;
|
$result = null;
|
||||||
app('log')->error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
Log::error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
||||||
app('log')->error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
|
|
||||||
throw new FireflyException('400004: Could not store new currency.', 0, $e);
|
throw new FireflyException('400004: Could not store new currency.', 0, $e);
|
||||||
}
|
}
|
||||||
@@ -79,7 +80,7 @@ class TransactionCurrencyFactory
|
|||||||
$currencyId = (int) $currencyId;
|
$currencyId = (int) $currencyId;
|
||||||
|
|
||||||
if ('' === $currencyCode && 0 === $currencyId) {
|
if ('' === $currencyCode && 0 === $currencyId) {
|
||||||
app('log')->debug('Cannot find anything on empty currency code and empty currency ID!');
|
Log::debug('Cannot find anything on empty currency code and empty currency ID!');
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,7 @@ class TransactionCurrencyFactory
|
|||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
app('log')->warning(sprintf('Currency ID is %d but found nothing!', $currencyId));
|
Log::warning(sprintf('Currency ID is %d but found nothing!', $currencyId));
|
||||||
}
|
}
|
||||||
// then by code:
|
// then by code:
|
||||||
if ('' !== $currencyCode) {
|
if ('' !== $currencyCode) {
|
||||||
@@ -98,9 +99,9 @@ class TransactionCurrencyFactory
|
|||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
app('log')->warning(sprintf('Currency code is %d but found nothing!', $currencyCode));
|
Log::warning(sprintf('Currency code is %d but found nothing!', $currencyCode));
|
||||||
}
|
}
|
||||||
app('log')->warning('Found nothing for currency.');
|
Log::warning('Found nothing for currency.');
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -25,14 +25,15 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Middleware;
|
namespace FireflyIII\Http\Middleware;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\GroupMembership;
|
use FireflyIII\Models\GroupMembership;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Models\Webhook;
|
use FireflyIII\Models\Webhook;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
@@ -289,15 +290,14 @@ class InterestingMessage
|
|||||||
{
|
{
|
||||||
// params:
|
// params:
|
||||||
// get parameters from request.
|
// get parameters from request.
|
||||||
$code = $request->get('code');
|
$code = (string) $request->get('code');
|
||||||
$message = $request->get('message');
|
$message = (string) $request->get('message');
|
||||||
|
try {
|
||||||
/** @var null|TransactionCurrency $currency */
|
$currency = Amount::getTransactionCurrencyByCode($code);
|
||||||
$currency = TransactionCurrency::whereCode($code)->first();
|
} catch (FireflyException) {
|
||||||
|
|
||||||
if (null === $currency) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('enabled' === $message) {
|
if ('enabled' === $message) {
|
||||||
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
|
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Rules\IsValidPositiveAmount;
|
use FireflyIII\Rules\IsValidPositiveAmount;
|
||||||
@@ -124,8 +125,9 @@ class PiggyBankStoreRequest extends FormRequest
|
|||||||
private function getCurrencyFromData(array $data): TransactionCurrency
|
private function getCurrencyFromData(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
$currencyId = (int)($data['transaction_currency_id'] ?? 0);
|
$currencyId = (int)($data['transaction_currency_id'] ?? 0);
|
||||||
$currency = TransactionCurrency::find($currencyId);
|
try {
|
||||||
if (null === $currency) {
|
$currency = Amount::getTransactionCurrencyById($currencyId);
|
||||||
|
} catch (FireflyException) {
|
||||||
return Amount::getPrimaryCurrency();
|
return Amount::getPrimaryCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Http\Requests;
|
namespace FireflyIII\Http\Requests;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use Illuminate\Validation\Validator;
|
use Illuminate\Validation\Validator;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
@@ -129,8 +130,9 @@ class PiggyBankUpdateRequest extends FormRequest
|
|||||||
private function getCurrencyFromData(array $data): TransactionCurrency
|
private function getCurrencyFromData(array $data): TransactionCurrency
|
||||||
{
|
{
|
||||||
$currencyId = (int) ($data['transaction_currency_id'] ?? 0);
|
$currencyId = (int) ($data['transaction_currency_id'] ?? 0);
|
||||||
$currency = TransactionCurrency::find($currencyId);
|
try {
|
||||||
if (null === $currency) {
|
$currency = Amount::getTransactionCurrencyById($currencyId);
|
||||||
|
} catch (FireflyException) {
|
||||||
return Amount::getPrimaryCurrency();
|
return Amount::getPrimaryCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@ use FireflyIII\Models\TransactionGroup;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
||||||
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||||
@@ -400,7 +401,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
|
|||||||
}
|
}
|
||||||
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
||||||
if ($currencyId > 0) {
|
if ($currencyId > 0) {
|
||||||
return TransactionCurrency::find($currencyId);
|
return Amount::getTransactionCurrencyById($currencyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -166,7 +166,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
|
|||||||
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
$currencyDecimalPlaces = $journal['currency_decimal_places'];
|
||||||
}
|
}
|
||||||
if (true === $convertToPrimary && $journalCurrencyId !== $currencyId) {
|
if (true === $convertToPrimary && $journalCurrencyId !== $currencyId) {
|
||||||
$currencies[$journalCurrencyId] ??= TransactionCurrency::find($journalCurrencyId);
|
$currencies[$journalCurrencyId] ??= Amount::getTransactionCurrencyById($journalCurrencyId);
|
||||||
$amount = $converter->convert($currencies[$journalCurrencyId], $primaryCurrency, $journal['date'], $amount);
|
$amount = $converter->convert($currencies[$journalCurrencyId], $primaryCurrency, $journal['date'], $amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\PiggyBank;
|
namespace FireflyIII\Repositories\PiggyBank;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
|
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
|
||||||
use FireflyIII\Events\Model\PiggyBank\ChangedName;
|
use FireflyIII\Events\Model\PiggyBank\ChangedName;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
@@ -32,12 +33,11 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
use FireflyIII\Support\Http\Api\ExchangeRateConverter;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait ModifiesPiggyBanks
|
* Trait ModifiesPiggyBanks
|
||||||
@@ -287,7 +287,7 @@ trait ModifiesPiggyBanks
|
|||||||
$piggyBank->name = $data['name'];
|
$piggyBank->name = $data['name'];
|
||||||
}
|
}
|
||||||
if (array_key_exists('transaction_currency_id', $data) && is_int($data['transaction_currency_id'])) {
|
if (array_key_exists('transaction_currency_id', $data) && is_int($data['transaction_currency_id'])) {
|
||||||
$currency = TransactionCurrency::find($data['transaction_currency_id']);
|
$currency = Amount::getTransactionCurrencyById($data['transaction_currency_id']);
|
||||||
if (null !== $currency) {
|
if (null !== $currency) {
|
||||||
$piggyBank->transaction_currency_id = $currency->id;
|
$piggyBank->transaction_currency_id = $currency->id;
|
||||||
}
|
}
|
||||||
@@ -339,8 +339,7 @@ trait ModifiesPiggyBanks
|
|||||||
->where('accounts.user_id', $this->user->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
->where('piggy_banks.order', '<=', $newOrder)->where('piggy_banks.order', '>', $oldOrder)
|
||||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||||
->distinct()->decrement('piggy_banks.order')
|
->distinct()->decrement('piggy_banks.order');
|
||||||
;
|
|
||||||
|
|
||||||
$piggyBank->order = $newOrder;
|
$piggyBank->order = $newOrder;
|
||||||
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
Log::debug(sprintf('[1] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||||
@@ -353,8 +352,7 @@ trait ModifiesPiggyBanks
|
|||||||
->where('accounts.user_id', $this->user->id)
|
->where('accounts.user_id', $this->user->id)
|
||||||
->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
|
->where('piggy_banks.order', '>=', $newOrder)->where('piggy_banks.order', '<', $oldOrder)
|
||||||
->where('piggy_banks.id', '!=', $piggyBank->id)
|
->where('piggy_banks.id', '!=', $piggyBank->id)
|
||||||
->distinct()->increment('piggy_banks.order')
|
->distinct()->increment('piggy_banks.order');
|
||||||
;
|
|
||||||
|
|
||||||
$piggyBank->order = $newOrder;
|
$piggyBank->order = $newOrder;
|
||||||
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
Log::debug(sprintf('[2] Order of piggy #%d ("%s") from %d to %d', $piggyBank->id, $piggyBank->name, $oldOrder, $newOrder));
|
||||||
|
@@ -354,7 +354,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
|
|||||||
->first()
|
->first()
|
||||||
;
|
;
|
||||||
if (null !== $currencyPreference) {
|
if (null !== $currencyPreference) {
|
||||||
$currency = TransactionCurrency::where('id', $currencyPreference->data)->first();
|
$currency = Amount::getTransactionCurrencyById((int) $currencyPreference->data);
|
||||||
}
|
}
|
||||||
$journalId = $row->transaction_journal_id;
|
$journalId = $row->transaction_journal_id;
|
||||||
$return[$journalId] ??= [];
|
$return[$journalId] ??= [];
|
||||||
|
@@ -32,6 +32,7 @@ use FireflyIII\Models\ObjectGroup;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||||
@@ -141,7 +142,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
}
|
}
|
||||||
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
||||||
if ($currencyId > 0) {
|
if ($currencyId > 0) {
|
||||||
return TransactionCurrency::find($currencyId);
|
return Amount::getTransactionCurrencyById($currencyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@@ -29,11 +29,11 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Support\Facades\Preferences;
|
use FireflyIII\Support\Facades\Preferences;
|
||||||
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Singleton\PreferencesSingleton;
|
use FireflyIII\Support\Singleton\PreferencesSingleton;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use NumberFormatter;
|
use NumberFormatter;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Amount.
|
* Class Amount.
|
||||||
@@ -85,7 +85,7 @@ class Amount
|
|||||||
|
|
||||||
public function formatByCurrencyId(int $currencyId, string $amount, ?bool $coloured = null): string
|
public function formatByCurrencyId(int $currencyId, string $amount, ?bool $coloured = null): string
|
||||||
{
|
{
|
||||||
$format = TransactionCurrency::find($currencyId);
|
$format = $this->getTransactionCurrencyById($currencyId);
|
||||||
|
|
||||||
return $this->formatFlat($format->symbol, $format->decimal_places, $amount, $coloured);
|
return $this->formatFlat($format->symbol, $format->decimal_places, $amount, $coloured);
|
||||||
}
|
}
|
||||||
@@ -115,6 +115,40 @@ class Amount
|
|||||||
return (string)$amount;
|
return (string)$amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTransactionCurrencyById(int $currencyId): TransactionCurrency
|
||||||
|
{
|
||||||
|
$instance = PreferencesSingleton::getInstance();
|
||||||
|
$key = sprintf('transaction_currency_%d', $currencyId);
|
||||||
|
/** @var TransactionCurrency|null $pref */
|
||||||
|
$pref = $instance->getPreference($key);
|
||||||
|
if (null !== $pref) {
|
||||||
|
return $pref;
|
||||||
|
}
|
||||||
|
$currency = TransactionCurrency::find($currencyId);
|
||||||
|
if (null === $currency) {
|
||||||
|
throw new FireflyException(sprintf('Could not find a transaction currency with ID #%d', $currencyId));
|
||||||
|
}
|
||||||
|
$instance->setPreference($key, $currency);
|
||||||
|
return $currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransactionCurrencyByCode(string $code): TransactionCurrency
|
||||||
|
{
|
||||||
|
$instance = PreferencesSingleton::getInstance();
|
||||||
|
$key = sprintf('transaction_currency_%s', $code);
|
||||||
|
/** @var TransactionCurrency|null $pref */
|
||||||
|
$pref = $instance->getPreference($key);
|
||||||
|
if (null !== $pref) {
|
||||||
|
return $pref;
|
||||||
|
}
|
||||||
|
$currency = TransactionCurrency::whereCode($code)->first();
|
||||||
|
if (null === $currency) {
|
||||||
|
throw new FireflyException(sprintf('Could not find a transaction currency with code "%s"', $code));
|
||||||
|
}
|
||||||
|
$instance->setPreference($key, $currency);
|
||||||
|
return $currency;
|
||||||
|
}
|
||||||
|
|
||||||
public function convertToPrimary(?User $user = null): bool
|
public function convertToPrimary(?User $user = null): bool
|
||||||
{
|
{
|
||||||
$instance = PreferencesSingleton::getInstance();
|
$instance = PreferencesSingleton::getInstance();
|
||||||
|
@@ -26,7 +26,7 @@ namespace FireflyIII\Support;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ class Balance
|
|||||||
foreach ($result as $entry) {
|
foreach ($result as $entry) {
|
||||||
$accountId = (int) $entry->account_id;
|
$accountId = (int) $entry->account_id;
|
||||||
$currencyId = (int) $entry->transaction_currency_id;
|
$currencyId = (int) $entry->transaction_currency_id;
|
||||||
$currencies[$currencyId] ??= TransactionCurrency::find($currencyId);
|
$currencies[$currencyId] ??= Amount::getTransactionCurrencyById($currencyId);
|
||||||
$return[$accountId] ??= [];
|
$return[$accountId] ??= [];
|
||||||
if (array_key_exists($currencyId, $return[$accountId])) {
|
if (array_key_exists($currencyId, $return[$accountId])) {
|
||||||
continue;
|
continue;
|
||||||
|
@@ -23,7 +23,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Support\Binder;
|
namespace FireflyIII\Support\Binder;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Routing\Route;
|
use Illuminate\Routing\Route;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@@ -38,10 +40,12 @@ class CurrencyCode implements BinderInterface
|
|||||||
public static function routeBinder(string $value, Route $route): TransactionCurrency
|
public static function routeBinder(string $value, Route $route): TransactionCurrency
|
||||||
{
|
{
|
||||||
if (auth()->check()) {
|
if (auth()->check()) {
|
||||||
$currency = TransactionCurrency::where('code', trim($value))->first();
|
try {
|
||||||
if (null !== $currency) {
|
$currency = Amount::getTransactionCurrencyByCode(trim($value));
|
||||||
return $currency;
|
} catch(FireflyException) {
|
||||||
|
throw new NotFoundHttpException();
|
||||||
}
|
}
|
||||||
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotFoundHttpException();
|
throw new NotFoundHttpException();
|
||||||
|
@@ -28,6 +28,7 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Enums\TransactionTypeEnum;
|
use FireflyIII\Enums\TransactionTypeEnum;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Facades\Navigation;
|
use FireflyIII\Support\Facades\Navigation;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -184,7 +185,7 @@ class AccountBalanceGrouped
|
|||||||
if (array_key_exists($currencyId, $this->currencies)) {
|
if (array_key_exists($currencyId, $this->currencies)) {
|
||||||
return $this->currencies[$currencyId];
|
return $this->currencies[$currencyId];
|
||||||
}
|
}
|
||||||
$this->currencies[$currencyId] = TransactionCurrency::find($currencyId);
|
$this->currencies[$currencyId] = Amount::getTransactionCurrencyById($currencyId);
|
||||||
|
|
||||||
return $this->currencies[$currencyId];
|
return $this->currencies[$currencyId];
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Models\CurrencyExchangeRate;
|
|||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -264,7 +265,7 @@ class ExchangeRateConverter
|
|||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return (int) $cache->get();
|
return (int) $cache->get();
|
||||||
}
|
}
|
||||||
$euro = TransactionCurrency::whereCode('EUR')->first();
|
$euro = Amount::getTransactionCurrencyByCode('EUR');
|
||||||
++$this->queryCount;
|
++$this->queryCount;
|
||||||
if (null === $euro) {
|
if (null === $euro) {
|
||||||
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
|
throw new FireflyException('Cannot find EUR in system, cannot do currency conversion.');
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Http\Api;
|
|||||||
|
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class SummaryBalanceGrouped
|
class SummaryBalanceGrouped
|
||||||
@@ -110,7 +111,7 @@ class SummaryBalanceGrouped
|
|||||||
// transaction info:
|
// transaction info:
|
||||||
$currencyId = (int) $journal['currency_id'];
|
$currencyId = (int) $journal['currency_id'];
|
||||||
$amount = bcmul((string) $journal['amount'], $multiplier);
|
$amount = bcmul((string) $journal['amount'], $multiplier);
|
||||||
$currency = $this->currencies[$currencyId] ?? TransactionCurrency::find($currencyId);
|
$currency = $this->currencies[$currencyId] ?? Amount::getTransactionCurrencyById($currencyId);
|
||||||
$this->currencies[$currencyId] = $currency;
|
$this->currencies[$currencyId] = $currency;
|
||||||
$pcAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
|
$pcAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
|
||||||
if ((int) $journal['foreign_currency_id'] === $this->default->id) {
|
if ((int) $journal['foreign_currency_id'] === $this->default->id) {
|
||||||
|
@@ -38,8 +38,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
*/
|
*/
|
||||||
trait ValidatesUserGroupTrait
|
trait ValidatesUserGroupTrait
|
||||||
{
|
{
|
||||||
protected ?UserGroup $userGroup = null;
|
protected UserGroup $userGroup;
|
||||||
protected ?User $user = null;
|
protected User $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An "undocumented" filter
|
* An "undocumented" filter
|
||||||
|
@@ -142,7 +142,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
|
|||||||
$accountId = (int)$item->account_id;
|
$accountId = (int)$item->account_id;
|
||||||
$currencyId = (int)$item->data;
|
$currencyId = (int)$item->data;
|
||||||
if (!array_key_exists($currencyId, $this->currencies)) {
|
if (!array_key_exists($currencyId, $this->currencies)) {
|
||||||
$this->currencies[$currencyId] = TransactionCurrency::find($currencyId);
|
$this->currencies[$currencyId] = Amount::getTransactionCurrencyById($currencyId);
|
||||||
}
|
}
|
||||||
// $this->accountCurrencies[$accountId] = $this->currencies[$currencyId];
|
// $this->accountCurrencies[$accountId] = $this->currencies[$currencyId];
|
||||||
}
|
}
|
||||||
|
@@ -121,7 +121,7 @@ class PiggyBankEventEnrichment implements EnrichmentInterface
|
|||||||
$accountId = (int)$item->account_id;
|
$accountId = (int)$item->account_id;
|
||||||
$currencyId = (int)$item->data;
|
$currencyId = (int)$item->data;
|
||||||
if (!array_key_exists($currencyId, $this->currencies)) {
|
if (!array_key_exists($currencyId, $this->currencies)) {
|
||||||
$this->currencies[$currencyId] = TransactionCurrency::find($currencyId);
|
$this->currencies[$currencyId] = Amount::getTransactionCurrencyById($currencyId);
|
||||||
}
|
}
|
||||||
$this->accountCurrencies[$accountId] = $this->currencies[$currencyId];
|
$this->accountCurrencies[$accountId] = $this->currencies[$currencyId];
|
||||||
}
|
}
|
||||||
|
@@ -321,7 +321,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
|||||||
if ($this->convertToPrimary && null !== $entry->foreign_currency_id && (int)$entry->foreign_currency_id !== $this->primaryCurrency->id) {
|
if ($this->convertToPrimary && null !== $entry->foreign_currency_id && (int)$entry->foreign_currency_id !== $this->primaryCurrency->id) {
|
||||||
// TODO this is very database intensive.
|
// TODO this is very database intensive.
|
||||||
/** @var TransactionCurrency $foreignCurrency */
|
/** @var TransactionCurrency $foreignCurrency */
|
||||||
$foreignCurrency = TransactionCurrency::find($entry->foreign_currency_id);
|
$foreignCurrency = Amount::getTransactionCurrencyById($entry->foreign_currency_id);
|
||||||
$array['pc_foreign_amount'] = $converter->convert($foreignCurrency, $this->primaryCurrency, $entry->date, $entry->amount);
|
$array['pc_foreign_amount'] = $converter->convert($foreignCurrency, $this->primaryCurrency, $entry->date, $entry->amount);
|
||||||
}
|
}
|
||||||
$result[] = $array;
|
$result[] = $array;
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Models\AccountBalance;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -171,7 +172,7 @@ class AccountBalanceCalculator
|
|||||||
*/
|
*/
|
||||||
foreach ($currencies as $currencyId => $balance) {
|
foreach ($currencies as $currencyId => $balance) {
|
||||||
/** @var null|TransactionCurrency $currency */
|
/** @var null|TransactionCurrency $currency */
|
||||||
$currency = TransactionCurrency::find($currencyId);
|
$currency = Amount::getTransactionCurrencyById($currencyId);
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
Log::error(sprintf('Could not find currency #%d, will not save account balance.', $currencyId));
|
Log::error(sprintf('Could not find currency #%d, will not save account balance.', $currencyId));
|
||||||
|
|
||||||
|
@@ -285,7 +285,7 @@ class Steam
|
|||||||
$sumOfDay = $this->floatalize($sumOfDay);
|
$sumOfDay = $this->floatalize($sumOfDay);
|
||||||
|
|
||||||
// find currency of this entry, does not have to exist.
|
// find currency of this entry, does not have to exist.
|
||||||
$currencies[$entry->transaction_currency_id] ??= TransactionCurrency::find($entry->transaction_currency_id);
|
$currencies[$entry->transaction_currency_id] ??= Amount::getTransactionCurrencyById($entry->transaction_currency_id);
|
||||||
|
|
||||||
// make sure this $entry has its own $entryCurrency
|
// make sure this $entry has its own $entryCurrency
|
||||||
/** @var TransactionCurrency $entryCurrency */
|
/** @var TransactionCurrency $entryCurrency */
|
||||||
@@ -502,7 +502,7 @@ class Steam
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TransactionCurrency::find((int)$result->data);
|
return Amount::getTransactionCurrencyById((int)$result->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
||||||
@@ -524,7 +524,7 @@ class Steam
|
|||||||
$singleton = PreferencesSingleton::getInstance();
|
$singleton = PreferencesSingleton::getInstance();
|
||||||
foreach ($others as $key => $amount) {
|
foreach ($others as $key => $amount) {
|
||||||
$preference = $singleton->getPreference($key);
|
$preference = $singleton->getPreference($key);
|
||||||
$currency = $preference ?? TransactionCurrency::where('code', $key)->first();
|
$currency = $preference ?? Amount::getTransactionCurrencyByCode($key);
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -162,9 +162,9 @@ class AmountFormat extends AbstractExtension
|
|||||||
static function (string $amount, string $code, ?bool $coloured = null): string {
|
static function (string $amount, string $code, ?bool $coloured = null): string {
|
||||||
$coloured ??= true;
|
$coloured ??= true;
|
||||||
|
|
||||||
/** @var null|TransactionCurrency $currency */
|
try {
|
||||||
$currency = TransactionCurrency::whereCode($code)->first();
|
$currency = Amount::getTransactionCurrencyByCode($code);
|
||||||
if (null === $currency) {
|
} catch(FireflyException) {
|
||||||
Log::error(sprintf('Could not find currency with code "%s". Fallback to primary currency.', $code));
|
Log::error(sprintf('Could not find currency with code "%s". Fallback to primary currency.', $code));
|
||||||
$currency = Amount::getPrimaryCurrency();
|
$currency = Amount::getPrimaryCurrency();
|
||||||
Log::error(sprintf('Fallback currency is "%s".', $currency->code));
|
Log::error(sprintf('Fallback currency is "%s".', $currency->code));
|
||||||
|
@@ -99,7 +99,7 @@ class General extends AbstractExtension
|
|||||||
}
|
}
|
||||||
// for multi currency accounts.
|
// for multi currency accounts.
|
||||||
if ($usePrimary && $key !== $primary->code) {
|
if ($usePrimary && $key !== $primary->code) {
|
||||||
$strings[] = app('amount')->formatAnything(TransactionCurrency::where('code', $key)->first(), $balance, false);
|
$strings[] = app('amount')->formatAnything(Amount::getTransactionCurrencyByCode($key), $balance, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user