From 0ac1cfcb9cb49f4487e765bde8031bbbfe7ee60d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 8 Nov 2021 14:09:06 +1100 Subject: [PATCH] Fixes for Quote Templates --- app/Utils/TemplateEngine.php | 44 +++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index f5f7c1b3a9de..def0b1b1156a 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -16,6 +16,8 @@ use App\Models\Client; use App\Models\ClientContact; use App\Models\Invoice; use App\Models\InvoiceInvitation; +use App\Models\Quote; +use App\Models\QuoteInvitation; use App\Services\PdfMaker\Designs\Utilities\DesignHelpers; use App\Utils\Ninja; use App\Utils\Traits\MakesHash; @@ -254,18 +256,38 @@ class TemplateEngine 'send_email' => true, ]); - $this->entity_obj = Invoice::factory()->create([ - 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, - 'client_id' => $client->id, - ]); - $invitation = InvoiceInvitation::factory()->create([ - 'user_id' => auth()->user()->id, - 'company_id' => auth()->user()->company()->id, - 'invoice_id' => $this->entity_obj->id, - 'client_contact_id' => $contact->id, - ]); + if($this->entity == 'invoice') + { + $this->entity_obj = Invoice::factory()->create([ + 'user_id' => auth()->user()->id, + 'company_id' => auth()->user()->company()->id, + 'client_id' => $client->id, + ]); + + $invitation = InvoiceInvitation::factory()->create([ + 'user_id' => auth()->user()->id, + 'company_id' => auth()->user()->company()->id, + 'invoice_id' => $this->entity_obj->id, + 'client_contact_id' => $contact->id, + ]); + } + + if($this->entity == 'quote') + { + $this->entity_obj = Quote::factory()->create([ + 'user_id' => auth()->user()->id, + 'company_id' => auth()->user()->company()->id, + 'client_id' => $client->id, + ]); + + $invitation = QuoteInvitation::factory()->create([ + 'user_id' => auth()->user()->id, + 'company_id' => auth()->user()->company()->id, + 'quote_id' => $this->entity_obj->id, + 'client_contact_id' => $contact->id, + ]); + } $this->entity_obj->setRelation('invitations', $invitation); $this->entity_obj->setRelation('client', $client);