- Accept every design as CUSTOM in PreviewController

- Logic for excluding elements in table footer
- PdfMaker will now return plain HTML + str_replace filter
- HTMLEngine updated variables and aliases
- Added 'payment_due' translation
- Hipster: Updated variables
This commit is contained in:
Benjamin Beganović 2020-09-09 14:47:26 +02:00
parent 455c604ecd
commit 6288529907
7 changed files with 37 additions and 28 deletions

View File

@ -173,14 +173,7 @@ class PreviewController extends BaseController
$html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice'); $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']]); $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);
$state = [ $state = [
'template' => $design->elements([ 'template' => $design->elements([

View File

@ -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) { foreach ($variables as $variable) {
if ($variable == '$total_taxes' || $variable == '$line_taxes') { if ($variable == '$total_taxes' || $variable == '$line_taxes') {
continue; continue;

View File

@ -79,7 +79,9 @@ trait DesignHelpers
$document->importNode($element, true) $document->importNode($element, true)
); );
return $document->saveXML(); $html = $this->document->saveHTML();
return str_replace('%24', '$', $html);
} }
return ''; return '';

View File

@ -71,14 +71,8 @@ class PdfMaker
public function getCompiledHTML($final = false) public function getCompiledHTML($final = false)
{ {
if ($final) { $html = $this->document->saveHTML();
$html = $this->document->saveXML();
$filtered = strtr($html, $this->filters); return str_replace('%24', '$', $html);
return $filtered;
}
return $this->document->saveXML();
} }
} }

View File

@ -104,6 +104,7 @@ class HtmlEngine
//$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')]; //$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')];
$data['$invoice.date'] = &$data['$date']; $data['$invoice.date'] = &$data['$date'];
$data['$due_date'] = ['value' => $this->entity->due_date ?: ' ', 'label' => ctrans('texts.'.$this->entity_string.'_due_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.due_date'] = &$data['$due_date'];
$data['$invoice.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $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')]; $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['$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['$total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')];
$data['$amount'] = &$data['$total']; $data['$amount'] = &$data['$total'];
$data['$amount_due'] = ['value' => &$data['$total']['value'], 'label' => ctrans('texts.amount_due')];
$data['$quote.total'] = &$data['$total']; $data['$quote.total'] = &$data['$total'];
$data['$invoice.total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.invoice_total')]; $data['$invoice.total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.invoice_total')];
$data['$invoice.amount'] = &$data['$total']; $data['$invoice.amount'] = &$data['$total'];
@ -275,10 +277,10 @@ class HtmlEngine
$data['$company3'] = ['value' => $this->settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')]; $data['$company3'] = ['value' => $this->settings->custom_value3 ?: ' ', 'label' => $this->makeCustomField('company3')];
$data['$company4'] = ['value' => $this->settings->custom_value4 ?: ' ', 'label' => $this->makeCustomField('company4')]; $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_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_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_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_surcharge4'] = ['value' => $this->entity->custom_surcharge4 ?: ' ', 'label' => $this->makeCustomField('custom_surcharge4')];
$data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')]; $data['$product.date'] = ['value' => '', 'label' => ctrans('texts.date')];
$data['$product.discount'] = ['value' => '', 'label' => ctrans('texts.discount')]; $data['$product.discount'] = ['value' => '', 'label' => ctrans('texts.discount')];

View File

@ -3266,4 +3266,6 @@ return [
'add_payment_method_first' => 'add payment method', 'add_payment_method_first' => 'add payment method',
'no_items_selected' => 'No items selected.', 'no_items_selected' => 'No items selected.',
'payment_due' => 'Payment due',
]; ];

View File

@ -185,8 +185,8 @@
<span class="entity-property-value">$entity_number</span> <span class="entity-property-value">$entity_number</span>
</span> </span>
<span> <span>
<span class="entity-property-label">$entity_date_label:</span> <span class="entity-property-label">$date_label:</span>
<span class="entity-property-value">$entity_date</span> <span class="entity-property-value">$date</span>
</span> </span>
<span> <span>
<span class="entity-property-label">$payment_due_label:</span> <span class="entity-property-label">$payment_due_label:</span>