diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 73728ca27752..1371b6ed4cc2 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -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); } diff --git a/app/Http/Controllers/TemplateController.php b/app/Http/Controllers/TemplateController.php index 0e70e56c2311..fbaa066fad78 100644 --- a/app/Http/Controllers/TemplateController.php +++ b/app/Http/Controllers/TemplateController.php @@ -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') : ''; diff --git a/app/Http/Requests/Template/ShowTemplateRequest.php b/app/Http/Requests/Template/ShowTemplateRequest.php new file mode 100644 index 000000000000..56488c5491e8 --- /dev/null +++ b/app/Http/Requests/Template/ShowTemplateRequest.php @@ -0,0 +1,51 @@ +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() + { + + } +} diff --git a/app/Transformers/DocumentTransformer.php b/app/Transformers/DocumentTransformer.php index e0c36a7553fd..9f76163c07cb 100644 --- a/app/Transformers/DocumentTransformer.php +++ b/app/Transformers/DocumentTransformer.php @@ -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 ]; diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index cd1d5e6b0220..2c61f7031f48 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -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; } -} \ No newline at end of file +} diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index ea57ba4067aa..cde42e5b6490 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -138,6 +138,7 @@ trait MakesInvoiceValues //$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')]; $data['$invoice.date'] = &$data['$date']; $data['$invoice.due_date'] = ['value' => $this->due_date ?: ' ', 'label' => ctrans('texts.due_date')]; + $data['$due_date'] = &$data['$invoice.due_date']; $data['$invoice.number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$invoice.po_number'] = ['value' => $this->po_number ?: ' ', 'label' => ctrans('texts.po_number')]; $data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: ' ', 'label' => ctrans('texts.taxes')]; @@ -174,23 +175,27 @@ trait MakesInvoiceValues $data['$subtotal'] = ['value' => Number::formatMoney($this->calc()->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')]; $data['$invoice.subtotal'] = &$data['$subtotal']; $data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->balance, $this->client) ?: ' ', '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) ?: ' ', 'label' => ctrans('texts.partial_due')]; $data['$total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')]; + $data['$quote.total'] = &$data['$total']; $data['$invoice.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.invoice_total')]; $data['$invoice.amount'] = &$data['$total']; $data['$quote.amount'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.quote_total')]; - $data['$credit_total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_total')]; - $data['$credit.amount'] = &$data['$credit_total']; + $data['$credit.total'] = ['value' => Number::formatMoney($this->calc()->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.credit_total')]; + $data['$credit.number'] = ['value' => $this->number ?: ' ', 'label' => ctrans('texts.credit_number')]; + $data['$credit.amount'] = &$data['$credit.total']; $data['$balance'] = ['value' => Number::formatMoney($this->calc()->getBalance(), $this->client) ?: ' ', 'label' => ctrans('texts.balance')]; $data['$invoice.balance'] = &$data['$balance']; $data['$taxes'] = ['value' => Number::formatMoney($this->calc()->getItemTotalTaxes(), $this->client) ?: ' ', 'label' => ctrans('texts.taxes')]; $data['$invoice.taxes'] = &$data['$taxes']; - $data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: ' ', 'label' => $this->makeCustomField('invoice1')]; - $data['$invoice.custom2'] = ['value' => $this->custom_value2 ?: ' ', 'label' => $this->makeCustomField('invoice2')]; - $data['$invoice.custom3'] = ['value' => $this->custom_value3 ?: ' ', 'label' => $this->makeCustomField('invoice3')]; - $data['$invoice.custom4'] = ['value' => $this->custom_value4 ?: ' ', 'label' => $this->makeCustomField('invoice4')]; + $data['$invoice.custom1'] = ['value' => $this->custom_value1 ?: ' ', 'label' => $this->makeCustomField('invoice1')]; + $data['$invoice.custom2'] = ['value' => $this->custom_value2 ?: ' ', 'label' => $this->makeCustomField('invoice2')]; + $data['$invoice.custom3'] = ['value' => $this->custom_value3 ?: ' ', 'label' => $this->makeCustomField('invoice3')]; + $data['$invoice.custom4'] = ['value' => $this->custom_value4 ?: ' ', 'label' => $this->makeCustomField('invoice4')]; $data['$invoice.public_notes'] = ['value' => $this->public_notes ?: ' ', '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 : ' ', 'label' => $this->makeCustomField('contact1')]; $data['$contact2'] = ['value' => isset($contact) ? $contact->custom_value2 : ' ', 'label' => $this->makeCustomField('contact1')]; $data['$contact3'] = ['value' => isset($contact) ? $contact->custom_value3 : ' ', 'label' => $this->makeCustomField('contact1')]; @@ -282,12 +287,12 @@ trait MakesInvoiceValues $logo = $this->company->present()->logo($settings); - $data['$company.logo'] = ['value' => "logo" ?: ' ', 'label' => ctrans('texts.logo')]; - $data['$company_logo'] = &$data['$company.logo']; - $data['$company1'] = ['value' => $settings->custom_value1 ?: ' ', 'label' => $this->makeCustomField('company1')]; - $data['$company2'] = ['value' => $settings->custom_value2 ?: ' ', 'label' => $this->makeCustomField('company2')]; - $data['$company3'] = ['value' => $settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')]; - $data['$company4'] = ['value' => $settings->custom_value4 ?: ' ', 'label' => $this->makeCustomField('company4')]; + $data['$company.logo'] = ['value' => "logo" ?: ' ', 'label' => ctrans('texts.logo')]; + $data['$company_logo'] = &$data['$company.logo']; + $data['$company1'] = ['value' => $settings->custom_value1 ?: ' ', 'label' => $this->makeCustomField('company1')]; + $data['$company2'] = ['value' => $settings->custom_value2 ?: ' ', 'label' => $this->makeCustomField('company2')]; + $data['$company3'] = ['value' => $settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')]; + $data['$company4'] = ['value' => $settings->custom_value4 ?: ' ', 'label' => $this->makeCustomField('company4')]; $data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')]; $data['$product.discount'] = ['value' => '', 'label' => ctrans('texts.discount')]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 894ebb4ef247..d6d6d2a05ea1 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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', ];