diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 137e0d085abb..375b9ca38b13 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -197,7 +197,6 @@ class PreviewController extends BaseController return response()->json(['message' => 'This server cannot handle this request.'], 400); } - $company = auth()->user()->company(); MultiDB::setDb($company->db); diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index 34a6fe52d5a3..6766763bdc51 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -102,7 +102,12 @@ class PdfMock return $entity; } - + + /** + * getMergedSettings + * + * @return object + */ public function getMergedSettings() :object { match ($this->request['settings_type']) { @@ -115,17 +120,32 @@ class PdfMock return $settings; } - + + /** + * getTaxMap + * + * @return void + */ private function getTaxMap() { return collect([['name' => 'GST', 'total' => 10]]); } - + + /** + * getTotalTaxMap + * + * @return void + */ private function getTotalTaxMap() { return [['name' => 'GST', 'total' => 10]]; } - + + /** + * getStubVariables + * + * @return void + */ public function getStubVariables() { return ['values' => diff --git a/app/Services/Pdf/PdfService.php b/app/Services/Pdf/PdfService.php index d18e98ec7b06..77c99919ed1d 100644 --- a/app/Services/Pdf/PdfService.php +++ b/app/Services/Pdf/PdfService.php @@ -61,18 +61,25 @@ class PdfService $this->options = $options; } + public function boot(): self + { + $this->init(); + + return $this; + } + /** * Resolves the PDF generation type and * attempts to generate a PDF from the HTML * string. - * + * * @return mixed | Exception * */ public function getPdf() { try { - $pdf = $this->init()->resolvePdfEngine($this->getHtml()); + $pdf = $this->resolvePdfEngine($this->getHtml()); $numbered_pdf = $this->pageNumbering($pdf, $this->company); @@ -95,7 +102,6 @@ class PdfService */ public function getHtml(): string { - $this->init(); $html = $this->builder->getCompiledHTML(); diff --git a/tests/Pdf/PdfServiceTest.php b/tests/Pdf/PdfServiceTest.php index 384215809165..4bba1ff7b01d 100644 --- a/tests/Pdf/PdfServiceTest.php +++ b/tests/Pdf/PdfServiceTest.php @@ -38,7 +38,7 @@ class PdfServiceTest extends TestCase $invitation = $this->invoice->invitations->first(); - $service = new PdfService($invitation); + $service = (new PdfService($invitation))->boot(); $this->assertNotNull($service->getPdf()); @@ -49,7 +49,7 @@ class PdfServiceTest extends TestCase $invitation = $this->invoice->invitations->first(); - $service = new PdfService($invitation); + $service = (new PdfService($invitation))->boot(); $this->assertIsString($service->getHtml()); @@ -60,7 +60,7 @@ class PdfServiceTest extends TestCase $invitation = $this->invoice->invitations->first(); - $service = new PdfService($invitation); + $service = (new PdfService($invitation))->boot(); $this->assertInstanceOf(PdfService::class, $service); @@ -71,7 +71,7 @@ class PdfServiceTest extends TestCase $invitation = $this->invoice->invitations->first(); - $service = (new PdfService($invitation))->init(); + $service = (new PdfService($invitation))->boot(); $this->assertInstanceOf(PdfConfiguration::class, $service->config); @@ -82,7 +82,7 @@ class PdfServiceTest extends TestCase { $invitation = $this->invoice->invitations->first(); - $service = (new PdfService($invitation))->init(); + $service = (new PdfService($invitation))->boot(); $this->assertEquals(2, $service->config->design->id); @@ -92,7 +92,7 @@ class PdfServiceTest extends TestCase { $invitation = $this->invoice->invitations->first(); - $service = (new PdfService($invitation))->init(); + $service = (new PdfService($invitation))->boot(); $this->assertIsArray($service->html_variables); @@ -102,7 +102,7 @@ class PdfServiceTest extends TestCase { $invitation = $this->invoice->invitations->first(); - $service = (new PdfService($invitation))->init(); + $service = (new PdfService($invitation))->boot(); $this->assertIsString($service->designer->template);