From 7dc4ecd209b7f014d74551527f2c6fbcb8415cde Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 23 Jun 2021 12:43:29 +1000 Subject: [PATCH] Forward requests to V5 and disable V4 --- .../Commands/SendRecurringInvoices.php | 11 ++++++++-- app/Console/Commands/SendReminders.php | 8 +++---- .../Controllers/ClientPortalController.php | 11 ++++++++++ .../Controllers/Migration/StepsController.php | 22 +++++++++++++++---- app/Traits/GenerateMigrationResources.php | 2 +- ...21_06_22_234707_add_forward_url_for_v5.php | 1 + resources/views/accounts/management.blade.php | 3 ++- 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 55815f327..11a8e0cd9 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -70,7 +70,9 @@ class SendRecurringInvoices extends Command ->get(); foreach ($accounts as $account) { - $account->checkCounterReset(); + + if(!$account->is_disabled) + $account->checkCounterReset(); } } @@ -94,6 +96,11 @@ class SendRecurringInvoices extends Command $this->info(date('r') . ' Processing Invoice: '. $recurInvoice->id); $account = $recurInvoice->account; + + if($account->is_disabled){ + continue; + } + $account->loadLocalizationSettings($recurInvoice->client); Auth::loginUsingId($recurInvoice->activeUser()->id); @@ -127,7 +134,7 @@ class SendRecurringInvoices extends Command foreach ($expenses as $expense) { $shouldSendToday = $expense->shouldSendToday(); - if (! $shouldSendToday) { + if (! $shouldSendToday || $expense->account->is_disabled) { continue; } diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index d2ee90376..29591e998 100644 --- a/app/Console/Commands/SendReminders.php +++ b/app/Console/Commands/SendReminders.php @@ -109,7 +109,7 @@ class SendReminders extends Command /** @var Invoice $invoice */ foreach ($delayedAutoBillInvoices as $invoice) { - if ($invoice->isPaid()) { + if ($invoice->isPaid() || $invoice->account->is_deleted) { continue; } @@ -128,7 +128,7 @@ class SendReminders extends Command $this->info(date('r ') . $accounts->count() . ' accounts found with fees enabled'); foreach ($accounts as $account) { - if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) { + if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS) || $account->is_disabled) { continue; } @@ -155,7 +155,7 @@ class SendReminders extends Command $this->info(date('r ') . count($accounts) . ' accounts found with reminders enabled'); foreach ($accounts as $account) { - if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) { + if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS) || $account->is_disabled) { continue; } @@ -201,7 +201,7 @@ class SendReminders extends Command $account = $scheduledReport->account; $account->loadLocalizationSettings(); - if (! $account->hasFeature(FEATURE_REPORTS)) { + if (! $account->hasFeature(FEATURE_REPORTS) || $account->is_disabled) { continue; } diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index d8c15ea43..4bb11aac9 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -67,6 +67,17 @@ class ClientPortalController extends BaseController $client = $invoice->client; $account = $invoice->account; + /* Forward requests from V4 to V5 if the domain is set */ + if(strlen($account->forward_url_for_v5) >1){ + + if ($invoice->isType(INVOICE_TYPE_QUOTE)) + $entity = 'quote'; + else + $entity = 'invoice'; + + return redirect($account->forward_url_for_v5."/client/".$entity."/".$invitationKey); + } + if (request()->silent) { session(['silent:' . $client->id => true]); return redirect(request()->url() . (request()->borderless ? '?borderless=true' : '')); diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index c659ff58f..1ab40663c 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -102,6 +102,14 @@ class StepsController extends BaseController } $account = \Auth::user()->account; + + if(strlen($request->input('url')) == 0) { + $account->is_disabled = false; + } + else { + $account->is_disabled = true; + } + $account->forward_url_for_v5 = rtrim($request->input('url'),'/'); $account->save(); @@ -201,22 +209,28 @@ class StepsController extends BaseController ); } + $completeService = (new CompleteService(session('MIGRATION_ACCOUNT_TOKEN'))); + try { $migrationData = $this->generateMigrationData($request->all()); - $completeService = (new CompleteService(session('MIGRATION_ACCOUNT_TOKEN'))) - ->data($migrationData) + + $completeService->data($migrationData) ->endpoint(session('MIGRATION_ENDPOINT')) ->start(); } - finally { + catch(\Exception $e){ + info($e->getMessage()); + return view('migration.completed', ['customMessage' => $e->getMessage()]); + } + if ($completeService->isSuccessful()) { return view('migration.completed'); } return view('migration.completed', ['customMessage' => $completeService->getErrors()[0]]); - } + } public function completed() diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index e958afdc9..a3d823d20 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -171,7 +171,7 @@ info("get company"); 'all_pages_footer' => $this->account->all_pages_footer ? (bool) $this->account->all_pages_footer : true, 'all_pages_header' => $this->account->all_pages_header ? (bool) $this->account->all_pages_header : true, 'show_currency_code' => $this->account->show_currency_code ? (bool) $this->account->show_currency_code : false, - 'enable_client_portal_password' => $this->account->enable_portal_password ? (bool) $this->account->enable_portal_password : true, + 'enable_client_portal_password' => $this->account->enable_portal_password ? (bool) $this->account->enable_portal_password : false, 'send_portal_password' => $this->account->send_portal_password ? (bool) $this->account->send_portal_password : false, 'recurring_number_prefix' => $this->account->recurring_invoice_number_prefix ? $this->account->recurring_invoice_number_prefix : 'R', 'enable_client_portal' => $this->account->enable_client_portal ? (bool) $this->account->enable_client_portal : false, diff --git a/database/migrations/2021_06_22_234707_add_forward_url_for_v5.php b/database/migrations/2021_06_22_234707_add_forward_url_for_v5.php index 718c7e31d..7b033cb6a 100644 --- a/database/migrations/2021_06_22_234707_add_forward_url_for_v5.php +++ b/database/migrations/2021_06_22_234707_add_forward_url_for_v5.php @@ -15,6 +15,7 @@ class AddForwardUrlForV5 extends Migration { Schema::table('accounts', function ($table) { $table->text('forward_url_for_v5')->default(''); + $table->boolean('is_disabled')->default(false); }); } diff --git a/resources/views/accounts/management.blade.php b/resources/views/accounts/management.blade.php index a72f4ccf8..9acb3c80d 100644 --- a/resources/views/accounts/management.blade.php +++ b/resources/views/accounts/management.blade.php @@ -277,7 +277,8 @@
- Once you are ready to forward your customers, enter your client portal URL for V5 here:
+ Once you are ready to forward your customers, enter your client portal URL for V5 here:

+ Please note once enabled. Your V4 account will become disabled. This means that your recurring invoices and any reminders will no longer fire from V4.

To renable your V4 installation simply set the forwarding url to a blank/empty value.