Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix for issue #328. Turns out the import routine converts accounts back and forth instead of creating new entries.
James Colead2b254be0a9
diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.phpindex 9bdad2023e..483722fd6e 100644--- a/app/Crud/Account/AccountCrud.php+++ b/app/Crud/Account/AccountCrud.php@@ -148,16 +148,20 @@ class AccountCrud implements AccountCrudInterfaceif (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;}diff --git a/app/Import/ImportStorage.php b/app/Import/ImportStorage.phpindex 81ab4d9e05..44be15d5e6 100644--- a/app/Import/ImportStorage.php+++ b/app/Import/ImportStorage.php@@ -293,7 +293,7 @@ class ImportStorageprivate 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]);diff --git a/app/Import/ImportValidator.php b/app/Import/ImportValidator.phpindex f9861defa1..58e6145abe 100644--- a/app/Import/ImportValidator.php+++ b/app/Import/ImportValidator.php@@ -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;diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex 9765a008f7..f38288e919 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -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',