1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
* Fixes for designs

* minor fixes
This commit is contained in:
David Bomba 2020-03-26 19:25:44 +11:00 committed by GitHub
parent 9fb609faca
commit 2ed7c557b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 32 deletions

View File

@ -92,7 +92,6 @@ class PreviewController extends BaseController
strlen(request()->input('entity')) > 1 &&
strlen(request()->input('entity_id')) > 1 &&
request()->has('body')) {
$design_object = json_decode(json_encode(request()->input('design')));
if (!is_object($design_object)) {
@ -152,6 +151,8 @@ class PreviewController extends BaseController
$design_object = json_decode(json_encode(request()->input('design')));
//\Log::error(print_r($design_object,1));
if (!is_object($design_object)) {
return response()->json(['message' => 'Invalid custom design object'], 400);
}

View File

@ -107,7 +107,6 @@ class TemplateController extends BaseController
*/
public function show()
{
$entity = request()->has('entity') ? request()->input('entity') : '';
$entity_id = request()->has('entity_id') ? request()->input('entity_id') : '';
$subject = request()->has('subject') ? request()->input('subject') : '';

View File

@ -0,0 +1,51 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Requests\Template;
use App\Http\Requests\Request;
class ShowTemplateRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
"template" => "sometimes",
];
}
protected function prepareForValidation()
{
$input = $this->all();
$this->replace($input);
}
public function message()
{
}
}

View File

@ -48,7 +48,7 @@ class DocumentTransformer extends EntityTransformer
'height' => (int) $document->height,
'is_default' => (bool) $document->is_default,
'updated_at' => (int) $document->updated_at,
'archived_at' => (int) $document->deleted_at
'archived_at' => (int) $document->deleted_at,
'created_at' => (int) $document->created_at
];

View File

@ -37,7 +37,7 @@ class TemplateEngine
private $settings_entity;
function __construct($body, $subject, $entity, $entity_id, $template)
public function __construct($body, $subject, $entity, $entity_id, $template)
{
$this->body = $body;
@ -52,7 +52,6 @@ class TemplateEngine
$this->entity_obj = null;
$this->settings_entity = null;
}
public function build()
@ -66,8 +65,7 @@ class TemplateEngine
private function setEntity()
{
if(strlen($this->entity) > 1 && strlen($this->entity_id) >1)
{
if (strlen($this->entity) > 1 && strlen($this->entity_id) >1) {
$class = 'App\Models\\'.ucfirst($this->entity);
$this->entity_obj = $class::whereId($this->decodePrimaryKey($this->entity_id))->company()->first();
}
@ -89,14 +87,12 @@ class TemplateEngine
/* If the body / subject are not populated we need to get the defaults */
private function setTemplates()
{
if(strlen($this->subject) == 0 && strlen($this->template) > 1)
{
if (strlen($this->subject) == 0 && strlen($this->template) > 1) {
$subject_template = str_replace("template", "subject", $this->template);
$this->subject = EmailTemplateDefaults::getDefaultTemplate($subject_template, $this->settings_entity->locale());
}
if(strlen($this->body) == 0 && strlen($this->template) > 1)
{
if (strlen($this->body) == 0 && strlen($this->template) > 1) {
$this->body = EmailTemplateDefaults::getDefaultTemplate($this->template, $this->settings_entity->locale());
}
@ -105,18 +101,17 @@ class TemplateEngine
private function replaceValues()
{
if($this->entity_obj)
if ($this->entity_obj) {
$this->entityValues();
else
} else {
$this->fakerValues();
}
return $this;
}
private function fakerValues()
{
$labels = $this->makeFakerLabels();
$values = $this->makeFakerValues();
@ -131,7 +126,6 @@ class TemplateEngine
]);
$this->body = $converter->convertToHtml($this->body);
$this->subject = $converter->convertToHtml($this->subject);
}
@ -151,7 +145,6 @@ class TemplateEngine
]);
$this->body = $converter->convertToHtml($this->body);
$this->subject = $converter->convertToHtml($this->subject);
}
@ -181,4 +174,4 @@ class TemplateEngine
return $data;
}
}
}

View File

