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:
parent
745bca2889
commit
2e3179d83e
@ -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);
|
||||
|
||||
|
@ -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 = [];
|
||||
|
||||
|
36
tests/Feature/PdfMaker/ExampleIntegrationTest.php
Normal file
36
tests/Feature/PdfMaker/ExampleIntegrationTest.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user