diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.php index 8b02964620..25aae371a9 100644 --- a/app/Crud/Account/AccountCrud.php +++ b/app/Crud/Account/AccountCrud.php @@ -51,32 +51,6 @@ class AccountCrud implements AccountCrudInterface $this->user = $user; } - /** - * @param string $iban - * @param array $types - * - * @return Account - */ - public function findByIban(string $iban, array $types): Account - { - $query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban'); - - if (count($types) > 0) { - $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); - $query->whereIn('account_types.type', $types); - } - - $accounts = $query->get(['accounts.*']); - /** @var Account $account */ - foreach ($accounts as $account) { - if ($account->iban === $iban) { - return $account; - } - } - - return new Account; - } - /** * @param string $name * @param array $types diff --git a/app/Crud/Account/AccountCrudInterface.php b/app/Crud/Account/AccountCrudInterface.php index 77d7b4ae76..2f1ee936ac 100644 --- a/app/Crud/Account/AccountCrudInterface.php +++ b/app/Crud/Account/AccountCrudInterface.php @@ -25,14 +25,6 @@ use Illuminate\Support\Collection; interface AccountCrudInterface { - /** - * @param string $iban - * @param array $types - * - * @return Account - */ - public function findByIban(string $iban, array $types): Account; - /** * @param string $name * @param array $types diff --git a/app/Import/Converter/AssetAccountIban.php b/app/Import/Converter/AssetAccountIban.php index d773487cfb..96bf71779c 100644 --- a/app/Import/Converter/AssetAccountIban.php +++ b/app/Import/Converter/AssetAccountIban.php @@ -62,7 +62,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface } // not mapped? Still try to find it first: - $account = $crud->findByIban($value, [AccountType::ASSET]); + $account = $repository->findByIban($value, [AccountType::ASSET]); if (!is_null($account->id)) { Log::debug('Found account by IBAN', ['id' => $account->id]); $this->setCertainty(50); diff --git a/app/Import/Converter/OpposingAccountIban.php b/app/Import/Converter/OpposingAccountIban.php index e04a128810..6d46b2662b 100644 --- a/app/Import/Converter/OpposingAccountIban.php +++ b/app/Import/Converter/OpposingAccountIban.php @@ -61,7 +61,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface } // not mapped? Still try to find it first: - $account = $crud->findByIban($value, []); + $account = $repository->findByIban($value, []); if (!is_null($account->id)) { Log::debug('Found account by IBAN', ['id' => $account->id]); Log::info( diff --git a/app/Import/Setup/CsvSetup.php b/app/Import/Setup/CsvSetup.php index f34c06aa8a..67c4cd77fd 100644 --- a/app/Import/Setup/CsvSetup.php +++ b/app/Import/Setup/CsvSetup.php @@ -23,6 +23,7 @@ use FireflyIII\Import\Specifics\SpecificInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Illuminate\Http\Request; use League\Csv\Reader; use Log; @@ -177,8 +178,9 @@ class CsvSetup implements SetupInterface */ public function saveImportConfiguration(array $data, FileBag $files): bool { - /** @var AccountCrud $repository */ - $repository = app(AccountCrud::class, [auth()->user()]); + /** @var AccountRepositoryInterface $repository */ + $repository = app(AccountRepositoryInterface::class, [auth()->user()]); + $importId = $data['csv_import_account'] ?? 0; $account = $repository->find(intval($importId)); @@ -384,6 +386,10 @@ class CsvSetup implements SetupInterface //do something here foreach ($indexes as $index) { // this is simply 1, 2, 3, etc. + if (!isset($row[$index])) { + // don't really know how to handle this. Just skip, for now. + continue; + } $value = $row[$index]; if (strlen($value) > 0) { diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index bd0f44f0ce..cc4dba77b8 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -19,6 +19,7 @@ use DB; use FireflyIII\Models\Account; use FireflyIII\Models\Transaction; use FireflyIII\User; +use Illuminate\Support\Collection; /** @@ -119,6 +120,32 @@ class AccountRepository implements AccountRepositoryInterface return new Account; } + /** + * @param string $iban + * @param array $types + * + * @return Account + */ + public function findByIban(string $iban, array $types): Account + { + $query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban'); + + if (count($types) > 0) { + $query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id'); + $query->whereIn('account_types.type', $types); + } + + $accounts = $query->get(['accounts.*']); + /** @var Account $account */ + foreach ($accounts as $account) { + if ($account->iban === $iban) { + return $account; + } + } + + return new Account; + } + /** * Returns the date of the very first transaction in this account. * diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index f2c1495162..59396e215c 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -58,6 +58,14 @@ interface AccountRepositoryInterface */ public function findByAccountNumber(string $number, array $types): Account; + /** + * @param string $iban + * @param array $types + * + * @return Account + */ + public function findByIban(string $iban, array $types): Account; + /** * Returns the date of the very first transaction in this account. *