mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix various code.
This commit is contained in:
@@ -40,6 +40,8 @@ use Illuminate\Support\Facades\DB;
|
||||
use Override;
|
||||
use stdClass;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class AccountRepository
|
||||
*
|
||||
@@ -68,7 +70,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->where('accounts.active', true)
|
||||
->where(
|
||||
static function (EloquentBuilder $q1) use ($number): void {
|
||||
$json = \Safe\json_encode($number);
|
||||
$json = json_encode($number);
|
||||
$q1->where('account_meta.name', '=', 'account_number');
|
||||
$q1->where('account_meta.data', '=', $json);
|
||||
}
|
||||
@@ -167,7 +169,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$account = $this->user->accounts()->find($accountId);
|
||||
if (null === $account) {
|
||||
$account = $this->userGroup->accounts()->find($accountId);
|
||||
return $this->userGroup->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/** @var null|Account */
|
||||
|
@@ -49,13 +49,13 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUserGroup($this->userGroup)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
|
||||
if (null !== $accounts && $accounts->count() > 0) {
|
||||
if ($accounts instanceof Collection && $accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (null !== $budgets && $budgets->count() > 0) {
|
||||
if ($budgets instanceof Collection && $budgets->count() > 0) {
|
||||
$collector->setBudgets($budgets);
|
||||
}
|
||||
if (null === $budgets || (0 === $budgets->count())) {
|
||||
if (!$budgets instanceof Collection || (0 === $budgets->count())) {
|
||||
$collector->setBudgets($this->getBudgets());
|
||||
}
|
||||
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
|
||||
|
@@ -41,6 +41,8 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class CurrencyRepository
|
||||
*
|
||||
@@ -81,7 +83,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// is being used in accounts:
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((string) $currency->id))->count();
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string) $currency->id))->count();
|
||||
if ($meta > 0) {
|
||||
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
|
||||
@@ -89,7 +91,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
|
||||
// second search using integer check.
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((int) $currency->id))->count();
|
||||
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((int) $currency->id))->count();
|
||||
if ($meta > 0) {
|
||||
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
|
||||
@@ -117,7 +119,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
// is being used in accounts (as integer)
|
||||
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('account_meta.name', 'currency_id')->where('account_meta.data', \Safe\json_encode($currency->id))->count()
|
||||
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
|
||||
;
|
||||
if ($meta > 0) {
|
||||
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
|
||||
@@ -239,7 +241,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
{
|
||||
$result = $this->findCurrencyNull($currencyId, $currencyCode);
|
||||
|
||||
if (null === $result) {
|
||||
if (!$result instanceof TransactionCurrency) {
|
||||
Log::debug('Grabbing default currency for this user...');
|
||||
|
||||
/** @var null|TransactionCurrency $result */
|
||||
@@ -262,11 +264,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
{
|
||||
Log::debug(sprintf('Now in findCurrencyNull("%s", "%s")', $currencyId, $currencyCode));
|
||||
$result = $this->find((int) $currencyId);
|
||||
if (null === $result) {
|
||||
if (!$result instanceof TransactionCurrency) {
|
||||
Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode));
|
||||
$result = $this->findByCode((string) $currencyCode);
|
||||
}
|
||||
if (null !== $result && false === $result->enabled) {
|
||||
if ($result instanceof TransactionCurrency && false === $result->enabled) {
|
||||
Log::debug(sprintf('Also enabled currency %s', $result->code));
|
||||
$this->enable($result);
|
||||
}
|
||||
|
@@ -109,7 +109,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
|
||||
public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate
|
||||
{
|
||||
$object->rate = $rate;
|
||||
if (null !== $date) {
|
||||
if ($date instanceof Carbon) {
|
||||
$object->date = $date;
|
||||
}
|
||||
$object->save();
|
||||
|
Reference in New Issue
Block a user