From b438309736010535f45d78d882b3aa16b29cf6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 13:55:02 +0200 Subject: [PATCH 01/36] Playful: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Playful.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 5 +- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 1e1db7661ff1..e9bb71bc0eaf 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -133,21 +133,7 @@ class Playful extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-teal-600'], '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 text-right', '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'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold text-teal-600', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Playful extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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'], 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold text-teal-600', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 2b10162b73ae..5a7817ec387b 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -15,13 +15,10 @@ class ExampleIntegrationTest extends TestCase public function testExample() { - $this->markTestSkipped('WIP'); - - $invoice = Invoice::first(); $invitation = $invoice->invitations()->first(); - $engine = new HtmlEngine($invitation, 'invoice'); + $engine = new HtmlEngine(null, $invitation, 'invoice'); $design = new Playful(); $product_table_columns = json_decode( From da74ecba6e4b5ad49297d92ee8da759b88e379ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:00:23 +0200 Subject: [PATCH 02/36] Bold: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Bold.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index e35bc8281e2d..26297f6f9930 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -133,21 +133,7 @@ class Bold extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], '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 text-right', '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'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-teal-600 font-semibold', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Bold extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-teal-600 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 5a7817ec387b..943a9833e8b0 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Playful; +use App\Services\PdfMaker\Designs\Bold; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Playful(); + $design = new Bold(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Playful::class) + ->design(Bold::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 0597b01847219056f212b4fcbc7900feb58cff81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:03:25 +0200 Subject: [PATCH 03/36] Business: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Business.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index 65470bbdff7d..606ec9e97e65 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -133,21 +133,7 @@ class Business extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], '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 text-right', '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'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-blue-900 font-semibold', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-blue-900 font-semibold']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Business extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-blue-900 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-blue-900 font-semibold']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 943a9833e8b0..8171603cf99c 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Bold; +use App\Services\PdfMaker\Designs\Business; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Bold(); + $design = new Business(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Bold::class) + ->design(Business::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 9ee8a1658e3bc108b1f2fbfbb46b40bc08722014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:05:40 +0200 Subject: [PATCH 04/36] Clean: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Clean.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 64c1b61e1e5b..e03a40f4ee66 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -133,21 +133,7 @@ class Clean extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], '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 text-right', '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'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Clean extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 8171603cf99c..63204b38fdc6 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Business; +use App\Services\PdfMaker\Designs\Clean; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Business(); + $design = new Clean(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Business::class) + ->design(Clean::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 6cdcf0d914fcb194db500ba1906b242b1369ecd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:17:55 +0200 Subject: [PATCH 05/36] Creative: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Creative.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index c62ff86d79d0..725f78126bea 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -133,21 +133,7 @@ class Creative extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left'], '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 text-right', '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 border-t-4 border-pink-700'], '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 font-semibold text-pink-700']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Creative extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 border-t-4 border-pink-700'], '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 font-semibold text-pink-700']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 63204b38fdc6..ec4c6dbe2aed 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Clean; +use App\Services\PdfMaker\Designs\Creative; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Clean(); + $design = new Creative(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Clean::class) + ->design(Creative::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From fe1cef3d62b2dcc01cd3cfa0d7cbcb000958cd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:22:18 +0200 Subject: [PATCH 06/36] Elegant: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Elegant.php | 53 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index dcc8dbfe0be2..7ea5848cf76f 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -134,21 +134,7 @@ class Elegant extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left border-dashed border-b border-black'], '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 text-right', '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'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'px-4 text-right text-xl text-green-600 font-semibold', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-green-600']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -176,7 +162,7 @@ class Elegant extends BaseDesign } foreach ($items as $row) { - $element = ['element' => 'tr', 'properties' => ['class' => 'border-dashed border-b border-black'] ,'content' => '', 'elements' => []]; + $element = ['element' => 'tr', 'properties' => ['class' => 'border-dashed border-b border-black'], 'content' => '', 'elements' => []]; foreach ($this->context['product-table-columns'] as $key => $cell) { $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-3']]; @@ -187,4 +173,39 @@ class Elegant extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'px-4 text-right text-xl text-green-600 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-green-600']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index ec4c6dbe2aed..1bea8f1d2d1d 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Creative; +use App\Services\PdfMaker\Designs\Elegant; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Creative(); + $design = new Elegant(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Creative::class) + ->design(Elegant::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 80b6512df462eb7bbc1ee1b8d88839c9e1a01701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:25:43 +0200 Subject: [PATCH 07/36] Hipster: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Hipster.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index d459a8b15c16..3a8e76c9fc85 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -133,21 +133,7 @@ class Hipster extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left'], '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' => 'px-4 py-4 text-rightt', 'colspan' => '4']], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'border-l-2 border-black 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' => 'border-l-2 border-black px-4 py-2 text-right']], - ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], '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' => 'border-l-2 border-black px-4 py-2 text-right']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -186,4 +172,35 @@ class Hipster extends BaseDesign return $elements; } + + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'px-4 py-4 text-rightt', 'colspan' => '4']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'border-l-2 border-black 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' => 'border-l-2 border-black px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], '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' => 'border-l-2 border-black px-4 py-2 text-right']], + ]], + ]; + } } diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 1bea8f1d2d1d..24f995d35084 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Elegant; +use App\Services\PdfMaker\Designs\Hipster; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Elegant(); + $design = new Hipster(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Elegant::class) + ->design(Hipster::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 00fcb1dd327f380acf2c7f511a9212f904ea1aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:28:36 +0200 Subject: [PATCH 08/36] Modern: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Modern.php | 47 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index c08c284c7f2b..2741fb118058 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -107,21 +107,7 @@ class Modern extends BaseDesign return [ ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left text-white bg-gray-900'], '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 text-right', '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-900 text-white text-xl'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], - ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], ]; } @@ -161,6 +147,37 @@ class Modern extends BaseDesign return $elements; } + public function tableFooter() + { + return [ + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', '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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-900 text-white text-xl'], 'elements' => [ + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ]; + } + public function companyDetails() { $variables = $this->entity->company->settings->pdf_variables->company_details; diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 24f995d35084..a335b6dc75fd 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Hipster; +use App\Services\PdfMaker\Designs\Modern; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Hipster(); + $design = new Modern(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Hipster::class) + ->design(Modern::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 007ec3a85a9e57f8d0247a1c6a841f30f2cdc725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 14:30:56 +0200 Subject: [PATCH 09/36] Plain: - Extract table footer into tableFooter() - Add all footer elements --- app/Services/PdfMaker/Designs/Plain.php | 45 +++++++++++++------ .../PdfMaker/ExampleIntegrationTest.php | 6 +-- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index fc251b272fd2..3b069708b067 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -116,20 +116,37 @@ class Plain extends BaseDesign return [ ['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']], - ]], + ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], + ]; + } + + public function tableFooter() + { + return [ + ['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' => '', 'elements' => [ + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], + ]], + ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total', '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/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index a335b6dc75fd..72f3ee9f0d01 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Modern; +use App\Services\PdfMaker\Designs\Plain; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Modern(); + $design = new Plain(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -38,7 +38,7 @@ class ExampleIntegrationTest extends TestCase $maker = new PdfMaker($state, 'invoice'); $maker - ->design(Modern::class) + ->design(Plain::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 7870985aa82011d140a81c8df20d2d80ee5d7554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 15:58:05 +0200 Subject: [PATCH 10/36] Logic for calculating remaning spaces for colspans --- .../Designs/Utilities/BuildTableHeader.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php b/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php index 41529dc16b75..86f6f5c5ff10 100644 --- a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php +++ b/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php @@ -10,7 +10,7 @@ * @license https://opensource.org/licenses/AAL */ - namespace App\Services\PdfMaker\Designs\Utilities; +namespace App\Services\PdfMaker\Designs\Utilities; trait BuildTableHeader { @@ -52,4 +52,17 @@ trait BuildTableHeader } } } + + /** + * Calculates the remaining colspans. + * + * @param int $taken + * @return int + */ + public function calculateColspan(int $taken): int + { + $total = (int) count($this->context['product-table-columns']); + + return (int)$total - $taken; + } } From a531019e3e9973fd3aea9151af3fa230722179d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 16:02:37 +0200 Subject: [PATCH 11/36] Update remaining colspans on design files --- app/Services/PdfMaker/Designs/Bold.php | 12 ++++++------ app/Services/PdfMaker/Designs/Business.php | 12 ++++++------ app/Services/PdfMaker/Designs/Clean.php | 12 ++++++------ app/Services/PdfMaker/Designs/Creative.php | 12 ++++++------ app/Services/PdfMaker/Designs/Elegant.php | 14 +++++++------- app/Services/PdfMaker/Designs/Hipster.php | 12 ++++++------ app/Services/PdfMaker/Designs/Modern.php | 12 ++++++------ app/Services/PdfMaker/Designs/Plain.php | 12 ++++++------ app/Services/PdfMaker/Designs/Playful.php | 12 ++++++------ 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index 26297f6f9930..5d401ccfbda5 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -177,28 +177,28 @@ class Bold extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-teal-600 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-teal-600 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index 606ec9e97e65..2ad7ef32986b 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -177,28 +177,28 @@ class Business extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-blue-900 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-blue-900 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-blue-900 font-semibold']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index e03a40f4ee66..3b79c971d825 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -177,28 +177,28 @@ class Clean extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 725f78126bea..8fae8e662cb9 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -177,28 +177,28 @@ class Creative extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 border-t-4 border-pink-700'], '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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right font-semibold text-pink-700']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 7ea5848cf76f..46b1ddcc7f53 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -178,32 +178,32 @@ class Elegant extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'px-4 text-right text-xl text-green-600 font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'px-4 text-right text-xl text-green-600 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-green-600']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 3a8e76c9fc85..a1032ded3ed3 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -177,28 +177,28 @@ class Hipster extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'px-4 py-4 text-rightt', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'px-4 py-4 text-rightt', 'colspan' => $this->calculateColspan(3)]], ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'border-l-2 border-black 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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], '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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 2741fb118058..f091ed00628a 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -151,28 +151,28 @@ class Modern extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-900 text-white text-xl'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 3b069708b067..ff0d90658c56 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -124,28 +124,28 @@ class Plain extends BaseDesign { return [ ['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' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', '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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]; diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index e9bb71bc0eaf..35bc1cf729b5 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -177,28 +177,28 @@ class Playful extends BaseDesign { return [ ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], ['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_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '6']], + ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold text-teal-600', 'colspan' => '6']], + ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold text-teal-600', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]; From 8381d37431a30315b7ef9e088255f89ec4e7821a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 16:11:10 +0200 Subject: [PATCH 12/36] Update entity type: - Default entity type is 'product' - Added type check - Fixed double slash in design path --- app/Services/PdfMaker/Designs/Bold.php | 11 ++++++++--- app/Services/PdfMaker/Designs/Business.php | 11 ++++++++--- app/Services/PdfMaker/Designs/Clean.php | 9 +++++++-- app/Services/PdfMaker/Designs/Creative.php | 11 ++++++++--- app/Services/PdfMaker/Designs/Elegant.php | 9 +++++++-- app/Services/PdfMaker/Designs/Hipster.php | 9 +++++++-- app/Services/PdfMaker/Designs/Modern.php | 9 +++++++-- app/Services/PdfMaker/Designs/Plain.php | 9 +++++++-- app/Services/PdfMaker/Designs/Playful.php | 9 +++++++-- tests/Feature/PdfMaker/ExampleIntegrationTest.php | 2 +- 10 files changed, 67 insertions(+), 22 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index 5d401ccfbda5..5abe49dae4bc 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -32,21 +32,26 @@ class Bold extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() { return file_get_contents( - base_path('resources/views/pdf-designs//bold.html') + base_path('resources/views/pdf-designs/bold.html') ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index 2ad7ef32986b..a5adbc706c93 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -32,21 +32,26 @@ class Business extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() { return file_get_contents( - base_path('resources/views/pdf-designs//business.html') + base_path('resources/views/pdf-designs/business.html') ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 3b79c971d825..5949d432dac7 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -32,7 +32,7 @@ class Clean extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() @@ -42,11 +42,16 @@ class Clean extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 8fae8e662cb9..8b78e365276d 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -32,21 +32,26 @@ class Creative extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() { return file_get_contents( - base_path('resources/views/pdf-designs//creative.html') + base_path('resources/views/pdf-designs/creative.html') ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 46b1ddcc7f53..752d7f1cdc3a 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -32,7 +32,7 @@ class Elegant extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() @@ -42,11 +42,16 @@ class Elegant extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index a1032ded3ed3..4f08da9de847 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -32,7 +32,7 @@ class Hipster extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() @@ -42,11 +42,16 @@ class Hipster extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index f091ed00628a..a6297e46054d 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -32,7 +32,7 @@ class Modern extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() @@ -42,11 +42,16 @@ class Modern extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index ff0d90658c56..cd7de4f96a0c 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -32,7 +32,7 @@ class Plain extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html(): ?string @@ -42,11 +42,16 @@ class Plain extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 35bc1cf729b5..a3c512b3d8bf 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -32,7 +32,7 @@ class Playful extends BaseDesign /** Global state of the design, @var array */ public $context; - /** Type of entity => invoice||quote */ + /** Type of entity => product||task */ public $type; public function html() @@ -42,11 +42,16 @@ class Playful extends BaseDesign ); } - public function elements(array $context, string $type = 'invoice'): array + public function elements(array $context, string $type = 'product'): array { $this->context = $context; + $this->type = $type; + if ($type !== 'product' || $type !== 'task') { + throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); + } + $this->setup(); return [ diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 72f3ee9f0d01..f2f032d480ec 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -35,7 +35,7 @@ class ExampleIntegrationTest extends TestCase 'variables' => $engine->generateLabelsAndValues(), ]; - $maker = new PdfMaker($state, 'invoice'); + $maker = new PdfMaker($state, 'product'); $maker ->design(Plain::class) From f7408e1fb3f71a6226db534964dcd15c05e554bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 17:47:17 +0200 Subject: [PATCH 13/36] Added new labels & update designs --- app/Services/PdfMaker/Designs/Bold.php | 6 +----- app/Services/PdfMaker/Designs/Business.php | 4 ---- app/Services/PdfMaker/Designs/Clean.php | 4 ---- app/Services/PdfMaker/Designs/Creative.php | 4 ---- app/Services/PdfMaker/Designs/Elegant.php | 4 ---- app/Services/PdfMaker/Designs/Hipster.php | 4 ---- app/Services/PdfMaker/Designs/Modern.php | 4 ---- app/Services/PdfMaker/Designs/Plain.php | 4 ---- app/Services/PdfMaker/Designs/Playful.php | 4 ---- app/Utils/HtmlEngine.php | 13 +++++++++---- resources/views/pdf-designs/bold.html | 2 +- resources/views/pdf-designs/business.html | 2 +- resources/views/pdf-designs/clean.html | 2 +- resources/views/pdf-designs/creative.html | 4 ++-- resources/views/pdf-designs/elegant.html | 2 +- resources/views/pdf-designs/hipster.html | 6 +++--- resources/views/pdf-designs/playful.html | 4 ++-- tests/Feature/PdfMaker/ExampleIntegrationTest.php | 8 ++++---- 18 files changed, 25 insertions(+), 56 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index 5abe49dae4bc..ef3fd00106ad 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -48,10 +48,6 @@ class Bold extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ @@ -148,7 +144,7 @@ class Bold extends BaseDesign $elements = []; - foreach ($this->context['product-table-columns'] as $column) { + foreach ($this->context["{$this->type}-table-columns"] as $column) { $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'text-xl px-4 py-2']]; } diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index a5adbc706c93..7da3d7a68b52 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -48,10 +48,6 @@ class Business extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 5949d432dac7..bf9dfaf5ec36 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -48,10 +48,6 @@ class Clean extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 8b78e365276d..5eb27d9b46f1 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -48,10 +48,6 @@ class Creative extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 752d7f1cdc3a..d1ea33c8167d 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -48,10 +48,6 @@ class Elegant extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 4f08da9de847..2839dd3783a7 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -48,10 +48,6 @@ class Hipster extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index a6297e46054d..1caf7ef398ef 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -48,10 +48,6 @@ class Modern extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index cd7de4f96a0c..8d05119ade37 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -48,10 +48,6 @@ class Plain extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index a3c512b3d8bf..72dcf0840167 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -48,10 +48,6 @@ class Playful extends BaseDesign $this->type = $type; - if ($type !== 'product' || $type !== 'task') { - throw new \Exception("Type '{$type}' is not allowed. Allowed values are 'product' or 'task'."); - } - $this->setup(); return [ diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index ff05c519beb3..c37d944c5d81 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -96,6 +96,7 @@ class HtmlEngine $data = []; $data['$global-margin'] = ['value' => 'm-12', 'label' => '']; + $data['$global-padding'] = ['value' => 'p-12', 'label' => '']; $data['$tax'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$app_url'] = ['value' => $this->generateAppUrl(), 'label' => '']; $data['$from'] = ['value' => '', 'label' => ctrans('texts.from')]; @@ -175,11 +176,11 @@ class HtmlEngine $data['$invoice.custom4'] = ['value' => $this->entity->custom_value4 ?: ' ', 'label' => $this->makeCustomField('invoice4')]; $data['$invoice.public_notes'] = ['value' => $this->entity->public_notes ?: ' ', 'label' => ctrans('texts.public_notes')]; $data['$entity.public_notes'] = &$data['$invoice.public_notes']; + + $data['$entity_issued_to'] = ['value' => '', 'label' => ctrans("texts.{$this->entity_string}_issued_to")]; - // $data['$your_invoice'] = ; - // $data['$quote'] = ; - // $data['$your_quote'] = ; - // + $data['$your_' . $this->entity_string] = ['value' => '', 'label' => ctrans("texts.your_{$this->entity_string}")]; + $data['$quote.date'] = ['value' => $this->entity->date ?: ' ', 'label' => ctrans('texts.quote_date')]; $data['$quote.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.quote_number')]; $data['$quote.po_number'] = &$data['$invoice.po_number']; @@ -297,6 +298,10 @@ class HtmlEngine $data['$task.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$contact.signature'] = ['value' => $this->invitation->signature_base64, 'label' => ctrans('texts.signature')]; + $data['$thanks'] = ['value' => '', 'label' => ctrans('texts.thanks')]; + $data['$from'] = ['value' => '', 'label' => ctrans('texts.from')]; + $data['$to'] = ['value' => '', 'label' => ctrans('texts.to')]; + // $data['custom_label1'] = ['value' => '', 'label' => ctrans('texts.')]; // $data['custom_label2'] = ['value' => '', 'label' => ctrans('texts.')]; // $data['custom_label3'] = ['value' => '', 'label' => ctrans('texts.')]; diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index f8ae4539a63e..025589e20ade 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -44,7 +44,7 @@

- $your-invoice + $your_entity_label

diff --git a/resources/views/pdf-designs/business.html b/resources/views/pdf-designs/business.html index 956e98e2bad9..768fcc56e625 100644 --- a/resources/views/pdf-designs/business.html +++ b/resources/views/pdf-designs/business.html @@ -52,7 +52,7 @@
-

$invoice-issued-to

+

$entity_issued_to_label

diff --git a/resources/views/pdf-designs/clean.html b/resources/views/pdf-designs/clean.html index 84b636873b8d..77b3847c70e2 100644 --- a/resources/views/pdf-designs/clean.html +++ b/resources/views/pdf-designs/clean.html @@ -34,7 +34,7 @@
-

$entity

+

$entity_label

diff --git a/resources/views/pdf-designs/creative.html b/resources/views/pdf-designs/creative.html index f9b247a992d1..cf29f49f8c1b 100644 --- a/resources/views/pdf-designs/creative.html +++ b/resources/views/pdf-designs/creative.html @@ -49,8 +49,8 @@
- $entity - #$entity-number + $entity_label + #$entity_number
diff --git a/resources/views/pdf-designs/elegant.html b/resources/views/pdf-designs/elegant.html index 120e9891d5a4..ad8e72c47bba 100644 --- a/resources/views/pdf-designs/elegant.html +++ b/resources/views/pdf-designs/elegant.html @@ -42,7 +42,7 @@
-

$thanks

+

$thanks_label

diff --git a/resources/views/pdf-designs/hipster.html b/resources/views/pdf-designs/hipster.html index f9e7b2b89f0f..b9db88c8619f 100644 --- a/resources/views/pdf-designs/hipster.html +++ b/resources/views/pdf-designs/hipster.html @@ -17,7 +17,7 @@

- $from: + $from_label:

@@ -26,7 +26,7 @@ class="col-span-5 pl-4 border-l border-black" id="client-details" > -

$to:

+

$to_label:

- $entity + $entity_label

-

$to:

+

$to_label:

@@ -48,7 +48,7 @@
-

$from:

+

$from_label:

diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index f2f032d480ec..98a2ca6148f8 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\PdfMaker; use App\Models\Invoice; -use App\Services\PdfMaker\Designs\Plain; +use App\Services\PdfMaker\Designs\Playful; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; @@ -19,7 +19,7 @@ class ExampleIntegrationTest extends TestCase $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); - $design = new Plain(); + $design = new Playful(); $product_table_columns = json_decode( json_encode($invoice->company->settings->pdf_variables), @@ -35,10 +35,10 @@ class ExampleIntegrationTest extends TestCase 'variables' => $engine->generateLabelsAndValues(), ]; - $maker = new PdfMaker($state, 'product'); + $maker = new PdfMaker($state); $maker - ->design(Plain::class) + ->design(Playful::class) ->build(); exec('echo "" > storage/logs/laravel.log'); From 085d08bbcb82c9fcf22eb8743bb541101c41f3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 7 Aug 2020 18:30:04 +0200 Subject: [PATCH 14/36] (wip) Conditionally display tfoot items --- app/Services/PdfMaker/Designs/Bold.php | 4 ++-- app/Services/PdfMaker/Designs/Business.php | 4 ++-- app/Services/PdfMaker/Designs/Clean.php | 4 ++-- app/Services/PdfMaker/Designs/Creative.php | 4 ++-- app/Services/PdfMaker/Designs/Elegant.php | 4 ++-- app/Services/PdfMaker/Designs/Hipster.php | 4 ++-- app/Services/PdfMaker/Designs/Modern.php | 4 ++-- app/Services/PdfMaker/Designs/Plain.php | 4 ++-- app/Services/PdfMaker/Designs/Playful.php | 14 ++++++------ ...{BuildTableHeader.php => TableHelpers.php} | 22 ++++++++++++++++++- 10 files changed, 44 insertions(+), 24 deletions(-) rename app/Services/PdfMaker/Designs/Utilities/{BuildTableHeader.php => TableHelpers.php} (80%) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index ef3fd00106ad..1cdf2705707c 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Bold extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index 7da3d7a68b52..b841e7cb6e02 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Business extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index bf9dfaf5ec36..72bded182459 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Clean extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 5eb27d9b46f1..80d34b37533e 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Creative extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index d1ea33c8167d..df39cc3543eb 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Elegant extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 2839dd3783a7..072e8ec8d93c 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Hipster extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 1caf7ef398ef..16cf056ae2b5 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Modern extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 8d05119ade37..6876ef9c0b6f 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Plain extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 72dcf0840167..a9ded2365031 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\BuildTableHeader; +use App\Services\PdfMaker\Designs\Utilities\TableHelpers; use App\Utils\Traits\MakesInvoiceValues; class Playful extends BaseDesign { - use MakesInvoiceValues, BuildTableHeader; + use MakesInvoiceValues, TableHelpers; /** Global list of table elements, @var array */ public $elements; @@ -179,14 +179,14 @@ class Playful extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], @@ -198,7 +198,7 @@ class Playful extends BaseDesign ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold text-teal-600', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php b/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php similarity index 80% rename from app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php rename to app/Services/PdfMaker/Designs/Utilities/TableHelpers.php index 86f6f5c5ff10..e3b39b72680f 100644 --- a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php +++ b/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php @@ -12,7 +12,7 @@ namespace App\Services\PdfMaker\Designs\Utilities; -trait BuildTableHeader +trait TableHelpers { /** * This method will help us decide either we show @@ -65,4 +65,24 @@ trait BuildTableHeader return (int)$total - $taken; } + + /** + * Return "true" or "false" based on null or empty check. + * We need to return false as string because of HTML parsing. + * + * @param string $property + * @return string + */ + public function toggleHiddenProperty(string $property): string + { + if (is_null($property)) { + return 'false'; + } + + if (empty($property)) { + return 'false'; + } + + return 'true'; + } } From 84e618d1b6d5131faadc5f9928c981072e269fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 12:57:53 +0200 Subject: [PATCH 15/36] Remove string requirement from toggleHiddenProperty --- app/Services/PdfMaker/Designs/Utilities/TableHelpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php b/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php index e3b39b72680f..38f2cb63a2fc 100644 --- a/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php @@ -70,10 +70,10 @@ trait TableHelpers * Return "true" or "false" based on null or empty check. * We need to return false as string because of HTML parsing. * - * @param string $property + * @param mixed $property * @return string */ - public function toggleHiddenProperty(string $property): string + public function toggleHiddenProperty($property): string { if (is_null($property)) { return 'false'; From 2f408045689950a4a0d40bacdac328b92e650218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 13:18:05 +0200 Subject: [PATCH 16/36] Update designs so they reference Invoice or Quote --- app/Utils/HtmlEngine.php | 11 +++++------ resources/views/pdf-designs/clean.html | 2 +- resources/views/pdf-designs/elegant.html | 3 +++ resources/views/pdf-designs/modern.html | 5 +++++ resources/views/pdf-designs/plain.html | 5 +++++ resources/views/pdf-designs/playful.html | 7 ++++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index c37d944c5d81..f8b2fd4b7c13 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -118,7 +118,7 @@ class HtmlEngine $data['$invoice.total_taxes'] = &$data['$total_taxes']; if ($this->entity_string == 'invoice') { - $data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.invoice')]; + $data['$entity'] = ['value' => '', 'label' => ctrans('texts.invoice')]; $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.invoice_terms')]; $data['$terms'] = &$data['$entity.terms']; @@ -126,7 +126,7 @@ class HtmlEngine } if ($this->entity_string == 'quote') { - $data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.quote')]; + $data['$entity'] = ['value' => '', 'label' => ctrans('texts.quote')]; $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.quote_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.quote_terms')]; $data['$terms'] = &$data['$entity.terms']; @@ -134,7 +134,7 @@ class HtmlEngine } if ($this->entity_string == 'credit') { - $data['$entity_label'] = ['value' => '', 'label' => ctrans('texts.credit')]; + $data['$entity'] = ['value' => '', 'label' => ctrans('texts.credit')]; $data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.credit_number')]; $data['$entity.terms'] = ['value' => $this->entity->terms ?: ' ', 'label' => ctrans('texts.credit_terms')]; $data['$terms'] = &$data['$entity.terms']; @@ -177,9 +177,8 @@ class HtmlEngine $data['$invoice.public_notes'] = ['value' => $this->entity->public_notes ?: ' ', 'label' => ctrans('texts.public_notes')]; $data['$entity.public_notes'] = &$data['$invoice.public_notes']; - $data['$entity_issued_to'] = ['value' => '', 'label' => ctrans("texts.{$this->entity_string}_issued_to")]; - - $data['$your_' . $this->entity_string] = ['value' => '', 'label' => ctrans("texts.your_{$this->entity_string}")]; + $data['$entity_issued_to'] = ['value' => '', 'label' => ctrans("texts.{$this->entity_string}_issued_to")]; + $data['$your_entity'] = ['value' => '', 'label' => ctrans("texts.your_{$this->entity_string}")]; $data['$quote.date'] = ['value' => $this->entity->date ?: ' ', 'label' => ctrans('texts.quote_date')]; $data['$quote.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.quote_number')]; diff --git a/resources/views/pdf-designs/clean.html b/resources/views/pdf-designs/clean.html index 77b3847c70e2..df44b4a7b642 100644 --- a/resources/views/pdf-designs/clean.html +++ b/resources/views/pdf-designs/clean.html @@ -34,7 +34,7 @@
-

