1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Extract variables from the HtmlEngine

This commit is contained in:
Benjamin Beganović 2020-07-29 13:37:05 +02:00
parent 745bca2889
commit 2e3179d83e
3 changed files with 40 additions and 7 deletions

View File

@ -116,7 +116,8 @@ trait PdfMakerUtilities
public function updateVariables(array $variables)
{
$html = strtr($this->getCompiledHTML(), $variables);
$html = strtr($this->getCompiledHTML(), $variables['labels']);
$html = strtr($this->getCompiledHTML(), $variables['values']);
$this->document->loadHTML($html);

View File

@ -29,18 +29,14 @@ class HtmlEngine
public $company;
public $designer;
public $settings;
public $entity_calc;
public $entity_string;
public function __construct(Designer $designer, $invitation, $entity_string)
public function __construct($invitation, $entity_string)
{
$this->designer = $designer;
$this->invitation = $invitation;
$this->entity = $invitation->{$entity_string};
@ -347,7 +343,7 @@ class HtmlEngine
return $data;
}
private function generateLabelsAndValues()
public function generateLabelsAndValues()
{
$data = [];

View File

@ -0,0 +1,36 @@
<?php
namespace Tests\Feature\PdfMaker;
use App\Models\Invoice;
use App\Services\PdfMaker\Designs\Plain;
use App\Services\PdfMaker\PdfMaker;
use App\Utils\HtmlEngine;
use Tests\TestCase;
class ExampleIntegrationTest extends TestCase
{
public function testExample()
{
$invoice = Invoice::first();
$invitation = $invoice->invitations()->first();
$engine = new HtmlEngine($invitation, 'invoice');
$state = [
'template' => [
],
'variables' => $engine->generateLabelsAndValues(),
];
$maker = new PdfMaker($state);
$maker
->design(Plain::class)
->build();
info($state);
info($maker->getCompiledHTML());
}
}