Fixes for Quote PDF servicE

This commit is contained in:
David Bomba 2020-07-06 14:16:24 +10:00
parent d6b58fe5b8
commit 1deb503929
2 changed files with 53 additions and 3 deletions

View File

@ -0,0 +1,51 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Services\Quote;
use App\Jobs\Quote\CreateQuotePdf;
use App\Models\ClientContact;
use App\Models\Quote;
use App\Services\AbstractService;
use Illuminate\Support\Facades\Storage;
class GetQuotePdf extends AbstractService
{
public function __construct(Quote $quote, ClientContact $contact = null)
{
$this->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);
}
}

View File

@ -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