Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some changes.
James Cole1658c666ab8c
diff --git a/app/Helpers/Csv/Converter/AssetAccountIban.php b/app/Helpers/Csv/Converter/AssetAccountIban.phpindex aea16d7964..a2229bdc94 100644--- a/app/Helpers/Csv/Converter/AssetAccountIban.php+++ b/app/Helpers/Csv/Converter/AssetAccountIban.php@@ -5,6 +5,7 @@ namespace FireflyIII\Helpers\Csv\Converter;use Auth;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;+use Log;/*** Class AssetAccountIban@@ -25,27 +26,33 @@ class AssetAccountIban extends BasicConverter implements ConverterInterfacereturn $account;}- // find or create new account:- $accountType = AccountType::where('type', 'Asset account')->first();- $set = Auth::user()->accounts()->where('account_type_id', $accountType->id)->get();- /** @var Account $entry */- foreach ($set as $entry) {- if ($entry->iban == $this->value) {- return $entry;+ if (strlen($this->value) > 0) {+ // find or create new account:+ $accountType = AccountType::where('type', 'Asset account')->first();+ $set = Auth::user()->accounts()->accountTypeIn(['Default account', 'Asset account'])->get(['accounts.*']);+ /** @var Account $entry */+ foreach ($set as $entry) {+ if ($entry->iban == $this->value) {+ Log::debug('AssetAccountIban::convert found an Account (#' . $entry->id . ': ' . $entry->name . ') with IBAN ' . $this->value);++ return $entry;+ }}++ // create it if doesn't exist.+ $account = Account::firstOrCreateEncrypted(+ [+ 'name' => $this->value,+ 'iban' => $this->value,+ 'user_id' => Auth::user()->id,+ 'account_type_id' => $accountType->id,+ 'active' => 1,+ ]+ );++ return $account;}- // create it if doesnt exist.- $account = Account::firstOrCreateEncrypted(- [- 'name' => $this->value,- 'iban' => $this->value,- 'user_id' => Auth::user()->id,- 'account_type_id' => $accountType->id,- 'active' => 1,- ]- );-- return $account;+ return null;}}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/AssetAccountName.php b/app/Helpers/Csv/Converter/AssetAccountName.phpindex cf1ff1a666..3fc708c20b 100644--- a/app/Helpers/Csv/Converter/AssetAccountName.php+++ b/app/Helpers/Csv/Converter/AssetAccountName.php@@ -1,6 +1,7 @@<?phpnamespace FireflyIII\Helpers\Csv\Converter;+use Auth;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;@@ -10,7 +11,7 @@ use FireflyIII\Models\AccountType;** @package FireflyIII\Helpers\Csv\Converter*/-class AssetAccountName extends BasicConverter implements ConverterInterface+class AssetAccountName extends BasicConverter implements ConverterInterface{/**@@ -26,7 +27,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface}// find or create new account:$accountType = AccountType::where('type', 'Asset account')->first();- $set = Auth::user()->accounts()->where('account_type_id', $accountType->id)->get();+ $set = Auth::user()->accounts()->accountTypeIn(['Asset account', 'Default account'])->get();/** @var Account $entry */foreach ($set as $entry) {if ($entry->name == $this->value) {diff --git a/app/Helpers/Csv/Converter/OpposingAccountIban.php b/app/Helpers/Csv/Converter/OpposingAccountIban.phpindex cbd4b70a73..92bad04d5e 100644--- a/app/Helpers/Csv/Converter/OpposingAccountIban.php+++ b/app/Helpers/Csv/Converter/OpposingAccountIban.php@@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;use Auth;use FireflyIII\Models\Account;+use Log;/*** Class OpposingAccountIban@@ -25,11 +26,15 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterfacereturn $account;} else {- $set = Auth::user()->accounts()->get();- /** @var Account $account */- foreach ($set as $account) {- if ($account->iban == $this->value) {- return $account;+ if (strlen($this->value) > 0) {+ $set = Auth::user()->accounts()->get();+ /** @var Account $account */+ foreach ($set as $account) {+ if ($account->iban == $this->value) {+ Log::debug('OpposingAccountIban::convert found an Account (#' . $account->id . ': ' . $account->name . ') with IBAN ' . $this->value);++ return $account;+ }}}diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.phpindex 07372518e6..edadb10d8e 100644--- a/app/Helpers/Csv/Importer.php+++ b/app/Helpers/Csv/Importer.php@@ -239,7 +239,7 @@ class Importer$transactionType = TransactionType::where('type', 'Withdrawal')->first();}- if ($data['opposing-account-object']->accountType->type == 'Asset account') {+ if (in_array($data['opposing-account-object']->accountType->type, ['Asset account', 'Default account'])) {$transactionType = TransactionType::where('type', 'Transfer')->first();}diff --git a/app/Helpers/Csv/PostProcessing/OpposingAccount.php b/app/Helpers/Csv/PostProcessing/OpposingAccount.phpindex 91214edd05..e8fe7a4220 100644--- a/app/Helpers/Csv/PostProcessing/OpposingAccount.php+++ b/app/Helpers/Csv/PostProcessing/OpposingAccount.php@@ -1,10 +1,11 @@<?phpnamespace FireflyIII\Helpers\Csv\PostProcessing;++use Auth;use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;-use Auth;-use FireflyIII\Validation\FireflyValidator;+use Log;use Validator;/**@@ -23,17 +24,25 @@ class OpposingAccount implements PostProcessorInterface*/public function process(){+ Log::debug('Start post processing opposing account');// first priority. try to find the account based on ID,// if any.if ($this->data['opposing-account-id'] instanceof Account) {+ Log::debug('opposing-account-id is an account (#' . $this->data['opposing-account-id']->id . ': ' . $this->data['opposing-account-id']->name . ')');$this->data['opposing-account-object'] = $this->data['opposing-account-id'];+ Log::debug('Done post processing opposing account.');return $this->data;}// second: try to find the account based on IBAN, if any.if ($this->data['opposing-account-iban'] instanceof Account) {+ Log::debug(+ 'opposing-account-iban is an account (#' .+ $this->data['opposing-account-iban']->id . ': ' . $this->data['opposing-account-iban']->name . ')'+ );$this->data['opposing-account-object'] = $this->data['opposing-account-iban'];+ Log::debug('Done post processing opposing account.');return $this->data;}@@ -41,27 +50,44 @@ class OpposingAccount implements PostProcessorInterface$rules = ['iban' => 'iban'];$check = ['iban' => $this->data['opposing-account-iban']];$validator = Validator::make($check, $rules);+ $result = !$validator->fails();- if (is_string($this->data['opposing-account-iban']) && $validator->valid()) {- $this->data['opposing-account-object'] = $this->parseIbanString();+ if (is_string($this->data['opposing-account-iban']) && strlen($this->data['opposing-account-iban']) > 0) {+ Log::debug('opposing-account-iban is an IBAN string (' . $this->data['opposing-account-iban'] . ')');+ if ($result) {+ Log::debug('opposing-account-iban is a valid IBAN string!');+ Log::debug('Go to parseIbanString()');+ $this->data['opposing-account-object'] = $this->parseIbanString();+ Log::debug('Done post processing opposing account.');- return $this->data;+ return $this->data;+ } else {+ Log::debug('opposing-account-iban is NOT a valid IBAN string!');+ }}// third: try to find account based on name, if any.if ($this->data['opposing-account-name'] instanceof Account) {-+ Log::debug(+ 'opposing-account-name is an Account (#' .+ $this->data['opposing-account-name']->id . ': ' . $this->data['opposing-account-name']->name . ') '+ );$this->data['opposing-account-object'] = $this->data['opposing-account-name'];+ Log::debug('Done post processing opposing account.');return $this->data;}if (is_string($this->data['opposing-account-name'])) {+ Log::debug('Opposing account name is a string: ' . $this->data['opposing-account-name']);+ Log::debug('Go to parseNameString');$this->data['opposing-account-object'] = $this->parseNameString();+ Log::debug('Done post processing opposing account.');return $this->data;}+ Log::debug('Done post processing opposing account.');return null;@@ -81,26 +107,30 @@ class OpposingAccount implements PostProcessorInterface*/protected function parseIbanString(){-+ Log::debug('Parse IBAN string!');// create by name and/or iban.$accountType = $this->getAccountType();- $accounts = Auth::user()->accounts()->where('account_type_id', $accountType->id)->get();+ $accounts = Auth::user()->accounts()->get();foreach ($accounts as $entry) {if ($entry->iban == $this->data['opposing-account-iban']) {+ Log::debug('Found existing account with this IBAN: (#' . $entry->id . ': ' . $entry->name . ')');return $entry;}}// create if not exists:+ $name = is_string($this->data['opposing-account-name']) && strlen($this->data['opposing-account-name']) > 0 ? $this->data['opposing-account-name']+ : $this->data['opposing-account-iban'];$account = Account::firstOrCreateEncrypted(['user_id' => Auth::user()->id,'account_type_id' => $accountType->id,- 'name' => $this->data['opposing-account-iban'],+ 'name' => $name,'iban' => $this->data['opposing-account-iban'],'active' => true,]);+ Log::debug('Created new (' . $accountType->type . ')B account with this IBAN: (#' . $account->id . ': ' . $account->name . ')');return $account;}@@ -120,6 +150,8 @@ class OpposingAccount implements PostProcessorInterface// create revenue account:return AccountType::where('type', 'Revenue account')->first();++}}@@ -132,6 +164,8 @@ class OpposingAccount implements PostProcessorInterface$accounts = Auth::user()->accounts()->where('account_type_id', $accountType->id)->get();foreach ($accounts as $entry) {if ($entry->name == $this->data['opposing-account-name']) {+ Log::debug('Found an account with this name (#' . $entry->id . ': ' . $entry->name . ')');+return $entry;}}@@ -146,6 +180,9 @@ class OpposingAccount implements PostProcessorInterface]);+ Log::debug('Created a new (' . $accountType->type . ')A account with this name (#' . $account->id . ': ' . $account->name . ')');++return $account;}}\ No newline at end of filediff --git a/config/csv.php b/config/csv.phpindex 6b8048194d..9b5914f796 100644--- a/config/csv.php+++ b/config/csv.php@@ -4,11 +4,11 @@ return ['RabobankDescription'],'post_processors' => [- 'OpposingAccount','Description','Amount','Currency',- 'Bill'+ 'Bill',+ 'OpposingAccount', // must be after Amount!],'roles' => [