From 7e9afd7849d45b16ff1b8998ea5b402ca0a5c7c9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 24 Nov 2021 08:57:24 +1100 Subject: [PATCH] Ninja plan --- .../ClientPortal/NinjaPlanController.php | 60 +++++++++- app/Http/ViewComposers/PortalComposer.php | 9 +- .../portal/ninja2020/plan/index.blade.php | 103 ++++++++++++++++++ 3 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 resources/views/portal/ninja2020/plan/index.blade.php diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index a534340ba539..c2a4a1d6bd9c 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -19,8 +19,10 @@ use App\Models\Account; use App\Models\ClientContact; use App\Models\Company; use App\Models\Invoice; +use App\Models\RecurringInvoice; use App\Models\Subscription; use App\Utils\Ninja; +use App\Utils\Traits\MakesHash; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; use Illuminate\Http\Response; @@ -29,6 +31,7 @@ use Illuminate\Support\Facades\Auth; class NinjaPlanController extends Controller { + use MakesHash; public function index(string $contact_key, string $account_or_company_key) { @@ -66,6 +69,7 @@ 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(); @@ -73,14 +77,17 @@ class NinjaPlanController extends Controller if($account && $account->isPaidHostedClient()) { - if(Carbon::parse($account->plan_expires).lt(now())){ + $data['account'] = $account; + + if(Carbon::parse($account->plan_expires)->lt(now())){ //expired get the most recent invoice for payment $late_invoice = Invoice::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('client_id', Auth::guard('contact')->user()->client->id) ->where('status_id', Invoice::STATUS_SENT) - ->orderBy('id', DESC) + ->whereNotNull('subscription_id') + ->orderBy('id', 'DESC') ->first(); if($late_invoice) @@ -90,17 +97,62 @@ class NinjaPlanController extends Controller //build list of upgrades. - $data['monthly_plans'] = Subscription::on('db-ninja-01') + $monthly_plans = Subscription::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('group_id', 6) ->get(); - $data['yearly_plans'] = Subscription::on('db-ninja-01') + $yearly_plans = Subscription::on('db-ninja-01') ->where('company_id', Auth::guard('contact')->user()->company->id) ->where('group_id', 31) ->get(); + + $monthly_plans->merge($yearly_plans); } } + $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/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 32034c05dfbd..ca8472aaa496 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -115,17 +115,16 @@ class PortalComposer $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download']; $data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar']; - - if(Ninja::isHosted() && auth('contact')->user()->company->id == config('ninja.ninja_default_company_id')) - $data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card']; - - if (auth('contact')->user()->client->getSetting('enable_client_portal_tasks')) { $data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock']; } $data[] = ['title' => ctrans('texts.statement'), 'url' => 'client.statement', 'icon' => 'activity']; + if(Ninja::isHosted() && auth('contact')->user()->company->id == config('ninja.ninja_default_company_id')) + $data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card']; + + return $data; } } diff --git a/resources/views/portal/ninja2020/plan/index.blade.php b/resources/views/portal/ninja2020/plan/index.blade.php new file mode 100644 index 000000000000..ce62369f8488 --- /dev/null +++ b/resources/views/portal/ninja2020/plan/index.blade.php @@ -0,0 +1,103 @@ +@extends('portal.ninja2020.layout.app') +@section('meta_title', ctrans('texts.pro_plan_call_to_action')) + +@section('body') + + +
+
+

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

+

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

+
+
+
+
+
+ {{ ctrans('texts.plan') }} +
+
+ {{ $account->plan ? ucfirst($account->plan) : 'Free' }} +
+
+ @if($account->plan) + +
+
+ {{ ctrans('texts.expires') }} +
+
+ {{ $client->formatDate($account->plan_expires, $client->date_format()) }} +
+
+ + @if($account->plan == 'enterprise') + +
+
+ {{ ctrans('texts.users')}} +
+
+ {{ $account->num_users }} +
+
+ + @endif + + @endif + +
+
+ {{ ctrans('texts.plan_change') }} +
+
+
+ + + @if($current_recurring_id) + + @else + + @endif + +
+
+ +
+
+
+ +@endsection + +@push('footer') + + +@endpush \ No newline at end of file