diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index 739f573f3556..a534340ba539 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -18,10 +18,13 @@ use App\Libraries\MultiDB; use App\Models\Account; use App\Models\ClientContact; use App\Models\Company; +use App\Models\Invoice; +use App\Models\Subscription; use App\Utils\Ninja; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Auth; class NinjaPlanController extends Controller @@ -57,4 +60,47 @@ class NinjaPlanController extends Controller return redirect()->route('client.catchall'); } + + public function plan() + { + //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(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) + ->first(); + + if($late_invoice) + $data['late_invoice'] = $late_invoice; + + } + + //build list of upgrades. + + $data['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') + ->where('company_id', Auth::guard('contact')->user()->company->id) + ->where('group_id', 31) + ->get(); + } + } + + } } diff --git a/app/Http/ViewComposers/PortalComposer.php b/app/Http/ViewComposers/PortalComposer.php index 3f589c759ef1..32034c05dfbd 100644 --- a/app/Http/ViewComposers/PortalComposer.php +++ b/app/Http/ViewComposers/PortalComposer.php @@ -115,6 +115,11 @@ 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']; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 3afda95c0172..7e273e7ff56e 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4340,6 +4340,7 @@ $LANG = array( 'no_available_methods' => 'We can\'t find any credit cards on your device. Read more about this.', 'gocardless_mandate_not_ready' => 'Payment mandate is not ready. Please try again later.', 'payment_type_instant_bank_pay' => 'Instant Bank Pay', + ); return $LANG; diff --git a/routes/client.php b/routes/client.php index 31478e3c6712..cd8860c6f960 100644 --- a/routes/client.php +++ b/routes/client.php @@ -31,6 +31,8 @@ Route::get('client/ninja/{contact_key}/{company_key}', 'ClientPortal\NinjaPlanCo Route::group(['middleware' => ['auth:contact', 'locale', 'check_client_existence','domain_db'], 'prefix' => 'client', 'as' => 'client.'], function () { Route::get('dashboard', 'ClientPortal\DashboardController@index')->name('dashboard'); // name = (dashboard. index / create / show / update / destroy / edit + Route::get('plan', 'ClientPortal\NinjaPlanController@plan')->name('plan'); // name = (dashboard. index / create / show / update / destroy / edit + Route::get('invoices', 'ClientPortal\InvoiceController@index')->name('invoices.index')->middleware('portal_enabled'); Route::post('invoices/payment', 'ClientPortal\InvoiceController@bulk')->name('invoices.bulk'); Route::get('invoices/{invoice}', 'ClientPortal\InvoiceController@show')->name('invoice.show');