Add secondary domain choice

This commit is contained in:
Hillel Coren 2017-01-12 15:12:02 +02:00
parent 1c010084d6
commit 0095cdf7dd
20 changed files with 164 additions and 78 deletions

View File

@ -464,7 +464,6 @@ if (!defined('APP_NAME'))
define('FEATURE_MORE_CLIENTS', 'more_clients'); // No trial allowed define('FEATURE_MORE_CLIENTS', 'more_clients'); // No trial allowed
// Whitelabel // Whitelabel
define('FEATURE_CLIENT_PORTAL_CSS', 'client_portal_css');
define('FEATURE_WHITE_LABEL', 'feature_white_label'); define('FEATURE_WHITE_LABEL', 'feature_white_label');
// Enterprise // Enterprise

24
app/Constants/Domain.php Normal file
View File

@ -0,0 +1,24 @@
<?php namespace App\Constants;
class Domain
{
const INVOICENINJA_COM = 1;
const INVOICE_SERVICES = 2;
public static function getDomainFromId($id)
{
switch ($id) {
case static::INVOICENINJA_COM:
return 'invoiceninja.com';
case static::INVOICE_SERVICES:
return 'invoice.services';
}
return 'invoiceninja.com';
}
public static function getLinkFromId($id)
{
return 'https://app.' . static::getDomainFromId($id);
}
}

View File