$entity_label

+

$entity_label

diff --git a/resources/views/pdf-designs/elegant.html b/resources/views/pdf-designs/elegant.html index ad8e72c47bba..4bb0858a619f 100644 --- a/resources/views/pdf-designs/elegant.html +++ b/resources/views/pdf-designs/elegant.html @@ -24,6 +24,9 @@
+
+

$your_entity_label

+
diff --git a/resources/views/pdf-designs/modern.html b/resources/views/pdf-designs/modern.html index 4807d549b3ef..22ec9df4c304 100644 --- a/resources/views/pdf-designs/modern.html +++ b/resources/views/pdf-designs/modern.html @@ -30,6 +30,11 @@
+
+

+ $your_entity_label +

+
+
+

+ $your_entity_label +

+
diff --git a/resources/views/pdf-designs/playful.html b/resources/views/pdf-designs/playful.html index 692076442896..beeee6b5bba6 100644 --- a/resources/views/pdf-designs/playful.html +++ b/resources/views/pdf-designs/playful.html @@ -15,7 +15,7 @@ #product-table tbody > tr > td:first-child { color: #9b2c2c; } - + #product-table tbody > tr > td:last-child { color: #9b2c2c; font-weight: bold; @@ -39,6 +39,11 @@
+
+

+ $your_entity_label +

