diff --git a/app/Services/Pdf/PdfConfiguration.php b/app/Services/Pdf/PdfConfiguration.php index 0cb663f5c11b..64b17df36b1c 100644 --- a/app/Services/Pdf/PdfConfiguration.php +++ b/app/Services/Pdf/PdfConfiguration.php @@ -11,6 +11,7 @@ namespace App\Services\Pdf; +use App\DataMapper\CompanySettings; use App\Models\Client; use App\Models\Credit; use App\Models\CreditInvitation; @@ -47,6 +48,8 @@ class PdfConfiguration public $service; + public array $pdf_variables; + public function __construct(PdfService $service) { @@ -59,12 +62,33 @@ class PdfConfiguration $this->setEntityType() ->setEntityProperties() + ->setPdfVariables() ->setDesign(); return $this; } + private function setPdfVariables() :self + { + + $default = (array) CompanySettings::getEntityVariableDefaults(); + $variables = $this->service->company->pdf_variables; + + foreach ($default as $property => $value) { + if (array_key_exists($property, $variables)) { + continue; + } + + $variables[$property] = $value; + } + + $this->pdf_variables = $variables; + + return $this; + + } + private function setEntityType() { diff --git a/app/Services/Pdf/PdfService.php b/app/Services/Pdf/PdfService.php index 043adcf85a9a..7264100242fe 100644 --- a/app/Services/Pdf/PdfService.php +++ b/app/Services/Pdf/PdfService.php @@ -19,6 +19,8 @@ class PdfService public $invitation; + public Company $company; + public PdfConfiguration $config; public PdfBuilder $builder; @@ -32,6 +34,8 @@ class PdfService $this->invitation = $invitation; + $this->company = $invitation->company; + $this->config = (new PdfConfiguration($this))->init(); $this->html_variables = (new HtmlEngine($invitation))->generateLabelsAndValues();