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
// Whitelabel
define('FEATURE_CLIENT_PORTAL_CSS', 'client_portal_css');
define('FEATURE_WHITE_LABEL', 'feature_white_label');
// 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->fill($request->all());
$account->subdomain = $request->subdomain;
$account->iframe_url = $request->iframe_url;
$account->save();
return redirect('settings/' . ACCOUNT_CLIENT_PORTAL)
@ -805,6 +807,7 @@ class AccountController extends BaseController
{
$account = $request->user()->account;
$account->fill($request->all());
$account->bcc_email = $request->bcc_email;
$account->save();
return redirect('settings/' . ACCOUNT_EMAIL_SETTINGS)

View File

@ -85,10 +85,8 @@ class Account extends Eloquent
'pdf_email_attachment',
'document_email_attachment',
'email_design_id',
'bcc_email',
'enable_email_markup',
'subdomain',
'iframe_url',
'domain_id',
];
/**
@ -475,6 +473,17 @@ class Account extends Eloquent
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 null $client
@ -994,7 +1003,6 @@ class Account extends Eloquent
return false;
}
// Fallthrough
case FEATURE_CLIENT_PORTAL_CSS:
case FEATURE_REMOVE_CREATED_BY:
return !empty($planDetails);// A plan is required even for self-hosted users
@ -1556,9 +1564,7 @@ class Account extends Eloquent
if ($headerFont != $bodyFont) {
$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;
}
@ -1707,6 +1713,15 @@ class Account extends Eloquent
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)

View File

@ -68,14 +68,19 @@ class Invitation extends EntityModel
$this->load('account');
}
$account = $this->account;
$iframe_url = $account->iframe_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) {
return "{$iframe_url}?{$this->invitation_key}";
} elseif ($this->account->subdomain) {
$url = Utils::replaceSubdomain($url, $this->account->subdomain);
$url = Utils::replaceSubdomain($url, $account->subdomain);
}
}

View File

@ -108,7 +108,7 @@ class Mailer
if (! $response) {
$error = trans('texts.postmark_error', ['link' => link_to('https://status.postmarkapp.com/')]);
Utils::logError($error);
// TODO throw the exception once all emails are sent using the queue
return $error;
}
@ -124,7 +124,7 @@ class Mailer
$invitation = $data['invitation'];
$invitation->email_error = $emailError;
$invitation->save();
} elseif ( ! Utils::isNinja()) {
} elseif ( ! Utils::isNinjaProd()) {
Utils::logError(Utils::getErrorString($exception));
}

View File

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

View File

@ -263,6 +263,7 @@ return [
'Utils' => App\Libraries\Utils::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->integer('client_number_counter')->default(0)->nullable();
$table->text('client_number_pattern')->nullable();
$table->tinyInteger('domain_id')->default(1)->nullable();
});
Schema::table('activities', function ($table)
@ -65,6 +66,7 @@ class AddInclusiveTaxes extends Migration
$table->dropColumn('client_number_prefix');
$table->dropColumn('client_number_counter');
$table->dropColumn('client_number_pattern');
$table->dropColumn('domain_id');
});
Schema::table('activities', function ($table)

View File

@ -849,7 +849,7 @@ $LANG = array(
'light' => 'Light',
'dark' => 'Dark',
'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.',
'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.',
@ -2313,7 +2313,11 @@ $LANG = array(
'emailed_invoices' => 'Successfully emailed invoices',
'emailed_quotes' => 'Successfully emailed quotes',
'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',
);
return $LANG;

View File

@ -11,6 +11,9 @@
.checkbox-inline input[type="checkbox"] {
margin-left:-20px !important;
}
.iframe_url {
display: none;
}
</style>
@stop
@ -35,14 +38,6 @@
{!! Former::populateField('require_invoice_signature', intval($account->require_invoice_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])
<div class="row">
@ -53,42 +48,91 @@
<h3 class="panel-title">{!! trans('texts.settings') !!}</h3>
</div>
<div class="panel-body">
<div class="col-md-10 col-md-offset-1">
{!! Former::inline_radios('custom_invoice_link')
->onchange('onCustomLinkChange()')
->label(trans('texts.website_url'))
->radios([
trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'],
trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'],
])->check($account->iframe_url ? 'website' : 'subdomain') !!}
{{ Former::setOption('capitalize_translations', false) }}
<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>
{!! Former::text('subdomain')
->placeholder(trans('texts.www'))
->onchange('onSubdomainChange()')
->addGroupClass('subdomain')
->label(' ')
->help(trans('texts.subdomain_help')) !!}
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="link">
<div class="panel-body">
{!! Former::text('iframe_url')
->placeholder('https://www.example.com/invoice')
->appendIcon('question-sign')
->addGroupClass('iframe_url')
->label(' ')
->help(trans('texts.subdomain_help')) !!}
@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')
->onchange('onCustomLinkChange()')
->label(trans('texts.customize'))
->radios([
trans('texts.subdomain') => ['value' => 'subdomain', 'name' => 'custom_link'],
trans('texts.website') => ['value' => 'website', 'name' => 'custom_link'],
])->check($account->iframe_url ? 'website' : 'subdomain') !!}
{{ Former::setOption('capitalize_translations', false) }}
{!! Former::text('subdomain')
->placeholder(Utils::isNinja() ? 'app' : trans('texts.www'))
->onchange('onSubdomainChange()')
->addGroupClass('subdomain')
->label(' ')
->help(trans('texts.subdomain_help')) !!}
{!! Former::text('iframe_url')
->placeholder('https://www.example.com/invoice')
->appendIcon('question-sign')
->addGroupClass('iframe_url')
->label(' ')
->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')
->text(trans('texts.enable'))
->help(trans('texts.enable_client_portal_help'))
->value(1) !!}
{!! Former::checkbox('enable_client_portal')
->text(trans('texts.enable'))
->help(trans('texts.enable_client_portal_help'))
->value(1) !!}
{!! Former::checkbox('enable_client_portal_dashboard')
->text(trans('texts.enable'))
->help(trans('texts.enable_client_portal_dashboard_help'))
->value(1) !!}
</div>
</div>
<div role="tabpanel" class="tab-pane" id="custom_css">
<div class="panel-body">
{!! Former::checkbox('enable_client_portal_dashboard')
->text(trans('texts.enable'))
->help(trans('texts.enable_client_portal_dashboard_help'))
->value(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>
</div>
</div>
</div>
@ -252,23 +296,6 @@
</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>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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