From 57317630714d9eb04357002032054e22b3b6c826 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 19 Sep 2024 13:38:03 +1000 Subject: [PATCH] Fixes for previews --- app/Http/Controllers/PreviewController.php | 2 ++ app/Jobs/Mailgun/ProcessMailgunWebhook.php | 2 +- app/Services/Pdf/PdfMock.php | 6 +++--- app/Services/Template/TemplateService.php | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 517f36ce47..3ddc283fbc 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -293,9 +293,11 @@ class PreviewController extends BaseController $ts = (new TemplateService()); try { + $ts->setCompany($company) ->setTemplate($design_object) ->mock(); + } catch(SyntaxError $e) { } catch(\Exception $e) { return response()->json(['message' => 'invalid data access', 'errors' => ['design.design.body' => $e->getMessage()]], 422); diff --git a/app/Jobs/Mailgun/ProcessMailgunWebhook.php b/app/Jobs/Mailgun/ProcessMailgunWebhook.php index b0f1ed65aa..0f01612091 100644 --- a/app/Jobs/Mailgun/ProcessMailgunWebhook.php +++ b/app/Jobs/Mailgun/ProcessMailgunWebhook.php @@ -362,7 +362,7 @@ class ProcessMailgunWebhook implements ShouldQueue $bounce = new EmailBounce( $this->request['event-data']['tags'][0], - $this->request['event-data']['envelope']['sender'], + $this->request['event-data']['envelope']['sender'] ?? $this->request['event-data']['envelope']['from'], $this->message_id ); diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index 5ef5350e9d..91e3a82dfa 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -66,7 +66,7 @@ class PdfMock $pdf_config->setPdfVariables(); $pdf_config->setCurrency(Currency::find($this->settings->currency_id)); $pdf_config->setCountry(Country::find($this->settings->country_id ?: 840)); - $pdf_config->currency_entity = $this->mock->client; + $pdf_config->currency_entity = $this->mock->client ?? $this->mock->vendor; if(isset($this->request['design_id']) && $design = Design::withTrashed()->find($this->request['design_id'])) { $pdf_config->design = $design; @@ -171,11 +171,11 @@ class PdfMock { $settings = $this->company->settings; - match ($this->request['settings_type']) { + match ($this->request['settings_type'] ?? '') { 'group' => $settings = ClientSettings::buildClientSettings($this->company->settings, $this->request['settings']), 'client' => $settings = ClientSettings::buildClientSettings($this->company->settings, $this->request['settings']), 'company' => $settings = (object)$this->request['settings'], - default => $settings = (object)$this->request['settings'], + default => $settings = (object)$this->company->settings, }; $settings = CompanySettings::setProperties($settings); diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index 4810c42dfa..1a890ec6e2 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -218,7 +218,7 @@ class TemplateService $tm = new TemplateMock($this->company); $tm->setSettings($this->getSettings())->init(); - $this->entity = $this->company->invoices()->first() ?? $this->company->quotes()->first(); + $this->entity = $this->company->invoices()->first() ?? $this->company->quotes()->first() ?? (new \App\Services\Pdf\PdfMock(['entity_type' => 'invoice'], $this->company))->initEntity(); $this->data = $tm->engines;