mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 10:53:37 +00:00
Move findByIban
This commit is contained in:
@@ -51,32 +51,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
$this->user = $user;
|
$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 string $name
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@@ -25,14 +25,6 @@ use Illuminate\Support\Collection;
|
|||||||
interface AccountCrudInterface
|
interface AccountCrudInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $iban
|
|
||||||
* @param array $types
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function findByIban(string $iban, array $types): Account;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@@ -62,7 +62,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// 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)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by IBAN', ['id' => $account->id]);
|
Log::debug('Found account by IBAN', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
|
@@ -61,7 +61,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $crud->findByIban($value, []);
|
$account = $repository->findByIban($value, []);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by IBAN', ['id' => $account->id]);
|
Log::debug('Found account by IBAN', ['id' => $account->id]);
|
||||||
Log::info(
|
Log::info(
|
||||||
|
@@ -23,6 +23,7 @@ use FireflyIII\Import\Specifics\SpecificInterface;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -177,8 +178,9 @@ class CsvSetup implements SetupInterface
|
|||||||
*/
|
*/
|
||||||
public function saveImportConfiguration(array $data, FileBag $files): bool
|
public function saveImportConfiguration(array $data, FileBag $files): bool
|
||||||
{
|
{
|
||||||
/** @var AccountCrud $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountCrud::class, [auth()->user()]);
|
$repository = app(AccountRepositoryInterface::class, [auth()->user()]);
|
||||||
|
|
||||||
$importId = $data['csv_import_account'] ?? 0;
|
$importId = $data['csv_import_account'] ?? 0;
|
||||||
$account = $repository->find(intval($importId));
|
$account = $repository->find(intval($importId));
|
||||||
|
|
||||||
@@ -384,6 +386,10 @@ class CsvSetup implements SetupInterface
|
|||||||
|
|
||||||
//do something here
|
//do something here
|
||||||
foreach ($indexes as $index) { // this is simply 1, 2, 3, etc.
|
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];
|
$value = $row[$index];
|
||||||
if (strlen($value) > 0) {
|
if (strlen($value) > 0) {
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ use DB;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,6 +120,32 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return new Account;
|
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.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
@@ -58,6 +58,14 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function findByAccountNumber(string $number, array $types): Account;
|
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.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user