diff --git a/app/Services/Quote/GetQuotePdf.php b/app/Services/Quote/GetQuotePdf.php new file mode 100644 index 000000000000..92a46ef59983 --- /dev/null +++ b/app/Services/Quote/GetQuotePdf.php @@ -0,0 +1,51 @@ +quote = $quote; + + $this->contact = $contact; + } + + public function run() + { + if (!$this->contact) { + $this->contact = $this->quote->client->primary_contact()->first(); + } + + $invitation = $this->quote->invitations->where('client_contact_id', $this->contact->id)->first(); + + $path = $this->quote->client->invoice_filepath(); + + $file_path = $path . $this->quote->number . '.pdf'; + + $disk = config('filesystems.default'); + + $file = Storage::disk($disk)->exists($file_path); + + if (!$file) { + $file_path = CreateQuotePdf::dispatchNow($invitation); + } + + return Storage::disk($disk)->path($file_path); + } +} diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 71424e31c6b4..20f7f84e6f16 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -16,6 +16,7 @@ use App\Models\Invoice; use App\Models\Quote; use App\Repositories\QuoteRepository; use App\Services\Quote\CreateInvitations; +use App\Services\Quote\GetQuotePdf; class QuoteService { @@ -65,9 +66,7 @@ class QuoteService public function getQuotePdf($contact = null) { - $get_invoice_pdf = new GetQuotePdf(); - - return $get_invoice_pdf($this->quote, $contact); + return (new GetQuotePdf($this->quote, $contact))->run(); } public function sendEmail($contact = null) :QuoteService