@ -138,6 +138,7 @@ trait MakesInvoiceValues
//$data['$invoice_date'] = ['value' => $this->date ?: '&nbsp;', 'label' => ctrans('texts.invoice_date')];
$data['$invoice.date'] = &$data['$date'];
$data['$invoice.due_date'] = ['value' => $this->due_date ?: '&nbsp;', 'label' => ctrans('texts.due_date')];
$data['$due_date'] = &$data['$invoice.due_date'];
$data['$invoice.number'] = ['value' => $this->number ?: '&nbsp;', 'label' => ctrans('texts.invoice_number')];
$data['$invoice.po_number'] = ['value' => $this->po_number ?: '&nbsp;', 'label' => ctrans('texts.po_number')];
$data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: '&nbsp;', 'label' => ctrans('texts.taxes')];
@ -174,23 +175,27 @@ trait MakesInvoiceValues
$data['$subtotal'] = ['value' => Number::formatMoney($this->calc()->getSubTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.subtotal')];
$data['$invoice.subtotal'] = &$data['$subtotal'];
$data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance_due')];
$data['$quote.balance_due'] = &$data['$invoice.balance_due'];
$data['$balance_due'] = &$data['$invoice.balance_due'];
$data['$invoice.partial_due'] = ['value' => Number::formatMoney($this->partial, $this->client) ?: '&nbsp;', 'label' => ctrans('texts.partial_due')];
$data['$total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.total')];
$data['$quote.total'] = &$data['$total'];
$data['$invoice.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.invoice_total')];
$data['$invoice.amount'] = &$data['$total'];
$data['$quote.amount'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.quote_total')];
$data['$credit_total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_total')];
$data['$credit.amount'] = &$data['$credit_total'];
$data['$credit.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.credit_total')];
$data['$credit.number'] = ['value' => $this->number ?: '&nbsp;', 'label' => ctrans('texts.credit_number')];
$data['$credit.amount'] = &$data['$credit.total'];
$data['$balance'] = ['value' => Number::formatMoney($this->calc()->getBalance(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.balance')];
$data['$invoice.balance'] = &$data['$balance'];
$data['$taxes'] = ['value' => Number::formatMoney($this->calc()->getItemTotalTaxes(), $this->client) ?: '&nbsp;', 'label' => ctrans('texts.taxes')];
$data['$invoice.taxes'] = &$data['$taxes'];
$data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')];
$data['$invoice.custom2'] = ['value' => $this->custom_value2 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice2')];
$data['$invoice.custom3'] = ['value' => $this->custom_value3 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice3')];
$data['$invoice.custom4'] = ['value' => $this->custom_value4 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice4')];
$data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice1')];
$data['$invoice.custom2'] = ['value' => $this->custom_value2 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice2')];
$data['$invoice.custom3'] = ['value' => $this->custom_value3 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice3')];
$data['$invoice.custom4'] = ['value' => $this->custom_value4 ?: '&nbsp;', 'label' => $this->makeCustomField('invoice4')];
$data['$invoice.public_notes'] = ['value' => $this->public_notes ?: '&nbsp;', 'label' => ctrans('texts.public_notes')];
$data['$entity.public_notes'] = &$data['$invoice.public_notes'];
@ -256,8 +261,8 @@ trait MakesInvoiceValues
$contact = $this->client->primary_contact()->first();
}
$data['$contact_name'] = ['value' => isset($contact) ? $contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')];
$data['$contact.name'] = &$data['$contact_name'];
$data['$contact_name'] =
$data['$contact.name'] = ['value' => isset($contact) ? $contact->present()->name() : 'no contact name on record', 'label' => ctrans('texts.contact_name')];
$data['$contact1'] = ['value' => isset($contact) ? $contact->custom_value1 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$contact2'] = ['value' => isset($contact) ? $contact->custom_value2 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
$data['$contact3'] = ['value' => isset($contact) ? $contact->custom_value3 : '&nbsp;', 'label' => $this->makeCustomField('contact1')];
@ -282,12 +287,12 @@ trait MakesInvoiceValues
$logo = $this->company->present()->logo($settings);
$data['$company.logo'] = ['value' => "<img src='{$logo}' class='w-48' alt='logo'>" ?: '&nbsp;', 'label' => ctrans('texts.logo')];
$data['$company_logo'] = &$data['$company.logo'];
$data['$company1'] = ['value' => $settings->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('company1')];
$data['$company2'] = ['value' => $settings->custom_value2 ?: '&nbsp;', 'label' => $this->makeCustomField('company2')];
$data['$company3'] = ['value' => $settings->custom_value3 ?: '&nbsp;', 'label' => $this->makeCustomField('company3')];
$data['$company4'] = ['value' => $settings->custom_value4 ?: '&nbsp;', 'label' => $this->makeCustomField('company4')];
$data['$company.logo'] = ['value' => "<img src='{$logo}' class='w-48' alt='logo'>" ?: '&nbsp;', 'label' => ctrans('texts.logo')];
$data['$company_logo'] = &$data['$company.logo'];
$data['$company1'] = ['value' => $settings->custom_value1 ?: '&nbsp;', 'label' => $this->makeCustomField('company1')];
$data['$company2'] = ['value' => $settings->custom_value2 ?: '&nbsp;', 'label' => $this->makeCustomField('company2')];
$data['$company3'] = ['value' => $settings->custom_value3 ?: '&nbsp;', 'label' => $this->makeCustomField('company3')];
$data['$company4'] = ['value' => $settings->custom_value4 ?: '&nbsp;', 'label' => $this->makeCustomField('company4')];
$data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')];
$data['$product.discount'] = ['value' => '', 'label' => ctrans('texts.discount')];

View File

@ -3147,4 +3147,6 @@ return [
'email_link_not_working' => 'If button above isn\'t working for you, please click on the link',
'credit_terms' => 'Credit Terms',
'display_log' => 'Display Log',
'send_fail_logs_to_our_server' => 'Send error logs to our servers for analysis',
'setup' => 'Setup',
];