mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixes #694
This commit is contained in:
parent
780bec35bb
commit
9b6ccdd43a
@ -37,6 +37,8 @@ class ImportAccount
|
|||||||
private $accountName = [];
|
private $accountName = [];
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $accountNumber = [];
|
private $accountNumber = [];
|
||||||
|
/** @var int */
|
||||||
|
private $defaultAccountId = 0;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $expectedType = '';
|
private $expectedType = '';
|
||||||
/** @var AccountRepositoryInterface */
|
/** @var AccountRepositoryInterface */
|
||||||
@ -115,6 +117,14 @@ class ImportAccount
|
|||||||
$this->accountNumber = $accountNumber;
|
$this->accountNumber = $accountNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $defaultAccountId
|
||||||
|
*/
|
||||||
|
public function setDefaultAccountId(int $defaultAccountId)
|
||||||
|
{
|
||||||
|
$this->defaultAccountId = $defaultAccountId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
@ -249,6 +259,12 @@ class ImportAccount
|
|||||||
$search = intval($array['mapped']);
|
$search = intval($array['mapped']);
|
||||||
$account = $this->repository->find($search);
|
$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) {
|
if ($account->accountType->type !== $this->expectedType) {
|
||||||
Log::error(
|
Log::error(
|
||||||
sprintf(
|
sprintf(
|
||||||
@ -256,6 +272,7 @@ class ImportAccount
|
|||||||
$this->expectedType
|
$this->expectedType
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,6 +314,14 @@ class ImportAccount
|
|||||||
}
|
}
|
||||||
$this->expectedType = $oldExpectedType;
|
$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));
|
Log::debug(sprintf('Found no account of type %s so must create one ourselves.', $this->expectedType));
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
@ -181,11 +181,18 @@ class ImportBill
|
|||||||
Log::debug('Finding a mapped bill based on', $array);
|
Log::debug('Finding a mapped bill based on', $array);
|
||||||
|
|
||||||
$search = intval($array['mapped']);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,11 +181,17 @@ class ImportBudget
|
|||||||
Log::debug('Finding a mapped budget based on', $array);
|
Log::debug('Finding a mapped budget based on', $array);
|
||||||
|
|
||||||
$search = intval($array['mapped']);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,11 +175,17 @@ class ImportCategory
|
|||||||
Log::debug('Finding a mapped category based on', $array);
|
Log::debug('Finding a mapped category based on', $array);
|
||||||
|
|
||||||
$search = intval($array['mapped']);
|
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,6 +209,13 @@ class ImportCurrency
|
|||||||
$search = intval($array['mapped']);
|
$search = intval($array['mapped']);
|
||||||
$currency = $this->repository->find($search);
|
$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));
|
Log::debug(sprintf('Found currency! #%d ("%s"). Return it', $currency->id, $currency->name));
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
|
@ -301,7 +301,7 @@ class ImportStorage
|
|||||||
private function storeImportJournal(int $index, ImportJournal $importJournal): bool
|
private function storeImportJournal(int $index, ImportJournal $importJournal): bool
|
||||||
{
|
{
|
||||||
Log::debug(sprintf('Going to store object #%d with description "%s"', $index, $importJournal->description));
|
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();
|
$asset = $importJournal->asset->getAccount();
|
||||||
$amount = $importJournal->getAmount();
|
$amount = $importJournal->getAmount();
|
||||||
$currency = $this->getCurrency($importJournal, $asset);
|
$currency = $this->getCurrency($importJournal, $asset);
|
||||||
|
Loading…
Reference in New Issue
Block a user