Fixes for new reports

This commit is contained in:
David Bomba 2025-11-03 11:59:08 +11:00
parent ff280b4c5b
commit f5f447a3ff
5 changed files with 31 additions and 11 deletions

View File

@ -1739,10 +1739,13 @@ $products = str_getcsv($this->input['product_key'], ',', "'");
$data = [ $data = [
"{$model_string}s" => $query->get(), "{$model_string}s" => $query->get(),
"start_date" => $this->start_date,
"end_date" => $this->end_date,
]; ];
$ts = new TemplateService($template); $ts = new TemplateService($template);
$ts->setCompany($this->company); $ts->setCompany($this->company);
$ts->addGlobal(['currency_code' => $this->company->currency()->code]);
$ts->build($data); $ts->build($data);
return $ts->getPdf(); return $ts->getPdf();

View File

@ -184,13 +184,28 @@ class PdfBuilder
$document->validateOnParse = true; $document->validateOnParse = true;
@$document->loadHTML(mb_convert_encoding($this->service->designer->template, 'HTML-ENTITIES', 'UTF-8')); @$document->loadHTML($this->convertHtmlToEntities($this->service->designer->template));
// @$document->loadHTML(mb_convert_encoding($this->service->designer->template, 'HTML-ENTITIES', 'UTF-8'));
$this->document = $document; $this->document = $document;
return $this; return $this;
} }
/**
* Convert HTML string to HTML entities (replacement for deprecated mb_convert_encoding)
* Maintains exact same functionality as mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')
*
* @param string $html
* @return string
*/
private function convertHtmlToEntities(string $html): string
{
// Encode all non-ASCII characters (code points 0x80 and above) as numeric HTML entities
// This matches the exact behavior of mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')
return mb_encode_numericentity($html, [0x80, 0x10FFFF, 0, 0xFFFF], 'UTF-8');
}
/** /**
* parseTwigElements * parseTwigElements
* *
@ -2167,7 +2182,8 @@ $f->appendXML('<![CDATA[' . $decoded_template . ']]>');
$html = strtr($this->getCompiledHTML(), $this->service->html_variables['labels']); $html = strtr($this->getCompiledHTML(), $this->service->html_variables['labels']);
$html = strtr($html, $this->service->html_variables['values']); $html = strtr($html, $this->service->html_variables['values']);
@$this->document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); @$this->document->loadHTML($this->convertHtmlToEntities($html));
// @$this->document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
//new block //new block
// $html = htmlspecialchars_decode($html, ENT_QUOTES | ENT_HTML5); // $html = htmlspecialchars_decode($html, ENT_QUOTES | ENT_HTML5);

File diff suppressed because one or more lines are too long

View File

@ -151,16 +151,17 @@ class TemplateService
$filter = new \Twig\TwigFilter('groupBy', \Closure::fromCallable(function (?iterable $items, ?string $property) { $filter = new \Twig\TwigFilter('groupBy', \Closure::fromCallable(function (?iterable $items, ?string $property) {
if ($items === null || $property === null) { if ($items === null || $property === null) {
return []; return [$items];
} }
return collect($items)->groupBy($property)->toArray(); $x = collect($items)->groupBy($property)->toArray();
return $x;
})); }));
$this->twig->addFilter($filter); $this->twig->addFilter($filter);
$allowedTags = ['if', 'for', 'set', 'filter']; $allowedTags = ['if', 'for', 'set', 'filter'];
$allowedFilters = ['groupBy','capitalize', 'abs', 'date_modify', 'keys', 'join', 'reduce', 'format_date','json_decode','date_modify','trim','round','format_spellout_number','split', 'reduce','replace', 'escape', 'e', 'reverse', 'shuffle', 'slice', 'batch', 'title', 'sort', 'split', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date', 'sum', 'number_format','nl2br','striptags','markdown_to_html']; $allowedFilters = ['default', 'groupBy','capitalize', 'abs', 'date_modify', 'keys', 'join', 'reduce', 'format_date','json_decode','date_modify','trim','round','format_spellout_number','split', 'reduce','replace', 'escape', 'e', 'reverse', 'shuffle', 'slice', 'batch', 'title', 'sort', 'split', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date', 'sum', 'number_format','nl2br','striptags','markdown_to_html'];
$allowedFunctions = ['range', 'cycle', 'constant', 'date','img','t']; $allowedFunctions = ['range', 'cycle', 'constant', 'date','img','t'];
$allowedProperties = ['type_id']; $allowedProperties = ['type_id'];
// $allowedMethods = ['img','t']; // $allowedMethods = ['img','t'];
@ -523,7 +524,7 @@ class TemplateService
$processed = []; $processed = [];
if (in_array($key, ['aging', 'unapplied']) || !$value->first() || (in_array($key, ['projects','tasks']) && !$value->first()->client)) { if (in_array($key, ['aging', 'unapplied', 'start_date', 'end_date']) || !$value->first() || (in_array($key, ['projects', 'tasks']) && !$value->first()->client)) {
return $processed; return $processed;
} }
@ -1035,7 +1036,7 @@ class TemplateService
'address' => $entity->client->present()->address(), 'address' => $entity->client->present()->address(),
'shipping_address' => $entity->client->present()->shipping_address(), 'shipping_address' => $entity->client->present()->shipping_address(),
'locale' => substr($entity->client->locale(), 0, 2), 'locale' => substr($entity->client->locale(), 0, 2),
'location' => $entity->service()->location(false), 'location' => $entity->location ? $entity->service()->location(false) : [],
] : []; ] : [];
} }

View File

@ -143,7 +143,7 @@ class TemplateEngine
/* If the body / subject are not populated we need to get the defaults */ /* If the body / subject are not populated we need to get the defaults */
private function setTemplates() 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); $subject_template = str_replace('template', 'subject', $this->template);
if (strlen($this->settings_entity->getSetting($subject_template)) > 1) { if (strlen($this->settings_entity->getSetting($subject_template)) > 1) {
@ -153,7 +153,7 @@ class TemplateEngine
} }
} }
if (strlen($this->body) == 0 && strlen($this->template) > 1) { if (strlen($this->body) == 0 && strlen($this->template ?? '') > 1) {
if (strlen($this->settings_entity->getSetting($this->template)) > 1) { if (strlen($this->settings_entity->getSetting($this->template)) > 1) {
$this->body = $this->settings_entity->getSetting($this->template); $this->body = $this->settings_entity->getSetting($this->template);
} else { } else {