From ad68d64dca7f36a11434dec90edf24d080c4efe1 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 21 Apr 2016 22:01:17 +0300 Subject: [PATCH] Changes for white label license --- app/Console/Commands/SendRenewalInvoices.php | 8 +++++-- app/Http/Middleware/StartupCheck.php | 2 ++ app/Http/routes.php | 1 + .../2016_04_16_103943_enterprise_plan.php | 23 ++++++++++++++----- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/SendRenewalInvoices.php b/app/Console/Commands/SendRenewalInvoices.php index 64db2fad4fb1..87a840aed2c0 100644 --- a/app/Console/Commands/SendRenewalInvoices.php +++ b/app/Console/Commands/SendRenewalInvoices.php @@ -62,8 +62,12 @@ class SendRenewalInvoices extends Command $invoice->due_date = date('Y-m-d', strtotime('+ 10 days')); $invoice->save(); - $this->mailer->sendInvoice($invoice); - $this->info("Sent invoice to {$client->getDisplayName()}"); + if ($term == PLAN_TERM_YEARLY) { + $this->mailer->sendInvoice($invoice); + $this->info("Sent {$term}ly {$plan} invoice to {$client->getDisplayName()}"); + } else { + $this->info("Created {$term}ly {$plan} invoice for {$client->getDisplayName()}"); + } } $this->info('Done'); diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php index be96ade97efe..63197550d9c0 100644 --- a/app/Http/Middleware/StartupCheck.php +++ b/app/Http/Middleware/StartupCheck.php @@ -142,7 +142,9 @@ class StartupCheck } elseif ($productId == PRODUCT_WHITE_LABEL) { if ($data == 'valid') { $company = Auth::user()->account->company; + $company->plan_term = PLAN_TERM_YEARLY; $company->plan_paid = date_create()->format('Y-m-d'); + $company->plan_expires = date_create()->modify('+1 year')->format('Y-m-d'); $company->plan = PLAN_WHITE_LABEL; $company->save(); diff --git a/app/Http/routes.php b/app/Http/routes.php index 48f06e5e7b3d..e5915b394a2b 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -554,6 +554,7 @@ if (!defined('CONTACT_EMAIL')) { define('NINJA_GATEWAY_CONFIG', 'NINJA_GATEWAY_CONFIG'); define('NINJA_WEB_URL', 'https://www.invoiceninja.com'); define('NINJA_APP_URL', 'https://app.invoiceninja.com'); + define('NINJA_DATE', '2000-01-01'); define('NINJA_VERSION', '2.5.1.3'); define('SOCIAL_LINK_FACEBOOK', 'https://www.facebook.com/invoiceninja'); diff --git a/database/migrations/2016_04_16_103943_enterprise_plan.php b/database/migrations/2016_04_16_103943_enterprise_plan.php index 8ca5632ad358..8a3a63717367 100644 --- a/database/migrations/2016_04_16_103943_enterprise_plan.php +++ b/database/migrations/2016_04_16_103943_enterprise_plan.php @@ -127,13 +127,24 @@ class EnterprisePlan extends Migration $company->plan_started = $primaryAccount->pro_plan_paid; $company->plan_paid = $primaryAccount->pro_plan_paid; + $expires = DateTime::createFromFormat('Y-m-d', $primaryAccount->pro_plan_paid); + $expires->modify('+1 year'); + $expires = $expires->format('Y-m-d'); + + // check for self host white label licenses if (!Utils::isNinjaProd()) { - $company->plan = 'white_label'; - $company->plan_term = null; - } elseif ($company->plan_paid != '2000-01-01'/* NINJA_DATE*/) { - $expires = DateTime::createFromFormat('Y-m-d', $primaryAccount->pro_plan_paid); - $expires->modify('+1 year'); - $company->plan_expires = $expires->format('Y-m-d'); + if ($company->plan_paid) { + $company->plan = 'white_label'; + // old ones were unlimited, new ones are yearly + if ($company->plan_paid == NINJA_DATE) { + $company->plan_term = null; + } else { + $company->plan_term = PLAN_TERM_YEARLY; + $company->plan_expires = $expires; + } + } + } elseif ($company->plan_paid != NINJA_DATE) { + $company->plan_expires = $expires; } }