1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Http/Controllers/ClientPortal/NinjaPlanController.php

107 lines
3.9 KiB
PHP
Raw Normal View History

2021-09-01 06:02:57 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\ClientPortal;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\Uploads\StoreUploadRequest;
use App\Libraries\MultiDB;
2021-10-03 04:36:43 +02:00
use App\Models\Account;
2021-09-01 06:02:57 +02:00
use App\Models\ClientContact;
2021-09-01 07:03:01 +02:00
use App\Models\Company;
2021-11-23 11:39:43 +01:00
use App\Models\Invoice;
use App\Models\Subscription;
2021-09-01 06:02:57 +02:00
use App\Utils\Ninja;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
2021-11-23 11:39:43 +01:00
use Illuminate\Support\Carbon;
2021-09-09 08:59:23 +02:00
use Illuminate\Support\Facades\Auth;
2021-09-01 06:02:57 +02:00
class NinjaPlanController extends Controller
{
2021-10-03 04:36:43 +02:00
public function index(string $contact_key, string $account_or_company_key)
2021-09-01 06:02:57 +02:00
{
2021-10-03 04:36:43 +02:00
MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
$company = Company::where('company_key', $account_or_company_key)->first();
if(!$company){
MultiDB::findAndSetDbByAccountKey($account_or_company_key);
$account = Account::where('key', $account_or_company_key)->first();
}
else
$account = $company->account;
2021-09-11 08:26:00 +02:00
if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first())
2021-09-01 07:03:01 +02:00
{
2021-09-03 15:24:18 +02:00
nlog("Ninja Plan Controller - Found and set Client Contact");
2021-09-01 07:03:01 +02:00
Auth::guard('contact')->login($client_contact,true);
2021-09-01 06:02:57 +02:00
/* Current paid users get pushed straight to subscription overview page*/
2021-09-01 06:36:22 +02:00
if($account->isPaidHostedClient())
2021-10-22 01:55:58 +02:00
return redirect('/client/dashboard');
2021-09-01 06:02:57 +02:00
/* Users that are not paid get pushed to a custom purchase page */
return $this->render('subscriptions.ninja_plan', ['settings' => $client_contact->company->settings]);
}
return redirect()->route('client.catchall');
}
2021-11-23 11:39:43 +01:00
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();
}
}
}
2021-09-01 06:02:57 +02:00
}