2022-12-23 03:58:08 +01:00
|
|
|
<?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 string $template;
|
|
|
|
|
2023-02-21 08:39:07 +01:00
|
|
|
public function __construct(public PdfService $service)
|
2022-12-23 03:58:08 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function build() :self
|
|
|
|
{
|
|
|
|
/*If the design is custom*/
|
2023-02-21 08:39:07 +01:00
|
|
|
if ($this->service->config->design->is_custom) {
|
2022-12-23 03:58:08 +01:00
|
|
|
$this->template = $this->composeFromPartials(json_decode(json_encode($this->service->config->design->design), true));
|
2023-02-21 08:39:07 +01:00
|
|
|
} else {
|
|
|
|
$this->template = file_get_contents(config('ninja.designs.base_path') . strtolower($this->service->config->design->name) . '.html');
|
2022-12-23 03:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the user has implemented a custom design, then we need to rebuild the design at this point
|
|
|
|
*/
|
2022-12-28 11:28:58 +01:00
|
|
|
|
|
|
|
/**
|
2023-02-21 08:39:07 +01:00
|
|
|
* Returns the custom HTML design as
|
2022-12-28 11:28:58 +01:00
|
|
|
* a string
|
2023-02-21 08:39:07 +01:00
|
|
|
*
|
2022-12-28 11:28:58 +01:00
|
|
|
* @param array
|
|
|
|
* @return string
|
2023-02-21 08:39:07 +01:00
|
|
|
*
|
2022-12-28 11:28:58 +01:00
|
|
|
*/
|
2022-12-23 03:58:08 +01:00
|
|
|
private function composeFromPartials(array $partials) :string
|
|
|
|
{
|
|
|
|
$html = '';
|
|
|
|
|
|
|
|
$html .= $partials['includes'];
|
|
|
|
$html .= $partials['header'];
|
|
|
|
$html .= $partials['body'];
|
|
|
|
$html .= $partials['footer'];
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2023-02-21 08:39:07 +01:00
|
|
|
}
|