Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add button to remove unused accounts.
James Cole4ad666d9640d
diff --git a/app/Api/V1/Controllers/Data/DestroyController.php b/app/Api/V1/Controllers/Data/DestroyController.phpindex adba823dbc..ad7b41e66b 100644--- a/app/Api/V1/Controllers/Data/DestroyController.php+++ b/app/Api/V1/Controllers/Data/DestroyController.php@@ -45,12 +45,15 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface;use FireflyIII\Services\Internal\Destroy\AccountDestroyService;use FireflyIII\Services\Internal\Destroy\JournalDestroyService;use Illuminate\Http\JsonResponse;+use Illuminate\Support\Facades\Log;/*** Class DestroyController*/class DestroyController extends Controller{+ private bool $unused;+/*** This endpoint is documented at:* https://api-docs.firefly-iii.org/#/data/destroyData@@ -62,8 +65,8 @@ class DestroyController extends Controller*/public function destroy(DestroyRequest $request): JsonResponse{- $objects = $request->getObjects();-+ $objects = $request->getObjects();+ $this->unused = $request->boolean('unused', false);switch ($objects) {default:throw new FireflyException(sprintf('This endpoint can\'t handle object "%s"', $objects));@@ -260,9 +263,19 @@ class DestroyController extends Controller$repository = app(AccountRepositoryInterface::class);$collection = $repository->getAccountsByType($types);$service = app(AccountDestroyService::class);+/** @var Account $account */foreach ($collection as $account) {- $service->destroy($account, null);+ $count = $account->transactions()->count();+ if (true === $this->unused && 0 === $count) {+ Log::info(sprintf('Deleted unused account #%d "%s"', $account->id, $account->name));+ $service->destroy($account, null);+ continue;+ }+ if (false === $this->unused) {+ Log::info(sprintf('Deleting account #%d "%s"', $account->id, $account->name));+ $service->destroy($account, null);+ }}}diff --git a/app/Api/V1/Requests/Data/DestroyRequest.php b/app/Api/V1/Requests/Data/DestroyRequest.phpindex 2bc93dbb56..2b77fc5614 100644--- a/app/Api/V1/Requests/Data/DestroyRequest.php+++ b/app/Api/V1/Requests/Data/DestroyRequest.php@@ -56,6 +56,7 @@ class DestroyRequest extends FormRequestreturn ['objects' => sprintf('required|min:1|string|in:%s', $valid),+ 'unused' => 'in:true,false',];}}diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.phpindex 6f816018e7..fa686b3af4 100644--- a/app/Helpers/Report/NetWorth.php+++ b/app/Helpers/Report/NetWorth.php@@ -33,6 +33,7 @@ use FireflyIII\Support\CacheProperties;use FireflyIII\User;use Illuminate\Support\Collection;use JsonException;+use Illuminate\Support\Facades\Log;/***diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 7d6d2435e4..8b03bd5821 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -1344,6 +1344,9 @@ return ['delete_data_title' => 'Delete data from Firefly III','permanent_delete_stuff' => 'You can delete stuff from Firefly III. Using the buttons below means that your items will be removed from view and hidden. There is no undo-button for this, but the items may remain in the database where you can salvage them if necessary.','other_sessions_logged_out' => 'All your other sessions have been logged out.',+ 'delete_unused_accounts' => 'Deleting unused accounts will clean your auto-complete lists.',+ 'delete_all_unused_accounts' => 'Delete unused accounts',+ 'deleted_all_unused_accounts' => 'All unused accounts are deleted','delete_all_budgets' => 'Delete ALL your budgets','delete_all_categories' => 'Delete ALL your categories','delete_all_tags' => 'Delete ALL your tags',diff --git a/resources/views/profile/index.twig b/resources/views/profile/index.twigindex 11a56516cd..3698ecb27e 100644--- a/resources/views/profile/index.twig+++ b/resources/views/profile/index.twig@@ -257,6 +257,21 @@data-type="liabilities" class="confirm btn btn-warning btn-sm"><spanclass="fa fa-ticket"></span> {{ 'delete_all_liabilities'|_ }}</button></div>+ <h4>{{ 'accounts'|_ }}</h4>+ <p>+ <em class="text-info">+ {{ 'delete_unused_accounts'|_ }}+ </em>+ </p>+ <div class="btn-group">+ <button type="button"+ data-success="{{ trans('firefly.deleted_all_unused_accounts')|escape('html') }}"+ data-type="unused_accounts" class="confirm btn btn-warning btn-sm"><span+ class="fa fa-credit-card"></span> {{ 'delete_all_unused_accounts'|_ }}+ </button>+ </div>++<h4>{{ 'transactions'|_ }}</h4><div class="btn-group"><button type="button"@@ -301,9 +316,12 @@var classes = link.find('i').attr('class');var url = deleteAPIRoute + '?objects=' + link.data('type');// different URL for purge route:- if(link.data('type') === 'purge') {+ if (link.data('type') === 'purge') {url = '{{ route('api.v1.data.purge') }}';}+ if (link.data('type') === 'unused_accounts') {+ url = deleteAPIRoute + '?objects=accounts&unused=true';+ }// replace icon with loading thinglink.prop('disabled', true);