diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index c2a4a1d6bd..e41fb872a6 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -69,16 +69,13 @@ class NinjaPlanController extends Controller //harvest the current plan $data = []; - if(MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); - if($account && $account->isPaidHostedClient()) + if($account) { - $data['account'] = $account; - if(Carbon::parse($account->plan_expires)->lt(now())){ //expired get the most recent invoice for payment @@ -90,69 +87,58 @@ class NinjaPlanController extends Controller ->orderBy('id', 'DESC') ->first(); - if($late_invoice) + //account status means user cannot perform upgrades until they pay their account. $data['late_invoice'] = $late_invoice; } - //build list of upgrades. + $recurring_invoice = RecurringInvoice::on('db-ninja-01') + ->where('client_id', auth('contact')->user()->client->id) + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->whereNotNull('subscription_id') + ->where('status_id', RecurringInvoice::STATUS_ACTIVE) + ->orderBy('id', 'desc') + ->first(); - $monthly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 6) - ->get(); + $monthly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 6) + ->orderBy('promo_price', 'ASC') + ->get(); - $yearly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 31) - ->get(); + $yearly_plans = Subscription::on('db-ninja-01') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 31) + ->orderBy('promo_price', 'ASC') + ->get(); + + $monthly_plans = $monthly_plans->merge($yearly_plans); + + $current_subscription_id = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->subscription_id) : false; + + //remove existing subscription + if($current_subscription_id){ + + $monthly_plans = $monthly_plans->filter(function ($plan) use($current_subscription_id){ + return (string)$plan->hashed_id != (string)$current_subscription_id; + }); + + } + + $data['account'] = $account; + $data['client'] = Auth::guard('contact')->user()->client; + $data['plans'] = $monthly_plans; + $data['current_subscription_id'] = $current_subscription_id; + $data['current_recurring_id'] = $recurring_invoice ? $recurring_invoice->hashed_id : false; + + return $this->render('plan.index', $data); - $monthly_plans->merge($yearly_plans); } + } + else + return redirect()->route('client.catchall'); - $recurring_invoice = RecurringInvoice::query() - ->where('client_id', auth('contact')->user()->client->id) - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->whereNotNull('subscription_id') - ->where('status_id', RecurringInvoice::STATUS_ACTIVE) - ->orderBy('id', 'desc') - ->first(); - - - $data['late_invoice'] = Invoice::first(); - - $monthly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - // ->where('group_id', 6) - ->orderBy('promo_price', 'ASC') - ->get(); - - $yearly_plans = Subscription::on('db-ninja-01') - ->where('company_id', Auth::guard('contact')->user()->company->id) - ->where('group_id', 31) - ->orderBy('promo_price', 'ASC') - ->get(); - - $monthly_plans->merge($yearly_plans); - - $current_subscription_id = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->subscription_id) : false; - - //remove existing subscription - if($current_subscription_id){ - - $monthly_plans = $monthly_plans->filter(function ($plan) use($current_subscription_id){ - return (string)$plan->hashed_id != (string)$current_subscription_id; - }); - - } - - $data['account'] = Account::first(); - $data['client'] = Auth::guard('contact')->user()->client; - $data['plans'] = $monthly_plans; - $data['current_subscription_id'] = $current_subscription_id; - $data['current_recurring_id'] = $recurring_invoice ? $this->encodePrimaryKey($recurring_invoice->hashed_id) : false; - - return $this->render('plan.index', $data); + } } diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php index 35372358ef..71f0ac4f57 100644 --- a/app/Http/Livewire/RequiredClientInfo.php +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -60,8 +60,8 @@ class RequiredClientInfo extends Component 'contact_first_name' => 'first_name', 'contact_last_name' => 'last_name', - 'contact_email' => 'email', - 'contact_phone' => 'phone', + // 'contact_email' => 'email', + // 'contact_phone' => 'phone', ]; public $show_form = false; @@ -141,7 +141,7 @@ class RequiredClientInfo extends Component $_field = $this->mappings[$field['name']]; if (Str::startsWith($field['name'], 'client_')) { - if (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field}) || $this->contact->client->{$_field} = 840) { + if (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field}) || $this->contact->client->{$_field} == 840) { $this->show_form = true; } else { $this->fields[$index]['filled'] = true; @@ -149,7 +149,7 @@ class RequiredClientInfo extends Component } if (Str::startsWith($field['name'], 'contact_')) { - if ((empty($this->contact->{$_field}) || is_null($this->contact->{$_field})) || $this->contact->client->{$_field} = 840) { + if ((empty($this->contact->{$_field}) || is_null($this->contact->{$_field})) || $this->contact->client->{$_field} == 840) { $this->show_form = true; } else { $this->fields[$index]['filled'] = true; diff --git a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php index f5ae39999f..3568ff8cf5 100644 --- a/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php +++ b/app/Http/Livewire/SubscriptionRecurringInvoicesTable.php @@ -38,6 +38,7 @@ class SubscriptionRecurringInvoicesTable extends Component ->where('client_id', auth('contact')->user()->client->id) ->where('company_id', $this->company->id) ->whereNotNull('subscription_id') + ->where('is_deleted', false) ->where('status_id', RecurringInvoice::STATUS_ACTIVE) ->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc') ->withTrashed() diff --git a/app/PaymentDrivers/Braintree/CreditCard.php b/app/PaymentDrivers/Braintree/CreditCard.php index 0613dfe8ab..f66304b52c 100644 --- a/app/PaymentDrivers/Braintree/CreditCard.php +++ b/app/PaymentDrivers/Braintree/CreditCard.php @@ -136,7 +136,7 @@ class CreditCard return $this->processSuccessfulPayment($result); } - $error = $result ?: 'Undefined gateway error'; + $error = 'Undefined gateway error'; return $this->processUnsuccessfulPayment($error); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index ba7da5f286..dad9c094b8 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -18,6 +18,7 @@ use App\Factory\InvoiceToRecurringInvoiceFactory; use App\Factory\RecurringInvoiceFactory; use App\Jobs\Util\SubscriptionWebhookHandler; use App\Jobs\Util\SystemLogger; +use App\Libraries\MultiDB; use App\Models\Client; use App\Models\ClientContact; use App\Models\Credit; @@ -240,10 +241,10 @@ class SubscriptionService elseif ($outstanding->count() > 1) { //user is changing plan mid frequency cycle //we cannot handle this if there are more than one invoice outstanding. - return null; + return $target->price; } - return null; + return $target->price; } @@ -439,7 +440,7 @@ class SubscriptionService $credit = false; /* Only generate a credit if the previous invoice was paid in full. */ - if($last_invoice->balance == 0) + if($last_invoice && $last_invoice->balance == 0) $credit = $this->createCredit($last_invoice, $target_subscription, $is_credit); $new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice); diff --git a/resources/views/portal/ninja2020/plan/index.blade.php b/resources/views/portal/ninja2020/plan/index.blade.php index ce62369f84..4ab6008db6 100644 --- a/resources/views/portal/ninja2020/plan/index.blade.php +++ b/resources/views/portal/ninja2020/plan/index.blade.php @@ -1,5 +1,5 @@ @extends('portal.ninja2020.layout.app') -@section('meta_title', ctrans('texts.pro_plan_call_to_action')) +@section('meta_title', ctrans('texts.account_management')) @section('body') @@ -7,11 +7,8 @@

