mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor getPlanDetails
This commit is contained in:
parent
63b2c2c6b1
commit
454e9bc861
@ -130,10 +130,10 @@ class AccountController extends BaseController
|
|||||||
$plan = Input::get('plan');
|
$plan = Input::get('plan');
|
||||||
$term = Input::get('plan_term');
|
$term = Input::get('plan_term');
|
||||||
|
|
||||||
$planDetails = $account->getPlanDetails(false);
|
$planDetails = $account->getPlanDetails(false, false);
|
||||||
|
|
||||||
$credit = 0;
|
$credit = 0;
|
||||||
if ($planDetails['active']) {
|
if ($planDetails) {
|
||||||
if ($planDetails['plan'] == PLAN_PRO && $plan == PLAN_ENTERPRISE) {
|
if ($planDetails['plan'] == PLAN_PRO && $plan == PLAN_ENTERPRISE) {
|
||||||
// Upgrade from pro to enterprise
|
// Upgrade from pro to enterprise
|
||||||
if($planDetails['term'] == PLAN_TERM_YEARLY && $term == PLAN_TERM_MONTHLY) {
|
if($planDetails['term'] == PLAN_TERM_YEARLY && $term == PLAN_TERM_MONTHLY) {
|
||||||
@ -367,7 +367,7 @@ class AccountController extends BaseController
|
|||||||
$account = Auth::user()->account;
|
$account = Auth::user()->account;
|
||||||
$data = [
|
$data = [
|
||||||
'account' => $account,
|
'account' => $account,
|
||||||
'planDetails' => $account->getPlanDetails(),
|
'planDetails' => $account->getPlanDetails(true),
|
||||||
'title' => trans('texts.account_management'),
|
'title' => trans('texts.account_management'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -806,7 +806,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return $plan_details && $plan_details['active'];
|
return !empty($plan_details);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEnterprise(&$plan_details = null)
|
public function isEnterprise(&$plan_details = null)
|
||||||
@ -821,10 +821,10 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return $plan_details && $plan_details['active'] && $plan_details['plan'] == PLAN_ENTERPRISE;
|
return $plan_details && $plan_details['plan'] == PLAN_ENTERPRISE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPlanDetails($include_trial = true)
|
public function getPlanDetails($include_inactive = false, $include_trial = true)
|
||||||
{
|
{
|
||||||
if (!$this->company) {
|
if (!$this->company) {
|
||||||
return null;
|
return null;
|
||||||
@ -861,6 +861,10 @@ class Account extends Eloquent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$include_inactive && !$plan_active && !$trial_plan) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Should we show plan details or trial details?
|
// Should we show plan details or trial details?
|
||||||
if (($plan && !$trial_plan) || !$include_trial) {
|
if (($plan && !$trial_plan) || !$include_trial) {
|
||||||
$use_plan = true;
|
$use_plan = true;
|
||||||
@ -872,10 +876,7 @@ class Account extends Eloquent
|
|||||||
$use_plan = true;
|
$use_plan = true;
|
||||||
} elseif (empty($plan_active) && !empty($trial_active)) {
|
} elseif (empty($plan_active) && !empty($trial_active)) {
|
||||||
$use_plan = false;
|
$use_plan = false;
|
||||||
} elseif (empty($plan_active) && empty($trial_active)) {
|
} elseif (!empty($plan_active) && !empty($trial_active)) {
|
||||||
// Neither are active; use whichever expired most recently
|
|
||||||
$use_plan = $plan_expires >= $trial_expires;
|
|
||||||
} else {
|
|
||||||
// Both are active; use whichever is a better plan
|
// Both are active; use whichever is a better plan
|
||||||
if ($plan == PLAN_ENTERPRISE) {
|
if ($plan == PLAN_ENTERPRISE) {
|
||||||
$use_plan = true;
|
$use_plan = true;
|
||||||
@ -885,6 +886,9 @@ class Account extends Eloquent
|
|||||||
// They're both the same; show the plan
|
// They're both the same; show the plan
|
||||||
$use_plan = true;
|
$use_plan = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Neither are active; use whichever expired most recently
|
||||||
|
$use_plan = $plan_expires >= $trial_expires;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -917,7 +921,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
|
|
||||||
return $plan_details && $plan_details['trial'] && $plan_details['active'];;
|
return $plan_details && $plan_details['trial'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isEligibleForTrial($plan = null)
|
public function isEligibleForTrial($plan = null)
|
||||||
@ -943,7 +947,7 @@ class Account extends Eloquent
|
|||||||
|
|
||||||
public function getCountTrialDaysLeft()
|
public function getCountTrialDaysLeft()
|
||||||
{
|
{
|
||||||
$planDetails = $this->getPlanDetails();
|
$planDetails = $this->getPlanDetails(true);
|
||||||
|
|
||||||
if(!$planDetails || !$planDetails['trial']) {
|
if(!$planDetails || !$planDetails['trial']) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -959,7 +963,7 @@ class Account extends Eloquent
|
|||||||
{
|
{
|
||||||
$planDetails = $this->getPlanDetails();
|
$planDetails = $this->getPlanDetails();
|
||||||
|
|
||||||
if ($planDetails && $planDetails['active']) {
|
if ($planDetails) {
|
||||||
$date = $planDetails['expires'];
|
$date = $planDetails['expires'];
|
||||||
$date = max($date, date_create());
|
$date = max($date, date_create());
|
||||||
} else {
|
} else {
|
||||||
@ -979,7 +983,7 @@ class Account extends Eloquent
|
|||||||
return self::isPro($plan_details) && $plan_details['expires'];
|
return self::isPro($plan_details) && $plan_details['expires'];
|
||||||
} else {
|
} else {
|
||||||
$plan_details = $this->getPlanDetails();
|
$plan_details = $this->getPlanDetails();
|
||||||
return $plan_details && $plan_details['active'];
|
return $plan_details;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user