mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 10:53:37 +00:00
Moved find() method to new class.
This commit is contained in:
@@ -52,21 +52,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $accountId
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function find(int $accountId): Account
|
|
||||||
{
|
|
||||||
$account = $this->user->accounts()->find($accountId);
|
|
||||||
if (is_null($account)) {
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $account;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $number
|
* @param string $number
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@@ -25,13 +25,6 @@ use Illuminate\Support\Collection;
|
|||||||
interface AccountCrudInterface
|
interface AccountCrudInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $accountId
|
|
||||||
*
|
|
||||||
* @return Account
|
|
||||||
*/
|
|
||||||
public function find(int $accountId): Account;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $number
|
* @param string $number
|
||||||
* @param array $types
|
* @param array $types
|
||||||
|
@@ -95,17 +95,16 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ARI $repository
|
* @param ARI $repository
|
||||||
* @param AccountCrudInterface $crud
|
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
*/
|
*/
|
||||||
public function destroy(ARI $repository, AccountCrudInterface $crud, Account $account)
|
public function destroy(ARI $repository, Account $account)
|
||||||
{
|
{
|
||||||
$type = $account->accountType->type;
|
$type = $account->accountType->type;
|
||||||
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
$typeName = config('firefly.shortNamesByFullName.' . $type);
|
||||||
$name = $account->name;
|
$name = $account->name;
|
||||||
$moveTo = $crud->find(intval(Input::get('move_account_before_delete')));
|
$moveTo = $repository->find(intval(Input::get('move_account_before_delete')));
|
||||||
|
|
||||||
$repository->destroy($account, $moveTo);
|
$repository->destroy($account, $moveTo);
|
||||||
|
|
||||||
|
@@ -15,13 +15,13 @@ namespace FireflyIII\Http\Controllers\Popup;
|
|||||||
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collection\BalanceLine;
|
use FireflyIII\Helpers\Collection\BalanceLine;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
@@ -93,8 +93,11 @@ class ReportController extends Controller
|
|||||||
/** @var BudgetRepositoryInterface $budgetRepository */
|
/** @var BudgetRepositoryInterface $budgetRepository */
|
||||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||||
$budget = $budgetRepository->find(intval($attributes['budgetId']));
|
$budget = $budgetRepository->find(intval($attributes['budgetId']));
|
||||||
$crud = app('FireflyIII\Crud\Account\AccountCrudInterface');
|
|
||||||
$account = $crud->find(intval($attributes['accountId']));
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
|
$account = $repository->find(intval($attributes['accountId']));
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
|
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
|
||||||
@@ -187,9 +190,11 @@ class ReportController extends Controller
|
|||||||
private function expenseEntry(array $attributes): string
|
private function expenseEntry(array $attributes): string
|
||||||
{
|
{
|
||||||
/** @var AccountTaskerInterface $tasker */
|
/** @var AccountTaskerInterface $tasker */
|
||||||
$tasker = app(AccountTaskerInterface::class);
|
$tasker = app(AccountTaskerInterface::class);
|
||||||
$crud = app(AccountCrudInterface::class);
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$account = $crud->find(intval($attributes['accountId']));
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
|
$account = $repository->find(intval($attributes['accountId']));
|
||||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
||||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||||
@@ -222,12 +227,12 @@ class ReportController extends Controller
|
|||||||
{
|
{
|
||||||
/** @var AccountTaskerInterface $tasker */
|
/** @var AccountTaskerInterface $tasker */
|
||||||
$tasker = app(AccountTaskerInterface::class);
|
$tasker = app(AccountTaskerInterface::class);
|
||||||
/** @var AccountCrudInterface $crud */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$crud = app(AccountCrudInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$account = $crud->find(intval($attributes['accountId']));
|
$account = $repository->find(intval($attributes['accountId']));
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
||||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||||
|
|
||||||
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
||||||
$journals = $journals->filter(
|
$journals = $journals->filter(
|
||||||
|
@@ -13,8 +13,8 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Import\Converter;
|
namespace FireflyIII\Import\Converter;
|
||||||
|
|
||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,8 +39,9 @@ class AccountId extends BasicConverter implements ConverterInterface
|
|||||||
|
|
||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
|
||||||
$account = $repository->find(intval($this->mapping[$value]));
|
$account = $repository->find(intval($this->mapping[$value]));
|
||||||
|
@@ -16,6 +16,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +43,11 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -58,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 = $repository->findByIban($value, [AccountType::ASSET]);
|
$account = $crud->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);
|
||||||
@@ -67,7 +71,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => 'Asset account with IBAN ' . $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
['name' => 'Asset account with IBAN ' . $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
||||||
'active' => true, 'openingBalance' => 0]
|
'active' => true, 'openingBalance' => 0]
|
||||||
);
|
);
|
||||||
|
@@ -16,6 +16,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +43,11 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -58,7 +62,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $repository->findByName($value, [AccountType::ASSET]);
|
$account = $crud->findByName($value, [AccountType::ASSET]);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found asset account by name', ['value' => $value, 'id' => $account->id]);
|
Log::debug('Found asset account by name', ['value' => $value, 'id' => $account->id]);
|
||||||
|
|
||||||
@@ -66,7 +70,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => $value, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
['name' => $value, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
|
||||||
'active' => true]
|
'active' => true]
|
||||||
);
|
);
|
||||||
|
@@ -16,6 +16,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +41,11 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -55,7 +59,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $repository->findByAccountNumber($value, [AccountType::ASSET]);
|
$account = $crud->findByAccountNumber($value, [AccountType::ASSET]);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
Log::debug('Found account by name', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
@@ -65,7 +69,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
|
|
||||||
// try to find by the name we would give it:
|
// try to find by the name we would give it:
|
||||||
$accountName = 'Asset account with number ' . e($value);
|
$accountName = 'Asset account with number ' . e($value);
|
||||||
$account = $repository->findByName($accountName, [AccountType::ASSET]);
|
$account = $crud->findByName($accountName, [AccountType::ASSET]);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
Log::debug('Found account by name', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
@@ -74,7 +78,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
||||||
'accountType' => 'asset',
|
'accountType' => 'asset',
|
||||||
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
||||||
|
@@ -15,6 +15,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
|
|
||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,8 +42,11 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -57,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 = $repository->findByIban($value, []);
|
$account = $crud->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(
|
||||||
@@ -69,7 +73,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
|
['name' => $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
|
||||||
'openingBalance' => 0]
|
'openingBalance' => 0]
|
||||||
);
|
);
|
||||||
|
@@ -15,6 +15,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
|
|
||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,8 +42,11 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -57,7 +61,7 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $repository->findByName($value, []);
|
$account = $crud->findByName($value, []);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found opposing account by name', ['id' => $account->id]);
|
Log::debug('Found opposing account by name', ['id' => $account->id]);
|
||||||
Log::info(
|
Log::info(
|
||||||
@@ -69,7 +73,7 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
|
|||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => $value, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
|
['name' => $value, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
|
||||||
'openingBalance' => 0,
|
'openingBalance' => 0,
|
||||||
]
|
]
|
||||||
|
@@ -16,6 +16,7 @@ namespace FireflyIII\Import\Converter;
|
|||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
use FireflyIII\Crud\Account\AccountCrudInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +43,11 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var AccountCrudInterface $repository */
|
/** @var AccountCrudInterface $crud */
|
||||||
$repository = app(AccountCrudInterface::class, [$this->user]);
|
$crud = app(AccountCrudInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$this->user]);
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapping[$value])) {
|
if (isset($this->mapping[$value])) {
|
||||||
@@ -58,7 +62,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// not mapped? Still try to find it first:
|
// not mapped? Still try to find it first:
|
||||||
$account = $repository->findByAccountNumber($value, []);
|
$account = $crud->findByAccountNumber($value, []);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by number', ['id' => $account->id]);
|
Log::debug('Found account by number', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
@@ -68,7 +72,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
|
|
||||||
// try to find by the name we would give it:
|
// try to find by the name we would give it:
|
||||||
$accountName = 'Import account with number ' . e($value);
|
$accountName = 'Import account with number ' . e($value);
|
||||||
$account = $repository->findByName($accountName, [AccountType::IMPORT]);
|
$account = $crud->findByName($accountName, [AccountType::IMPORT]);
|
||||||
if (!is_null($account->id)) {
|
if (!is_null($account->id)) {
|
||||||
Log::debug('Found account by name', ['id' => $account->id]);
|
Log::debug('Found account by name', ['id' => $account->id]);
|
||||||
$this->setCertainty(50);
|
$this->setCertainty(50);
|
||||||
@@ -77,7 +81,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$account = $repository->store(
|
$account = $crud->store(
|
||||||
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
['name' => $accountName, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id,
|
||||||
'accountType' => 'import',
|
'accountType' => 'import',
|
||||||
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
'virtualBalance' => 0, 'accountNumber' => $value, 'active' => true]
|
||||||
|
@@ -13,9 +13,9 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Import;
|
namespace FireflyIII\Import;
|
||||||
|
|
||||||
use FireflyIII\Crud\Account\AccountCrud;
|
|
||||||
use FireflyIII\Import\Importer\ImporterInterface;
|
use FireflyIII\Import\Importer\ImporterInterface;
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,7 +56,9 @@ class ImportProcedure
|
|||||||
$validator->setUser($job->user);
|
$validator->setUser($job->user);
|
||||||
$validator->setJob($job);
|
$validator->setJob($job);
|
||||||
if ($job->configuration['import-account'] != 0) {
|
if ($job->configuration['import-account'] != 0) {
|
||||||
$repository = app(AccountCrud::class, [$job->user]);
|
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class, [$job->user]);
|
||||||
$validator->setDefaultImportAccount($repository->find($job->configuration['import-account']));
|
$validator->setDefaultImportAccount($repository->find($job->configuration['import-account']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,17 +16,9 @@ namespace FireflyIII\Repositories\Account;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\PiggyBank;
|
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Query\JoinClause;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Steam;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,6 +77,21 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $accountId
|
||||||
|
*
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
public function find(int $accountId): Account
|
||||||
|
{
|
||||||
|
$account = $this->user->accounts()->find($accountId);
|
||||||
|
if (is_null($account)) {
|
||||||
|
return new Account;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the date of the very first transaction in this account.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
@@ -14,11 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Repositories\Account;
|
namespace FireflyIII\Repositories\Account;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface AccountRepositoryInterface
|
* Interface AccountRepositoryInterface
|
||||||
@@ -47,6 +43,13 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Account $account, Account $moveTo): bool;
|
public function destroy(Account $account, Account $moveTo): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
public function find(int $accountId): 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