From f0f62790a6543c4801193e5b04119f90706ec1d2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 28 Dec 2016 16:39:29 +0200 Subject: [PATCH] Show dashboard alert when white label license is expired --- app/Http/Controllers/DashboardController.php | 3 +++ app/Http/Controllers/NinjaController.php | 12 ++++++++++++ app/Http/routes.php | 1 + app/Libraries/Utils.php | 5 +++++ app/Models/Company.php | 9 +++++++++ resources/lang/en/texts.php | 2 ++ resources/views/dashboard.blade.php | 4 ++++ 7 files changed, 36 insertions(+) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 37c4be420181..35397787f1d4 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -47,6 +47,8 @@ class DashboardController extends BaseController && env('BLUEVINE_PARTNER_UNIQUE_ID') && $account->created_at <= date( 'Y-m-d', strtotime( '-1 month' )); + $showWhiteLabelExpired = Utils::isSelfHost() && $account->company->hasExpiredPlan(PLAN_WHITE_LABEL); + // check if the account has quotes $hasQuotes = false; foreach ([$upcoming, $pastDue] as $data) { @@ -96,6 +98,7 @@ class DashboardController extends BaseController 'expenses' => $expenses, 'tasks' => $tasks, 'showBlueVinePromo' => $showBlueVinePromo, + 'showWhiteLabelExpired' => $showWhiteLabelExpired, ]; if ($showBlueVinePromo) { diff --git a/app/Http/Controllers/NinjaController.php b/app/Http/Controllers/NinjaController.php index 2a0725239eec..cab57f9da2b5 100644 --- a/app/Http/Controllers/NinjaController.php +++ b/app/Http/Controllers/NinjaController.php @@ -6,6 +6,7 @@ use Input; use Utils; use View; use Validator; +use Auth; use URL; use Cache; use Omnipay; @@ -274,4 +275,15 @@ class NinjaController extends BaseController Session::flash('error', $message); Utils::logError("Payment Error [{$type}]: " . ($exception ? Utils::getErrorString($exception) : $message), 'PHP', true); } + + public function hideWhiteLabelMessage() + { + $user = Auth::user(); + $company = $user->account->company; + + $company->plan = null; + $company->save(); + + return RESULT_SUCCESS; + } } diff --git a/app/Http/routes.php b/app/Http/routes.php index a8031c276812..6c3137c4e04a 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -228,6 +228,7 @@ Route::group(['middleware' => 'auth:user'], function() { Route::post('bluevine/signup', 'BlueVineController@signup'); Route::get('bluevine/hide_message', 'BlueVineController@hideMessage'); Route::get('bluevine/completed', 'BlueVineController@handleCompleted'); + Route::get('white_label/hide_message', 'NinjaController@hideWhiteLabelMessage'); }); Route::group([ diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 1a57630131d6..4b4ac2341edb 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -67,6 +67,11 @@ class Utils return self::isNinjaProd() || self::isNinjaDev(); } + public static function isSelfHost() + { + return ! static::isNinjaProd(); + } + public static function isNinjaProd() { if (Utils::isReseller()) { diff --git a/app/Models/Company.php b/app/Models/Company.php index 0aa8c1037c5f..680cc92a0838 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -88,6 +88,15 @@ class Company extends Eloquent return Carbon::parse($this->plan_expires) >= Carbon::today(); } + public function hasExpiredPlan($plan) + { + if ($this->plan != $plan) { + return false; + } + + return Carbon::parse($this->plan_expires) < Carbon::today(); + } + public function hasEarnedPromo() { if ( ! Utils::isNinjaProd() || Utils::isPro()) { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 2b3cc98ef57f..8e9d99109545 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2286,6 +2286,8 @@ $LANG = array( 'require' => 'Require', 'license_expiring' => 'Note: Your license will expire in :count days, :link to renew it.', 'security_confirmation' => 'Your email address has been confirmed.', + 'white_label_expired' => 'Your white label license has expired, please consider renewing it to help support our project.', + 'renew_license' => 'Renew License', ); diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 48b2246fa39b..ff678fcbc494 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -204,6 +204,10 @@ @include('partials/bluevine_promo') @endif +@if ($showWhiteLabelExpired) + @include('partials/white_label_expired') +@endif +