diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 33d6f7cd605c..fc251b272fd2 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -26,12 +26,15 @@ class Plain extends BaseDesign /** @var App\Models\Client */ public $client; - /** @var App\Models\Invoice */ - public $invoice; + /** @var App\Models\Invoice || @var App\Models\Quote */ + public $entity; - /** Global state of the design, @var string */ + /** Global state of the design, @var array */ public $context; + /** Type of entity => invoice||quote */ + public $type; + public function html(): ?string { return file_get_contents( @@ -39,9 +42,11 @@ class Plain extends BaseDesign ); } - public function elements(array $context): array + public function elements(array $context, string $type = 'invoice'): array { $this->context = $context; + $this->type = $type; + $this->setup(); return [ @@ -66,7 +71,7 @@ class Plain extends BaseDesign public function companyAddress(): array { - $variables = $this->invoice->company->settings->pdf_variables->company_address; + $variables = $this->entity->company->settings->pdf_variables->company_address; $elements = []; @@ -79,7 +84,7 @@ class Plain extends BaseDesign public function entityDetails(): array { - $variables = $this->invoice->company->settings->pdf_variables->invoice_details; + $variables = $this->entity->company->settings->pdf_variables->invoice_details; $elements = []; @@ -95,7 +100,7 @@ class Plain extends BaseDesign public function clientDetails(): array { - $variables = $this->invoice->company->settings->pdf_variables->client_details; + $variables = $this->entity->company->settings->pdf_variables->client_details; $elements = []; @@ -146,7 +151,7 @@ class Plain extends BaseDesign { $elements = []; - $items = $this->transformLineItems($this->invoice->line_items); + $items = $this->transformLineItems($this->entity->line_items); if (count($items) == 0) { return []; diff --git a/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php b/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php index 36e36b474640..9a01ee42da63 100644 --- a/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php +++ b/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php @@ -20,8 +20,8 @@ class BaseDesign $this->client = $this->context['client']; } - if (isset($this->context['invoice'])) { - $this->invoice = $this->context['invoice']; + if (isset($this->context['entity'])) { + $this->entity = $this->context['entity']; } } } diff --git a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php b/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php index 5459242cb570..41529dc16b75 100644 --- a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php +++ b/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php @@ -26,7 +26,7 @@ trait BuildTableHeader public function processTaxColumns(): void { if (in_array('$product.tax', $this->context['product-table-columns'])) { - $line_items = collect($this->invoice->line_items); + $line_items = collect($this->entity->line_items); $tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count(); $tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', 1)->count(); diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 7e3b6d468879..92d6efdb04bc 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -30,13 +30,13 @@ class ExampleIntegrationTest extends TestCase $state = [ 'template' => $design->elements([ 'client' => $invoice->client, - 'invoice' => $invoice, + 'entity' => $invoice, 'product-table-columns' => $product_table_columns, ]), 'variables' => $engine->generateLabelsAndValues(), ]; - $maker = new PdfMaker($state); + $maker = new PdfMaker($state, 'invoice'); $maker ->design(Plain::class)