mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Resolve design template
This commit is contained in:
parent
bce476977b
commit
5cf629d5de
139
app/Services/Pdf/PdfBuilder.php
Normal file
139
app/Services/Pdf/PdfBuilder.php
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services\Pdf;
|
||||||
|
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
|
||||||
|
class PdfBuilder
|
||||||
|
{
|
||||||
|
|
||||||
|
public PdfService $service;
|
||||||
|
|
||||||
|
public function __construct(PdfService $service)
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
80
app/Services/Pdf/PdfDesigner.php
Normal file
80
app/Services/Pdf/PdfDesigner.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services\Pdf;
|
||||||
|
|
||||||
|
class PdfDesigner
|
||||||
|
{
|
||||||
|
|
||||||
|
const BOLD = 'bold';
|
||||||
|
const BUSINESS = 'business';
|
||||||
|
const CLEAN = 'clean';
|
||||||
|
const CREATIVE = 'creative';
|
||||||
|
const ELEGANT = 'elegant';
|
||||||
|
const HIPSTER = 'hipster';
|
||||||
|
const MODERN = 'modern';
|
||||||
|
const PLAIN = 'plain';
|
||||||
|
const PLAYFUL = 'playful';
|
||||||
|
const CUSTOM = 'custom';
|
||||||
|
const CALM = 'calm';
|
||||||
|
|
||||||
|
const DELIVERY_NOTE = 'delivery_note';
|
||||||
|
const STATEMENT = 'statement';
|
||||||
|
const PURCHASE_ORDER = 'purchase_order';
|
||||||
|
|
||||||
|
|
||||||
|
public PdfService $service;
|
||||||
|
|
||||||
|
public string $template;
|
||||||
|
|
||||||
|
public function __construct(PdfService $service)
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -172,10 +172,6 @@ class Design extends BaseDesign
|
|||||||
$this->sharedFooterElements(),
|
$this->sharedFooterElements(),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// 'swiss-qr' => [
|
|
||||||
// 'id' => 'swiss-qr',
|
|
||||||
// 'elements' => $this->swissQrCodeElement(),
|
|
||||||
// ]
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user