diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index a7f907946ad8..c76152059250 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -16,6 +16,7 @@ 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; @@ -112,13 +113,14 @@ class PreviewController extends BaseController 'variables' => $html->generateLabelsAndValues(), ]; + $design = new Design(request()->design['name']); $maker = new PdfMaker($state); $maker - ->design($design_namespace) + ->design($design) ->build(); - $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(), auth()->user()->company()); + $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); return response()->download($file_path)->deleteFileAfterSend(true); } @@ -171,16 +173,13 @@ class PreviewController extends BaseController $html = new HtmlEngine(null, $invoice->invitations()->first(), 'invoice'); - /** TODO: This request() does not contain design string - making it impossible to update its content. */ - $design_namespace = 'App\Services\PdfMaker\Designs\\' . request()->design['name']; - - $design_class = new $design_namespace(); + $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_class->elements([ + 'template' => $design->elements([ 'client' => $invoice->client, 'entity' => $invoice, 'pdf_variables' => (array) $invoice->company->settings->pdf_variables, @@ -191,12 +190,12 @@ class PreviewController extends BaseController $maker = new PdfMaker($state); $maker - ->design($design_namespace) + ->design($design) ->build(); - $maker->getCompiledHTML(); + info($maker->getCompiledHTML(true)); - $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(), auth()->user()->company()); + $file_path = PreviewPdf::dispatchNow($maker->getCompiledHTML(true), auth()->user()->company()); DB::rollBack(); diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 968ed24eeb95..7f62682e2a14 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,12 +87,10 @@ class CreateInvoicePdf implements ShouldQueue $html = new HtmlEngine(null, $this->invitation, 'invoice'); - $design_namespace = 'App\Services\PdfMaker\Designs\\' . $design->name; - - $design_class = new $design_namespace(); + $template = new PdfMakerDesign(strtolower($design->name)); $state = [ - 'template' => $design_class->elements([ + 'template' => $template->elements([ 'client' => $this->invoice->client, 'entity' => $this->invoice, 'pdf_variables' => (array)$this->invoice->company->settings->pdf_variables, @@ -106,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/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 59a2c0cac1dc..f97c85ed0cbe 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -12,9 +12,10 @@ 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 Design extends BaseDesign { @@ -35,19 +36,19 @@ class Design extends BaseDesign /** Construct options */ public $options; - const BOLD = 'bold.html'; - const BUSINESS = 'business.html'; - const CLEAN = 'clean.html'; - const CREATIVE = 'creative.html'; - const ELEGANT = 'elegant.html'; - const HIPSTER = 'hipster.html'; - const MODERN = 'modern.html'; - const PLAIN = 'plain.html'; - const PLAYFUL = 'playful.html'; + 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 = []) { - $this->design = $design; + Str::endsWith('.html', $design) ? $this->design = $design : $this->design = "{$design}.html"; $this->options = $options; } @@ -216,8 +217,13 @@ class Design extends BaseDesign ]; foreach ($variables as $variable) { - ['element' => 'tr', 'properties' => ['hidden' => 'false'], 'elements' => [ - ['element' => 'td', 'content' => $variable . '_label', 'properties' => ['colspan' => $this->calculateColspan(1)]], + 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], ]]; } diff --git a/app/Services/PdfMaker/PdfMaker.php b/app/Services/PdfMaker/PdfMaker.php index 57460b0f565b..e399f8b2892a 100644 --- a/app/Services/PdfMaker/PdfMaker.php +++ b/app/Services/PdfMaker/PdfMaker.php @@ -28,6 +28,8 @@ class PdfMaker private $filters = [ ' '', + ' '', + ']]]]>]]>' => '', ']]>' => '', '' => '', ]; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 0accbcac6f17..c5895f2a19d5 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 .= '