This commit is contained in:
James Cole
2017-07-10 19:52:31 +02:00
parent 780bec35bb
commit 9b6ccdd43a
6 changed files with 61 additions and 10 deletions

View File

@@ -37,6 +37,8 @@ class ImportAccount
private $accountName = [];
/** @var array */
private $accountNumber = [];
/** @var int */
private $defaultAccountId = 0;
/** @var string */
private $expectedType = '';
/** @var AccountRepositoryInterface */
@@ -115,6 +117,14 @@ class ImportAccount
$this->accountNumber = $accountNumber;
}
/**
* @param int $defaultAccountId
*/
public function setDefaultAccountId(int $defaultAccountId)
{
$this->defaultAccountId = $defaultAccountId;
}
/**
* @param User $user
*/
@@ -249,6 +259,12 @@ class ImportAccount
$search = intval($array['mapped']);
$account = $this->repository->find($search);
if (is_null($account->id)) {
Log::error(sprintf('There is no account with id #%d. Invalid mapping will be ignored!', $search));
return new Account;
}
if ($account->accountType->type !== $this->expectedType) {
Log::error(
sprintf(
@@ -256,6 +272,7 @@ class ImportAccount
$this->expectedType
)
);
return new Account;
}
@@ -297,6 +314,14 @@ class ImportAccount
}
$this->expectedType = $oldExpectedType;
// if search for an asset account, fall back to given "default account" (mandatory)
if ($this->expectedType === AccountType::ASSET) {
$this->account = $this->repository->find($this->defaultAccountId);
Log::debug(sprintf('Fall back to default account #%d "%s"', $this->account->id, $this->account->name));
return true;
}
Log::debug(sprintf('Found no account of type %s so must create one ourselves.', $this->expectedType));
$data = [