diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 61f7a45b5581..d30a8958e40e 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -173,14 +173,7 @@ class PreviewController extends BaseController $html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice'); - if (isset(request()->design['name'])) { - $design = new Design(strtolower(request()->design['name'])); - } else { - $design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]); - } - - // $designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity)); - // $html = $this->generateEntityHtml($designer, $entity_obj); + $design = new Design(Design::CUSTOM, ['custom_partials' => request()->design['design']]); $state = [ 'template' => $design->elements([ diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 56a9b1128621..5cc9516f8e79 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -67,7 +67,7 @@ class Design extends BaseDesign : config('ninja.designs.base_path'); return file_get_contents( - $path.$this->design + $path . $this->design ); } @@ -164,7 +164,7 @@ class Design extends BaseDesign foreach ($variables as $variable) { $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'elements' => [ - ['element' => 'th', 'content' => $variable.'_label'], + ['element' => 'th', 'content' => $variable . '_label'], ['element' => 'th', 'content' => $variable], ]]; } @@ -187,7 +187,7 @@ class Design extends BaseDesign $elements = []; foreach ($this->context['pdf_variables']["{$this->type}_columns"] as $column) { - $elements[] = ['element' => 'th', 'content' => $column.'_label']; + $elements[] = ['element' => 'th', 'content' => $column . '_label']; } return $elements; @@ -226,6 +226,22 @@ class Design extends BaseDesign ]], ]; + foreach (['discount', 'custom_surcharge1', 'custom_surcharge2', 'custom_surcharge3', 'custom_surcharge4'] as $property) { + $variable = sprintf('%s%s', '$', $property); + + if ( + !is_null($this->entity->{$property}) || + !empty($this->entity->{$property}) || + $this->entity->{$property} !== 0 + ) { + continue; + } + + $variables = array_filter($variables, function ($m) use ($variable) { + return $m != $variable; + }); + } + foreach ($variables as $variable) { if ($variable == '$total_taxes' || $variable == '$line_taxes') { continue; @@ -233,7 +249,7 @@ class Design extends BaseDesign $elements[] = ['element' => 'div', 'elements' => [ ['element' => 'span', 'content' => 'This is placeholder for the 3rd fraction of element.', 'properties' => ['style' => 'opacity: 0%']], // Placeholder for fraction of element (3fr) - ['element' => 'span', 'content' => $variable.'_label'], + ['element' => 'span', 'content' => $variable . '_label'], ['element' => 'span', 'content' => $variable], ]]; } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index 4b682059b878..886b10fcd4b0 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -79,7 +79,9 @@ trait DesignHelpers $document->importNode($element, true) ); - return $document->saveXML(); + $html = $document->saveHTML(); + + return str_replace('%24', '$', $html); } return ''; diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index 3958e1d7a323..df9c97eb57d0 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -71,14 +71,8 @@ class PdfMaker public function getCompiledHTML($final = false) { - if ($final) { - $html = $this->document->saveXML(); - - $filtered = strtr($html, $this->filters); - - return $filtered; - } - - return $this->document->saveXML(); + $html = $this->document->saveHTML(); + + return str_replace('%24', '$', $html); } } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index b0c33fc9cc1c..fc0d7160619b 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -104,6 +104,7 @@ class HtmlEngine //$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')]; $data['$invoice.date'] = &$data['$date']; $data['$due_date'] = ['value' => $this->entity->due_date ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_date')]; + $data['$payment_due'] = ['value' => $this->entity->due_date ?: ' ', 'label' => ctrans('texts.payment_due')]; $data['$invoice.due_date'] = &$data['$due_date']; $data['$invoice.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$invoice.po_number'] = ['value' => $this->entity->po_number ?: ' ', 'label' => ctrans('texts.po_number')]; @@ -154,6 +155,7 @@ class HtmlEngine $data['$partial_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; $data['$total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')]; $data['$amount'] = &$data['$total']; + $data['$amount_due'] = ['value' => &$data['$total']['value'], 'label' => ctrans('texts.amount_due')]; $data['$quote.total'] = &$data['$total']; $data['$invoice.total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.invoice_total')]; $data['$invoice.amount'] = &$data['$total']; @@ -275,10 +277,10 @@ class HtmlEngine $data['$company3'] = ['value' => $this->settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')]; $data['$company4'] = ['value' => $this->settings->custom_value4 ?: ' ', 'label' => $this->makeCustomField('company4')]; - $data['$custom_surcharge1'] = ['value' => $this->entity->custom_surcharge1, 'label' => $this->makeCustomField('custom_surcharge1')]; - $data['$custom_surcharge2'] = ['value' => $this->entity->custom_surcharge2, 'label' => $this->makeCustomField('custom_surcharge2')]; - $data['$custom_surcharge3'] = ['value' => $this->entity->custom_surcharge3, 'label' => $this->makeCustomField('custom_surcharge3')]; - $data['$custom_surcharge4'] = ['value' => $this->entity->custom_surcharge4, 'label' => $this->makeCustomField('custom_surcharge4')]; + $data['$custom_surcharge1'] = ['value' => $this->entity->custom_surcharge1 ?: ' ', 'label' => $this->makeCustomField('custom_surcharge1')]; + $data['$custom_surcharge2'] = ['value' => $this->entity->custom_surcharge2 ?: ' ', 'label' => $this->makeCustomField('custom_surcharge2')]; + $data['$custom_surcharge3'] = ['value' => $this->entity->custom_surcharge3 ?: ' ', 'label' => $this->makeCustomField('custom_surcharge3')]; + $data['$custom_surcharge4'] = ['value' => $this->entity->custom_surcharge4 ?: ' ', 'label' => $this->makeCustomField('custom_surcharge4')]; $data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')]; $data['$product.discount'] = ['value' => '', 'label' => ctrans('texts.discount')]; @@ -313,6 +315,8 @@ class HtmlEngine $data['_rate2'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['_rate3'] = ['value' => '', 'label' => ctrans('texts.tax')]; + $data['$font-size'] = ['value' => $this->settings->font_size . 'px', 'label' => '']; + // $data['custom_label1'] = ['value' => '', 'label' => ctrans('texts.')]; // $data['custom_label2'] = ['value' => '', 'label' => ctrans('texts.')]; // $data['custom_label3'] = ['value' => '', 'label' => ctrans('texts.')]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index b30cd4dc14ec..b9f14b54c991 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3266,4 +3266,6 @@ return [ 'add_payment_method_first' => 'add payment method', 'no_items_selected' => 'No items selected.', + + 'payment_due' => 'Payment due', ]; diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index 3e48b0e257bc..2d8ca4c86f0b 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -3,144 +3,147 @@
+ + - + + + -