. */ declare(strict_types=1); namespace FireflyIII\Support\Form; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Log; use Throwable; /** * Class AccountForm * * All form methods that are account related. * * TODO describe all methods. * TODO optimize repositories and methods. */ class AccountForm { use FormSupport; private function getAccountsGrouped(array $types, AccountRepositoryInterface $repository = null): array { if (null === $repository) { $repository = $this->getAccountRepository(); } $accountList = $repository->getActiveAccountsByType($types); $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]; $grouped = []; /** @var Account $account */ foreach ($accountList as $account) { $role = (string)$repository->getMetaValue($account, 'account_role'); if (in_array($account->accountType->type, $liabilityTypes, true)) { $role = sprintf('l_%s', $account->accountType->type); } elseif ('' === $role) { if (AccountType::EXPENSE === $account->accountType->type) { $role = 'expense_account'; } elseif (AccountType::REVENUE === $account->accountType->type) { $role = 'revenue_account'; } else { $role = 'no_account_type'; } } $key = (string) trans(sprintf('firefly.opt_group_%s', $role)); $grouped[$key][$account->id] = $account->name; } return $grouped; } /** * Shows a