diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 55815f327..e1b511856 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->account_email_settings->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->account_email_settings->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->account_email_settings->is_disabled) { continue; } diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index d2ee90376..de24f7277 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->account_email_settings->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->account_email_settings->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->account_email_settings->is_disabled) { continue; } diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index d8c15ea43..c83ff2d30 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->account_email_settings->forward_url_for_v5) >1){ + + if ($invoice->isType(INVOICE_TYPE_QUOTE)) + $entity = 'quote'; + else + $entity = 'invoice'; + + return redirect($account->account_email_settings->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 68b200162..e7e4d76a6 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\BaseController; use App\Http\Requests\MigrationAuthRequest; use App\Http\Requests\MigrationCompaniesRequest; use App\Http\Requests\MigrationEndpointRequest; +use App\Http\Requests\MigrationForwardRequest; use App\Http\Requests\MigrationTypeRequest; use App\Libraries\Utils; use App\Models\Account; @@ -15,6 +16,8 @@ use App\Services\Migration\CompleteService; use App\Traits\GenerateMigrationResources; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; +use Validator; +use Illuminate\Http\Request; class StepsController extends BaseController { @@ -83,6 +86,36 @@ class StepsController extends BaseController ); } + public function forwardUrl(Request $request) + { + + $rules = [ + 'url' => 'nullable|url', + ]; + + $validator = Validator::make($request->all(), $rules); + + if ($validator->fails()) { + return back() + ->withErrors($validator) + ->withInput(); + } + + $account_settings = \Auth::user()->account->account_email_settings; + + if(strlen($request->input('url')) == 0) { + $account_settings->is_disabled = false; + } + else { + $account_settings->is_disabled = true; + } + + $account_settings->forward_url_for_v5 = rtrim($request->input('url'),'/'); + $account_settings->save(); + + return back(); + } + public function endpoint() { if ($this->shouldGoBack('endpoint')) { @@ -176,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/Http/Requests/MigrationForwardRequest.php b/app/Http/Requests/MigrationForwardRequest.php new file mode 100644 index 000000000..3cb594e91 --- /dev/null +++ b/app/Http/Requests/MigrationForwardRequest.php @@ -0,0 +1,30 @@ + 'nullable|url', + ]; + } +} diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index e958afdc9..84e74b1d0 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, @@ -211,9 +211,53 @@ info("get company"); 'auto_archive_quote' => $this->account->auto_archive_quote ? (bool) $this->account->auto_archive_quote : false, 'auto_email_invoice' => $this->account->auto_email_invoice ? (bool) $this->account->auto_email_invoice : false, 'counter_padding' => $this->account->invoice_number_padding ?: 4, + 'reply_to_email' => $this->account->account_email_settings->reply_to_email ?: '', + 'bcc_email' => $this->account->account_email_settings->bcc_email ?: '', + 'email_subject_invoice' => $this->account->account_email_settings->email_subject_invoice ?: '', + 'email_subject_quote' => $this->account->account_email_settings->email_subject_quote ?: '', + 'email_subject_payment' => $this->account->account_email_settings->email_subject_payment ?: '', + 'email_template_invoice' => $this->account->account_email_settings->email_template_invoice ?: '', + 'email_template_quote' => $this->account->account_email_settings->email_template_quote ?: '', + 'email_template_payment' => $this->account->account_email_settings->email_template_payment ?: '', + 'email_subject_reminder1' => $this->account->account_email_settings->email_subject_reminder1 ?: '', + 'email_subject_reminder2' => $this->account->account_email_settings->email_subject_reminder2 ?: '', + 'email_subject_reminder3' => $this->account->account_email_settings->email_subject_reminder3 ?: '', + 'email_subject_reminder_endless' => $this->account->account_email_settings->email_subject_reminder4 ?: '', + 'email_template_reminder1' => $this->account->account_email_settings->email_template_reminder1 ?: '', + 'email_template_reminder2' => $this->account->account_email_settings->email_template_reminder2 ?: '', + 'email_template_reminder3' => $this->account->account_email_settings->email_template_reminder3 ?: '', + 'email_template_reminder_endless' => $this->account->account_email_settings->email_template_reminder4 ?: '', + 'late_fee_amount1' => $this->account->account_email_settings->late_fee1_amount ?: 0, + 'late_fee_amount2' => $this->account->account_email_settings->late_fee2_amount ?: 0, + 'late_fee_amount3' => $this->account->account_email_settings->late_fee3_amount ?: 0, + 'late_fee_percent1' => $this->account->account_email_settings->late_fee1_percent ?: 0, + 'late_fee_percent2' => $this->account->account_email_settings->late_fee2_percent ?: 0, + 'late_fee_percent3' => $this->account->account_email_settings->late_fee3_percent ?: 0, + 'enable_reminder1' => $this->account->enable_reminder1 ? true : false, + 'enable_reminder2' => $this->account->enable_reminder2 ? true : false, + 'enable_reminder3' => $this->account->enable_reminder3 ? true : false, + 'enable_reminder_endless' => $this->account->enable_reminder4 ? true : false, + 'num_days_reminder1' => $this->account->num_days_reminder1 ?: 0, + 'num_days_reminder2' => $this->account->num_days_reminder2 ?: 0, + 'num_days_reminder3' => $this->account->num_days_reminder3 ?: 0, + 'schedule_reminder1' => $this->buildReminderString($this->account->direction_reminder1, $this->account->field_reminder1), + 'schedule_reminder2' => $this->buildReminderString($this->account->direction_reminder2, $this->account->field_reminder2), + 'schedule_reminder3' => $this->buildReminderString($this->account->direction_reminder3, $this->account->field_reminder3), + 'endless_reminder_frequency_id' => $this->account->account_email_settings->reset_counter_frequency_id ? $this->transformFrequencyId($this->account->account_email_settings->reset_counter_frequency_id) : 0, + 'email_signature' => $this->account->email_footer ?: '', ]; } + private function buildReminderString($direction, $field) + { + + $direction_string = $direction == 1 ? "after_" : "before_"; + $field_string = $field == 1 ? "due_date" : "invoice_date"; + + return $direction_string.$field_string; + + } + public function getTaxRates() { info("get tax rates"); 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 new file mode 100644 index 000000000..07ba15532 --- /dev/null +++ b/database/migrations/2021_06_22_234707_add_forward_url_for_v5.php @@ -0,0 +1,31 @@ +text('forward_url_for_v5')->default(''); + $table->boolean('is_disabled')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/views/accounts/management.blade.php b/resources/views/accounts/management.blade.php index d9efb8979..1c920624b 100644 --- a/resources/views/accounts/management.blade.php +++ b/resources/views/accounts/management.blade.php @@ -264,9 +264,46 @@ - {!! Former::close() !!} +
+
+

Forward customers to V5

+
+
+
+ {{ csrf_field() }} +
+ +
+
+ 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. +

+
+
+
+ +
+ + @if($errors->has('url')) +
+ @foreach ($errors->get('url') as $message) + + + {{ $message }} + + @endforeach +
+ @endif +
+ +
+
+
+
+
+ @if (! Auth::user()->account->isNinjaOrLicenseAccount())
diff --git a/routes/web.php b/routes/web.php index ab2062bfb..107c8e9d5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -159,6 +159,7 @@ Route::group(['middleware' => ['lookup:user', 'auth:user']], function () { Route::get('migration/companies', 'Migration\StepsController@companies'); Route::post('migration/companies', 'Migration\StepsController@handleCompanies'); Route::get('migration/completed', 'Migration\StepsController@completed'); + Route::post('migration/forward', 'Migration\StepsController@forwardUrl'); Route::get('migration/import', 'Migration\StepsController@import');