diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index e9f7891822..c761520592 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -16,6 +16,9 @@ use App\Designs\Designer; use App\Factory\InvoiceFactory; use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Util\PreviewPdf; +use App\Services\PdfMaker\Design; +use App\Services\PdfMaker\PdfMaker; +use App\Utils\HtmlEngine; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceHtml; use Illuminate\Support\Facades\DB; @@ -92,11 +95,32 @@ class PreviewController extends BaseController $entity_obj->load('client'); - $designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity)); + $html = new HtmlEngine(null, $entity_obj->invitations()->first(), request()->entity_type); - $html = $this->generateEntityHtml($designer, $entity_obj); + $design_namespace = 'App\Services\PdfMaker\Designs\\' . request()->design['name']; - $file_path = PreviewPdf::dispatchNow($html, auth()->user()->company()); + $design_class = new $design_namespace(); + + // $designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity)); + // $html = $this->generateEntityHtml($designer, $entity_obj); + + $state = [ + 'template' => $design_class->elements([ + 'client' => $entity_obj->client, + 'entity' => $entity_obj, + 'pdf_variables' => (array) $entity_obj->company->settings->pdf_variables, + ]), + 'variables' => $html->generateLabelsAndValues(), + ]; + + $design = new Design(request()->design['name']); + $maker = new PdfMaker($state); + + $maker + ->design($design) + ->build(); + + $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); return response()->download($file_path)->deleteFileAfterSend(true); } @@ -147,17 +171,37 @@ class PreviewController extends BaseController return response()->json(['message' => 'Invalid custom design object'], 400); } - $designer = new Designer($invoice, $design_object, auth()->user()->company()->settings->pdf_variables, lcfirst(request()->input('entity'))); + $html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice'); - $html = $this->generateEntityHtml($designer, $invoice, $contact); -info($html); - $file_path = PreviewPdf::dispatchNow($html, auth()->user()->company()); + $design = new Design(strtolower(request()->design['name'])); + + // $designer = new Designer($entity_obj, $design_object, $entity_obj->client->getSetting('pdf_variables'), lcfirst($entity)); + // $html = $this->generateEntityHtml($designer, $entity_obj); + + $state = [ + 'template' => $design->elements([ + 'client' => $invoice->client, + 'entity' => $invoice, + 'pdf_variables' => (array) $invoice->company->settings->pdf_variables, + ]), + 'variables' => $html->generateLabelsAndValues(), + ]; + + $maker = new PdfMaker($state); + + $maker + ->design($design) + ->build(); + + info($maker->getCompiledHTML(true)); + + $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); DB::rollBack(); $response = Response::make($file_path, 200); $response->header('Content-Type', 'application/pdf'); - return $response; + return $response; } } diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 2d81fcdd7a..7f62682e2a 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -20,6 +20,7 @@ use App\Models\ClientContact; use App\Models\Company; use App\Models\Design; use App\Models\Invoice; +use App\Services\PdfMaker\Design as PdfMakerDesign; use App\Services\PdfMaker\PdfMaker as PdfMakerService; use App\Utils\HtmlEngine; use App\Utils\PhantomJS\Phantom; @@ -86,17 +87,13 @@ class CreateInvoicePdf implements ShouldQueue $html = new HtmlEngine(null, $this->invitation, 'invoice'); - $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); + $template = new PdfMakerDesign(strtolower($design->name)); $state = [ - 'template' => $design_class->elements([ + 'template' => $template->elements([ 'client' => $this->invoice->client, 'entity' => $this->invoice, - 'product-table-columns' => $pdf_variables['product_columns'], + 'pdf_variables' => (array)$this->invoice->company->settings->pdf_variables, ]), 'variables' => $html->generateLabelsAndValues(), 'options' => [ @@ -108,15 +105,15 @@ class CreateInvoicePdf implements ShouldQueue $maker = new PdfMakerService($state); $maker - ->design($design_namespace) + ->design($template) ->build(); //todo - move this to the client creation stage so we don't keep hitting this unnecessarily Storage::makeDirectory($path, 0775); - info($maker->getCompiledHTML()); + info($maker->getCompiledHTML(true)); - $pdf = $this->makePdf(null, null, $maker->getCompiledHTML()); + $pdf = $this->makePdf(null, null, $maker->getCompiledHTML(true)); $instance = Storage::disk($this->disk)->put($file_path, $pdf); diff --git a/app/Jobs/Quote/CreateQuotePdf.php b/app/Jobs/Quote/CreateQuotePdf.php index e7bb0d2381..4c63eacb1a 100644 --- a/app/Jobs/Quote/CreateQuotePdf.php +++ b/app/Jobs/Quote/CreateQuotePdf.php @@ -94,7 +94,7 @@ class CreateQuotePdf implements ShouldQueue 'template' => $design_class->elements([ 'client' => $this->quote->client, 'entity' => $this->quote, - 'product-table-columns' => $pdf_variables['product_columns'], + 'pdf_variables' => (array)$this->quote->company->settings->pdf_variables, ]), 'variables' => $html->generateLabelsAndValues(), 'options' => [ diff --git a/app/Services/PdfMaker/Designs/Modern.php b/app/Services/PdfMaker/Design.php similarity index 62% rename from app/Services/PdfMaker/Designs/Modern.php rename to app/Services/PdfMaker/Design.php index 8ffbd31713..f97c85ed0c 100644 --- a/app/Services/PdfMaker/Designs/Modern.php +++ b/app/Services/PdfMaker/Design.php @@ -10,22 +10,17 @@ * @license https://opensource.org/licenses/AAL */ -namespace App\Services\PdfMaker\Designs; +namespace App\Services\PdfMaker; +use Illuminate\Support\Str; +use App\Utils\Traits\MakesInvoiceValues; use App\Services\PdfMaker\Designs\Utilities\BaseDesign; use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; -use App\Utils\Traits\MakesInvoiceValues; -class Modern extends BaseDesign +class Design extends BaseDesign { use MakesInvoiceValues, DesignHelpers; - /** Global list of table elements, @var array */ - public $elements; - - /** @var App\Models\Client */ - public $client; - /** @var App\Models\Invoice || @var App\Models\Quote */ public $entity; @@ -35,10 +30,37 @@ class Modern extends BaseDesign /** Type of entity => product||task */ public $type; - public function html() + /** Design string */ + public $design; + + /** Construct options */ + public $options; + + 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'; + + public function __construct(string $design = null, array $options = []) { + Str::endsWith('.html', $design) ? $this->design = $design : $this->design = "{$design}.html"; + + $this->options = $options; + } + + public function html(): ?string + { + $path = isset($this->options['custom_path']) + ? $this->options['custom_path'] + : config('ninja.designs.base_path'); + return file_get_contents( - base_path('resources/views/pdf-designs/modern.html') + $path . $this->design ); } @@ -51,18 +73,6 @@ class Modern extends BaseDesign $this->setup(); return [ - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], 'company-details' => [ 'id' => 'company-details', 'elements' => $this->companyDetails(), @@ -71,6 +81,18 @@ class Modern extends BaseDesign 'id' => 'company-address', 'elements' => $this->companyAddress(), ], + 'client-details' => [ + 'id' => 'client-details', + 'elements' => $this->clientDetails(), + ], + 'entity-details' => [ + 'id' => 'entity-details', + 'elements' => $this->entityDetails(), + ], + 'product-table' => [ + 'id' => 'product-table', + 'elements' => $this->productTable(), + ], 'footer-elements' => [ 'id' => 'footer', 'elements' => [ @@ -80,29 +102,9 @@ class Modern extends BaseDesign ]; } - public function entityDetails(): array + public function companyDetails() { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-16 lg:pr-24 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-16 lg:pr-24 font-normal']], - ]]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; + $variables = $this->context['pdf_variables']['company_details']; $elements = []; @@ -113,12 +115,58 @@ class Modern extends BaseDesign return $elements; } + public function companyAddress(): array + { + $variables = $this->context['pdf_variables']['company_address']; + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'p', 'content' => $variable]; + } + + return $elements; + } + + public function clientDetails(): array + { + $variables = $this->context['pdf_variables']['client_details']; + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'p', 'content' => $variable]; + } + + return $elements; + } + + public function entityDetails(): array + { + $variables = $this->context['pdf_variables']['invoice_details']; + + if ($this->entity instanceof \App\Models\Quote) { + $variables = $this->context['pdf_variables']['quote_details']; + } + + $elements = []; + + foreach ($variables as $variable) { + $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'elements' => [ + ['element' => 'th', 'content' => $variable . '_label'], + ['element' => 'th', 'content' => $variable], + ]]; + } + + return $elements; + } + public function productTable(): array { 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' => $this->tableFooter()], + ['element' => 'thead', 'elements' => $this->buildTableHeader()], + ['element' => 'tbody', 'elements' => $this->buildTableBody()], + ['element' => 'tfoot', 'elements' => $this->tableFooter()], ]; } @@ -128,8 +176,8 @@ class Modern extends BaseDesign $elements = []; - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']]; + foreach ($this->context['pdf_variables']["{$this->type}_columns"] as $column) { + $elements[] = ['element' => 'th', 'content' => $column . '_label']; } return $elements; @@ -146,10 +194,10 @@ class Modern extends BaseDesign } foreach ($items as $row) { - $element = ['element' => 'tr', 'properties' => ['class' => 'border-t border-b border-gray-900'], 'content' => '', 'elements' => []]; + $element = ['element' => 'tr', 'elements' => []]; - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-4']]; + foreach ($this->context['pdf_variables']["{$this->type}_columns"] as $key => $cell) { + $element['elements'][] = ['element' => 'td', 'content' => $row[$cell]]; } $elements[] = $element; @@ -160,47 +208,26 @@ class Modern extends BaseDesign public function tableFooter() { - $variables = $this->entity->company->settings->pdf_variables->total_columns; + $variables = $this->context['pdf_variables']['total_columns']; $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], + ['element' => 'tr', 'elements' => [ + ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['colspan' => '100%']], ]], ]; foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], + if ($variable == '$total_taxes' || $variable == '$line_taxes') { + continue; + } + + $elements[] = ['element' => 'tr', 'elements' => [ + ['element' => 'td', 'properties' => ['colspan' => $this->calculateColspan(2)]], + ['element' => 'td', 'content' => $variable . '_label'], + ['element' => 'td', 'content' => $variable], ]]; } return $elements; } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } } diff --git a/app/Services/PdfMaker/Designs/Bold.php b/app/Services/PdfMaker/Designs/Bold.php deleted file mode 100644 index 264aee2a6b..0000000000 --- a/app/Services/PdfMaker/Designs/Bold.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/bold.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context["{$this->type}-table-columns"] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'text-xl px-4 py-2']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Business.php b/app/Services/PdfMaker/Designs/Business.php deleted file mode 100644 index a8a3410ad9..0000000000 --- a/app/Services/PdfMaker/Designs/Business.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/business.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-semibold text-white px-4 bg-blue-900 py-5']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-4 border-white px-4 py-4 bg-gray-200']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Clean.php b/app/Services/PdfMaker/Designs/Clean.php deleted file mode 100644 index 93189806b3..0000000000 --- a/app/Services/PdfMaker/Designs/Clean.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/clean.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left rounded-t-lg'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-semibold px-4 py-5']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t border-b px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Creative.php b/app/Services/PdfMaker/Designs/Creative.php deleted file mode 100644 index 1cd4e0fd73..0000000000 --- a/app/Services/PdfMaker/Designs/Creative.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/creative.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-medium uppercase text-pink-700 text-xl px-4 py-5']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Elegant.php b/app/Services/PdfMaker/Designs/Elegant.php deleted file mode 100644 index 2f11f2589e..0000000000 --- a/app/Services/PdfMaker/Designs/Elegant.php +++ /dev/null @@ -1,207 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/elegant.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-normal']], - ]]; - } - - return $elements; - } - - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function productTable(): array - { - 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' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-normal text-green-700 px-4 py-2']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $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']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Hipster.php b/app/Services/PdfMaker/Designs/Hipster.php deleted file mode 100644 index 3c622760eb..0000000000 --- a/app/Services/PdfMaker/Designs/Hipster.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/hipster.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'div', 'properties' => ['hidden' => $this->entityVariableCheck($variable), 'class' => 'space-x-4'], 'content' => '', 'elements' => [ - ['element' => 'span', 'content' => $variable . '_label', 'properties' => ['class' => 'font-semibold uppercase text-yellow-600']], - ['element' => 'span', 'content' => $variable, 'properties' => ['class' => 'uppercase']], - ]]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 uppercase']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-l-2 border-black px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'px-4 py-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'border-l-2 border-black px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Plain.php b/app/Services/PdfMaker/Designs/Plain.php deleted file mode 100644 index 48c7878198..0000000000 --- a/app/Services/PdfMaker/Designs/Plain.php +++ /dev/null @@ -1,191 +0,0 @@ - product||task */ - public $type; - - public function html(): ?string - { - return file_get_contents( - base_path('resources/views/pdf-designs/plain.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function entityDetails(): array - { - $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) { - $element = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-medium']], - ]]; - - $elements[] = $element; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-gray-200'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'px-4 py-2']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'border-t-2 border-b border-gray-200 px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Playful.php b/app/Services/PdfMaker/Designs/Playful.php deleted file mode 100644 index 906caeaebb..0000000000 --- a/app/Services/PdfMaker/Designs/Playful.php +++ /dev/null @@ -1,206 +0,0 @@ - product||task */ - public $type; - - public function html() - { - return file_get_contents( - base_path('resources/views/pdf-designs/playful.html') - ); - } - - public function elements(array $context, string $type = 'product'): array - { - $this->context = $context; - - $this->type = $type; - - $this->setup(); - - return [ - 'entity-details' => [ - 'id' => 'entity-details', - 'elements' => $this->entityDetails(), - ], - 'company-details' => [ - 'id' => 'company-details', - 'elements' => $this->companyDetails(), - ], - 'company-address' => [ - 'id' => 'company-address', - 'elements' => $this->companyAddress(), - ], - 'client-details' => [ - 'id' => 'client-details', - 'elements' => $this->clientDetails(), - ], - 'product-table' => [ - 'id' => 'product-table', - 'elements' => $this->productTable(), - ], - 'footer-elements' => [ - 'id' => 'footer', - 'elements' => [ - $this->sharedFooterElements(), - ], - ], - ]; - } - - public function entityDetails(): array - { - $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) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->entityVariableCheck($variable)], 'content' => '', 'elements' => [ - ['element' => 'th', 'content' => $variable . '_label', 'properties' => ['class' => 'text-left pr-4 font-normal']], - ['element' => 'th', 'content' => $variable, 'properties' => ['class' => 'text-left pr-4 font-medium']], - ]]; - } - - return $elements; - } - - public function companyDetails() - { - $variables = $this->entity->company->settings->pdf_variables->company_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function companyAddress(): array - { - $variables = $this->entity->company->settings->pdf_variables->company_address; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function clientDetails(): array - { - $variables = $this->entity->company->settings->pdf_variables->client_details; - - $elements = []; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'p', 'content' => $variable]; - } - - return $elements; - } - - public function productTable(): array - { - return [ - ['element' => 'thead', 'content' => '', 'properties' => ['class' => 'text-left bg-teal-600'], 'elements' => $this->buildTableHeader()], - ['element' => 'tbody', 'content' => '', 'elements' => $this->buildTableBody()], - ['element' => 'tfoot', 'content' => '', 'elements' => $this->tableFooter()], - ]; - } - - public function buildTableHeader(): array - { - $this->processTaxColumns(); - - $elements = []; - - foreach ($this->context['product-table-columns'] as $column) { - $elements[] = ['element' => 'th', 'content' => $column . '_label', 'properties' => ['class' => 'font-semibold text-white px-4 py-3']]; - } - - return $elements; - } - - public function buildTableBody(): array - { - $elements = []; - - $items = $this->transformLineItems($this->entity->line_items); - - if (count($items) == 0) { - return []; - } - - foreach ($items as $row) { - $element = ['element' => 'tr', 'properties' => ['class' => 'border-b-2 border-teal-600'], 'content' => '', 'elements' => []]; - - foreach ($this->context['product-table-columns'] as $key => $cell) { - $element['elements'][] = ['element' => 'td', 'content' => $row[$cell], 'properties' => ['class' => 'px-4 py-4']]; - } - - $elements[] = $element; - } - - return $elements; - } - - public function tableFooter() - { - $variables = $this->entity->company->settings->pdf_variables->total_columns; - - $elements = [ - ['element' => 'tr', 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => '$entity.public_notes', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => '100%']], - ]], - ]; - - foreach ($variables as $variable) { - $elements[] = ['element' => 'tr', 'properties' => ['hidden' => $this->toggleHiddenProperty($this->entity->calc()->getTotalDiscount())], 'content' => '', 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['class' => 'border-l-4 border-white px-4 text-right', 'colspan' => $this->calculateColspan(1)]], - ['element' => 'td', 'content' => $variable, 'properties' => ['class' => 'px-4 py-2 text-right']], - ]]; - } - - return $elements; - } -} diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index 844842b542..724db96dfb 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -79,10 +79,10 @@ trait DesignHelpers $document->importNode($element, true) ); - return $document->saveHTML(); + return $document->saveXML(); } - return null; + return ''; } /** @@ -96,7 +96,7 @@ trait DesignHelpers */ public function processTaxColumns(): void { - if (in_array('$product.tax', $this->context['product-table-columns'])) { + if (in_array('$product.tax', (array)$this->context['pdf_variables']['product_columns'])) { $line_items = collect($this->entity->line_items); $tax1 = $line_items->where('tax_name1', '<>', '')->where('type_id', 1)->count(); @@ -116,10 +116,10 @@ trait DesignHelpers array_push($taxes, '$product.tax_rate3'); } - $key = array_search('$product.tax', $this->context['product-table-columns'], true); + $key = array_search('$product.tax', $this->context['pdf_variables']['product_columns'], true); if ($key) { - array_splice($this->context['product-table-columns'], $key, 1, $taxes); + array_splice($this->context['pdf_variables']['product_columns'], $key, 1, $taxes); } } } @@ -132,7 +132,7 @@ trait DesignHelpers */ public function calculateColspan(int $taken): int { - $total = (int) count($this->context['product-table-columns']); + $total = (int) count($this->context['pdf_variables']['product_columns']); return (int)$total - $taken; } @@ -159,9 +159,9 @@ trait DesignHelpers 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']], + return ['element' => 'div', 'properties' => ['style' => 'display: flex; justify-content: space-between'], 'elements' => [ + ['element' => 'img', 'properties' => ['src' => '$contact.signature', 'style' => 'height: 5rem;']], + ['element' => 'img', 'properties' => ['src' => '$app_url/images/created-by-invoiceninja-new.png', 'style' => 'height: 5rem;', 'hidden' => $this->entity->user->account->isPaid() ? 'true' : 'false']], ]]; } @@ -177,16 +177,13 @@ trait DesignHelpers } if (is_null($this->entity->{$_variable})) { - // info("{$this->entity->id} $_variable is null!"); return true; } if (empty($this->entity->{$_variable})) { - // info("{$this->entity->id} $_variable is empty!"); return true; } - // info("{$this->entity->id} $_variable ALL GOOD!!"); return false; } } diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index 7e0e793fcb..e399f8b289 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -28,6 +28,8 @@ class PdfMaker private $filters = [ ' '', + ' '', + ']]]]>]]>' => '', ']]>' => '', '' => '', ]; @@ -43,9 +45,9 @@ class PdfMaker } } - public function design(string $design) + public function design(Design $design) { - $this->design = new $design(); + $this->design = $design; $this->initializeDomDocument(); @@ -71,12 +73,12 @@ class PdfMaker { if ($final) { $html = $this->document->saveXML(); - + $filtered = strtr($html, $this->filters); - + return $filtered; } - + return $this->document->saveXML(); } } diff --git a/app/Services/PdfMaker/PdfMakerUtilities.php b/app/Services/PdfMaker/PdfMakerUtilities.php index af2444478e..6339d2f27b 100644 --- a/app/Services/PdfMaker/PdfMakerUtilities.php +++ b/app/Services/PdfMaker/PdfMakerUtilities.php @@ -48,10 +48,17 @@ trait PdfMakerUtilities public function updateElementProperties(array $elements) { foreach ($elements as $element) { + + // if (!isset($element['tag']) || !isset($element['id']) || is_null($this->document->getElementById($element['id']))) { + // continue; + // } + if (isset($element['tag'])) { $node = $this->document->getElementsByTagName($element['tag'])->item(0); - } else { + } elseif(!is_null($this->document->getElementById($element['id']))) { $node = $this->document->getElementById($element['id']); + } else { + continue; } if (isset($element['properties'])) { @@ -109,7 +116,7 @@ trait PdfMakerUtilities public function createElementContent($element, $children) { foreach ($children as $child) { - $_child = $this->document->createElement($child['element'], $child['content']); + $_child = $this->document->createElement($child['element'], isset($child['content']) ? $child['content'] : ''); $element->appendChild($_child); if (isset($child['properties'])) { @@ -259,7 +266,7 @@ trait PdfMakerUtilities } if ( - $header = $this->document->getElementById('header') && + $header = $this->document->getElementById('header') && isset($this->data['options']['all_pages_header']) && $this->data['options']['all_pages_header'] ) { diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 0accbcac6f..c5895f2a19 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -483,7 +483,8 @@ class HtmlEngine } foreach ($this->entity_calc->getTotalTaxMap() as $tax) { - $data .= ''; + $data .= ''; + $data .= ''; $data .= ''. $tax['name'] .''; $data .= ''. Number::formatMoney($tax['total'], $this->client) .''; } diff --git a/config/ninja.php b/config/ninja.php index 29eeb1c5ad..8f8d544ce5 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -128,5 +128,8 @@ return [ 'system' => [ 'node_path' => env('NODE_PATH', false), 'npm_path' => env('NPM_PATH', false) - ] + ], + 'designs' => [ + 'base_path' => resource_path('views/pdf-designs/'), + ], ]; diff --git a/database/seeds/DesignSeeder.php b/database/seeds/DesignSeeder.php index 129a308de8..06ce6dd897 100644 --- a/database/seeds/DesignSeeder.php +++ b/database/seeds/DesignSeeder.php @@ -2,6 +2,7 @@ use App\Models\Bank; use App\Models\Design; +use App\Services\PdfMaker\Design as PdfMakerDesign; use Illuminate\Database\Seeder; class DesignSeeder extends Seeder @@ -36,16 +37,16 @@ class DesignSeeder extends Seeder } foreach (Design::all() as $design) { - $class = 'App\Designs\\'.$design->name; - $invoice_design = new $class(); + $template = new PdfMakerDesign(strtolower($design->name)); + $template->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 = $template->getSectionHTML('includes'); + $design_object->header = $template->getSectionHTML('head', false); + $design_object->body = $template->getSectionHTML('body', false); + $design_object->product = $template->getSectionHTML('product-table'); + $design_object->task = $template->getSectionHTML('task-table'); + $design_object->footer = $template->getSectionHTML('footer', false); $design->design = $design_object; $design->save(); diff --git a/resources/views/pdf-designs/bold.html b/resources/views/pdf-designs/bold.html index 20ad3a369a..1cf41f0eb7 100644 --- a/resources/views/pdf-designs/bold.html +++ b/resources/views/pdf-designs/bold.html @@ -1,77 +1,140 @@ - - - - - - - + + + + - - - -