2020-08-04 13:33:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-08-04 13:33:38 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-08-04 13:33:38 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-08-04 13:33:38 +02:00
|
|
|
*/
|
|
|
|
|
2020-08-07 15:58:05 +02:00
|
|
|
namespace App\Services\PdfMaker\Designs\Utilities;
|
2020-08-04 13:33:38 +02:00
|
|
|
|
2020-11-06 13:13:04 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-08-11 17:19:52 +02:00
|
|
|
use DOMDocument;
|
|
|
|
use DOMXPath;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Exception;
|
2021-04-13 16:43:35 +02:00
|
|
|
use League\CommonMark\CommonMarkConverter;
|
2020-08-11 17:19:52 +02:00
|
|
|
|
2020-08-10 17:07:30 +02:00
|
|
|
trait DesignHelpers
|
2020-08-04 13:33:38 +02:00
|
|
|
{
|
2020-11-06 13:13:04 +01:00
|
|
|
use MakesHash;
|
|
|
|
|
2020-08-11 17:19:52 +02:00
|
|
|
public $document;
|
|
|
|
|
|
|
|
public $xpath;
|
|
|
|
|
|
|
|
public function setup(): self
|
|
|
|
{
|
2021-08-24 16:06:34 +02:00
|
|
|
$this->syncPdfVariables();
|
|
|
|
|
2022-06-06 14:27:17 +02:00
|
|
|
if (isset($this->context['vendor'])) {
|
|
|
|
$this->vendor = $this->context['vendor'];
|
|
|
|
}
|
|
|
|
|
2020-08-11 17:19:52 +02:00
|
|
|
if (isset($this->context['client'])) {
|
|
|
|
$this->client = $this->context['client'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->context['entity'])) {
|
|
|
|
$this->entity = $this->context['entity'];
|
|
|
|
}
|
|
|
|
|
2021-08-20 15:38:15 +02:00
|
|
|
if (isset($this->context['invoices'])) {
|
|
|
|
$this->invoices = $this->context['invoices'];
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-12-08 00:16:13 +01:00
|
|
|
if ($this->invoices->count() >= 1) {
|
2021-09-16 15:04:24 +02:00
|
|
|
$this->entity = $this->invoices->first();
|
|
|
|
}
|
2021-08-20 15:38:15 +02:00
|
|
|
}
|
|
|
|
|
2021-08-23 14:21:28 +02:00
|
|
|
if (isset($this->context['payments'])) {
|
|
|
|
$this->payments = $this->context['payments'];
|
|
|
|
}
|
|
|
|
|
2023-04-19 04:31:27 +02:00
|
|
|
if (isset($this->context['credits'])) {
|
|
|
|
$this->credits = $this->context['credits'];
|
|
|
|
}
|
|
|
|
|
2021-08-24 15:33:41 +02:00
|
|
|
if (isset($this->context['aging'])) {
|
|
|
|
$this->aging = $this->context['aging'];
|
|
|
|
}
|
|
|
|
|
2020-08-11 17:19:52 +02:00
|
|
|
$this->document();
|
|
|
|
|
2022-06-10 09:04:16 +02:00
|
|
|
$this->settings_object = $this->vendor ? $this->vendor->company : $this->client;
|
|
|
|
|
|
|
|
$this->company = $this->vendor ? $this->vendor->company : $this->client->company;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-08-11 17:19:52 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-08-24 16:06:34 +02:00
|
|
|
protected function syncPdfVariables(): void
|
|
|
|
{
|
|
|
|
$default = (array) \App\DataMapper\CompanySettings::getEntityVariableDefaults();
|
|
|
|
$variables = $this->context['pdf_variables'];
|
|
|
|
|
|
|
|
foreach ($default as $property => $value) {
|
|
|
|
if (array_key_exists($property, $variables)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$variables[$property] = $value;
|
|
|
|
}
|
2021-09-24 11:34:03 +02:00
|
|
|
|
|
|
|
$this->context['pdf_variables'] = $variables;
|
2021-08-24 16:06:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-11 17:19:52 +02:00
|
|
|
/**
|
|
|
|
* Initialize local dom document instance. Used for getting raw HTML out of template.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
|
|
|
* @return $this
|
2020-08-11 17:19:52 +02:00
|
|
|
*/
|
|
|
|
public function document(): self
|
|
|
|
{
|
|
|
|
$document = new DOMDocument();
|
|
|
|
|
|
|
|
$document->validateOnParse = true;
|
|
|
|
@$document->loadHTML($this->html());
|
|
|
|
|
|
|
|
$this->document = $document;
|
|
|
|
$this->xpath = new DOMXPath($document);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get specific section HTML.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
|
|
|
* @param string $section
|
|
|
|
* @param bool $id
|
|
|
|
* @return null|string
|
2020-08-11 17:19:52 +02:00
|
|
|
*/
|
|
|
|
public function getSectionHTML(string $section, $id = true): ?string
|
|
|
|
{
|
|
|
|
if ($id) {
|
|
|
|
$element = $this->document->getElementById($section);
|
|
|
|
} else {
|
|
|
|
$elements = $this->document->getElementsByTagName($section);
|
|
|
|
$element = $elements[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$document = new DOMDocument();
|
|
|
|
$document->preserveWhiteSpace = false;
|
|
|
|
$document->formatOutput = true;
|
|
|
|
|
|
|
|
if ($element) {
|
|
|
|
$document->appendChild(
|
|
|
|
$document->importNode($element, true)
|
|
|
|
);
|
|
|
|
|
2020-09-09 17:14:55 +02:00
|
|
|
$html = $document->saveHTML();
|
2020-09-09 14:47:26 +02:00
|
|
|
|
|
|
|
return str_replace('%24', '$', $html);
|
2020-08-11 17:19:52 +02:00
|
|
|
}
|
|
|
|
|
2020-08-20 17:48:10 +02:00
|
|
|
return '';
|
2020-08-11 17:19:52 +02:00
|
|
|
}
|
|
|
|
|
2020-08-04 13:33:38 +02:00
|
|
|
/**
|
|
|
|
* This method will help us decide either we show
|
|
|
|
* one "tax rate" column in the table or 3 custom tax rates.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
2020-08-04 13:33:38 +02:00
|
|
|
* Logic below will help us calculate that & inject the result in the
|
|
|
|
* global state of the $context (design state).
|
2020-11-25 15:19:52 +01:00
|
|
|
*
|
2020-11-04 14:56:08 +01:00
|
|
|
* @param string $type "product" or "task"
|
2020-08-04 13:33:38 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
2020-11-04 14:56:08 +01:00
|
|
|
public function processTaxColumns(string $type): void
|
2020-08-04 13:33:38 +02:00
|
|
|
{
|
2023-05-17 12:17:37 +02:00
|
|
|
$column_type = $type;
|
2023-05-17 12:46:12 +02:00
|
|
|
|
|
|
|
if ($type == 'product') {
|
2020-11-04 14:56:08 +01:00
|
|
|
$type_id = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type == 'task') {
|
|
|
|
$type_id = 2;
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-05-17 12:47:39 +02:00
|
|
|
/** 17-05-2023 need to explicity define product_quote here */
|
2023-05-17 12:46:12 +02:00
|
|
|
if ($type == 'product_quote') {
|
|
|
|
$type_id = 1;
|
|
|
|
$column_type = 'product_quote';
|
|
|
|
$type = 'product';
|
|
|
|
}
|
|
|
|
|
2020-11-04 14:56:08 +01:00
|
|
|
|
|
|
|
// At the moment we pass "task" or "product" as type.
|
|
|
|
// However, "pdf_variables" contains "$task.tax" or "$product.tax" <-- Notice the dollar sign.
|
|
|
|
// This sprintf() will help us convert "task" or "product" into "$task" or "$product" without
|
|
|
|
// evaluating the variable.
|
|
|
|
|
2023-05-17 12:17:37 +02:00
|
|
|
if (in_array(sprintf('%s%s.tax', '$', $type), (array) $this->context['pdf_variables']["{$column_type}_columns"])) {
|
2020-11-04 14:56:08 +01:00
|
|
|
$line_items = collect($this->entity->line_items)->filter(function ($item) use ($type_id) {
|
|
|
|
return $item->type_id = $type_id;
|
|
|
|
});
|
|
|
|
|
|
|
|
$tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', $type_id)->count();
|
|
|
|
$tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', $type_id)->count();
|
|
|
|
$tax3 = $line_items->where('tax_name3', '<>', '')->where('type_id', $type_id)->count();
|
2020-08-04 13:33:38 +02:00
|
|
|
|
|
|
|
$taxes = [];
|
|
|
|
|
|
|
|
if ($tax1 > 0) {
|
2020-11-04 14:56:08 +01:00
|
|
|
array_push($taxes, sprintf('%s%s.tax_rate1', '$', $type));
|
2020-08-04 13:33:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($tax2 > 0) {
|
2020-11-04 14:56:08 +01:00
|
|
|
array_push($taxes, sprintf('%s%s.tax_rate2', '$', $type));
|
2020-08-04 13:33:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($tax3 > 0) {
|
2020-11-04 14:56:08 +01:00
|
|
|
array_push($taxes, sprintf('%s%s.tax_rate3', '$', $type));
|
2020-08-04 13:33:38 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 12:17:37 +02:00
|
|
|
$key = array_search(sprintf('%s%s.tax', '$', $type), $this->context['pdf_variables']["{$column_type}_columns"], true);
|
2020-08-04 13:33:38 +02:00
|
|
|
|
2022-06-11 01:07:09 +02:00
|
|
|
if ($key !== false) {
|
2023-05-17 12:17:37 +02:00
|
|
|
array_splice($this->context['pdf_variables']["{$column_type}_columns"], $key, 1, $taxes);
|
2020-08-04 13:33:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 15:58:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the remaining colspans.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
|
|
|
* @param int $taken
|
|
|
|
* @return int
|
2020-08-07 15:58:05 +02:00
|
|
|
*/
|
|
|
|
public function calculateColspan(int $taken): int
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$total = (int) count($this->context['pdf_variables']['product_columns']);
|
2020-08-07 15:58:05 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return (int) $total - $taken;
|
2020-08-07 15:58:05 +02:00
|
|
|
}
|
2020-08-07 18:30:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return "true" or "false" based on null or empty check.
|
|
|
|
* We need to return false as string because of HTML parsing.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
|
|
|
* @param mixed $property
|
|
|
|
* @return string
|
2020-08-07 18:30:04 +02:00
|
|
|
*/
|
2020-08-10 12:57:53 +02:00
|
|
|
public function toggleHiddenProperty($property): string
|
2020-08-07 18:30:04 +02:00
|
|
|
{
|
|
|
|
if (is_null($property)) {
|
|
|
|
return 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($property)) {
|
|
|
|
return 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'true';
|
|
|
|
}
|
2020-08-11 17:53:11 +02:00
|
|
|
|
|
|
|
public function sharedFooterElements()
|
|
|
|
{
|
2021-09-27 17:59:14 +02:00
|
|
|
// We want to show headers for statements, no exceptions.
|
|
|
|
$statements = "
|
2023-09-19 03:43:26 +02:00
|
|
|
document.querySelectorAll('#statement-credit-table > thead > tr > th, #statement-invoice-table > thead > tr > th, #statement-payment-table > thead > tr > th, #statement-aging-table > thead > tr > th').forEach(t => {
|
2021-09-27 17:59:14 +02:00
|
|
|
t.hidden = false;
|
|
|
|
});
|
|
|
|
";
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2023-09-19 02:05:13 +02:00
|
|
|
// $javascript = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{if(""!==t.innerText){let e=t.getAttribute("data-ref").slice(0,-3);document.querySelector(`th[data-ref="${e}-th"]`).removeAttribute("hidden")}}),document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{let e=t.getAttribute("data-ref").slice(0,-3);(e=document.querySelector(`th[data-ref="${e}-th"]`)).hasAttribute("hidden")&&""==t.innerText&&t.setAttribute("hidden","true")})},!1);';
|
|
|
|
$javascript = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("#custom-table > tbody > tr >td, #product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{if(""!==t.innerText){let e=t.getAttribute("data-ref").slice(0,-3);document.querySelector(`th[data-ref="${e}-th"]`).removeAttribute("hidden")}}),document.querySelectorAll("#custom-table > tbody > tr > td, #product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{let e=t.getAttribute("data-ref").slice(0,-3);(e=document.querySelector(`th[data-ref="${e}-th"]`)).hasAttribute("hidden")&&""==t.innerText&&t.setAttribute("hidden","true")})},!1);';
|
2020-09-17 14:28:55 +02:00
|
|
|
|
2021-04-09 13:06:14 +02:00
|
|
|
// Previously we've been decoding the HTML on the backend and XML parsing isn't good options because it requires,
|
|
|
|
// strict & valid HTML to even output/decode. Decoding is now done on the frontend with this piece of Javascript.
|
|
|
|
|
2021-04-25 15:52:00 +02:00
|
|
|
$html_decode = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(`[data-state="encoded-html"]`).forEach(e=>e.innerHTML=e.innerText)},!1);';
|
2021-04-09 13:06:14 +02:00
|
|
|
|
2021-01-05 17:48:06 +01:00
|
|
|
return ['element' => 'div', 'elements' => [
|
2021-09-27 17:59:14 +02:00
|
|
|
['element' => 'script', 'content' => $statements],
|
2021-01-05 17:48:06 +01:00
|
|
|
['element' => 'script', 'content' => $javascript],
|
2021-04-09 13:06:14 +02:00
|
|
|
['element' => 'script', 'content' => $html_decode],
|
2021-01-05 17:48:06 +01:00
|
|
|
]];
|
2020-08-11 17:53:11 +02:00
|
|
|
}
|
2020-08-14 14:53:55 +02:00
|
|
|
|
2023-01-30 23:25:40 +01:00
|
|
|
|
|
|
|
public function entityVariableCheck(string $variable): bool
|
|
|
|
{
|
|
|
|
// Extract $invoice.date => date
|
|
|
|
// so we can append date as $entity->date and not $entity->$invoice.date;
|
|
|
|
|
|
|
|
// When it comes to invoice balance, we'll always show it.
|
|
|
|
if ($variable == '$invoice.total') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some variables don't map 1:1 to table columns. This gives us support for such cases.
|
|
|
|
$aliases = [
|
|
|
|
'$quote.balance_due' => 'partial',
|
2023-07-15 01:17:38 +02:00
|
|
|
'$purchase_order.po_number' => 'number',
|
|
|
|
'$purchase_order.total' => 'amount',
|
|
|
|
'$purchase_order.due_date' => 'due_date',
|
|
|
|
'$purchase_order.balance_due' => 'balance_due',
|
2023-01-30 23:25:40 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
$_variable = explode('.', $variable)[1];
|
|
|
|
} catch (Exception $e) {
|
|
|
|
throw new Exception('Company settings seems to be broken. Missing $entity.variable type.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (\in_array($variable, \array_keys($aliases))) {
|
|
|
|
$_variable = $aliases[$variable];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($this->entity->{$_variable})) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->entity->{$_variable})) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function entityVariableCheckx(string $variable): string
|
2020-08-14 14:53:55 +02:00
|
|
|
{
|
|
|
|
// Extract $invoice.date => date
|
|
|
|
// so we can append date as $entity->date and not $entity->$invoice.date;
|
|
|
|
|
2020-11-20 14:31:47 +01:00
|
|
|
// When it comes to invoice balance, we'll always show it.
|
|
|
|
if ($variable == '$invoice.total') {
|
2023-01-30 01:07:55 +01:00
|
|
|
return 'visible';
|
2020-11-20 14:31:47 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
// Some variables don't map 1:1 to table columns. This gives us support for such cases.
|
2021-09-20 08:47:54 +02:00
|
|
|
$aliases = [
|
|
|
|
'$quote.balance_due' => 'partial',
|
|
|
|
];
|
|
|
|
|
2020-08-14 14:53:55 +02:00
|
|
|
try {
|
|
|
|
$_variable = explode('.', $variable)[1];
|
2020-10-28 11:10:49 +01:00
|
|
|
} catch (Exception $e) {
|
2023-01-30 11:40:20 +01:00
|
|
|
nlog("Company settings seems to be broken. Could not resolve {$variable} type.");
|
|
|
|
return 'collapse';
|
2020-08-14 14:53:55 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 08:47:54 +02:00
|
|
|
if (\in_array($variable, \array_keys($aliases))) {
|
|
|
|
$_variable = $aliases[$variable];
|
|
|
|
}
|
|
|
|
|
2020-08-14 14:53:55 +02:00
|
|
|
if (is_null($this->entity->{$_variable})) {
|
2023-01-30 01:07:55 +01:00
|
|
|
return 'collapse';
|
2020-08-14 14:53:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->entity->{$_variable})) {
|
2023-01-30 01:07:55 +01:00
|
|
|
return 'collapse';
|
2020-08-14 14:53:55 +02:00
|
|
|
}
|
|
|
|
|
2023-01-30 01:07:55 +01:00
|
|
|
return 'visible';
|
2020-08-14 14:53:55 +02:00
|
|
|
}
|
2020-09-08 13:21:07 +02:00
|
|
|
|
|
|
|
public function composeFromPartials(array $partials)
|
|
|
|
{
|
|
|
|
$html = '';
|
|
|
|
|
2020-10-07 18:42:41 +02:00
|
|
|
$html .= $partials['includes'];
|
2020-09-08 13:21:07 +02:00
|
|
|
$html .= $partials['header'];
|
|
|
|
$html .= $partials['body'];
|
|
|
|
$html .= $partials['footer'];
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2020-11-06 13:13:04 +01:00
|
|
|
|
2020-12-22 13:56:09 +01:00
|
|
|
public function processCustomColumns(string $type): void
|
|
|
|
{
|
|
|
|
$custom_columns = [];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
foreach ((array) $this->client->company->custom_fields as $field => $value) {
|
2020-12-22 13:56:09 +01:00
|
|
|
info($field);
|
|
|
|
|
|
|
|
if (\Illuminate\Support\Str::startsWith($field, $type)) {
|
2022-06-21 11:57:17 +02:00
|
|
|
$custom_columns[] = '$'.$type.'.'.$field;
|
2020-12-22 13:56:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$key = array_search(sprintf('%s%s.description', '$', $type), $this->context['pdf_variables']["{$type}_columns"], true);
|
|
|
|
|
2022-06-11 01:07:09 +02:00
|
|
|
if ($key !== false) {
|
2020-12-22 13:56:09 +01:00
|
|
|
array_splice($this->context['pdf_variables']["{$type}_columns"], $key + 1, 0, $custom_columns);
|
|
|
|
}
|
|
|
|
}
|
2021-03-10 16:55:49 +01:00
|
|
|
|
|
|
|
public function getCustomFieldValue(string $field): string
|
|
|
|
{
|
|
|
|
// In custom_fields column we store fields like: company1-4,
|
|
|
|
// while in settings, they're stored in custom_value1-4 format.
|
|
|
|
// That's why we need this mapping.
|
|
|
|
|
|
|
|
$fields = [
|
|
|
|
'company1' => 'custom_value1',
|
|
|
|
'company2' => 'custom_value2',
|
|
|
|
'company3' => 'custom_value3',
|
|
|
|
'company4' => 'custom_value4',
|
|
|
|
];
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! array_key_exists($field, $fields)) {
|
2021-03-10 16:55:49 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->client->company->custom_fields && ! property_exists($this->client->company->custom_fields, $field)) {
|
2021-03-10 16:55:49 +01:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$value = $this->client->company->getSetting($fields[$field]);
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
return (new \App\Utils\Helpers())->formatCustomFieldValue(
|
2021-03-10 16:55:49 +01:00
|
|
|
$this->client->company->custom_fields,
|
|
|
|
$field,
|
|
|
|
$value,
|
|
|
|
$this->client
|
|
|
|
);
|
|
|
|
}
|
2021-04-13 16:43:35 +02:00
|
|
|
|
2024-01-29 05:43:40 +01:00
|
|
|
/**
|
|
|
|
* @todo - this is being called directl, - not through the calling class!!!!
|
|
|
|
* @design_flaw
|
|
|
|
*/
|
2021-04-13 16:43:35 +02:00
|
|
|
public static function parseMarkdownToHtml(string $markdown): ?string
|
|
|
|
{
|
2021-05-31 13:47:22 +02:00
|
|
|
// Use setting to determinate if parsing should be done.
|
|
|
|
// 'parse_markdown_on_pdfs'
|
|
|
|
|
2021-04-13 16:43:35 +02:00
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
|
|
|
|
2022-03-16 08:50:34 +01:00
|
|
|
return $converter->convert($markdown);
|
2021-04-13 16:43:35 +02:00
|
|
|
}
|
2021-05-31 14:08:24 +02:00
|
|
|
|
2021-08-09 16:49:12 +02:00
|
|
|
public function processNewLines(array &$items): void
|
|
|
|
{
|
|
|
|
foreach ($items as $key => $item) {
|
|
|
|
foreach ($item as $variable => $value) {
|
2022-06-21 11:57:17 +02:00
|
|
|
// $item[$variable] = nl2br($value, true);
|
|
|
|
$item[$variable] = str_replace("\n", '<br>', $value);
|
2021-08-09 16:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$items[$key] = $item;
|
|
|
|
}
|
|
|
|
}
|
2020-08-04 13:33:38 +02:00
|
|
|
}
|