+

$to_label:

Date: Mon, 10 Aug 2020 16:43:25 +0200 Subject: [PATCH 17/36] Added rule for "hidden" field --- app/Services/PdfMaker/PdfMakerUtilities.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index a696f5012fb5..bf0c74c1fa20 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -67,7 +67,7 @@ trait PdfMakerUtilities { $processed = []; - foreach($children as $child) { + foreach ($children as $child) { if (!isset($child['order'])) { $child['order'] = 0; } @@ -84,6 +84,14 @@ trait PdfMakerUtilities public function updateElementProperty($element, string $attribute, string $value) { + // We have exception for "hidden" property. + // hidden="true" or hidden="false" will both hide the element, + // that's why we have to create an exception here for this rule. + + if ($attribute == 'hidden' && ($value == false || $value == "false")) { + return $element; + } + $element->setAttribute($attribute, $value); if ($element->getAttribute($attribute) === $value) { @@ -117,7 +125,7 @@ trait PdfMakerUtilities public function updateVariables(array $variables) { $html = strtr($this->getCompiledHTML(), $variables['labels']); - + $html = strtr($html, $variables['values']); $this->document->loadHTML($html); From d00bbc7a37057906c33da2f2c1a1d477a08e000a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 17:04:42 +0200 Subject: [PATCH 18/36] Alias $outstanding as $balance_due --- app/Utils/HtmlEngine.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index f8b2fd4b7c13..190d7286eff4 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -151,6 +151,7 @@ class HtmlEngine $data['$invoice.balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')]; $data['$quote.balance_due'] = &$data['$invoice.balance_due']; $data['$balance_due'] = &$data['$invoice.balance_due']; + $data['$outstanding'] = &$data['$balance_due']; $data['$invoice.partial_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')]; $data['$total'] = ['value' => Number::formatMoney($this->entity_calc->getTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.total')]; $data['$amount'] = &$data['$total']; From 3d477b2ed19c570ae9dadf29199acc88bc246273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 17:04:51 +0200 Subject: [PATCH 19/36] Conditionally show footer items --- app/Services/PdfMaker/Designs/Bold.php | 14 +++++--------- app/Services/PdfMaker/Designs/Business.php | 16 ++++++---------- app/Services/PdfMaker/Designs/Clean.php | 14 +++++--------- app/Services/PdfMaker/Designs/Creative.php | 14 +++++--------- app/Services/PdfMaker/Designs/Elegant.php | 20 ++++++-------------- app/Services/PdfMaker/Designs/Hipster.php | 16 ++++++---------- app/Services/PdfMaker/Designs/Modern.php | 16 ++++++---------- app/Services/PdfMaker/Designs/Plain.php | 16 ++++++---------- app/Services/PdfMaker/Designs/Playful.php | 4 ---- 9 files changed, 45 insertions(+), 85 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index 1cdf2705707c..a99e11dc0645 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -179,26 +179,22 @@ class Bold extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial)], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-teal-600 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index b841e7cb6e02..dab35a2e074e 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -45,7 +45,7 @@ class Business extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -179,26 +179,22 @@ class Business extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial)], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right text-xl text-blue-900 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-blue-900 font-semibold']], ]], diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 72bded182459..c4bf6f706eb4 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -179,26 +179,22 @@ class Clean extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 80d34b37533e..ae5125ffe22b 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -179,26 +179,22 @@ class Creative extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount()), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 border-t-4 border-pink-700'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2 border-t-4 border-pink-700'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right font-semibold text-pink-700']], ]], diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index df39cc3543eb..8a62c783aca4 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -45,7 +45,7 @@ class Elegant extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -180,30 +180,22 @@ class Elegant extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'px-4 text-right text-xl text-green-600 font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right text-green-600']], ]], diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 072e8ec8d93c..b5f6a4e48dbb 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -45,7 +45,7 @@ class Hipster extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -179,26 +179,22 @@ class Hipster extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'px-4 py-4 text-rightt', 'colspan' => $this->calculateColspan(3)]], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 16cf056ae2b5..8cf68045ab78 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -45,7 +45,7 @@ class Modern extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -153,26 +153,22 @@ class Modern extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->partial)], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-900 text-white text-xl'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), 'class' => 'mt-8 px-4 py-2 bg-gray-900 text-white text-xl'], 'elements' => [ ['element' => 'td', 'content' => '$balance_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right font-semibold', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 6876ef9c0b6f..292f395dec9a 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -45,7 +45,7 @@ class Plain extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -126,26 +126,22 @@ class Plain extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => $this->calculateColspan(3)]], - ['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' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ + ['element' => 'tr', ['hidden' => $this->toggleHiddenProperty($this->entity->partial)], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2 bg-gray-300'], 'elements' => [ + ['element' => 'tr', 'content' => '', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->balance), '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' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$balance_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index a9ded2365031..0ef7ccd09f15 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -190,10 +190,6 @@ class Playful extends BaseDesign ['element' => 'td', 'content' => '$partial_due_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$partial_due', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], - ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => '$outstanding_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => '$outstanding', 'properties' => ['class' => 'px-4 py-2 text-right']], - ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ ['element' => 'td', 'content' => '$invoice_total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], ['element' => 'td', 'content' => '$invoice_total', 'properties' => ['class' => 'px-4 py-2 text-right']], From 950d6d3693bb3e90ec576334aa79aa5989e70d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 17:07:30 +0200 Subject: [PATCH 20/36] Rename TableHelpers to DesignHelpers --- app/Services/PdfMaker/Designs/Bold.php | 4 ++-- app/Services/PdfMaker/Designs/Business.php | 4 ++-- app/Services/PdfMaker/Designs/Clean.php | 4 ++-- app/Services/PdfMaker/Designs/Creative.php | 4 ++-- app/Services/PdfMaker/Designs/Elegant.php | 4 ++-- app/Services/PdfMaker/Designs/Hipster.php | 4 ++-- app/Services/PdfMaker/Designs/Modern.php | 4 ++-- app/Services/PdfMaker/Designs/Plain.php | 4 ++-- app/Services/PdfMaker/Designs/Playful.php | 4 ++-- .../Designs/Utilities/{TableHelpers.php => DesignHelpers.php} | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) rename app/Services/PdfMaker/Designs/Utilities/{TableHelpers.php => DesignHelpers.php} (99%) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index a99e11dc0645..cebddd7d7ab2 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Bold extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index dab35a2e074e..05fcc461cc83 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Business extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index c4bf6f706eb4..267ce5e561ac 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Clean extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index ae5125ffe22b..eace96b28e86 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Creative extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 8a62c783aca4..37f9edddb221 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Elegant extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index b5f6a4e48dbb..7ccea85decfb 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Hipster extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 8cf68045ab78..7710f00bca28 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Modern extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 292f395dec9a..9755adfd6f9e 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Plain extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 0ef7ccd09f15..59bf78e29ace 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -13,12 +13,12 @@ namespace App\Services\PdfMaker\Designs; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; -use App\Services\PdfMaker\Designs\Utilities\TableHelpers; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Traits\MakesInvoiceValues; class Playful extends BaseDesign { - use MakesInvoiceValues, TableHelpers; + use MakesInvoiceValues, DesignHelpers; /** Global list of table elements, @var array */ public $elements; diff --git a/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php similarity index 99% rename from app/Services/PdfMaker/Designs/Utilities/TableHelpers.php rename to app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index 38f2cb63a2fc..c9694aae58cb 100644 --- a/app/Services/PdfMaker/Designs/Utilities/TableHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -12,7 +12,7 @@ namespace App\Services\PdfMaker\Designs\Utilities; -trait TableHelpers +trait DesignHelpers { /** * This method will help us decide either we show From 5eb2ad0e77639937d9b8e7317dfd9f46352225fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 17:21:56 +0200 Subject: [PATCH 21/36] Fixes for invoice/quote settings on company level --- app/DataMapper/CompanySettings.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 2ee72347d74b..5badc576afae 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -553,20 +553,20 @@ class CompanySettings extends BaseSettings '$company.country', ], 'invoice_details' => [ - '$invoice.invoice_number', + '$invoice.number', '$invoice.po_number', - '$invoice.invoice_date', + '$invoice.date', '$invoice.due_date', '$invoice.balance_due', - '$invoice.invoice_total', + '$invoice.total', ], 'quote_details' => [ - '$quote.quote_number', + '$quote.number', '$quote.po_number', - '$quote.quote_date', + '$quote.date', '$quote.valid_until', '$quote.balance_due', - '$quote.quote_total', + '$quote.total', ], 'credit_details' => [ '$credit.credit_number', From 347ec1d4412e0dce6b79f4e2579be25c74a3d786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 17:31:23 +0200 Subject: [PATCH 22/36] Check if $entity is App\Models\Quote to make sure right variables are passed --- app/Services/PdfMaker/Designs/Bold.php | 4 ++++ app/Services/PdfMaker/Designs/Business.php | 4 ++++ app/Services/PdfMaker/Designs/Clean.php | 4 ++++ app/Services/PdfMaker/Designs/Creative.php | 4 ++++ app/Services/PdfMaker/Designs/Elegant.php | 4 ++++ app/Services/PdfMaker/Designs/Hipster.php | 4 ++++ app/Services/PdfMaker/Designs/Modern.php | 4 ++++ app/Services/PdfMaker/Designs/Plain.php | 4 ++++ app/Services/PdfMaker/Designs/Playful.php | 4 ++++ 9 files changed, 36 insertions(+) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index cebddd7d7ab2..3e43f9b18966 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -117,6 +117,10 @@ class Bold extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index 05fcc461cc83..ed86575e7433 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -117,6 +117,10 @@ class Business extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 267ce5e561ac..047761cc1a67 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -104,6 +104,10 @@ class Clean extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index eace96b28e86..a4b2e38ea578 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -117,6 +117,10 @@ class Creative extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 37f9edddb221..c2a518bbfef6 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -78,6 +78,10 @@ class Elegant extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 7ccea85decfb..21c14d904bc0 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -117,6 +117,10 @@ class Hipster extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 7710f00bca28..96dfa8c83306 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -78,6 +78,10 @@ class Modern extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 9755adfd6f9e..0094b0b62e84 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -87,6 +87,10 @@ class Plain extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 59bf78e29ace..7b7372abdf67 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -78,6 +78,10 @@ class Playful extends BaseDesign { $variables = $this->entity->company->settings->pdf_variables->invoice_details; + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->entity->company->settings->pdf_variables->quote_details; + } + $elements = []; foreach ($variables as $variable) { From b5f2ae6d6be5a12ac33fe2ad5ca359d8aee15d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 18:06:12 +0200 Subject: [PATCH 23/36] Fixes for PdfMaker tests --- .../Feature/PdfMaker/PdfMakerDesignsTest.php | 41 ++++++++++--------- tests/Feature/PdfMaker/PdfMakerTest.php | 31 ++++++++++---- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/tests/Feature/PdfMaker/PdfMakerDesignsTest.php b/tests/Feature/PdfMaker/PdfMakerDesignsTest.php index 4858957741d4..d836a7ba3410 100644 --- a/tests/Feature/PdfMaker/PdfMakerDesignsTest.php +++ b/tests/Feature/PdfMaker/PdfMakerDesignsTest.php @@ -24,27 +24,30 @@ class PdfMakerDesignsTest extends TestCase $this->state = [ 'variables' => [ - '$css' => asset('css/tailwindcss@1.4.6.css'), - '$global-margin' => 'm-12', - '$global-padding' => 'p-12', + 'labels' => [], + 'values' => [ + '$css' => asset('css/tailwindcss@1.4.6.css'), + '$global-margin' => 'm-12', + '$global-padding' => 'p-12', - '$company-logo' => 'https://invoiceninja-invoice-templates.netlify.app/assets/images/invoiceninja-logo.png', - '$company-name' => 'Invoice Ninja', - '$entity-number-label' => 'Invoice number', - '$entity-number' => '10000', - '$entity-date-label' => 'Invoice date', - '$entity-date' => '3th of June, 2025.', - '$due-date-label' => 'Due date', - '$due-date' => '5th of June, 2025.', - '$balance-due-label' => 'Balance due', - '$balance-due' => '$800.50', + '$company-logo' => 'https://invoiceninja-invoice-templates.netlify.app/assets/images/invoiceninja-logo.png', + '$company-name' => 'Invoice Ninja', + '$entity-number-label' => 'Invoice number', + '$entity-number' => '10000', + '$entity-date-label' => 'Invoice date', + '$entity-date' => '3th of June, 2025.', + '$due-date-label' => 'Due date', + '$due-date' => '5th of June, 2025.', + '$balance-due-label' => 'Balance due', + '$balance-due' => '$800.50', - '$terms-label' => 'Terms', - '$terms' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.', + '$terms-label' => 'Terms', + '$terms' => 'Trend and SEO report has been sent via email. This is really long text just to test the width of the elements.', - '$invoice-issued-to' => 'Invoice issued to:', + '$invoice-issued-to' => 'Invoice issued to:', - '$entity' => 'Invoice', + '$entity' => 'Invoice', + ], ], ]; } @@ -707,7 +710,7 @@ class PdfMakerDesignsTest extends TestCase $this->assertTrue(true); } -public function testElegant() + public function testElegant() { $state = [ 'template' => [ @@ -799,7 +802,7 @@ public function testElegant() ['element' => 'td', 'content' => '$2.00', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [ - ['element' => 'td', 'content' => 'Balance due', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], + ['element' => 'td', 'content' => 'Balance due', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '4']], ['element' => 'td', 'content' => '$2.00', 'properties' => ['class' => 'px-4 py-2 text-right']], ]], ]], diff --git a/tests/Feature/PdfMaker/PdfMakerTest.php b/tests/Feature/PdfMaker/PdfMakerTest.php index f29f2eddd39d..73ad3c8aef17 100644 --- a/tests/Feature/PdfMaker/PdfMakerTest.php +++ b/tests/Feature/PdfMaker/PdfMakerTest.php @@ -10,7 +10,10 @@ class PdfMakerTest extends TestCase { public $state = [ 'template' => [], - 'variables' => [], + 'variables' => [ + 'labels' => [], + 'values' => [], + ], ]; public function testDesignLoadsCorrectly() @@ -63,7 +66,10 @@ class PdfMakerTest extends TestCase ], ], ], - 'variables' => [], + 'variables' => [ + 'labels' => [], + 'values' => [], + ], ]; $maker = new PdfMaker($state); @@ -97,7 +103,10 @@ class PdfMakerTest extends TestCase ], ], 'variables' => [ - '$title' => 'Invoice Ninja', + 'labels' => [], + 'values' => [ + '$title' => 'Invoice Ninja', + ], ], ]; @@ -139,9 +148,12 @@ class PdfMakerTest extends TestCase ], ], 'variables' => [ - '$company' => 'Invoice Ninja', - '$email' => 'contact@invoiceninja.com', - '$country' => 'UK', + 'labels' => [], + 'values' => [ + '$company' => 'Invoice Ninja', + '$email' => 'contact@invoiceninja.com', + '$country' => 'UK', + ], ], ]; @@ -294,8 +306,11 @@ class PdfMakerTest extends TestCase ], ] ], - 'variables' =>[ - '$title' => 'Invoice Ninja', + 'variables' => [ + 'labels' => [], + 'values' => [ + '$title' => 'Invoice Ninja', + ], ] ]; From 8a23ed35ea83b655775df3f9415ca10d5de0081d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 10 Aug 2020 18:40:04 +0200 Subject: [PATCH 24/36] Fixes for global tests --- tests/Feature/PdfMaker/ExampleIntegrationTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/Feature/PdfMaker/ExampleIntegrationTest.php b/tests/Feature/PdfMaker/ExampleIntegrationTest.php index 98a2ca6148f8..1996280fdc51 100644 --- a/tests/Feature/PdfMaker/ExampleIntegrationTest.php +++ b/tests/Feature/PdfMaker/ExampleIntegrationTest.php @@ -7,15 +7,23 @@ use App\Services\PdfMaker\Designs\Playful; use App\Services\PdfMaker\PdfMaker; use App\Utils\HtmlEngine; use App\Utils\Traits\MakesInvoiceValues; +use Tests\MockAccountData; use Tests\TestCase; class ExampleIntegrationTest extends TestCase { - use MakesInvoiceValues; + use MakesInvoiceValues, MockAccountData; + + public function setUp(): void + { + parent::setUp(); + + $this->makeTestData(); + } public function testExample() { - $invoice = Invoice::first(); + $invoice = $this->invoice; $invitation = $invoice->invitations()->first(); $engine = new HtmlEngine(null, $invitation, 'invoice'); From e99bd59aa08c477ff7d846d260c0e938186ffcca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 17:19:52 +0200 Subject: [PATCH 25/36] Implement getting raw HTML out of sections --- .../PdfMaker/Designs/Utilities/BaseDesign.php | 11 +-- .../Designs/Utilities/DesignHelpers.php | 71 +++++++++++++++++++ tests/Feature/PdfMaker/ExampleDesign.php | 10 +++ tests/Feature/PdfMaker/PdfMakerTest.php | 13 +++- 4 files changed, 94 insertions(+), 11 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php b/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php index 9a01ee42da63..c567f20f235c 100644 --- a/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php +++ b/app/Services/PdfMaker/Designs/Utilities/BaseDesign.php @@ -14,14 +14,5 @@ namespace App\Services\PdfMaker\Designs\Utilities; class BaseDesign { - public function setup(): void - { - if (isset($this->context['client'])) { - $this->client = $this->context['client']; - } - - if (isset($this->context['entity'])) { - $this->entity = $this->context['entity']; - } - } + // .. } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index c9694aae58cb..d7f82cb2357d 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -12,8 +12,79 @@ namespace App\Services\PdfMaker\Designs\Utilities; +use DOMDocument; +use DOMXPath; + trait DesignHelpers { + public $document; + + public $xpath; + + public function setup(): self + { + if (isset($this->context['client'])) { + $this->client = $this->context['client']; + } + + if (isset($this->context['entity'])) { + $this->entity = $this->context['entity']; + } + + $this->document(); + + return $this; + } + + /** + * Initialize local dom document instance. Used for getting raw HTML out of template. + * + * @return $this + */ + public function document(): self + { + $document = new DOMDocument(); + + $document->validateOnParse = true; + @$document->loadHTML($this->html()); + + $this->document = $document; + $this->xpath = new DOMXPath($document); + + return $this; + } + + /** + * Get specific section HTML. + * + * @param string $section + * @param bool $id + * @return null|string + */ + public function getSectionHTML(string $section, $id = true): ?string + { + if ($id) { + $element = $this->document->getElementById($section); + } else { + $elements = $this->document->getElementsByTagName($section); + $element = $elements[0]; + } + + $document = new DOMDocument(); + $document->preserveWhiteSpace = false; + $document->formatOutput = true; + + if ($element) { + $document->appendChild( + $document->importNode($element, true) + ); + + return $document->saveHTML(); + } + + return null; + } + /** * This method will help us decide either we show * one "tax rate" column in the table or 3 custom tax rates. diff --git a/tests/Feature/PdfMaker/ExampleDesign.php b/tests/Feature/PdfMaker/ExampleDesign.php index a20d0681a1b3..df493b96b624 100644 --- a/tests/Feature/PdfMaker/ExampleDesign.php +++ b/tests/Feature/PdfMaker/ExampleDesign.php @@ -2,8 +2,18 @@ namespace Tests\Feature\PdfMaker; +use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; + class ExampleDesign { + use DesignHelpers; + + public $client; + + public $entity; + + public $context; + public function html() { return file_get_contents( diff --git a/tests/Feature/PdfMaker/PdfMakerTest.php b/tests/Feature/PdfMaker/PdfMakerTest.php index 73ad3c8aef17..083899c84d4a 100644 --- a/tests/Feature/PdfMaker/PdfMakerTest.php +++ b/tests/Feature/PdfMaker/PdfMakerTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature\PdfMaker; +use App\Services\PdfMaker\Designs\Plain; use App\Services\PdfMaker\PdfMaker; -use Spatie\Browsershot\Browsershot; use Tests\TestCase; class PdfMakerTest extends TestCase @@ -322,4 +322,15 @@ class PdfMakerTest extends TestCase $this->assertTrue(true); } + + public function testGetSectionHTMLWorks() + { + $design = new ExampleDesign(); + + $html = $design + ->document() + ->getSectionHTML('product-table'); + + $this->assertStringContainsString('id="product-table"', $html); + } } From 9c1cfd2e86647d455f4d679969730c4f64607506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 17:53:11 +0200 Subject: [PATCH 26/36] Shared footer elements --- app/Services/PdfMaker/Designs/Playful.php | 8 +++++++- app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php | 8 ++++++++ app/Services/PdfMaker/PdfMakerUtilities.php | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php index 7b7372abdf67..adb87ed290ac 100644 --- a/app/Services/PdfMaker/Designs/Playful.php +++ b/app/Services/PdfMaker/Designs/Playful.php @@ -45,7 +45,7 @@ class Playful extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -71,6 +71,12 @@ class Playful extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index d7f82cb2357d..ff9f89087115 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -156,4 +156,12 @@ trait DesignHelpers return 'true'; } + + public function sharedFooterElements() + { + return ['element' => 'div', 'properties' => ['class' => 'flex items-center justify-between mt-10'], 'content' => '', 'elements' => [ + ['element' => 'img', 'content' => '', 'properties' => ['src' => '$contact.signature', 'class' => 'h-40']], + ['element' => 'img', 'content' => '', 'properties' => ['src' => '$app_url/images/created-by-invoiceninja-new.png', 'class' => 'h-32', 'hidden' => $this->entity->user->account->isPaid() ? 'true' : 'false']], + ]]; + } } diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index bf0c74c1fa20..6a20c3fe66a5 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -128,7 +128,7 @@ trait PdfMakerUtilities $html = strtr($html, $variables['values']); - $this->document->loadHTML($html); + @$this->document->loadHTML($html); $this->document->saveHTML(); } From 00903c717afce28c14b0653c8b2e1885b7a7c511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 17:53:21 +0200 Subject: [PATCH 27/36] Playful footer elements --- resources/views/pdf-designs/playful.html | 109 +++++++++++------------ 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/resources/views/pdf-designs/playful.html b/resources/views/pdf-designs/playful.html index beeee6b5bba6..b70a6f025c26 100644 --- a/resources/views/pdf-designs/playful.html +++ b/resources/views/pdf-designs/playful.html @@ -1,69 +1,62 @@ - - - - - - + + + + - + + + + +
+
+ $company.name logo +
+
+
+
+
+ + +
+
+

+ $your_entity_label +

+
+
+

$to_label:

+
+
- - -
-
-

- $your_entity_label -

-
-
-

$to_label:

-
-
-
-
-
-

$from_label:

-
-
-
-
+
+

$from_label:

+
+
+
+
- -
- - + +
+ + +
+ + \ No newline at end of file From 1d7e4fd6c9287dbf0b2295f6e4c814540cd4cb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 17:57:35 +0200 Subject: [PATCH 28/36] Implement footer signature & white-label logo --- app/Services/PdfMaker/Designs/Bold.php | 6 ++ app/Services/PdfMaker/Designs/Business.php | 6 ++ app/Services/PdfMaker/Designs/Clean.php | 10 +- app/Services/PdfMaker/Designs/Creative.php | 6 ++ app/Services/PdfMaker/Designs/Elegant.php | 6 ++ app/Services/PdfMaker/Designs/Hipster.php | 6 ++ app/Services/PdfMaker/Designs/Modern.php | 6 ++ app/Services/PdfMaker/Designs/Plain.php | 6 ++ resources/views/pdf-designs/bold.html | 2 + resources/views/pdf-designs/business.html | 18 +--- resources/views/pdf-designs/clean.html | 2 + resources/views/pdf-designs/creative.html | 2 + resources/views/pdf-designs/elegant.html | 14 ++- resources/views/pdf-designs/hipster.html | 6 +- resources/views/pdf-designs/modern.html | 2 + resources/views/pdf-designs/plain.html | 2 + resources/views/pdf-designs/playful.html | 109 +++++++++++---------- 17 files changed, 137 insertions(+), 72 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php index 3e43f9b18966..e7940511c1f1 100644 --- a/app/Services/PdfMaker/Designs/Bold.php +++ b/app/Services/PdfMaker/Designs/Bold.php @@ -71,6 +71,12 @@ class Bold extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php index ed86575e7433..35aa366115b0 100644 --- a/app/Services/PdfMaker/Designs/Business.php +++ b/app/Services/PdfMaker/Designs/Business.php @@ -71,6 +71,12 @@ class Business extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php index 047761cc1a67..6808e9b9b03a 100644 --- a/app/Services/PdfMaker/Designs/Clean.php +++ b/app/Services/PdfMaker/Designs/Clean.php @@ -45,7 +45,7 @@ class Clean extends BaseDesign public function elements(array $context, string $type = 'product'): array { $this->context = $context; - + $this->type = $type; $this->setup(); @@ -70,7 +70,13 @@ class Clean extends BaseDesign 'product-table' => [ 'id' => 'product-table', 'elements' => $this->productTable(), - ] + ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index a4b2e38ea578..9c473a5a40b0 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -71,6 +71,12 @@ class Creative extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index c2a518bbfef6..3abbd460fe7d 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -71,6 +71,12 @@ class Elegant extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php index 21c14d904bc0..a339ddf5fb5b 100644 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ b/app/Services/PdfMaker/Designs/Hipster.php @@ -71,6 +71,12 @@ class Hipster extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Designs/Modern.php index 96dfa8c83306..fe2499e474e0 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Designs/Modern.php @@ -71,6 +71,12 @@ class Modern extends BaseDesign 'id' => 'company-address', 'elements' => $this->companyAddress(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 0094b0b62e84..4ca74cde5763 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -67,6 +67,12 @@ class Plain extends BaseDesign 'id' => 'product-table', 'elements' => $this->productTable(), ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], ]; } diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index 025589e20ade..e2b5f47d5f44 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -63,4 +63,6 @@
+ +
diff --git a/resources/views/pdf-designs/business.html b/resources/views/pdf-designs/business.html index 768fcc56e625..006412e3e5e6 100644 --- a/resources/views/pdf-designs/business.html +++ b/resources/views/pdf-designs/business.html @@ -70,21 +70,7 @@ id="product-table" class="w-full mt-20 rounded table-auto" > - - - + +
diff --git a/resources/views/pdf-designs/clean.html b/resources/views/pdf-designs/clean.html index df44b4a7b642..c6bced7f6172 100644 --- a/resources/views/pdf-designs/clean.html +++ b/resources/views/pdf-designs/clean.html @@ -45,4 +45,6 @@
+ +
diff --git a/resources/views/pdf-designs/creative.html b/resources/views/pdf-designs/creative.html index cf29f49f8c1b..0c76394c0ef0 100644 --- a/resources/views/pdf-designs/creative.html +++ b/resources/views/pdf-designs/creative.html @@ -64,4 +64,6 @@ class="w-full mt-10 border-t-4 border-pink-700 table-auto" > + +
diff --git a/resources/views/pdf-designs/elegant.html b/resources/views/pdf-designs/elegant.html index 4bb0858a619f..bac9f6564fa7 100644 --- a/resources/views/pdf-designs/elegant.html +++ b/resources/views/pdf-designs/elegant.html @@ -25,8 +25,10 @@
-

$your_entity_label

-
+

+ $your_entity_label +

+
@@ -45,7 +47,13 @@
-

$thanks_label

+

+ $thanks_label +

+ +
diff --git a/resources/views/pdf-designs/hipster.html b/resources/views/pdf-designs/hipster.html index b9db88c8619f..c07f41ba5e49 100644 --- a/resources/views/pdf-designs/hipster.html +++ b/resources/views/pdf-designs/hipster.html @@ -26,7 +26,9 @@ class="col-span-5 pl-4 border-l border-black" id="client-details" > -

$to_label:

+

+ $to_label: +

+ +
diff --git a/resources/views/pdf-designs/modern.html b/resources/views/pdf-designs/modern.html index 22ec9df4c304..e914d685649d 100644 --- a/resources/views/pdf-designs/modern.html +++ b/resources/views/pdf-designs/modern.html @@ -62,4 +62,6 @@
+ +
diff --git a/resources/views/pdf-designs/plain.html b/resources/views/pdf-designs/plain.html index 2e1a70647f31..a3b80423d307 100644 --- a/resources/views/pdf-designs/plain.html +++ b/resources/views/pdf-designs/plain.html @@ -45,4 +45,6 @@
+ +
diff --git a/resources/views/pdf-designs/playful.html b/resources/views/pdf-designs/playful.html index b70a6f025c26..7eea8ce1ebf2 100644 --- a/resources/views/pdf-designs/playful.html +++ b/resources/views/pdf-designs/playful.html @@ -1,62 +1,71 @@ + + + + - - - - + + - - + - #product-table tbody>tr>td:last-child { - color: #9b2c2c; - font-weight: bold; - } - - - - -
-
- $company.name logo -
-
-
-
-
- - -
-
-

- $your_entity_label -

-
-
-

$to_label:

-
-
+ + +
+
+ $company.name logo +
+
+
-
-

$from_label:

-
-
-
+ + +
+
+

+ $your_entity_label +

+
+
+

$to_label:

+
+
+
+
+
+

$from_label:

+
+
+
+
-
- -
- + +
+ -
- - \ No newline at end of file +
+ From 5ebe60c78e82ba71cea30e5c989047316ed34c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 18:36:56 +0200 Subject: [PATCH 29/36] Update DesignUpdate with new namespace --- app/Console/Commands/DesignUpdate.php | 15 +++++---- app/Services/PdfMaker/Designs/Photo.php | 45 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 app/Services/PdfMaker/Designs/Photo.php diff --git a/app/Console/Commands/DesignUpdate.php b/app/Console/Commands/DesignUpdate.php index 6575f4beda80..e5466438dabc 100644 --- a/app/Console/Commands/DesignUpdate.php +++ b/app/Console/Commands/DesignUpdate.php @@ -39,16 +39,17 @@ class DesignUpdate extends Command public function handle() { foreach (Design::whereIsCustom(false)->get() as $design) { - $class = 'App\Designs\\'.$design->name; + $class = 'App\Services\PdfMaker\Designs\\'.$design->name; $invoice_design = new $class(); + $invoice_design->document(); $design_object = new \stdClass; - $design_object->includes = $invoice_design->includes() ?: ''; - $design_object->header = $invoice_design->header() ?: ''; - $design_object->body = $invoice_design->body() ?: ''; - $design_object->product = $invoice_design->product() ?: ''; - $design_object->task = $invoice_design->task() ?: ''; - $design_object->footer = $invoice_design->footer() ?: ''; + $design_object->includes = $invoice_design->getSectionHTML('includes'); + $design_object->header = $invoice_design->getSectionHTML('head', false); + $design_object->body = $invoice_design->getSectionHTML('body', false); + $design_object->product = $invoice_design->getSectionHTML('product-table'); + $design_object->task = $invoice_design->getSectionHTML('task-table'); + $design_object->footer = $invoice_design->getSectionHTML('footer', false); $design->design = $design_object; $design->save(); diff --git a/app/Services/PdfMaker/Designs/Photo.php b/app/Services/PdfMaker/Designs/Photo.php new file mode 100644 index 000000000000..68c9d799dec7 --- /dev/null +++ b/app/Services/PdfMaker/Designs/Photo.php @@ -0,0 +1,45 @@ + product||task */ + public $type; + + public function html() + { + return file_get_contents( + base_path('resources/views/pdf-designs/bold.html') + ); + } +} From 2de19a4bb1c931ed857e447f061255d685d3294c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 18:50:00 +0200 Subject: [PATCH 30/36] Fix design 'hidden' properties --- app/Services/PdfMaker/Designs/Creative.php | 4 ++-- app/Services/PdfMaker/Designs/Elegant.php | 4 ++-- app/Services/PdfMaker/Designs/Plain.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php index 9c473a5a40b0..b37fd7c9dd01 100644 --- a/app/Services/PdfMaker/Designs/Creative.php +++ b/app/Services/PdfMaker/Designs/Creative.php @@ -189,8 +189,8 @@ class Creative extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount()), 'class' => 'mt-8 px-4 py-2'], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php index 3abbd460fe7d..beb858948355 100644 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ b/app/Services/PdfMaker/Designs/Elegant.php @@ -190,8 +190,8 @@ class Elegant extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(3)]], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php index 4ca74cde5763..ff0fa597a306 100644 --- a/app/Services/PdfMaker/Designs/Plain.php +++ b/app/Services/PdfMaker/Designs/Plain.php @@ -136,8 +136,8 @@ class Plain extends BaseDesign return [ ['element' => 'tr', 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 py-4', 'colspan' => $this->calculateColspan(3)]], - ['element' => 'td', 'content' => '$subtotal_label', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], - ['element' => 'td', 'content' => '$subtotal', 'properties' => [$this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], + ['element' => 'td', 'content' => '$subtotal_label', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-4 text-right', 'colspan' => '2']], + ['element' => 'td', 'content' => '$subtotal', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getSubTotal()), 'class' => 'px-4 py-2 text-right']], ]], ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ ['element' => 'td', 'content' => '$discount_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], From caa704af96678069eec1ab1522e00ef667d4b0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 11 Aug 2020 18:50:24 +0200 Subject: [PATCH 31/36] wip - CreateInvoicePdf --- app/Jobs/Invoice/CreateInvoicePdf.php | 37 ++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 67a68309bb91..791001100289 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -1,4 +1,5 @@ generate($this->invitation); + } App::setLocale($this->contact->preferredLocale()); @@ -81,14 +84,40 @@ class CreateInvoicePdf implements ShouldQueue $design = Design::find($invoice_design_id); - $designer = new Designer($this->invoice, $design, $this->invoice->client->getSetting('pdf_variables'), 'invoice'); + info('Start: ' . now()); - $html = (new HtmlEngine($designer, $this->invitation, 'invoice'))->build(); + $html = new HtmlEngine(null, $this->invitation, 'invoice'); + + $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name; + + $design_class = new $design_namespace(); + + $product_table_columns = json_decode( + json_encode($this->invoice->company->settings->pdf_variables), + 1 + )['product_columns']; + + $state = [ + 'template' => $design_class->elements([ + 'client' => $this->invoice->client, + 'entity' => $this->invoice, + 'product-table-columns' => $product_table_columns, + ]), + 'variables' => $html->generateLabelsAndValues(), + ]; + + $maker = new PdfMakerService($state); + + $maker + ->design($design_namespace) + ->build(); + + info('Done: ' . now()); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); - $pdf = $this->makePdf(null, null, $html); + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); $instance = Storage::disk($this->disk)->put($file_path, $pdf); From a302891bec805a4deb376bcd97ffecfaf8e8408a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 12 Aug 2020 19:14:14 +0200 Subject: [PATCH 32/36] Change $pdf_variables scope --- app/Jobs/Invoice/CreateInvoicePdf.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 791001100289..d014f1bc11e2 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -92,16 +92,13 @@ class CreateInvoicePdf implements ShouldQueue $design_class = new $design_namespace(); - $product_table_columns = json_decode( - json_encode($this->invoice->company->settings->pdf_variables), - 1 - )['product_columns']; + $pdf_variables = json_decode(json_encode($this->invoice->company->settings->pdf_variables), 1); $state = [ 'template' => $design_class->elements([ 'client' => $this->invoice->client, 'entity' => $this->invoice, - 'product-table-columns' => $product_table_columns, + 'product-table-columns' => $pdf_variables['product_columns'], ]), 'variables' => $html->generateLabelsAndValues(), ]; @@ -112,7 +109,7 @@ class CreateInvoicePdf implements ShouldQueue ->design($design_namespace) ->build(); - info('Done: ' . now()); + info($maker->getCompiledHTML()); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0755); From 207e271270aceb590733bc06d12da33c255c34fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 12 Aug 2020 19:14:22 +0200 Subject: [PATCH 33/36] Update CSS link on the designs --- resources/views/pdf-designs/bold.html | 2 +- resources/views/pdf-designs/business.html | 2 +- resources/views/pdf-designs/clean.html | 2 +- resources/views/pdf-designs/creative.html | 2 +- resources/views/pdf-designs/elegant.html | 2 +- resources/views/pdf-designs/hipster.html | 2 +- resources/views/pdf-designs/modern.html | 2 +- resources/views/pdf-designs/plain.html | 2 +- resources/views/pdf-designs/playful.html | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index e2b5f47d5f44..66b172cff9b7 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -8,7 +8,7 @@ /> - +