Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -62,17 +62,17 @@ class EnableCurrencies extends Command
private function correctCurrencies(UserGroup $userGroup): void
{
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$repos = app(CurrencyRepositoryInterface::class);
// first check if the user has any default currency (not necessarily the case, so can be forced).
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($userGroup);
Log::debug(sprintf('Now correcting currencies for user group #%d', $userGroup->id));
$found = [$defaultCurrency->id];
$found = [$defaultCurrency->id];
// get all meta entries
/** @var Collection $meta */
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->where('accounts.user_group_id', $userGroup->id)
->where('account_meta.name', 'currency_id')->groupBy('data')->get(['data'])
;
@@ -81,7 +81,7 @@ class EnableCurrencies extends Command
}
// get all from journals:
$journals = TransactionJournal::where('user_group_id', $userGroup->id)
$journals = TransactionJournal::where('user_group_id', $userGroup->id)
->groupBy('transaction_currency_id')->get(['transaction_currency_id'])
;
foreach ($journals as $entry) {
@@ -89,7 +89,7 @@ class EnableCurrencies extends Command
}
// get all from transactions
$transactions = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
$transactions = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_group_id', $userGroup->id)
->groupBy('transactions.transaction_currency_id', 'transactions.foreign_currency_id')
->get(['transactions.transaction_currency_id', 'transactions.foreign_currency_id'])
@@ -100,7 +100,7 @@ class EnableCurrencies extends Command
}
// get all from budget limits
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->groupBy('transaction_currency_id')
->get(['budget_limits.transaction_currency_id'])
;
@@ -108,8 +108,8 @@ class EnableCurrencies extends Command
$found[] = $entry->transaction_currency_id;
}
$found = array_values(array_unique($found));
$found = array_values(
$found = array_values(array_unique($found));
$found = array_values(
array_filter(
$found,
static function (int $currencyId) {
@@ -118,7 +118,7 @@ class EnableCurrencies extends Command
)
);
$valid = new Collection();
$valid = new Collection();
/** @var int $currencyId */
foreach ($found as $currencyId) {
@@ -127,7 +127,7 @@ class EnableCurrencies extends Command
$valid->push($currency);
}
}
$ids = $valid->pluck('id')->toArray();
$ids = $valid->pluck('id')->toArray();
Log::debug(sprintf('Found currencies for user group #%d: %s', $userGroup->id, implode(', ', $ids)));
$userGroup->currencies()->sync($ids);