diff --git a/app/Services/Pdf/PdfBuilder.php b/app/Services/Pdf/PdfBuilder.php new file mode 100644 index 000000000000..cbe7f402f544 --- /dev/null +++ b/app/Services/Pdf/PdfBuilder.php @@ -0,0 +1,139 @@ +service = $service; + } + + public function build() + { + + $this->getTemplate() + ->buildSections(); + + } + + private function getTemplate() :self + { + + $document = new DOMDocument(); + + $document->validateOnParse = true; + @$document->loadHTML(mb_convert_encoding($this->service->config->designer->template, 'HTML-ENTITIES', 'UTF-8')); + + $this->document = $document; + $this->xpath = new DOMXPath($document); + + return $this; + } + + private function buildSections() :self + { + $this->sections = [ + 'company-details' => [ + 'id' => 'company-details', + 'elements' => $this->companyDetails(), + ], + 'company-address' => [ + 'id' => 'company-address', + 'elements' => $this->companyAddress(), + ], + 'client-details' => [ + 'id' => 'client-details', + 'elements' => $this->clientDetails(), + ], + 'vendor-details' => [ + 'id' => 'vendor-details', + 'elements' => $this->vendorDetails(), + ], + 'entity-details' => [ + 'id' => 'entity-details', + 'elements' => $this->entityDetails(), + ], + 'delivery-note-table' => [ + 'id' => 'delivery-note-table', + 'elements' => $this->deliveryNoteTable(), + ], + 'product-table' => [ + 'id' => 'product-table', + 'elements' => $this->productTable(), + ], + 'task-table' => [ + 'id' => 'task-table', + 'elements' => $this->taskTable(), + ], + 'statement-invoice-table' => [ + 'id' => 'statement-invoice-table', + 'elements' => $this->statementInvoiceTable(), + ], + 'statement-invoice-table-totals' => [ + 'id' => 'statement-invoice-table-totals', + 'elements' => $this->statementInvoiceTableTotals(), + ], + 'statement-payment-table' => [ + 'id' => 'statement-payment-table', + 'elements' => $this->statementPaymentTable(), + ], + 'statement-payment-table-totals' => [ + 'id' => 'statement-payment-table-totals', + 'elements' => $this->statementPaymentTableTotals(), + ], + 'statement-aging-table' => [ + 'id' => 'statement-aging-table', + 'elements' => $this->statementAgingTable(), + ], + 'table-totals' => [ + 'id' => 'table-totals', + 'elements' => $this->tableTotals(), + ], + 'footer-elements' => [ + 'id' => 'footer', + 'elements' => [ + $this->sharedFooterElements(), + ], + ], + ]; + + return $this; + + } + + + + // if (isset($this->data['template']) && isset($this->data['variables'])) { + // $this->getEmptyElements($this->data['template'], $this->data['variables']); + // } + + // if (isset($this->data['template'])) { + // $this->updateElementProperties($this->data['template']); + // } + + // if (isset($this->data['variables'])) { + // $this->updateVariables($this->data['variables']); + // } + + // return $this; + + + + +} \ No newline at end of file diff --git a/app/Services/Pdf/PdfDesigner.php b/app/Services/Pdf/PdfDesigner.php new file mode 100644 index 000000000000..0f7cf9671226 --- /dev/null +++ b/app/Services/Pdf/PdfDesigner.php @@ -0,0 +1,80 @@ +service = $service; + } + + public function build() :self + { + + /*If the design is custom*/ + if ($this->service->config->design->is_custom) + { + + $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'); + } + + return $this; + } + + /** + * If the user has implemented a custom design, then we need to rebuild the design at this point + */ + private function composeFromPartials(array $partials) :string + { + $html = ''; + + $html .= $partials['includes']; + $html .= $partials['header']; + $html .= $partials['body']; + $html .= $partials['footer']; + + return $html; + } + + + + + +} \ No newline at end of file diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index df0d16ebae21..3ca76e076f0e 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -172,10 +172,6 @@ class Design extends BaseDesign $this->sharedFooterElements(), ], ], - // 'swiss-qr' => [ - // 'id' => 'swiss-qr', - // 'elements' => $this->swissQrCodeElement(), - // ] ]; }