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/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php
index 4c3b01bf6f5d..5f6ef18bb763 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',
diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php
index b4924a0badce..5b3ecbdfe724 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,33 @@ class CreateInvoicePdf implements ShouldQueue
$design = Design::find($invoice_design_id);
- $designer = new Designer($this->invoice, $design, $this->invoice->client->getSetting('pdf_variables'), 'invoice');
+ $html = new HtmlEngine(null, $this->invitation, 'invoice');
- $html = (new HtmlEngine($designer, $this->invitation, 'invoice'))->build();
+ $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name;
+
+ $design_class = new $design_namespace();
+
+ $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' => $pdf_variables['product_columns'],
+ ]),
+ 'variables' => $html->generateLabelsAndValues(),
+ ];
+
+ $maker = new PdfMakerService($state);
+
+ $maker
+ ->design($design_namespace)
+ ->build();
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
Storage::makeDirectory($path, 0775);
- $pdf = $this->makePdf(null, null, $html);
+ $pdf = $this->makePdf(null, null, $maker->getCompiledHTML());
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
diff --git a/app/Jobs/Quote/CreateQuotePdf.php b/app/Jobs/Quote/CreateQuotePdf.php
index e89016ad94a9..d1b759d73ef5 100644
--- a/app/Jobs/Quote/CreateQuotePdf.php
+++ b/app/Jobs/Quote/CreateQuotePdf.php
@@ -19,6 +19,7 @@ use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Design;
use App\Models\Invoice;
+use App\Services\PdfMaker\PdfMaker as PdfMakerService;
use App\Utils\HtmlEngine;
use App\Utils\PhantomJS\Phantom;
use App\Utils\Traits\MakesHash;
@@ -81,14 +82,33 @@ class CreateQuotePdf implements ShouldQueue
$design = Design::find($quote_design_id);
- $designer = new Designer($this->quote, $design, $this->quote->client->getSetting('pdf_variables'), 'quote');
+ $html = new HtmlEngine(null, $this->invitation, 'quote');
+
+ $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name;
+
+ $design_class = new $design_namespace();
+
+ $pdf_variables = json_decode(json_encode($this->quote->company->settings->pdf_variables), 1);
+
+ $state = [
+ 'template' => $design_class->elements([
+ 'client' => $this->quote->client,
+ 'entity' => $this->quote,
+ 'product-table-columns' => $pdf_variables['product_columns'],
+ ]),
+ 'variables' => $html->generateLabelsAndValues(),
+ ];
+
+ $maker = new PdfMakerService($state);
+
+ $maker
+ ->design($design_namespace)
+ ->build();
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
Storage::makeDirectory($path, 0775);
- $html = (new HtmlEngine($designer, $this->invitation, 'quote'))->build();
-
- $pdf = $this->makePdf(null, null, $html);
+ $pdf = $this->makePdf(null, null, $maker->getCompiledHTML());
$file_path = $path . $this->quote->number . '.pdf';
diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php
index e35bc8281e2d..d1fa02f3bee2 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Bold extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -32,19 +32,20 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Bold extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -116,6 +123,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) {
@@ -133,21 +144,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()],
];
}
@@ -157,7 +154,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']];
}
@@ -186,4 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 65470bbdff7d..a04a3c0c8508 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Business extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -32,19 +32,20 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Business extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -116,6 +123,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) {
@@ -133,21 +144,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 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 64c1b61e1e5b..1fd3848da6a1 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Clean extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -69,7 +70,13 @@ class Clean extends BaseDesign
'product-table' => [
'id' => 'product-table',
'elements' => $this->productTable(),
- ]
+ ],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -103,6 +110,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) {
@@ -133,21 +144,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 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 c62ff86d79d0..82cb3e833a32 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Creative extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -32,19 +32,20 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Creative extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -116,6 +123,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) {
@@ -133,21 +144,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 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 dcc8dbfe0be2..f9eea9fc16af 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Elegant extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Elegant extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -77,6 +84,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) {
@@ -134,21 +145,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 +173,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 +184,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 d459a8b15c16..a3ee624d7452 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Hipster extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Hipster extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -116,6 +123,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) {
@@ -133,21 +144,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 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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', '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', '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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']],
+ ]],
+ ['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 c08c284c7f2b..1259d14e363f 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Modern extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Modern extends BaseDesign
'id' => 'company-address',
'elements' => $this->companyAddress(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -77,6 +84,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) {
@@ -107,21 +118,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 +158,33 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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']],
+ ]],
+ ];
+ }
+
public function companyDetails()
{
$variables = $this->entity->company->settings->pdf_variables->company_details;
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')
+ );
+ }
+}
diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php
index fc251b272fd2..c119b308a560 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Plain extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -66,6 +67,12 @@ class Plain extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -86,6 +93,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) {
@@ -116,20 +127,33 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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 1e1db7661ff1..b8c2077d849a 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\DesignHelpers;
use App\Utils\Traits\MakesInvoiceValues;
class Playful extends BaseDesign
{
- use MakesInvoiceValues, BuildTableHeader;
+ use MakesInvoiceValues, DesignHelpers;
/** Global list of table elements, @var array */
public $elements;
@@ -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,9 +42,10 @@ 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;
$this->setup();
@@ -70,6 +71,12 @@ class Playful extends BaseDesign
'id' => 'product-table',
'elements' => $this->productTable(),
],
+ 'footer-elements' => [
+ 'id' => 'footer',
+ 'elements' => [
+ $this->sharedFooterElements(),
+ ],
+ ],
];
}
@@ -77,6 +84,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) {
@@ -133,21 +144,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 +183,31 @@ 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' => $this->calculateColspan(3)]],
+ ['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)]],
+ ['element' => 'td', 'content' => '$discount', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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']],
+ ]],
+ ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotal())], 'content' => '', 'properties' => ['class' => 'mt-8 px-4 py-2'], 'elements' => [
+ ['element' => 'td', 'content' => '$total_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]],
+ ['element' => 'td', 'content' => '$total', 'properties' => ['class' => 'px-4 py-2 text-right']],
+ ]],
+ ['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/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/BuildTableHeader.php b/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php
deleted file mode 100644
index 41529dc16b75..000000000000
--- a/app/Services/PdfMaker/Designs/Utilities/BuildTableHeader.php
+++ /dev/null
@@ -1,55 +0,0 @@
-context['product-table-columns'])) {
- $line_items = collect($this->entity->line_items);
-
- $tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count();
- $tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', 1)->count();
- $tax3 = $line_items->where('tax_name3', '<>', '')->where('type_id', 1)->count();
- $taxes = [];
-
- if ($tax1 > 0) {
- array_push($taxes, '$product.tax_rate1');
- }
-
- if ($tax2 > 0) {
- array_push($taxes, '$product.tax_rate2');
- }
-
- if ($tax3 > 0) {
- array_push($taxes, '$product.tax_rate3');
- }
-
- $key = array_search('$product.tax', $this->context['product-table-columns'], true);
-
- if ($key) {
- array_splice($this->context['product-table-columns'], $key, 1, $taxes);
- }
- }
- }
-}
diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php
new file mode 100644
index 000000000000..c298d7a9ff16
--- /dev/null
+++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php
@@ -0,0 +1,167 @@
+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.
+ *
+ * Logic below will help us calculate that & inject the result in the
+ * global state of the $context (design state).
+ *
+ * @return void
+ */
+ public function processTaxColumns(): void
+ {
+ if (in_array('$product.tax', $this->context['product-table-columns'])) {
+ $line_items = collect($this->entity->line_items);
+
+ $tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count();
+ $tax2 = $line_items->where('tax_name2', '<>', '')->where('type_id', 1)->count();
+ $tax3 = $line_items->where('tax_name3', '<>', '')->where('type_id', 1)->count();
+ $taxes = [];
+
+ if ($tax1 > 0) {
+ array_push($taxes, '$product.tax_rate1');
+ }
+
+ if ($tax2 > 0) {
+ array_push($taxes, '$product.tax_rate2');
+ }
+
+ if ($tax3 > 0) {
+ array_push($taxes, '$product.tax_rate3');
+ }
+
+ $key = array_search('$product.tax', $this->context['product-table-columns'], true);
+
+ if ($key) {
+ array_splice($this->context['product-table-columns'], $key, 1, $taxes);
+ }
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Return "true" or "false" based on null or empty check.
+ * We need to return false as string because of HTML parsing.
+ *
+ * @param mixed $property
+ * @return string
+ */
+ public function toggleHiddenProperty($property): string
+ {
+ if (is_null($property)) {
+ return 'false';
+ }
+
+ if (empty($property)) {
+ return 'false';
+ }
+
+ 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-32']],
+ ['element' => 'img', 'content' => '', 'properties' => ['src' => '$app_url/images/created-by-invoiceninja-new.png', 'class' => 'h-24', 'hidden' => $this->entity->user->account->isPaid() ? 'true' : 'false']],
+ ]];
+ }
+}
diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php
index a696f5012fb5..6a20c3fe66a5 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,10 +125,10 @@ trait PdfMakerUtilities
public function updateVariables(array $variables)
{
$html = strtr($this->getCompiledHTML(), $variables['labels']);
-
+
$html = strtr($html, $variables['values']);
- $this->document->loadHTML($html);
+ @$this->document->loadHTML($html);
$this->document->saveHTML();
}
diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php
index ff05c519beb3..5db0a9871360 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')];
@@ -107,8 +108,8 @@ class HtmlEngine
$data['$date'] = ['value' => $this->entity->date ?: ' ', 'label' => ctrans('texts.date')];
//$data['$invoice_date'] = ['value' => $this->date ?: ' ', 'label' => ctrans('texts.invoice_date')];
$data['$invoice.date'] = &$data['$date'];
- $data['$invoice.due_date'] = ['value' => $this->entity->due_date ?: ' ', 'label' => ctrans('texts.due_date')];
- $data['$due_date'] = &$data['$invoice.due_date'];
+ $data['$due_date'] = ['value' => $this->entity->due_date ?: ' ', 'label' => ctrans('texts.' . $this->entity_string . '_due_date')];
+ $data['$invoice.due_date'] = &$data['$due_date'];
$data['$invoice.number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.invoice_number')];
$data['$invoice.po_number'] = ['value' => $this->entity->po_number ?: ' ', 'label' => ctrans('texts.po_number')];
$data['$line_taxes'] = ['value' => $this->makeLineTaxes() ?: ' ', 'label' => ctrans('texts.taxes')];
@@ -117,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'];
@@ -125,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'];
@@ -133,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'];
@@ -147,10 +148,12 @@ class HtmlEngine
$data['$discount'] = &$data['$invoice.discount'];
$data['$subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
$data['$invoice.subtotal'] = &$data['$subtotal'];
- $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['$invoice.partial_due'] = ['value' => Number::formatMoney($this->entity->partial, $this->client) ?: ' ', 'label' => ctrans('texts.partial_due')];
+ $data['$balance_due'] = ['value' => Number::formatMoney($this->entity->balance, $this->client) ?: ' ', 'label' => ctrans('texts.balance_due')];
+ $data['$quote.balance_due'] = &$data['$balance_due'];
+ $data['$invoice.balance_due'] = &$data['$balance_due'];
+ $data['$balance_due'] = &$data['$balance_due'];
+ $data['$outstanding'] = &$data['$balance_due'];
+ $data['$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'];
$data['$quote.total'] = &$data['$total'];
@@ -175,11 +178,10 @@ 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['$your_invoice'] = ;
- // $data['$quote'] = ;
- // $data['$your_quote'] = ;
- //
+
+ $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')];
$data['$quote.po_number'] = &$data['$invoice.po_number'];
@@ -297,6 +299,14 @@ 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['_rate1'] = ['value' => '', 'label' => ctrans('texts.tax')];
+ $data['_rate2'] = ['value' => '', 'label' => ctrans('texts.tax')];
+ $data['_rate3'] = ['value' => '', 'label' => ctrans('texts.tax')];
+
// $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..66b172cff9b7 100644
--- a/resources/views/pdf-designs/bold.html
+++ b/resources/views/pdf-designs/bold.html
@@ -8,7 +8,7 @@
/>
-
+