diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index fc92f67890c7..49cbc094d6f6 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1307,6 +1307,16 @@ class AccountController extends BaseController return RESULT_SUCCESS; } + /** + * @return \Illuminate\Http\RedirectResponse + */ + public function purgeData() + { + $this->dispatch(new \App\Jobs\PurgeAccountData()); + + return redirect('/settings/account_management')->withMessage(trans('texts.purge_successful')); + } + /** * @return \Illuminate\Http\RedirectResponse */ diff --git a/app/Http/routes.php b/app/Http/routes.php index 76c42bde5b1b..2a4258f8c43a 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -257,6 +257,7 @@ Route::group([ Route::post('settings/change_plan', 'AccountController@changePlan'); Route::post('settings/cancel_account', 'AccountController@cancelAccount'); + Route::post('settings/purge_data', 'AccountController@purgeData'); Route::post('settings/company_details', 'AccountController@updateDetails'); Route::post('settings/{section?}', 'AccountController@doSection'); diff --git a/app/Jobs/PurgeAccountData.php b/app/Jobs/PurgeAccountData.php new file mode 100644 index 000000000000..c1f289e2cae3 --- /dev/null +++ b/app/Jobs/PurgeAccountData.php @@ -0,0 +1,61 @@ +account; + + if (! $user->is_admin) { + throw new Exception(trans('texts.forbidden')); + } + + // delete the documents from cloud storage + Document::scope()->each(function ($item, $key) { + $item->delete(); + }); + + $tables = [ + 'activities', + 'invitations', + 'account_gateway_tokens', + 'payment_methods', + 'credits', + 'expense_categories', + 'expenses', + 'invoice_items', + 'payments', + 'invoices', + 'tasks', + 'projects', + 'products', + 'vendor_contacts', + 'vendors', + 'contacts', + 'clients', + ]; + + foreach ($tables as $table) { + DB::table($table)->where('account_id', '=', $user->account_id)->delete(); + } + + $account->invoice_number_counter = 1; + $account->quote_number_counter = 1; + $account->client_number_counter = 1; + $account->save(); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 493811ee7b7f..af8b51dff120 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -369,7 +369,7 @@ $LANG = array( 'confirm_email_quote' => 'Are you sure you want to email this quote?', 'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?', 'cancel_account' => 'Delete Account', - 'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.', + 'cancel_account_message' => 'Warning: This will permanently delete your account, there is no undo.', 'go_back' => 'Go Back', 'data_visualizations' => 'Data Visualizations', 'sample_data' => 'Sample data shown', @@ -2449,6 +2449,13 @@ $LANG = array( 'create_credit_note' => 'Create Credit Note', 'menu' => 'Menu', 'error_incorrect_gateway_ids' => 'Error: The gateways table has incorrect ids.', + 'purge_data' => 'Purge Data', + 'delete_data' => 'Delete Data', + 'purge_data_help' => 'Permanently delete all data in the account, keeping the account and settings.', + 'cancel_account_help' => 'Permanently delete the account along with all data and setting.', + 'purge_successful' => 'Successfully purged account data', + 'forbidden' => 'Forbidden', + 'purge_data_message' => 'Warning: This will permanently erase your data, there is no undo.', ); diff --git a/resources/views/accounts/management.blade.php b/resources/views/accounts/management.blade.php index 8cb25b581872..8455d2c839db 100644 --- a/resources/views/accounts/management.blade.php +++ b/resources/views/accounts/management.blade.php @@ -221,38 +221,85 @@ {!! Former::close() !!} - {!! Former::open('settings/cancel_account')->addClass('cancel-account') !!}