Improvements for variable replacements

This commit is contained in:
David Bomba 2023-10-30 08:07:47 +11:00
parent a9188bf6e8
commit 872ac11329
2 changed files with 11 additions and 8 deletions

View File

@ -1036,10 +1036,13 @@ class PdfBuilder
*/ */
public function getTableTotals() :array public function getTableTotals() :array
{ {
//need to see where we don't pass all these particular variables. try and refactor thisout //need to see where we don't pass all these particular variables. try and refactor thisout
$_variables = array_key_exists('variables', $this->service->options) // $_variables = array_key_exists('variables', $this->service->options)
? $this->service->options['variables'] // ? $this->service->options['variables']
: ['values' => ['$entity.public_notes' => $this->service->config->entity->public_notes, '$entity.terms' => $this->service->config->entity->terms, '$entity_footer' => $this->service->config->entity->footer], 'labels' => []]; // : ['values' => ['$entity.public_notes' => $this->service->config->entity->public_notes, '$entity.terms' => $this->service->config->entity->terms, '$entity_footer' => $this->service->config->entity->footer], 'labels' => []];
$_variables = $this->service->html_variables;
$variables = $this->service->config->pdf_variables['total_columns']; $variables = $this->service->config->pdf_variables['total_columns'];

View File

@ -266,12 +266,12 @@ class Helpers
$_right = ''; $_right = '';
// If right side doesn't have any calculations, replace with raw ranges keyword. // If right side doesn't have any calculations, replace with raw ranges keyword.
if (! Str::contains($right, ['-', '+', '/', '*'])) { if (! Str::contains(str_replace("</", "", $right), ['-', '+', '/', '*'])) {
$_right = Carbon::createFromDate($currentDateTime->year, $currentDateTime->month)->translatedFormat('F Y'); $_right = Carbon::createFromDate($currentDateTime->year, $currentDateTime->month)->translatedFormat('F Y');
} }
// If right side contains one of math operations, calculate. // If right side contains one of math operations, calculate.
if (Str::contains($right, ['+'])) { if (Str::contains(str_replace("</", "", $right), ['+'])) {
$operation = preg_match_all('/(?!^-)[+*\/-](\s?-)?/', $right, $_matches); $operation = preg_match_all('/(?!^-)[+*\/-](\s?-)?/', $right, $_matches);
$_operation = array_shift($_matches)[0]; // + - $_operation = array_shift($_matches)[0]; // + -
@ -306,7 +306,7 @@ class Helpers
continue; continue;
} }
if (! Str::contains($match, ['-', '+', '/', '*'])) { if (! Str::contains(str_replace("</", "", $match), ['-', '+', '/', '*'])) {
$value = preg_replace( $value = preg_replace(
sprintf('/%s/', $matches->keys()->first()), sprintf('/%s/', $matches->keys()->first()),
$replacements['literal'][$matches->keys()->first()], $replacements['literal'][$matches->keys()->first()],
@ -315,7 +315,7 @@ class Helpers
); );
} }
if (Str::contains($match, ['-', '+', '/', '*'])) { if (Str::contains(str_replace("</", "", $match), ['-', '+', '/', '*'])) {
$operation = preg_match_all('/(?!^-)[+*\/-](\s?-)?/', $match, $_matches); $operation = preg_match_all('/(?!^-)[+*\/-](\s?-)?/', $match, $_matches);
$_operation = array_shift($_matches)[0]; $_operation = array_shift($_matches)[0];