Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Code for #1671
James Cole155480b3357e
diff --git a/app/Import/Mapper/AssetAccountIbans.php b/app/Import/Mapper/AssetAccountIbans.phpindex f79415e63b..35c9880377 100644--- a/app/Import/Mapper/AssetAccountIbans.php+++ b/app/Import/Mapper/AssetAccountIbans.php@@ -40,7 +40,12 @@ class AssetAccountIbans implements MapperInterface{/** @var AccountRepositoryInterface $accountRepository */$accountRepository = app(AccountRepositoryInterface::class);- $set = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);+ $set = $accountRepository->getAccountsByType(+ [AccountType::DEFAULT, AccountType::ASSET,+ AccountType::LOAN, AccountType::DEBT,+ AccountType::CREDITCARD, AccountType::MORTGAGE,+ ]+ );$topList = [];$list = [];@@ -49,10 +54,22 @@ class AssetAccountIbans implements MapperInterface$iban = $account->iban ?? '';$accountId = (int)$account->id;if (\strlen($iban) > 0) {- $topList[$accountId] = $account->iban . ' (' . $account->name . ')';+ $name = $account->iban . ' (' . $account->name . ')';++ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';+ }++ $topList[$accountId] = $name;}if ('' === $iban) {- $list[$accountId] = $account->name;+ $name = $account->name;+ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';+ }+ $list[$accountId] = $name;}}/** @noinspection AdditionOperationOnArraysInspection */diff --git a/app/Import/Mapper/AssetAccounts.php b/app/Import/Mapper/AssetAccounts.phpindex e1062074a0..91c5962f03 100644--- a/app/Import/Mapper/AssetAccounts.php+++ b/app/Import/Mapper/AssetAccounts.php@@ -40,7 +40,7 @@ class AssetAccounts implements MapperInterface{/** @var AccountRepositoryInterface $accountRepository */$accountRepository = app(AccountRepositoryInterface::class);- $set = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);+ $set = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]);$list = [];/** @var Account $account */@@ -51,6 +51,12 @@ class AssetAccounts implements MapperInterfaceif (\strlen($iban) > 0) {$name .= ' (' . $iban . ')';}++ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = trans('import.import_liability_select') . ': ' . $name;+ }+$list[$accountId] = $name;}asort($list);diff --git a/app/Import/Mapper/OpposingAccountIbans.php b/app/Import/Mapper/OpposingAccountIbans.phpindex d11a75323a..54fe60dd93 100644--- a/app/Import/Mapper/OpposingAccountIbans.php+++ b/app/Import/Mapper/OpposingAccountIbans.php@@ -44,7 +44,8 @@ class OpposingAccountIbans implements MapperInterface[AccountType::DEFAULT, AccountType::ASSET,AccountType::EXPENSE, AccountType::BENEFICIARY,- AccountType::REVENUE,+ AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,+ AccountType::CREDITCARD, AccountType::MORTGAGE,]);$topList = [];@@ -55,10 +56,23 @@ class OpposingAccountIbans implements MapperInterface$iban = $account->iban ?? '';$accountId = (int)$account->id;if (\strlen($iban) > 0) {- $topList[$accountId] = $account->iban . ' (' . $account->name . ')';+ $name = $account->iban . ' (' . $account->name . ')';++ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';+ }++ $topList[$accountId] = $name;+}if ('' === $iban) {- $list[$accountId] = $account->name;+ $name = $account->name;+ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = $name . ' (' . strtolower(trans('import.import_liability_select')) . ')';+ }+ $list[$accountId] = $name;}}/** @noinspection AdditionOperationOnArraysInspection */diff --git a/app/Import/Mapper/OpposingAccounts.php b/app/Import/Mapper/OpposingAccounts.phpindex 424cdafb37..d47c74d8b7 100644--- a/app/Import/Mapper/OpposingAccounts.php+++ b/app/Import/Mapper/OpposingAccounts.php@@ -44,7 +44,8 @@ class OpposingAccounts implements MapperInterface[AccountType::DEFAULT, AccountType::ASSET,AccountType::EXPENSE, AccountType::BENEFICIARY,- AccountType::REVENUE,+ AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,+ AccountType::CREDITCARD, AccountType::MORTGAGE,]);$list = [];@@ -57,6 +58,10 @@ class OpposingAccounts implements MapperInterfaceif (\strlen($iban) > 0) {$name .= ' (' . $iban . ')';}+ // is a liability?+ if (\in_array($account->accountType->type, [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], true)) {+ $name = trans('import.import_liability_select') . ': ' . $name;+ }$list[$accountId] = $name;}asort($list);diff --git a/resources/lang/en_US/import.php b/resources/lang/en_US/import.phpindex d00ecd230f..16f0e84c73 100644--- a/resources/lang/en_US/import.php+++ b/resources/lang/en_US/import.php@@ -37,6 +37,7 @@ return [// index page:'general_index_title' => 'Import a file','general_index_intro' => 'Welcome to Firefly III\'s import routine. There are a few ways of importing data into Firefly III, displayed here as buttons.',+// import provider strings (index):'button_fake' => 'Fake an import','button_file' => 'Import a file',@@ -110,6 +111,7 @@ return ['job_config_file_upload_type_help' => 'Select the type of file you will upload','job_config_file_upload_submit' => 'Upload files','import_file_type_csv' => 'CSV (comma separated values)',+ 'import_file_type_ofx' => 'OFX','file_not_utf8' => 'The file you have uploaded is not encoded as UTF-8 or ASCII. Firefly III cannot handle such files. Please use Notepad++ or Sublime to convert your file to UTF-8.','job_config_uc_title' => 'Import setup (2/4) - Basic file setup','job_config_uc_text' => 'To be able to import your file correctly, please validate the options below.',@@ -123,6 +125,7 @@ return ['job_config_uc_specifics_txt' => 'Some banks deliver badly formatted files. Firefly III can fix those automatically. If your bank delivers such files but it\'s not listed here, please open an issue on GitHub.','job_config_uc_submit' => 'Continue','invalid_import_account' => 'You have selected an invalid account to import into.',+ 'import_liability_select' => 'Liability',// job configuration for Spectre:'job_config_spectre_login_title' => 'Choose your login','job_config_spectre_login_text' => 'Firefly III has found :count existing login(s) in your Spectre account. Which one would you like to use to import from?',diff --git a/tests/Unit/Import/Mapper/AssetAccountIbansTest.php b/tests/Unit/Import/Mapper/AssetAccountIbansTest.phpindex f5775e28fa..638ac271e3 100644--- a/tests/Unit/Import/Mapper/AssetAccountIbansTest.php+++ b/tests/Unit/Import/Mapper/AssetAccountIbansTest.php@@ -28,8 +28,8 @@ use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;-use Tests\TestCase;use Log;+use Tests\TestCase;/*** Class AssetAccountIbansTest@@ -51,17 +51,25 @@ class AssetAccountIbansTest extends TestCase*/public function testGetMapBasic(): void{- $one = new Account;- $one->id = 17;- $one->name = 'Something';- $one->iban = 'IBAN';- $two = new Account;- $two->id = 53;- $two->name = 'Else';+ $asset = AccountType::where('type', AccountType::ASSET)->first();+ $loan = AccountType::where('type', AccountType::LOAN)->first();+ $one = new Account;+ $one->id = 17;+ $one->name = 'Something';+ $one->iban = 'IBAN';+ $one->account_type_id = $asset->id;++ $two = new Account;+ $two->id = 53;+ $two->name = 'Else';+ $two->account_type_id = $loan->id;+$collection = new Collection([$one, $two]);$repository = $this->mock(AccountRepositoryInterface::class);- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn($collection)->once();+ $repository->shouldReceive('getAccountsByType')->withArgs(+ [[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]]+ )->andReturn($collection)->once();$mapper = new AssetAccountIbans();$mapping = $mapper->getMap();@@ -69,7 +77,7 @@ class AssetAccountIbansTest extends TestCase// assert this is what the result looks like:$result = [0 => (string)trans('import.map_do_not_map'),- 53 => 'Else',+ 53 => 'Else (liability)',17 => 'IBAN (Something)',];$this->assertEquals($result, $mapping);diff --git a/tests/Unit/Import/Mapper/AssetAccountsTest.php b/tests/Unit/Import/Mapper/AssetAccountsTest.phpindex abfdc6cea1..5475c709ec 100644--- a/tests/Unit/Import/Mapper/AssetAccountsTest.php+++ b/tests/Unit/Import/Mapper/AssetAccountsTest.php@@ -28,8 +28,8 @@ use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;-use Tests\TestCase;use Log;+use Tests\TestCase;/*** Class AssetAccountsTest@@ -51,17 +51,26 @@ class AssetAccountsTest extends TestCase*/public function testGetMapBasic(): void{- $one = new Account;- $one->id = 23;- $one->name = 'Something';- $one->iban = 'IBAN';- $two = new Account;- $two->id = 19;- $two->name = 'Else';+ $asset = AccountType::where('type', AccountType::ASSET)->first();+ $loan = AccountType::where('type', AccountType::LOAN)->first();++ $one = new Account;+ $one->id = 23;+ $one->name = 'Something';+ $one->iban = 'IBAN';+ $one->account_type_id = $asset->id;++ $two = new Account;+ $two->id = 19;+ $two->name = 'Else';+ $two->account_type_id = $loan->id;+$collection = new Collection([$one, $two]);$repository = $this->mock(AccountRepositoryInterface::class);- $repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn($collection)->once();+ $repository->shouldReceive('getAccountsByType')->withArgs(+ [[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]]+ )->andReturn($collection)->once();$mapper = new AssetAccounts();$mapping = $mapper->getMap();@@ -69,7 +78,7 @@ class AssetAccountsTest extends TestCase// assert this is what the result looks like:$result = [0 => (string)trans('import.map_do_not_map'),- 19 => 'Else',+ 19 => 'Liability: Else',23 => 'Something (IBAN)',];diff --git a/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php b/tests/Unit/Import/Mapper/OpposingAccountIbansTest.phpindex da788d29b1..8eb1370518 100644--- a/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php+++ b/tests/Unit/Import/Mapper/OpposingAccountIbansTest.php@@ -28,8 +28,8 @@ use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;-use Tests\TestCase;use Log;+use Tests\TestCase;/*** Class OpposingAccountIbansTest@@ -51,18 +51,25 @@ class OpposingAccountIbansTest extends TestCase*/public function testGetMapBasic(): void{- $one = new Account;- $one->id = 21;- $one->name = 'Something';- $one->iban = 'IBAN';- $two = new Account;- $two->id = 17;- $two->name = 'Else';+ $asset = AccountType::where('type', AccountType::ASSET)->first();+ $loan = AccountType::where('type', AccountType::LOAN)->first();+ $one = new Account;+ $one->id = 21;+ $one->name = 'Something';+ $one->iban = 'IBAN';+ $one->account_type_id = $asset->id;++ $two = new Account;+ $two->id = 17;+ $two->name = 'Else';+ $two->account_type_id = $loan->id;+$collection = new Collection([$one, $two]);$repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('getAccountsByType')->withArgs(- [[AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE,]]+ [[AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE, AccountType::LOAN,+ AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE,]])->andReturn($collection)->once();$mapper = new OpposingAccountIbans();@@ -71,7 +78,7 @@ class OpposingAccountIbansTest extends TestCase// assert this is what the result looks like:$result = [0 => (string)trans('import.map_do_not_map'),- 17 => 'Else',+ 17 => 'Else (liability)',21 => 'IBAN (Something)',];$this->assertEquals($result, $mapping);diff --git a/tests/Unit/Import/Mapper/OpposingAccountsTest.php b/tests/Unit/Import/Mapper/OpposingAccountsTest.phpindex 597953b1d3..b780673b23 100644--- a/tests/Unit/Import/Mapper/OpposingAccountsTest.php+++ b/tests/Unit/Import/Mapper/OpposingAccountsTest.php@@ -28,8 +28,8 @@ use FireflyIII\Models\Account;use FireflyIII\Models\AccountType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;-use Tests\TestCase;use Log;+use Tests\TestCase;/*** Class OpposingAccountsTest@@ -51,18 +51,29 @@ class OpposingAccountsTest extends TestCase*/public function testGetMapBasic(): void{- $one = new Account;- $one->id = 13;- $one->name = 'Something';- $one->iban = 'IBAN';- $two = new Account;- $two->id = 9;- $two->name = 'Else';+ $asset = AccountType::where('type', AccountType::ASSET)->first();+ $loan = AccountType::where('type', AccountType::LOAN)->first();++ $one = new Account;+ $one->id = 13;+ $one->name = 'Something';+ $one->iban = 'IBAN';+ $one->account_type_id = $asset->id;+ $two = new Account;+ $two->id = 9;+ $two->name = 'Else';+ $two->account_type_id = $loan->id;+$collection = new Collection([$one, $two]);$repository = $this->mock(AccountRepositoryInterface::class);$repository->shouldReceive('getAccountsByType')->withArgs(- [[AccountType::DEFAULT, AccountType::ASSET, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::REVENUE,]]+ [[+ AccountType::DEFAULT, AccountType::ASSET,+ AccountType::EXPENSE, AccountType::BENEFICIARY,+ AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT,+ AccountType::CREDITCARD, AccountType::MORTGAGE,+ ]])->andReturn($collection)->once();$mapper = new OpposingAccounts();@@ -71,7 +82,7 @@ class OpposingAccountsTest extends TestCase// assert this is what the result looks like:$result = [0 => (string)trans('import.map_do_not_map'),- 9 => 'Else',+ 9 => 'Liability: Else',13 => 'Something (IBAN)',];$this->assertEquals($result, $mapping);