From ad2ff79336652d3c104c3ffbdd14194dcda27b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 4 Aug 2020 17:32:28 +0200 Subject: [PATCH] Complete Plain.php --- app/Services/PdfMaker/Designs/Plain.php | 94 ++++++++++++++----- resources/views/pdf-designs/plain.html | 4 +- .../PdfMaker/ExampleIntegrationTest.php | 9 +- 3 files changed, 80 insertions(+), 27 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 4d947f8d0aa2..b300ee058e85 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -58,37 +58,85 @@ class Plain implements DesignInterface return [ 'company-address' => [ 'id' => 'company-address', - 'elements' => [ - ['element' => 'p', 'content' => '$company.address1'], - ], + 'elements' => $this->companyAddress(), + ], + 'entity-details' => [ + 'id' => 'entity-details', + 'elements' => $this->entityDetails(), + ], + 'client-details' => [ + 'id' => 'client-details', + 'elements' => $this->clientDetails(), + ], + 'product-table' => [ + 'id' => 'product-table', + 'elements' => $this->productTable(), ], - $this->productTable(), ]; } + public function companyAddress(): array + { + $variables = $this->invoice->company->settings->pdf_variables->company_address; + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'p', 'content' => $variable]; + } + + return $elements; + } + + public function entityDetails(): array + { + $variables = $this->invoice->company->settings->pdf_variables->invoice_details; + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], + ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-medium']], + ]]; + } + + return $elements; + } + + public function clientDetails(): array + { + $variables = $this->invoice->company->settings->pdf_variables->client_details; + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'p', 'content' => $variable]; + } + + return $elements; + } + public function productTable(): array { return [ - 'id' => 'product-table', - 'elements' => [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], - ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-300'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], + ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->buildTableHeader()], + ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], + ['element' => 'tfoot', 'content' => '', 'elements' => [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => '4']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-300'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ]], ]; } diff --git a/resources/views/pdf-designs/plain.html b/resources/views/pdf-designs/plain.html index b2951b016cdf..2e9f38b0c30e 100644 --- a/resources/views/pdf-designs/plain.html +++ b/resources/views/pdf-designs/plain.html @@ -28,13 +28,13 @@
-
+
-
+
diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index a79d05317106..7e3b6d468879 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -23,7 +23,8 @@ class ExampleIntegrationTest extends TestCase $design = new Plain(); $product_table_columns = json_decode( - json_encode($invoice->company->settings->pdf_variables), 1 + json_encode($invoice->company->settings->pdf_variables), + 1 )['product_columns']; $state = [ @@ -41,6 +42,10 @@ class ExampleIntegrationTest extends TestCase ->design(Plain::class) ->build(); - info($maker->getCompiledHTML()); + exec('echo "" > storage/logs/laravel.log'); + + info($maker->getCompiledHTML(true)); + + $this->assertTrue(true); } }