@ -792,6 +792,8 @@ class AccountController extends BaseController
{ {
$account = $request->user()->account; $account = $request->user()->account;
$account->fill($request->all()); $account->fill($request->all());
$account->subdomain = $request->subdomain;
$account->iframe_url = $request->iframe_url;
$account->save(); $account->save();
return redirect('settings/' . ACCOUNT_CLIENT_PORTAL) return redirect('settings/' . ACCOUNT_CLIENT_PORTAL)
@ -805,6 +807,7 @@ class AccountController extends BaseController
{ {
$account = $request->user()->account; $account = $request->user()->account;
$account->fill($request->all()); $account->fill($request->all());
$account->bcc_email = $request->bcc_email;
$account->save(); $account->save();
return redirect('settings/' . ACCOUNT_EMAIL_SETTINGS) return redirect('settings/' . ACCOUNT_EMAIL_SETTINGS)

View File

@ -85,10 +85,8 @@ class Account extends Eloquent
'pdf_email_attachment', 'pdf_email_attachment',
'document_email_attachment', 'document_email_attachment',
'email_design_id', 'email_design_id',
'bcc_email',
'enable_email_markup', 'enable_email_markup',
'subdomain', 'domain_id',
'iframe_url',
]; ];
/** /**
@ -475,6 +473,17 @@ class Account extends Eloquent
return $this->date_format ? $this->date_format->format : DEFAULT_DATE_FORMAT; return $this->date_format ? $this->date_format->format : DEFAULT_DATE_FORMAT;
} }
public function getSampleLink()
{
$invitation = new Invitation();
$invitation->account = $this;
$invitation->invitation_key = '...';
return $invitation->getLink();
}
/** /**
* @param $amount * @param $amount
* @param null $client * @param null $client
@ -994,7 +1003,6 @@ class Account extends Eloquent
return false; return false;
} }
// Fallthrough // Fallthrough
case FEATURE_CLIENT_PORTAL_CSS:
case FEATURE_REMOVE_CREATED_BY: case FEATURE_REMOVE_CREATED_BY:
return !empty($planDetails);// A plan is required even for self-hosted users return !empty($planDetails);// A plan is required even for self-hosted users
@ -1556,9 +1564,7 @@ class Account extends Eloquent
if ($headerFont != $bodyFont) { if ($headerFont != $bodyFont) {
$css .= 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{'.$headerFont.'}'; $css .= 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6{'.$headerFont.'}';
} }
}
if ($this->hasFeature(FEATURE_CLIENT_PORTAL_CSS)) {
// For self-hosted users, a white-label license is required for custom CSS
$css .= $this->client_view_css; $css .= $this->client_view_css;
} }
@ -1707,6 +1713,15 @@ class Account extends Eloquent
return $invoice->isQuote() ? $this->require_quote_signature : $this->require_invoice_signature; return $invoice->isQuote() ? $this->require_quote_signature : $this->require_invoice_signature;
} }
public function emailMarkupEnabled()
{
if ( ! Utils::isNinja()) {
return false;
}
return $this->enable_email_markup;
}
} }
Account::updated(function ($account) Account::updated(function ($account)

View File

@ -68,14 +68,19 @@ class Invitation extends EntityModel
$this->load('account'); $this->load('account');
} }
$account = $this->account;
$iframe_url = $account->iframe_url;
$url = trim(SITE_URL, '/'); $url = trim(SITE_URL, '/');
$iframe_url = $this->account->iframe_url;
if ($this->account->hasFeature(FEATURE_CUSTOM_URL)) { if ($account->hasFeature(FEATURE_CUSTOM_URL)) {
if (Utils::isNinja()) {
$url = $account->present()->clientPortalLink();
}
if ($iframe_url && !$forceOnsite) { if ($iframe_url && !$forceOnsite) {
return "{$iframe_url}?{$this->invitation_key}"; return "{$iframe_url}?{$this->invitation_key}";
} elseif ($this->account->subdomain) { } elseif ($this->account->subdomain) {
$url = Utils::replaceSubdomain($url, $this->account->subdomain); $url = Utils::replaceSubdomain($url, $account->subdomain);
} }
} }

View File

@ -124,7 +124,7 @@ class Mailer
$invitation = $data['invitation']; $invitation = $data['invitation'];
$invitation->email_error = $emailError; $invitation->email_error = $emailError;
$invitation->save(); $invitation->save();
} elseif ( ! Utils::isNinja()) { } elseif ( ! Utils::isNinjaProd()) {
Utils::logError(Utils::getErrorString($exception)); Utils::logError(Utils::getErrorString($exception));
} }

View File

@ -2,6 +2,7 @@
use stdClass; use stdClass;
use Utils; use Utils;
use Domain;
use Laracasts\Presenter\Presenter; use Laracasts\Presenter\Presenter;
/** /**
@ -36,6 +37,11 @@ class AccountPresenter extends Presenter
return $currency->code; return $currency->code;
} }
public function clientPortalLink()
{
return Domain::getLinkFromId($this->entity->domain_id);
}
public function industry() public function industry()
{ {
return $this->entity->industry ? $this->entity->industry->name : ''; return $this->entity->industry ? $this->entity->industry->name : '';

View File

@ -263,6 +263,7 @@ return [
'Utils' => App\Libraries\Utils::class, 'Utils' => App\Libraries\Utils::class,
'HTMLUtils' => App\Libraries\HTMLUtils::class, 'HTMLUtils' => App\Libraries\HTMLUtils::class,
'Domain' => App\Constants\Domain::class,
], ],
]; ];

View File

@ -33,6 +33,7 @@ class AddInclusiveTaxes extends Migration
$table->text('client_number_prefix')->nullable(); $table->text('client_number_prefix')->nullable();
$table->integer('client_number_counter')->default(0)->nullable(); $table->integer('client_number_counter')->default(0)->nullable();
$table->text('client_number_pattern')->nullable(); $table->text('client_number_pattern')->nullable();
$table->tinyInteger('domain_id')->default(1)->nullable();
}); });
Schema::table('activities', function ($table) Schema::table('activities', function ($table)
@ -65,6 +66,7 @@ class AddInclusiveTaxes extends Migration
$table->dropColumn('client_number_prefix'); $table->dropColumn('client_number_prefix');
$table->dropColumn('client_number_counter'); $table->dropColumn('client_number_counter');
$table->dropColumn('client_number_pattern'); $table->dropColumn('client_number_pattern');
$table->dropColumn('domain_id');
}); });
Schema::table('activities', function ($table) Schema::table('activities', function ($table)

View File

@ -849,7 +849,7 @@ $LANG = array(
'light' => 'Light', 'light' => 'Light',
'dark' => 'Dark', 'dark' => 'Dark',
'industry_help' => 'Used to provide comparisons against the averages of companies of similar size and industry.', 'industry_help' => 'Used to provide comparisons against the averages of companies of similar size and industry.',
'subdomain_help' => 'Customize the invoice link subdomain or display the invoice on your own website.', 'subdomain_help' => 'Set the subdomain or display the invoice on your own website.',
'invoice_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the invoice number.', 'invoice_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the invoice number.',
'quote_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the quote number.', 'quote_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the quote number.',
'custom_client_fields_helps' => 'Add a field when creating a client and display the label and value on the PDF.', 'custom_client_fields_helps' => 'Add a field when creating a client and display the label and value on the PDF.',
@ -2313,6 +2313,10 @@ $LANG = array(
'emailed_invoices' => 'Successfully emailed invoices', 'emailed_invoices' => 'Successfully emailed invoices',
'emailed_quotes' => 'Successfully emailed quotes', 'emailed_quotes' => 'Successfully emailed quotes',
'website_url' => 'Website URL', 'website_url' => 'Website URL',
'domain' => 'Domain',
'domain_help' => 'Used in the client portal and when sending emails.',
'domain_help_website' => 'Used when sending emails.',
'preview' => 'Preview',
); );

View File

@ -11,6 +11,9 @@
.checkbox-inline input[type="checkbox"] { .checkbox-inline input[type="checkbox"] {
margin-left:-20px !important; margin-left:-20px !important;
} }
.iframe_url {
display: none;
}
</style> </style>
@stop @stop
@ -35,14 +38,6 @@
{!! Former::populateField('require_invoice_signature', intval($account->require_invoice_signature)) !!} {!! Former::populateField('require_invoice_signature', intval($account->require_invoice_signature)) !!}
{!! Former::populateField('require_quote_signature', intval($account->require_quote_signature)) !!} {!! Former::populateField('require_quote_signature', intval($account->require_quote_signature)) !!}
@if (!Utils::isNinja() && !Auth::user()->account->hasFeature(FEATURE_WHITE_LABEL))
<div class="alert alert-warning" style="font-size:larger;">
<center>
{!! trans('texts.white_label_custom_css', ['price' => WHITE_LABEL_PRICE, 'link'=>'<a href="#" onclick="$(\'#whiteLabelModal\').modal(\'show\');">'.trans('texts.white_label_purchase_link').'</a>']) !!}
</center>
</div>
@endif
@include('accounts.nav', ['selected' => ACCOUNT_CLIENT_PORTAL]) @include('accounts.nav', ['selected' => ACCOUNT_CLIENT_PORTAL])
<div class="row"> <div class="row">
@ -53,11 +48,38 @@
<h3 class="panel-title">{!! trans('texts.settings') !!}</h3> <h3 class="panel-title">{!! trans('texts.settings') !!}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="col-md-10 col-md-offset-1">
<div role="tabpanel">
<ul class="nav nav-tabs" role="tablist" style="border: none">
<li role="presentation" class="active">
<a href="#link" aria-controls="link" role="tab" data-toggle="tab">{{ trans('texts.link') }}</a>
</li>
<li role="presentation">
<a href="#navigation" aria-controls="navigation" role="tab" data-toggle="tab">{{ trans('texts.navigation') }}</a>
</li>
<li role="presentation">
<a href="#custom_css" aria-controls="custom_css" role="tab" data-toggle="tab">{{ trans('texts.custom_css') }}</a>
</li>
</ul>
</div>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="link">
<div class="panel-body">
@if (Utils::isNinja() && ! Utils::isReseller())
{!! Former::inline_radios('domain_id')
->label(trans('texts.domain'))
->radios([
'invoiceninja.com' => ['value' => \Domain::INVOICENINJA_COM, 'name' => 'domain_id'],
'invoice.services' => ['value' => \Domain::INVOICE_SERVICES, 'name' => 'domain_id'],
])->check($account->domain_id)
->help($account->iframe_url ? 'domain_help_website' : 'domain_help') !!}
@endif
{!! Former::inline_radios('custom_invoice_link') {!! Former::inline_radios('custom_invoice_link')
->onchange('onCustomLinkChange()') ->onchange('onCustomLinkChange()')
->label(trans('texts.website_url')) ->label(trans('texts.customize'))
->radios([ ->radios([
trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'], trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'],
trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'], trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'],
@ -65,7 +87,7 @@
{{ Former::setOption('capitalize_translations', false) }} {{ Former::setOption('capitalize_translations', false) }}
{!! Former::text('subdomain') {!! Former::text('subdomain')
->placeholder(trans('texts.www')) ->placeholder(Utils::isNinja() ? 'app' : trans('texts.www'))
->onchange('onSubdomainChange()') ->onchange('onSubdomainChange()')
->addGroupClass('subdomain') ->addGroupClass('subdomain')
->label(' ') ->label(' ')
@ -78,6 +100,13 @@
->label(' ') ->label(' ')
->help(trans('texts.subdomain_help')) !!} ->help(trans('texts.subdomain_help')) !!}
{!! Former::plaintext('preview')
->value($account->getSampleLink()) !!}
</div>
</div>
<div role="tabpanel" class="tab-pane" id="navigation">
<div class="panel-body">
{!! Former::checkbox('enable_client_portal') {!! Former::checkbox('enable_client_portal')
->text(trans('texts.enable')) ->text(trans('texts.enable'))
@ -89,6 +118,21 @@
->text(trans('texts.enable')) ->text(trans('texts.enable'))
->help(trans('texts.enable_client_portal_dashboard_help')) ->help(trans('texts.enable_client_portal_dashboard_help'))
->value(1) !!} ->value(1) !!}
</div>
</div>
<div role="tabpanel" class="tab-pane" id="custom_css">
<div class="panel-body">
{!! Former::textarea('client_view_css')
->label(trans('texts.custom_css'))
->rows(10)
->raw()
->maxlength(60000)
->style("min-width:100%;max-width:100%;font-family:'Roboto Mono', 'Lucida Console', Monaco, monospace;font-size:14px;'") !!}
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -252,23 +296,6 @@
</div> </div>
</div> </div>
</div> </div>
@if (Utils::hasFeature(FEATURE_CLIENT_PORTAL_CSS))
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{!! trans('texts.custom_css') !!}</h3>
</div>
<div class="panel-body">
<div class="col-md-10 col-md-offset-1">
{!! Former::textarea('client_view_css')
->label(trans('texts.custom_css'))
->rows(10)
->raw()
->maxlength(60000)
->style("min-width:100%;max-width:100%;font-family:'Roboto Mono', 'Lucida Console', Monaco, monospace;font-size:14px;'") !!}
</div>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
@extends('emails.master') @extends('emails.master')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.client_view_action') @include('emails.partials.client_view_action')
@endif @endif
@stop @stop

View File

@ -1,7 +1,7 @@
@extends('emails.master') @extends('emails.master')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.client_view_action') @include('emails.partials.client_view_action')
@endif @endif
@stop @stop

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body> <body>
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.client_view_action') @include('emails.partials.client_view_action')
@endif @endif
{!! $body !!} {!! $body !!}

View File

@ -1,7 +1,7 @@
@extends('emails.master_user') @extends('emails.master_user')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.user_view_action') @include('emails.partials.user_view_action')
@endif @endif
@stop @stop

View File

@ -1,7 +1,7 @@
@extends('emails.master_user') @extends('emails.master_user')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.user_view_action') @include('emails.partials.user_view_action')
@endif @endif
@stop @stop

View File

@ -1,7 +1,7 @@
@extends('emails.master_user') @extends('emails.master_user')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.user_view_action') @include('emails.partials.user_view_action')
@endif @endif
@stop @stop

View File

@ -1,7 +1,7 @@
@extends('emails.master_user') @extends('emails.master_user')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.user_view_action') @include('emails.partials.user_view_action')
@endif @endif
@stop @stop

View File

@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
</head> </head>
<body> <body>
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.client_view_action', ['link' => $link]) @include('emails.partials.client_view_action', ['link' => $link])
@endif @endif
{!! $body !!} {!! $body !!}

View File

@ -1,7 +1,7 @@
@extends('emails.master_user') @extends('emails.master_user')
@section('markup') @section('markup')
@if ($account->enable_email_markup) @if ($account->emailMarkupEnabled())
@include('emails.partials.user_view_action') @include('emails.partials.user_view_action')
@endif @endif
@stop @stop