This commit is contained in:
James Cole 2017-07-10 19:52:31 +02:00
parent 780bec35bb
commit 9b6ccdd43a
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
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 = [

View File

@ -181,11 +181,18 @@ class ImportBill
Log::debug('Finding a mapped bill based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
$bill = $this->repository->find($search);
Log::debug(sprintf('Found bill! #%d ("%s"). Return it', $account->id, $account->name));
if (is_null($bill->id)) {
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
return $account;
return new Bill;
}
Log::debug(sprintf('Found bill! #%d ("%s"). Return it', $bill->id, $bill->name));
return $bill;
}
/**

View File

@ -181,11 +181,17 @@ class ImportBudget
Log::debug('Finding a mapped budget based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
$budget = $this->repository->find($search);
Log::debug(sprintf('Found budget! #%d ("%s"). Return it', $account->id, $account->name));
if (is_null($budget->id)) {
Log::error(sprintf('There is no budget with id #%d. Invalid mapping will be ignored!', $search));
return $account;
return new Budget;
}
Log::debug(sprintf('Found budget! #%d ("%s"). Return it', $budget->id, $budget->name));
return $budget;
}
/**

View File

@ -175,11 +175,17 @@ class ImportCategory
Log::debug('Finding a mapped category based on', $array);
$search = intval($array['mapped']);
$account = $this->repository->find($search);
$category = $this->repository->find($search);
Log::debug(sprintf('Found category! #%d ("%s"). Return it', $account->id, $account->name));
if (is_null($category->id)) {
Log::error(sprintf('There is no category with id #%d. Invalid mapping will be ignored!', $search));
return $account;
return new Category;
}
Log::debug(sprintf('Found category! #%d ("%s"). Return it', $category->id, $category->name));
return $category;
}
/**

View File

@ -209,6 +209,13 @@ class ImportCurrency
$search = intval($array['mapped']);
$currency = $this->repository->find($search);
if (is_null($currency->id)) {
Log::error(sprintf('There is no currency with id #%d. Invalid mapping will be ignored!', $search));
return new TransactionCurrency;
}
Log::debug(sprintf('Found currency! #%d ("%s"). Return it', $currency->id, $currency->name));
return $currency;

View File

@ -301,7 +301,7 @@ class ImportStorage
private function storeImportJournal(int $index, ImportJournal $importJournal): bool
{
Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $importJournal->description));
$importJournal->asset->setDefaultAccountId($this->job->configuration['import-account']);
$asset = $importJournal->asset->getAccount();
$amount = $importJournal->getAmount();
$currency = $this->getCurrency($importJournal, $asset);