mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix for issue #328. Turns out the import routine converts accounts back and forth instead of creating new entries.
This commit is contained in:
parent
abc4f856ce
commit
ad2b254be0
@ -148,16 +148,20 @@ class AccountCrud implements AccountCrudInterface
|
||||
if (count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
|
||||
}
|
||||
Log::debug(sprintf('Searching for account named %s of the following type(s)', $name), ['types' => $types]);
|
||||
|
||||
$accounts = $query->get(['accounts.*']);
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->name === $name) {
|
||||
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
Log::debug('Found nothing.');
|
||||
|
||||
return new Account;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ class ImportStorage
|
||||
private function storeJournal($entry): TransactionJournal
|
||||
{
|
||||
|
||||
$billId = is_null($entry->fields['bill']) ? null : $entry->fields['bill']->id;
|
||||
$billId = is_null($entry->fields['bill']) || intval($entry->fields['bill']->id) === 0 ? null : intval($entry->fields['bill']->id);
|
||||
$journalData = [
|
||||
'user_id' => $entry->user->id,
|
||||
'transaction_type_id' => $entry->fields['transaction-type']->id,
|
||||
@ -310,7 +310,7 @@ class ImportStorage
|
||||
$journal = TransactionJournal::create($journalData);
|
||||
|
||||
foreach ($journal->getErrors()->all() as $err) {
|
||||
Log::error($err);
|
||||
Log::error('Error when storing journal: ' . $err);
|
||||
}
|
||||
Log::debug('Created journal', ['id' => $journal->id]);
|
||||
|
||||
|
@ -178,10 +178,25 @@ class ImportValidator
|
||||
$result = $repository->findByName($account->name, [$type]);
|
||||
if (is_null($result->id)) {
|
||||
// can convert account:
|
||||
Log::debug(sprintf('No account named %s of type %s, will convert.', $account->name, $type));
|
||||
$result = $repository->updateAccountType($account, $type);
|
||||
|
||||
Log::debug(sprintf('No account named %s of type %s, create new account.', $account->name, $type));
|
||||
$result = $repository->store(
|
||||
[
|
||||
'user' => $this->user->id,
|
||||
'accountType' => config('firefly.shortNamesByFullName.' . $type),
|
||||
'name' => $account->name,
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
'openingBalance' => 0,
|
||||
]
|
||||
);
|
||||
}
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Using another account named %s (#%d) of type %s, will use that one instead of %s (#%d)', $account->name, $result->id, $type, $account->name,
|
||||
$account->id
|
||||
)
|
||||
);
|
||||
|
||||
return $result;
|
||||
|
||||
|
@ -111,7 +111,6 @@ class TransactionJournal extends TransactionJournalSupport
|
||||
= [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'transaction_type_id' => 'required|exists:transaction_types,id',
|
||||
'bill_id' => 'exists:bills,id',
|
||||
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
|
||||
'description' => 'required|between:1,1024',
|
||||
'completed' => 'required|boolean',
|
||||
|
Loading…
Reference in New Issue
Block a user