From 3d91a186d54da0ccd1efcb0ca594612627f74a6d Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 18 Sep 2018 18:17:55 +0200 Subject: [PATCH] Remove credit card liability type from system. --- app/Console/Commands/UpgradeDatabase.php | 23 +++++++++++++++++++ .../Controllers/Account/CreateController.php | 2 -- .../Controllers/Account/EditController.php | 2 -- database/seeds/AccountTypeSeeder.php | 5 ++-- .../Account/CreateControllerTest.php | 1 - .../Account/EditControllerTest.php | 2 -- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index 246222edfa..a5de3d1e7b 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -98,6 +98,7 @@ class UpgradeDatabase extends Command $this->migrateAttachmentData(); $this->migrateBillsToRules(); $this->budgetLimitCurrency(); + $this->removeCCLiabilities(); $this->info('Firefly III database is up to date.'); @@ -535,6 +536,28 @@ class UpgradeDatabase extends Command } } + /** + * + */ + private function removeCCLiabilities(): void + { + $ccType = AccountType::where('type', AccountType::CREDITCARD)->first(); + $debtType =AccountType::where('type', AccountType::DEBT)->first(); + if(null === $ccType || null === $debtType) { + return; + } + /** @var Collection $accounts */ + $accounts = Account::where('account_type_id', $ccType->id)->get(); + foreach($accounts as $account) { + $account->account_type_id = $debtType->id; + $account->save(); + $this->line(sprintf('Converted credit card liability account "%s" (#%d) to generic debt liability.', $account->name, $account->id)); + } + if($accounts->count() > 0) { + $this->info('Credit card liability types are no longer supported and have been converted to generic debts. See: http://bit.ly/FF3-credit-cards'); + } + } + /** * This method makes sure that the transaction journal uses the currency given in the transaction. * diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index 6440aae26b..02c32fb94b 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -83,12 +83,10 @@ class CreateController extends Controller $debt = $this->repository->getAccountTypeByType(AccountType::DEBT); $loan = $this->repository->getAccountTypeByType(AccountType::LOAN); $mortgage = $this->repository->getAccountTypeByType(AccountType::MORTGAGE); - $creditCard = $this->repository->getAccountTypeByType(AccountType::CREDITCARD); $liabilityTypes = [ $debt->id => (string)trans('firefly.account_type_' . AccountType::DEBT), $loan->id => (string)trans('firefly.account_type_' . AccountType::LOAN), $mortgage->id => (string)trans('firefly.account_type_' . AccountType::MORTGAGE), - $creditCard->id => (string)trans('firefly.account_type_' . AccountType::CREDITCARD), ]; asort($liabilityTypes); diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index 2ce4d98aa7..b984efb5cb 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -90,12 +90,10 @@ class EditController extends Controller $debt = $this->repository->getAccountTypeByType(AccountType::DEBT); $loan = $this->repository->getAccountTypeByType(AccountType::LOAN); $mortgage = $this->repository->getAccountTypeByType(AccountType::MORTGAGE); - $creditCard = $this->repository->getAccountTypeByType(AccountType::CREDITCARD); $liabilityTypes = [ $debt->id => (string)trans('firefly.account_type_' . AccountType::DEBT), $loan->id => (string)trans('firefly.account_type_' . AccountType::LOAN), $mortgage->id => (string)trans('firefly.account_type_' . AccountType::MORTGAGE), - $creditCard->id => (string)trans('firefly.account_type_' . AccountType::CREDITCARD), ]; asort($liabilityTypes); diff --git a/database/seeds/AccountTypeSeeder.php b/database/seeds/AccountTypeSeeder.php index f695c310d8..c3bb0287e9 100644 --- a/database/seeds/AccountTypeSeeder.php +++ b/database/seeds/AccountTypeSeeder.php @@ -28,7 +28,7 @@ use Illuminate\Database\Seeder; */ class AccountTypeSeeder extends Seeder { - public function run() + public function run(): void { $types = [ AccountType::DEFAULT, @@ -42,8 +42,7 @@ class AccountTypeSeeder extends Seeder AccountType::LOAN, AccountType::RECONCILIATION, AccountType::DEBT, - AccountType::MORTGAGE, - AccountType::CREDITCARD, + AccountType::MORTGAGE ]; foreach ($types as $type) { try { diff --git a/tests/Feature/Controllers/Account/CreateControllerTest.php b/tests/Feature/Controllers/Account/CreateControllerTest.php index 33879f295f..9d558d8b25 100644 --- a/tests/Feature/Controllers/Account/CreateControllerTest.php +++ b/tests/Feature/Controllers/Account/CreateControllerTest.php @@ -73,7 +73,6 @@ class CreateControllerTest extends TestCase $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once(); - $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Credit card'])->andReturn(AccountType::find(13))->once(); $this->be($this->user()); $response = $this->get(route('accounts.create', ['asset'])); diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php index 44cf046a7b..cdcb965e36 100644 --- a/tests/Feature/Controllers/Account/EditControllerTest.php +++ b/tests/Feature/Controllers/Account/EditControllerTest.php @@ -86,7 +86,6 @@ class EditControllerTest extends TestCase $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once(); - $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Credit card'])->andReturn(AccountType::find(13))->once(); $this->be($this->user()); @@ -131,7 +130,6 @@ class EditControllerTest extends TestCase $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once(); $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once(); - $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Credit card'])->andReturn(AccountType::find(13))->once(); $this->be($this->user());