mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 04:54:36 -04:00
Updates for custom PDF designer
This commit is contained in:
parent
b60f0bc5dc
commit
10793f1d14
@ -33,7 +33,7 @@ class PdfBuilder
|
|||||||
private float $payment_amount_total = 0;
|
private float $payment_amount_total = 0;
|
||||||
/**
|
/**
|
||||||
* an array of sections to be injected into the template
|
* an array of sections to be injected into the template
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public array $sections = [];
|
public array $sections = [];
|
||||||
@ -46,29 +46,26 @@ class PdfBuilder
|
|||||||
public DomDocument $document;
|
public DomDocument $document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PdfService $service
|
* @param PdfService $service
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(PdfService $service)
|
public function __construct(PdfService $service)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->service = $service;
|
$this->service = $service;
|
||||||
|
|
||||||
$this->commonmark = new CommonMarkConverter([
|
$this->commonmark = new CommonMarkConverter([
|
||||||
'allow_unsafe_links' => false,
|
'allow_unsafe_links' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the template sections
|
* Builds the template sections
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function build(): self
|
public function build(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->getTemplate()
|
$this->getTemplate()
|
||||||
->buildSections()
|
->buildSections()
|
||||||
->getEmptyElements()
|
->getEmptyElements()
|
||||||
@ -93,13 +90,12 @@ class PdfBuilder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the template
|
* Generate the template
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getTemplate() :self
|
private function getTemplate() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
$document = new DOMDocument();
|
$document = new DOMDocument();
|
||||||
|
|
||||||
$document->validateOnParse = true;
|
$document->validateOnParse = true;
|
||||||
@ -111,50 +107,44 @@ class PdfBuilder
|
|||||||
$this->xpath = new DOMXPath($document);
|
$this->xpath = new DOMXPath($document);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates product entity sections
|
* Generates product entity sections
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getProductSections(): self
|
private function getProductSections(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->genericSectionBuilder()
|
$this->genericSectionBuilder()
|
||||||
->getClientDetails()
|
->getClientDetails()
|
||||||
->getProductAndTaskTables()
|
->getProductAndTaskTables()
|
||||||
->getProductEntityDetails()
|
->getProductEntityDetails()
|
||||||
->getProductTotals();
|
->getProductTotals();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mergeSections(array $section) :self
|
private function mergeSections(array $section) :self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->sections = array_merge($this->sections, $section);
|
$this->sections = array_merge($this->sections, $section);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates delivery note sections
|
* Generates delivery note sections
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getDeliveryNoteSections(): self
|
private function getDeliveryNoteSections(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->genericSectionBuilder()
|
$this->genericSectionBuilder()
|
||||||
->getProductTotals();
|
->getProductTotals();
|
||||||
|
|
||||||
$this->mergeSections([
|
$this->mergeSections([
|
||||||
'client-details' => [
|
'client-details' => [
|
||||||
'id' => 'client-details',
|
'id' => 'client-details',
|
||||||
'elements' => $this->clientDeliveryDetails(),
|
'elements' => $this->clientDeliveryDetails(),
|
||||||
@ -170,21 +160,19 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates statement sections
|
* Generates statement sections
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getStatementSections(): self
|
private function getStatementSections(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->genericSectionBuilder();
|
$this->genericSectionBuilder();
|
||||||
|
|
||||||
$this->mergeSections( [
|
$this->mergeSections([
|
||||||
'statement-invoice-table' => [
|
'statement-invoice-table' => [
|
||||||
'id' => 'statement-invoice-table',
|
'id' => 'statement-invoice-table',
|
||||||
'elements' => $this->statementInvoiceTable(),
|
'elements' => $this->statementInvoiceTable(),
|
||||||
@ -212,7 +200,6 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -223,13 +210,11 @@ class PdfBuilder
|
|||||||
*/
|
*/
|
||||||
public function statementInvoiceTableTotals(): array
|
public function statementInvoiceTableTotals(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$outstanding = $this->service->options['invoices']->sum('balance');
|
$outstanding = $this->service->options['invoices']->sum('balance');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['element' => 'p', 'content' => '$outstanding_label: ' . Number::formatMoney($outstanding, $this->service->config->client)],
|
['element' => 'p', 'content' => '$outstanding_label: ' . Number::formatMoney($outstanding, $this->service->config->client)],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +225,6 @@ class PdfBuilder
|
|||||||
*/
|
*/
|
||||||
public function statementPaymentTable(): array
|
public function statementPaymentTable(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
if (is_null($this->service->option['payments'])) {
|
if (is_null($this->service->option['payments'])) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -254,9 +238,9 @@ class PdfBuilder
|
|||||||
//24-03-2022 show payments per invoice
|
//24-03-2022 show payments per invoice
|
||||||
foreach ($this->service->options['invoices'] as $invoice) {
|
foreach ($this->service->options['invoices'] as $invoice) {
|
||||||
foreach ($invoice->payments as $payment) {
|
foreach ($invoice->payments as $payment) {
|
||||||
|
if ($payment->is_deleted) {
|
||||||
if($payment->is_deleted)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$element = ['element' => 'tr', 'elements' => []];
|
$element = ['element' => 'tr', 'elements' => []];
|
||||||
|
|
||||||
@ -275,14 +259,13 @@ class PdfBuilder
|
|||||||
['element' => 'thead', 'elements' => $this->buildTableHeader('statement_payment')],
|
['element' => 'thead', 'elements' => $this->buildTableHeader('statement_payment')],
|
||||||
['element' => 'tbody', 'elements' => $tbody],
|
['element' => 'tbody', 'elements' => $tbody],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the statement payments table
|
* Generates the statement payments table
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function statementPaymentTableTotals(): array
|
public function statementPaymentTableTotals(): array
|
||||||
{
|
{
|
||||||
@ -304,13 +287,12 @@ class PdfBuilder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the statement aging table
|
* Generates the statement aging table
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function statementAgingTable(): array
|
public function statementAgingTable(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
if (\array_key_exists('show_aging_table', $this->service->options) && $this->service->options['show_aging_table'] === false) {
|
if (\array_key_exists('show_aging_table', $this->service->options) && $this->service->options['show_aging_table'] === false) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -333,18 +315,17 @@ class PdfBuilder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the purchase order sections
|
* Generates the purchase order sections
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getPurchaseOrderSections(): self
|
private function getPurchaseOrderSections(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->genericSectionBuilder()
|
$this->genericSectionBuilder()
|
||||||
->getProductAndTaskTables()
|
->getProductAndTaskTables()
|
||||||
->getProductTotals();
|
->getProductTotals();
|
||||||
|
|
||||||
$this->mergeSections([
|
$this->mergeSections([
|
||||||
'vendor-details' => [
|
'vendor-details' => [
|
||||||
'id' => 'vendor-details',
|
'id' => 'vendor-details',
|
||||||
'elements' => $this->vendorDetails(),
|
'elements' => $this->vendorDetails(),
|
||||||
@ -356,19 +337,17 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the generic section which apply
|
* Generates the generic section which apply
|
||||||
* across all design templates
|
* across all design templates
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function genericSectionBuilder(): self
|
private function genericSectionBuilder(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->mergeSections([
|
$this->mergeSections([
|
||||||
'company-details' => [
|
'company-details' => [
|
||||||
'id' => 'company-details',
|
'id' => 'company-details',
|
||||||
@ -391,13 +370,12 @@ class PdfBuilder
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the invoices table for statements
|
* Generates the invoices table for statements
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function statementInvoiceTable(): array
|
public function statementInvoiceTable(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$tbody = [];
|
$tbody = [];
|
||||||
|
|
||||||
foreach ($this->service->options['invoices'] as $invoice) {
|
foreach ($this->service->options['invoices'] as $invoice) {
|
||||||
@ -424,7 +402,7 @@ class PdfBuilder
|
|||||||
*
|
*
|
||||||
* @param string $type "$product" or "$task"
|
* @param string $type "$product" or "$task"
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function buildTableBody(string $type): array
|
public function buildTableBody(string $type): array
|
||||||
{
|
{
|
||||||
@ -516,7 +494,7 @@ class PdfBuilder
|
|||||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => 'product_table-product.tax2-td']];
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => 'product_table-product.tax2-td']];
|
||||||
} elseif ($cell == '$product.tax_rate3') {
|
} elseif ($cell == '$product.tax_rate3') {
|
||||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => 'product_table-product.tax3-td']];
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => 'product_table-product.tax3-td']];
|
||||||
} else if ($cell == '$product.unit_cost' || $cell == '$task.rate') {
|
} elseif ($cell == '$product.unit_cost' || $cell == '$task.rate') {
|
||||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['style' => 'white-space: nowrap;', 'data-ref' => "{$_type}_table-" . substr($cell, 1) . '-td']];
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['style' => 'white-space: nowrap;', 'data-ref' => "{$_type}_table-" . substr($cell, 1) . '-td']];
|
||||||
} else {
|
} else {
|
||||||
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => "{$_type}_table-" . substr($cell, 1) . '-td']];
|
$element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['data-ref' => "{$_type}_table-" . substr($cell, 1) . '-td']];
|
||||||
@ -542,8 +520,7 @@ class PdfBuilder
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function transformLineItems($items, $table_type = '$product') :array
|
public function transformLineItems($items, $table_type = '$product') :array
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
$locale_info = localeconv();
|
$locale_info = localeconv();
|
||||||
@ -559,7 +536,7 @@ class PdfBuilder
|
|||||||
|
|
||||||
if ($table_type == '$task' && $item->type_id != 2) {
|
if ($table_type == '$task' && $item->type_id != 2) {
|
||||||
// if ($item->type_id != 4 && $item->type_id != 5) {
|
// if ($item->type_id != 4 && $item->type_id != 5) {
|
||||||
continue;
|
continue;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,7 +631,7 @@ class PdfBuilder
|
|||||||
*
|
*
|
||||||
* @param string $type "product" or "task"
|
* @param string $type "product" or "task"
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function buildTableHeader(string $type): array
|
public function buildTableHeader(string $type): array
|
||||||
{
|
{
|
||||||
@ -688,7 +665,6 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -703,7 +679,6 @@ class PdfBuilder
|
|||||||
*/
|
*/
|
||||||
public function processTaxColumns(string $type): void
|
public function processTaxColumns(string $type): void
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($type == 'product') {
|
if ($type == 'product') {
|
||||||
$type_id = 1;
|
$type_id = 1;
|
||||||
}
|
}
|
||||||
@ -746,15 +721,14 @@ class PdfBuilder
|
|||||||
array_splice($this->service->config->pdf_variables["{$type}_columns"], $key, 1, $taxes);
|
array_splice($this->service->config->pdf_variables["{$type}_columns"], $key, 1, $taxes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the javascript block for
|
* Generates the javascript block for
|
||||||
* hiding elements which need to be hidden
|
* hiding elements which need to be hidden
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function sharedFooterElements(): array
|
public function sharedFooterElements(): array
|
||||||
{
|
{
|
||||||
@ -777,20 +751,18 @@ class PdfBuilder
|
|||||||
['element' => 'script', 'content' => $javascript],
|
['element' => 'script', 'content' => $javascript],
|
||||||
['element' => 'script', 'content' => $html_decode],
|
['element' => 'script', 'content' => $html_decode],
|
||||||
]];
|
]];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the totals table for
|
* Generates the totals table for
|
||||||
* the product type entities
|
* the product type entities
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getProductTotals(): self
|
private function getProductTotals(): self
|
||||||
{
|
{
|
||||||
|
$this->mergeSections([
|
||||||
$this->mergeSections([
|
|
||||||
'table-totals' => [
|
'table-totals' => [
|
||||||
'id' => 'table-totals',
|
'id' => 'table-totals',
|
||||||
'elements' => $this->getTableTotals(),
|
'elements' => $this->getTableTotals(),
|
||||||
@ -798,7 +770,6 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -806,76 +777,62 @@ class PdfBuilder
|
|||||||
* Credits
|
* Credits
|
||||||
* Quotes
|
* Quotes
|
||||||
* Invoices
|
* Invoices
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function getProductEntityDetails(): self
|
private function getProductEntityDetails(): self
|
||||||
{
|
{
|
||||||
|
if ($this->service->config->entity_string == 'invoice') {
|
||||||
if($this->service->config->entity_string == 'invoice')
|
$this->mergeSections([
|
||||||
{
|
|
||||||
$this->mergeSections( [
|
|
||||||
'entity-details' => [
|
'entity-details' => [
|
||||||
'id' => 'entity-details',
|
'id' => 'entity-details',
|
||||||
'elements' => $this->invoiceDetails(),
|
'elements' => $this->invoiceDetails(),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
} elseif ($this->service->config->entity_string == 'quote') {
|
||||||
elseif($this->service->config->entity_string == 'quote')
|
$this->mergeSections([
|
||||||
{
|
|
||||||
|
|
||||||
$this->mergeSections( [
|
|
||||||
'entity-details' => [
|
'entity-details' => [
|
||||||
'id' => 'entity-details',
|
'id' => 'entity-details',
|
||||||
'elements' => $this->quoteDetails(),
|
'elements' => $this->quoteDetails(),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
} elseif ($this->service->config->entity_string == 'credit') {
|
||||||
}
|
$this->mergeSections([
|
||||||
elseif($this->service->config->entity_string == 'credit')
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->mergeSections( [
|
|
||||||
'entity-details' => [
|
'entity-details' => [
|
||||||
'id' => 'entity-details',
|
'id' => 'entity-details',
|
||||||
'elements' => $this->creditDetails(),
|
'elements' => $this->creditDetails(),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent entry point when building sections of the design content
|
* Parent entry point when building sections of the design content
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function buildSections() :self
|
private function buildSections() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
return match ($this->service->document_type) {
|
return match ($this->service->document_type) {
|
||||||
PdfService::PRODUCT => $this->getProductSections(),
|
PdfService::PRODUCT => $this->getProductSections(),
|
||||||
PdfService::DELIVERY_NOTE => $this->getDeliveryNoteSections(),
|
PdfService::DELIVERY_NOTE => $this->getDeliveryNoteSections(),
|
||||||
PdfService::STATEMENT => $this->getStatementSections(),
|
PdfService::STATEMENT => $this->getStatementSections(),
|
||||||
PdfService::PURCHASE_ORDER => $this->getPurchaseOrderSections(),
|
PdfService::PURCHASE_ORDER => $this->getPurchaseOrderSections(),
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the table totals for statements
|
* Generates the table totals for statements
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function statementTableTotals(): array
|
private function statementTableTotals(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [
|
['element' => 'div', 'properties' => ['style' => 'display: flex; flex-direction: column;'], 'elements' => [
|
||||||
['element' => 'div', 'properties' => ['style' => 'margin-top: 1.5rem; display: block; align-items: flex-start; page-break-inside: avoid; visible !important;'], 'elements' => [
|
['element' => 'div', 'properties' => ['style' => 'margin-top: 1.5rem; display: block; align-items: flex-start; page-break-inside: avoid; visible !important;'], 'elements' => [
|
||||||
@ -883,16 +840,15 @@ class PdfBuilder
|
|||||||
]],
|
]],
|
||||||
]],
|
]],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a variable check to ensure
|
* Performs a variable check to ensure
|
||||||
* the variable exists
|
* the variable exists
|
||||||
*
|
*
|
||||||
* @param string $variables
|
* @param string $variables
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function entityVariableCheck(string $variable): bool
|
public function entityVariableCheck(string $variable): bool
|
||||||
{
|
{
|
||||||
@ -925,15 +881,14 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//First pass done, need a second pass to abstract this content completely.
|
//First pass done, need a second pass to abstract this content completely.
|
||||||
/**
|
/**
|
||||||
* Builds the table totals for all entities, we'll want to split this
|
* Builds the table totals for all entities, we'll want to split this
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getTableTotals() :array
|
public function getTableTotals() :array
|
||||||
{
|
{
|
||||||
@ -980,7 +935,6 @@ class PdfBuilder
|
|||||||
if (in_array('$paid_to_date', $variables)) {
|
if (in_array('$paid_to_date', $variables)) {
|
||||||
$variables = \array_diff($variables, ['$paid_to_date']);
|
$variables = \array_diff($variables, ['$paid_to_date']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (['discount'] as $property) {
|
foreach (['discount'] as $property) {
|
||||||
@ -1057,19 +1011,17 @@ class PdfBuilder
|
|||||||
]];
|
]];
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the product and task tables
|
* Generates the product and task tables
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getProductAndTaskTables(): self
|
public function getProductAndTaskTables(): self
|
||||||
{
|
{
|
||||||
|
$this->mergeSections([
|
||||||
$this->mergeSections( [
|
|
||||||
'product-table' => [
|
'product-table' => [
|
||||||
'id' => 'product-table',
|
'id' => 'product-table',
|
||||||
'elements' => $this->productTable(),
|
'elements' => $this->productTable(),
|
||||||
@ -1081,19 +1033,17 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the client details
|
* Generates the client details
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getClientDetails(): self
|
public function getClientDetails(): self
|
||||||
{
|
{
|
||||||
|
$this->mergeSections([
|
||||||
$this->mergeSections( [
|
|
||||||
'client-details' => [
|
'client-details' => [
|
||||||
'id' => 'client-details',
|
'id' => 'client-details',
|
||||||
'elements' => $this->clientDetails(),
|
'elements' => $this->clientDetails(),
|
||||||
@ -1101,7 +1051,6 @@ class PdfBuilder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1111,7 +1060,6 @@ class PdfBuilder
|
|||||||
*/
|
*/
|
||||||
public function productTable(): array
|
public function productTable(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$product_items = collect($this->service->config->entity->line_items)->filter(function ($item) {
|
$product_items = collect($this->service->config->entity->line_items)->filter(function ($item) {
|
||||||
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5;
|
return $item->type_id == 1 || $item->type_id == 6 || $item->type_id == 5;
|
||||||
});
|
});
|
||||||
@ -1124,7 +1072,6 @@ class PdfBuilder
|
|||||||
['element' => 'thead', 'elements' => $this->buildTableHeader('product')],
|
['element' => 'thead', 'elements' => $this->buildTableHeader('product')],
|
||||||
['element' => 'tbody', 'elements' => $this->buildTableBody('$product')],
|
['element' => 'tbody', 'elements' => $this->buildTableBody('$product')],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1134,7 +1081,6 @@ class PdfBuilder
|
|||||||
*/
|
*/
|
||||||
public function taskTable(): array
|
public function taskTable(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$task_items = collect($this->service->config->entity->line_items)->filter(function ($item) {
|
$task_items = collect($this->service->config->entity->line_items)->filter(function ($item) {
|
||||||
return $item->type_id == 2;
|
return $item->type_id == 2;
|
||||||
});
|
});
|
||||||
@ -1147,19 +1093,17 @@ class PdfBuilder
|
|||||||
['element' => 'thead', 'elements' => $this->buildTableHeader('task')],
|
['element' => 'thead', 'elements' => $this->buildTableHeader('task')],
|
||||||
['element' => 'tbody', 'elements' => $this->buildTableBody('$task')],
|
['element' => 'tbody', 'elements' => $this->buildTableBody('$task')],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the statement details
|
* Generates the statement details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function statementDetails(): array
|
public function statementDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$s_date = $this->translateDate(now(), $this->service->config->client->date_format(), $this->service->config->client->locale());
|
$s_date = $this->translateDate(now(), $this->service->config->client->date_format(), $this->service->config->client->locale());
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -1176,33 +1120,29 @@ class PdfBuilder
|
|||||||
['element' => 'th', 'properties' => [], 'content' => Number::formatMoney($this->service->options['invoices']->sum('balance'), $this->service->config->client)],
|
['element' => 'th', 'properties' => [], 'content' => Number::formatMoney($this->service->options['invoices']->sum('balance'), $this->service->config->client)],
|
||||||
]],
|
]],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the invoice details
|
* Generates the invoice details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function invoiceDetails(): array
|
public function invoiceDetails(): array
|
||||||
{
|
{
|
||||||
|
$variables = $this->service->config->pdf_variables['invoice_details'];
|
||||||
$variables = $this->service->config->pdf_variables['invoice_details'];
|
|
||||||
|
|
||||||
return $this->genericDetailsBuilder($variables);
|
return $this->genericDetailsBuilder($variables);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the quote details
|
* Generates the quote details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function quoteDetails(): array
|
public function quoteDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['quote_details'];
|
$variables = $this->service->config->pdf_variables['quote_details'];
|
||||||
|
|
||||||
if ($this->service->config->entity->partial > 0) {
|
if ($this->service->config->entity->partial > 0) {
|
||||||
@ -1210,48 +1150,42 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->genericDetailsBuilder($variables);
|
return $this->genericDetailsBuilder($variables);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the credit note details
|
* Generates the credit note details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function creditDetails(): array
|
public function creditDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['credit_details'];
|
$variables = $this->service->config->pdf_variables['credit_details'];
|
||||||
|
|
||||||
return $this->genericDetailsBuilder($variables);
|
return $this->genericDetailsBuilder($variables);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the purchase order details
|
* Generates the purchase order details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function purchaseOrderDetails(): array
|
public function purchaseOrderDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['purchase_order_details'];
|
$variables = $this->service->config->pdf_variables['purchase_order_details'];
|
||||||
|
|
||||||
return $this->genericDetailsBuilder($variables);
|
return $this->genericDetailsBuilder($variables);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the deliveyr note details
|
* Generates the deliveyr note details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function deliveryNoteDetails(): array
|
public function deliveryNoteDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['invoice_details'];
|
$variables = $this->service->config->pdf_variables['invoice_details'];
|
||||||
|
|
||||||
$variables = array_filter($variables, function ($m) {
|
$variables = array_filter($variables, function ($m) {
|
||||||
@ -1259,19 +1193,17 @@ class PdfBuilder
|
|||||||
});
|
});
|
||||||
|
|
||||||
return $this->genericDetailsBuilder($variables);
|
return $this->genericDetailsBuilder($variables);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the custom values for the
|
* Generates the custom values for the
|
||||||
* entity.
|
* entity.
|
||||||
*
|
*
|
||||||
* @param array
|
* @param array
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function genericDetailsBuilder(array $variables): array
|
public function genericDetailsBuilder(array $variables): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
|
|
||||||
@ -1295,24 +1227,23 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the client delivery
|
* Generates the client delivery
|
||||||
* details array
|
* details array
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function clientDeliveryDetails(): array
|
public function clientDeliveryDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
if(!$this->service->config->client)
|
if (!$this->service->config->client) {
|
||||||
return $elements;
|
return $elements;
|
||||||
|
}
|
||||||
|
|
||||||
$elements = [
|
$elements = [
|
||||||
['element' => 'p', 'content' => ctrans('texts.delivery_note'), 'properties' => ['data-ref' => 'delivery_note-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
|
['element' => 'p', 'content' => ctrans('texts.delivery_note'), 'properties' => ['data-ref' => 'delivery_note-label', 'style' => 'font-weight: bold; text-transform: uppercase']],
|
||||||
@ -1327,26 +1258,25 @@ class PdfBuilder
|
|||||||
['element' => 'p', 'content' => optional($this->service->config->client->shipping_country)->name, 'show_empty' => false],
|
['element' => 'p', 'content' => optional($this->service->config->client->shipping_country)->name, 'show_empty' => false],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!is_null($this->service->config->contact)) {
|
if (!is_null($this->service->config->contact)) {
|
||||||
$elements[] = ['element' => 'p', 'content' => $this->service->config->contact->email, 'show_empty' => false, 'properties' => ['data-ref' => 'delivery_note-contact.email']];
|
$elements[] = ['element' => 'p', 'content' => $this->service->config->contact->email, 'show_empty' => false, 'properties' => ['data-ref' => 'delivery_note-contact.email']];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the client details section
|
* Generates the client details section
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function clientDetails(): array
|
public function clientDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
if(!$this->service->config->client)
|
if (!$this->service->config->client) {
|
||||||
return $elements;
|
return $elements;
|
||||||
|
}
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['client_details'];
|
$variables = $this->service->config->pdf_variables['client_details'];
|
||||||
|
|
||||||
@ -1355,12 +1285,11 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the delivery note table
|
* Generates the delivery note table
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function deliveryNoteTable(): array
|
public function deliveryNoteTable(): array
|
||||||
@ -1396,20 +1325,18 @@ class PdfBuilder
|
|||||||
['element' => 'thead', 'elements' => $thead],
|
['element' => 'thead', 'elements' => $thead],
|
||||||
['element' => 'tbody', 'elements' => $this->buildTableBody(PdfService::DELIVERY_NOTE)],
|
['element' => 'tbody', 'elements' => $this->buildTableBody(PdfService::DELIVERY_NOTE)],
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Passes an array of items by reference
|
* Passes an array of items by reference
|
||||||
* and performs a nl2br
|
* and performs a nl2br
|
||||||
*
|
*
|
||||||
* @param array
|
* @param array
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function processNewLines(array &$items): void
|
public function processNewLines(array &$items): void
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($items as $key => $item) {
|
foreach ($items as $key => $item) {
|
||||||
foreach ($item as $variable => $value) {
|
foreach ($item as $variable => $value) {
|
||||||
$item[$variable] = str_replace("\n", '<br>', $value);
|
$item[$variable] = str_replace("\n", '<br>', $value);
|
||||||
@ -1417,18 +1344,16 @@ class PdfBuilder
|
|||||||
|
|
||||||
$items[$key] = $item;
|
$items[$key] = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an arary of the company details
|
* Generates an arary of the company details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function companyDetails(): array
|
public function companyDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['company_details'];
|
$variables = $this->service->config->pdf_variables['company_details'];
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
@ -1438,19 +1363,17 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates an array of the company address
|
* Generates an array of the company address
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function companyAddress(): array
|
public function companyAddress(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['company_address'];
|
$variables = $this->service->config->pdf_variables['company_address'];
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
@ -1460,19 +1383,17 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates an array of vendor details
|
* Generates an array of vendor details
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function vendorDetails(): array
|
public function vendorDetails(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
$elements = [];
|
$elements = [];
|
||||||
|
|
||||||
$variables = $this->service->config->pdf_variables['vendor_details'];
|
$variables = $this->service->config->pdf_variables['vendor_details'];
|
||||||
@ -1482,7 +1403,6 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $elements;
|
return $elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1493,14 +1413,11 @@ class PdfBuilder
|
|||||||
|
|
||||||
public function getSectionNode(string $selector)
|
public function getSectionNode(string $selector)
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->document->getElementById($selector);
|
return $this->document->getElementById($selector);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateElementProperties() :self
|
public function updateElementProperties() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($this->sections as $element) {
|
foreach ($this->sections as $element) {
|
||||||
if (isset($element['tag'])) {
|
if (isset($element['tag'])) {
|
||||||
$node = $this->document->getElementsByTagName($element['tag'])->item(0);
|
$node = $this->document->getElementsByTagName($element['tag'])->item(0);
|
||||||
@ -1522,7 +1439,6 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateElementProperty($element, string $attribute, ?string $value)
|
public function updateElementProperty($element, string $attribute, ?string $value)
|
||||||
@ -1542,12 +1458,10 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createElementContent($element, $children) :self
|
public function createElementContent($element, $children) :self
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($children as $child) {
|
foreach ($children as $child) {
|
||||||
$contains_html = false;
|
$contains_html = false;
|
||||||
|
|
||||||
@ -1596,12 +1510,10 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateVariables()
|
public function updateVariables()
|
||||||
{
|
{
|
||||||
|
|
||||||
$html = strtr($this->getCompiledHTML(), $this->service->html_variables['labels']);
|
$html = strtr($this->getCompiledHTML(), $this->service->html_variables['labels']);
|
||||||
|
|
||||||
$html = strtr($html, $this->service->html_variables['values']);
|
$html = strtr($html, $this->service->html_variables['values']);
|
||||||
@ -1611,12 +1523,10 @@ class PdfBuilder
|
|||||||
$this->document->saveHTML();
|
$this->document->saveHTML();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateVariable(string $element, string $variable, string $value)
|
public function updateVariable(string $element, string $variable, string $value)
|
||||||
{
|
{
|
||||||
|
|
||||||
$element = $this->document->getElementById($element);
|
$element = $this->document->getElementById($element);
|
||||||
|
|
||||||
$original = $element->nodeValue;
|
$original = $element->nodeValue;
|
||||||
@ -1630,12 +1540,10 @@ class PdfBuilder
|
|||||||
);
|
);
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEmptyElements() :self
|
public function getEmptyElements() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($this->sections as $element) {
|
foreach ($this->sections as $element) {
|
||||||
if (isset($element['elements'])) {
|
if (isset($element['elements'])) {
|
||||||
$this->getEmptyChildrens($element['elements'], $this->service->html_variables);
|
$this->getEmptyChildrens($element['elements'], $this->service->html_variables);
|
||||||
@ -1643,12 +1551,10 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEmptyChildrens(array $children)
|
public function getEmptyChildrens(array $children)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach ($children as $key => $child) {
|
foreach ($children as $key => $child) {
|
||||||
if (isset($child['content']) && isset($child['show_empty']) && $child['show_empty'] === false) {
|
if (isset($child['content']) && isset($child['show_empty']) && $child['show_empty'] === false) {
|
||||||
$value = strtr($child['content'], $this->service->html_variables['values']);
|
$value = strtr($child['content'], $this->service->html_variables['values']);
|
||||||
@ -1663,7 +1569,5 @@ class PdfBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -14,21 +14,15 @@ namespace App\Services\Pdf;
|
|||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\Credit;
|
|
||||||
use App\Models\CreditInvitation;
|
use App\Models\CreditInvitation;
|
||||||
use App\Models\Currency;
|
use App\Models\Currency;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
|
||||||
use App\Models\InvoiceInvitation;
|
use App\Models\InvoiceInvitation;
|
||||||
use App\Models\PurchaseOrder;
|
|
||||||
use App\Models\PurchaseOrderInvitation;
|
use App\Models\PurchaseOrderInvitation;
|
||||||
use App\Models\Quote;
|
|
||||||
use App\Models\QuoteInvitation;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Models\RecurringInvoice;
|
|
||||||
use App\Models\RecurringInvoiceInvitation;
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
use App\Models\Vendor;
|
use App\Models\Vendor;
|
||||||
use App\Models\VendorContact;
|
use App\Models\VendorContact;
|
||||||
use App\Services\Pdf\PdfService;
|
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
@ -59,19 +53,23 @@ class PdfConfiguration
|
|||||||
|
|
||||||
public Currency $currency;
|
public Currency $currency;
|
||||||
|
|
||||||
|
public ?string $path;
|
||||||
|
|
||||||
|
public int $entity_design_id;
|
||||||
/**
|
/**
|
||||||
* The parent object of the currency
|
* The parent object of the currency
|
||||||
*
|
*
|
||||||
* @var App\Models\Client | App\Models\Vendor
|
* @var App\Models\Client | App\Models\Vendor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Client | Vendor $currency_entity;
|
public Client | Vendor $currency_entity;
|
||||||
|
|
||||||
public function __construct(public PdfService $service){}
|
public function __construct(public PdfService $service)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function init(): self
|
public function init(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->setEntityType()
|
$this->setEntityType()
|
||||||
->setPdfVariables()
|
->setPdfVariables()
|
||||||
->setDesign()
|
->setDesign()
|
||||||
@ -79,12 +77,10 @@ class PdfConfiguration
|
|||||||
->setLocale();
|
->setLocale();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setLocale(): self
|
private function setLocale(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
|
|
||||||
$t = app('translator');
|
$t = app('translator');
|
||||||
@ -94,23 +90,19 @@ class PdfConfiguration
|
|||||||
$t->replace(Ninja::transformTranslations($this->settings));
|
$t->replace(Ninja::transformTranslations($this->settings));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setCurrency(): self
|
private function setCurrency(): self
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->currency = $this->client ? $this->client->currency() : $this->vendor->currency();
|
$this->currency = $this->client ? $this->client->currency() : $this->vendor->currency();
|
||||||
|
|
||||||
$this->currency_entity = $this->client ? $this->client : $this->vendor;
|
$this->currency_entity = $this->client ? $this->client : $this->vendor;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setPdfVariables() :self
|
private function setPdfVariables() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
$default = (array) CompanySettings::getEntityVariableDefaults();
|
$default = (array) CompanySettings::getEntityVariableDefaults();
|
||||||
|
|
||||||
$variables = (array)$this->service->company->settings->pdf_variables;
|
$variables = (array)$this->service->company->settings->pdf_variables;
|
||||||
@ -126,12 +118,10 @@ class PdfConfiguration
|
|||||||
$this->pdf_variables = $variables;
|
$this->pdf_variables = $variables;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setEntityType()
|
private function setEntityType()
|
||||||
{
|
{
|
||||||
|
|
||||||
$entity_design_id = '';
|
$entity_design_id = '';
|
||||||
|
|
||||||
if ($this->service->invitation instanceof InvoiceInvitation) {
|
if ($this->service->invitation instanceof InvoiceInvitation) {
|
||||||
@ -188,18 +178,14 @@ class PdfConfiguration
|
|||||||
$this->path = $this->path.$this->entity->numberFormatter().'.pdf';
|
$this->path = $this->path.$this->entity->numberFormatter().'.pdf';
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setDesign()
|
private function setDesign()
|
||||||
{
|
{
|
||||||
|
|
||||||
$design_id = $this->entity->design_id ? : $this->decodePrimaryKey($this->settings_object->getSetting($this->entity_design_id));
|
$design_id = $this->entity->design_id ? : $this->decodePrimaryKey($this->settings_object->getSetting($this->entity_design_id));
|
||||||
|
|
||||||
$this->design = Design::find($design_id ?: 2);
|
$this->design = Design::find($design_id ?: 2);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -13,7 +13,6 @@ namespace App\Services\Pdf;
|
|||||||
|
|
||||||
class PdfDesigner
|
class PdfDesigner
|
||||||
{
|
{
|
||||||
|
|
||||||
const BOLD = 'bold';
|
const BOLD = 'bold';
|
||||||
const BUSINESS = 'business';
|
const BUSINESS = 'business';
|
||||||
const CLEAN = 'clean';
|
const CLEAN = 'clean';
|
||||||
@ -30,29 +29,19 @@ class PdfDesigner
|
|||||||
const STATEMENT = 'statement';
|
const STATEMENT = 'statement';
|
||||||
const PURCHASE_ORDER = 'purchase_order';
|
const PURCHASE_ORDER = 'purchase_order';
|
||||||
|
|
||||||
|
|
||||||
public PdfService $service;
|
|
||||||
|
|
||||||
public string $template;
|
public string $template;
|
||||||
|
|
||||||
public function __construct(PdfService $service)
|
public function __construct(public PdfService $service)
|
||||||
{
|
{
|
||||||
$this->service = $service;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function build() :self
|
public function build() :self
|
||||||
{
|
{
|
||||||
|
|
||||||
/*If the design is custom*/
|
/*If the design is custom*/
|
||||||
if ($this->service->config->design->is_custom)
|
if ($this->service->config->design->is_custom) {
|
||||||
{
|
|
||||||
|
|
||||||
$this->template = $this->composeFromPartials(json_decode(json_encode($this->service->config->design->design), true));
|
$this->template = $this->composeFromPartials(json_decode(json_encode($this->service->config->design->design), true));
|
||||||
|
} else {
|
||||||
}
|
$this->template = file_get_contents(config('ninja.designs.base_path') . strtolower($this->service->config->design->name) . '.html');
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->template = file_get_contents(config('ninja.designs.base_path') . strtolower($this->service->config->design->name) . '.html');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -63,12 +52,12 @@ class PdfDesigner
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the custom HTML design as
|
* Returns the custom HTML design as
|
||||||
* a string
|
* a string
|
||||||
*
|
*
|
||||||
* @param array
|
* @param array
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function composeFromPartials(array $partials) :string
|
private function composeFromPartials(array $partials) :string
|
||||||
{
|
{
|
||||||
@ -81,5 +70,4 @@ class PdfDesigner
|
|||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -18,8 +18,6 @@ use App\Models\InvoiceInvitation;
|
|||||||
use App\Models\PurchaseOrderInvitation;
|
use App\Models\PurchaseOrderInvitation;
|
||||||
use App\Models\QuoteInvitation;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Models\RecurringInvoiceInvitation;
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
use App\Services\Pdf\PdfConfiguration;
|
|
||||||
use App\Services\Pdf\PdfDesigner;
|
|
||||||
use App\Utils\HostedPDF\NinjaPdf;
|
use App\Utils\HostedPDF\NinjaPdf;
|
||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Utils\PhantomJS\Phantom;
|
||||||
@ -29,7 +27,6 @@ use App\Utils\VendorHtmlEngine;
|
|||||||
|
|
||||||
class PdfService
|
class PdfService
|
||||||
{
|
{
|
||||||
|
|
||||||
use PdfMaker, PageNumbering;
|
use PdfMaker, PageNumbering;
|
||||||
|
|
||||||
public InvoiceInvitation | QuoteInvitation | CreditInvitation | RecurringInvoiceInvitation | PurchaseOrderInvitation $invitation;
|
public InvoiceInvitation | QuoteInvitation | CreditInvitation | RecurringInvoiceInvitation | PurchaseOrderInvitation $invitation;
|
||||||
@ -57,7 +54,6 @@ class PdfService
|
|||||||
|
|
||||||
public function __construct($invitation, $document_type = 'product', $options = [])
|
public function __construct($invitation, $document_type = 'product', $options = [])
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->invitation = $invitation;
|
$this->invitation = $invitation;
|
||||||
|
|
||||||
$this->company = $invitation->company;
|
$this->company = $invitation->company;
|
||||||
@ -66,7 +62,7 @@ class PdfService
|
|||||||
|
|
||||||
$this->config = (new PdfConfiguration($this))->init();
|
$this->config = (new PdfConfiguration($this))->init();
|
||||||
|
|
||||||
$this->html_variables = $this->config->client ?
|
$this->html_variables = $this->config->client ?
|
||||||
(new HtmlEngine($invitation))->generateLabelsAndValues() :
|
(new HtmlEngine($invitation))->generateLabelsAndValues() :
|
||||||
(new VendorHtmlEngine($invitation))->generateLabelsAndValues();
|
(new VendorHtmlEngine($invitation))->generateLabelsAndValues();
|
||||||
|
|
||||||
@ -77,83 +73,55 @@ class PdfService
|
|||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
|
|
||||||
$this->builder = (new PdfBuilder($this))->build();
|
$this->builder = (new PdfBuilder($this))->build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the PDF generation type and
|
* Resolves the PDF generation type and
|
||||||
* attempts to generate a PDF from the HTML
|
* attempts to generate a PDF from the HTML
|
||||||
* string.
|
* string.
|
||||||
*
|
*
|
||||||
* @return mixed | Exception
|
* @return mixed | Exception
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getPdf()
|
public function getPdf()
|
||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
|
||||||
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom')
|
|
||||||
{
|
|
||||||
|
|
||||||
$pdf = (new Phantom)->convertHtmlToPdf($this->getHtml());
|
$pdf = (new Phantom)->convertHtmlToPdf($this->getHtml());
|
||||||
|
} elseif (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
|
||||||
}
|
|
||||||
elseif (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja')
|
|
||||||
{
|
|
||||||
|
|
||||||
$pdf = (new NinjaPdf())->build($this->getHtml());
|
$pdf = (new NinjaPdf())->build($this->getHtml());
|
||||||
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
$pdf = $this->makePdf(null, null, $this->getHtml());
|
$pdf = $this->makePdf(null, null, $this->getHtml());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
$numbered_pdf = $this->pageNumbering($pdf, $this->company);
|
||||||
|
|
||||||
if ($numbered_pdf)
|
if ($numbered_pdf) {
|
||||||
{
|
|
||||||
|
|
||||||
$pdf = $numbered_pdf;
|
$pdf = $numbered_pdf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
nlog(print_r($e->getMessage(), 1));
|
nlog(print_r($e->getMessage(), 1));
|
||||||
|
|
||||||
throw new \Exception($e->getMessage(), $e->getCode());
|
throw new \Exception($e->getMessage(), $e->getCode());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pdf;
|
return $pdf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the dom document to HTML
|
* Renders the dom document to HTML
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getHtml(): string
|
public function getHtml(): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$html = $this->builder->getCompiledHTML();
|
$html = $this->builder->getCompiledHTML();
|
||||||
|
|
||||||
if (config('ninja.log_pdf_html'))
|
if (config('ninja.log_pdf_html')) {
|
||||||
{
|
|
||||||
|
|
||||||
info($html);
|
info($html);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -17,7 +17,7 @@ use Tests\TestCase;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
//@covers App\DataMapper\BaseSettings
|
* @covers App\DataMapper\BaseSettings
|
||||||
*/
|
*/
|
||||||
class PdfGenerationTest extends TestCase
|
class PdfGenerationTest extends TestCase
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user