- {{ ctrans('texts.account_management') }} -

-

{{ ctrans('texts.plan_status') }} -

+
@@ -49,6 +46,29 @@ @endif + @if($late_invoice) + +
+

+ {{ ctrans('texts.invoice_status_id') }} +

+

+ {{ ctrans('texts.past_due') }} +

+
+
+
+
+ {{ ctrans('texts.invoice') }} +
+
+ {{ $late_invoice->number }} - {{ \App\Utils\Number::formatMoney($late_invoice->balance, $client) }} {{ ctrans('texts.pay_now')}} +
+
+
+ + @else +
{{ ctrans('texts.plan_change') }} @@ -71,10 +91,11 @@ {{ ctrans('texts.plan_upgrade') }} @endif -
+ @endif +
@@ -88,13 +109,15 @@ @if($current_recurring_id) document.getElementById('handlePlanChange').addEventListener('click', function() { - location.href = 'http://ninja.test:8000/client/subscriptions/{{ $current_recurring_id }}/plan_switch/' + document.getElementById("newPlan").value + ''; + if(document.getElementById("newPlan").value.length > 1) + location.href = 'https://invoiceninja.invoicing.co/client/subscriptions/{{ $current_recurring_id }}/plan_switch/' + document.getElementById("newPlan").value + ''; }); @else document.getElementById('handleNewPlan').addEventListener('click', function() { - location.href = 'http://ninja.test:8000/client/subscriptions/' + document.getElementById("newPlan").value + '/purchase'; + if(document.getElementById("newPlan").value.length > 1) + location.href = 'https://invoiceninja.invoicing.co/client/subscriptions/' + document.getElementById("newPlan").value + '/purchase'; }); @endif