1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Template Previews (#3527)

* Fixes for add / archiving / deleting users

* Working on templates

* Fixes for templating

* Fixes for templating

* Add referral code to account creation

* Fixes for development environment
This commit is contained in:
David Bomba 2020-03-25 13:50:08 +11:00 committed by GitHub
parent cd36f64423
commit 24c9121b1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 229 additions and 23 deletions

View File

@ -11,10 +11,60 @@
namespace App\DataMapper;
use Illuminate\Support\Facades\App;
use League\CommonMark\CommonMarkConverter;
class EmailTemplateDefaults
{
public static function getDefaultTemplate($template, $locale)
{
App::setLocale($locale);
switch ($template) {
case 'email_template_invoice':
return self::emailInvoiceTemplate();
break;
case 'email_template_quote':
return self::emailQuoteTemplate();
break;
case 'email_template_payment':
return self::emailPaymentTemplate();
break;
case 'email_template_payment_partial':
return self::emailPaymentTemplate();
break;
case 'email_template_statement':
return self::emailStatementTemplate();
break;
case 'email_template_reminder1':
return self::emailReminder1Template();
break;
case 'email_template_reminder2':
return self::emailReminder2Template();
break;
case 'email_template_reminder3':
return self::emailReminder3Template();
break;
case 'email_template_reminder_endless':
return self::emailReminderEndlessTemplate();
break;
case 'email_template_custom1':
return self::emailInvoiceTemplate();
break;
case 'email_template_custom2':
return self::emailInvoiceTemplate();
break;
case 'email_template_custom3':
return self::emailInvoiceTemplate();
break;
default:
return self::emailInvoiceTemplate();
break;
}
}
public static function emailInvoiceSubject()
{
return ctrans('texts.invoice_subject', ['number'=>'$number', 'account'=>'$company.name']);

View File

@ -11,7 +11,9 @@
namespace App\Http\Controllers;
use App\DataMapper\EmailTemplateDefaults;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\MakesTemplateData;
use League\CommonMark\CommonMarkConverter;
@ -19,6 +21,7 @@ class TemplateController extends BaseController
{
use MakesHash;
use MakesTemplateData;
use MakesInvoiceHtml;
public function __construct()
{
@ -103,13 +106,38 @@ class TemplateController extends BaseController
*/
public function show()
{
$entity_obj = null;
if (request()->has('entity') && request()->has('entity_id')) {
$class = 'App\Models\\'.ucfirst(request()->input('entity'));
$entity_obj = $class::whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first();
}
if($entity_obj){
$settings_entity = $entity_obj->client;
}
else{
$settings_entity = auth()->user()->company();
}
$subject = request()->input('subject') ?: '';
$body = request()->input('body') ?: '';
$template = request()->input('template') ?: '';
$include_wrapper = request()->input('include_wrapper') ?: false;
if(strlen($template) >1) {
$custom_template = $settings_entity->getSetting($template);
if(strlen($custom_template) > 1){
$body = $custom_template;
}
else {
$body = EmailTemplateDefaults::getDefaultTemplate($template, $settings_entity->locale());
}
}
$labels = $this->makeFakerLabels();
$values = $this->makeFakerValues();
@ -118,13 +146,40 @@ class TemplateController extends BaseController
$body = str_replace(array_keys($values), array_values($values), $body);
$converter = new CommonMarkConverter([
//'html_input' => 'strip',
'allow_unsafe_links' => false,
]);
$body = $converter->convertToHtml($body);
if($include_wrapper){
$email_style = $settings_entity->getSetting('email_style');
$email_style = 'dark';
$data['title'] = '';
$data['body'] = $body;
$data['footer'] = '';
if($email_style == 'custom') {
$wrapper = $settings_entity->getSetting('email_style_custom');
$this->renderView($wrapper, $data);
}
else {
$wrapper = $this->getTemplate();
$body = view($this->getTemplatePath($email_style), $data)->render();
}
}
$data = [
'subject' => request()->input('subject'),
'body' => $converter->convertToHtml($body),
'subject' => $subject,
'body' => $body,
];
return response()->json($data, 200);

View File

@ -15,6 +15,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\Response;
class CreateAccount
@ -33,6 +34,9 @@ class CreateAccount
return response()->json(array('message' => Ninja::parse()), 401);
}
$sp794f3f = Account::create($this->request);
$sp794f3f->referral_code = Str::random(32);
$sp794f3f->save();
$sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f);
$sp035a66->load('account');
$sp794f3f->default_company_id = $sp035a66->id;

View File

@ -13,11 +13,16 @@ namespace App\Listeners\User;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class DeletedUserActivity
class DeletedUserActivity implements ShouldQueue
{
use Dispatchable, InteractsWithSockets, SerializesModels;
protected $activityRepo;
/**
* Create the event listener.

View File

@ -292,6 +292,22 @@ class Company extends BaseModel
return $this->settings->company_logo ?: null;
}
public function locale()
{
return $this->getLocale();
}
public function getSetting($setting)
{
if (property_exists($this->settings, $setting) != false) {
return $this->settings->{$setting};
}
return null;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/

View File

@ -15,6 +15,7 @@ use App\Models\Activity;
use App\Models\Backup;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\User;
use App\Utils\Traits\MakesInvoiceHtml;
use Illuminate\Support\Facades\Log;
@ -64,7 +65,11 @@ class ActivityRepository extends BaseRepository
if (get_class($entity) == Client::class) {
$entity->load('company');
} else {
}
else if(get_class($entity) == User::class) {
}
else {
$entity->load('company', 'client');
}

View File

@ -60,6 +60,28 @@ class AccountTransformer extends EntityTransformer
'id' => (string)$this->encodePrimaryKey($account->id),
'default_url' => config('ninja.app_url'),
'plan' => $account->getPlan(),
'plan_term' => (string) $account->plan_terms,
'plan_started' => (string) $account->plan_started,
'plan_paid' => (string) $account->plan_paid,
'plan_expires' => (string) $account->plan_expires,
'user_agent' => (string) $account->user_agent,
'payment_id' => (string) $account->payment_id,
'trial_started' => (string) $account->trial_started,
'trial_plan' => (string) $account->trial_plan,
'pending_plan' => (string) $account->pending_plan,
'pending_term' => (string) $account->pending_term,
'plan_price' => (float) $account->plan_price,
'pending_plan_price' => (string) $account->pending_plan_price,
'num_users' => (int) $account->num_users,
'pending_num_users' => (int) $account->pending_num_users,
'utm_source' => (string) $account->utm_source,
'utm_medium' => (string) $account->utm_medium,
'utm_content' => (string) $account->utm_content,
'utm_term' => (string) $account->utm_term,
'discount' => (float) $account->discount,
'discount_expires' => (string) $account->discount_expires,
'bluevine_status' => (string) $account->bluevine_status,
'referral_code' => (string) $account->referral_code,
'latest_version' => (string)$account->latest_version,
'current_version' => (string)config('ninja.app_version'),
'updated_at' => (int)$account->updated_at,

View File

@ -57,6 +57,9 @@ class Ninja
public static function boot()
{
if(self::isNinjaDev())
return true;
$data = [
'license' => config('ninja.license'),
];

View File

@ -14,6 +14,7 @@ namespace App\Utils\Traits;
use App\Designs\Designer;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\File;
use Symfony\Component\Debug\Exception\FatalThrowableError;
/**
@ -102,4 +103,17 @@ trait MakesInvoiceHtml
return ob_get_clean();
}
/*
* Returns the base template we will be using.
*/
public function getTemplate(string $template = 'plain')
{
return File::get(resource_path('views/email/template/' . $template . '.blade.php'));
}
public function getTemplatePath(string $template = 'plain')
{
return 'email.template.' . $template;
}
}

View File

@ -1,10 +1,26 @@
@extends('email.template.master')
@section('title')
{{ $title }}
@endsection
@section('content')
@component('email.template.master', ['design' => 'dark'])
@slot('header')
@component('email.components.header', ['p' => '', 'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@if(isset($title))
{{$title}}
@endif
@endcomponent
{!! $body !!}
@endsection
@section('footer')
{!! $footer !!}
@endsection
@slot('footer')
@if(isset($footer))
{!! $footer !!}
@endif
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
For any info, please visit InvoiceNinja.
@endcomponent
@endslot
@endcomponent

View File

@ -1,10 +1,26 @@
@extends('email.template.master')
@section('title')
{{ $title }}
@endsection
@section('content')
@component('email.template.master', ['design' => 'light'])
@slot('header')
@component('email.components.header', ['p' => '', 'logo' => 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png'])
@if(isset($title))
{{$title}}
@endif
@endcomponent
{!! $body !!}
@endsection
@section('footer')
{!! $footer !!}
@endsection
@slot('footer')
@if(isset($footer))
{!! $footer !!}
@endif
@component('email.components.footer', ['url' => 'https://invoiceninja.com', 'url_text' => '© InvoiceNinja'])
For any info, please visit InvoiceNinja.
@endcomponent
@endslot
@endcomponent