From b0d1b7e1a14509e530a5ccec85c7fd697a2b177a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 16 May 2021 16:26:55 +1000 Subject: [PATCH] Fixes for delivering PDFs over the wire --- app/Models/Credit.php | 12 ++++++++++-- app/Models/Invoice.php | 11 +++++++++-- app/Models/Quote.php | 11 +++++++++-- app/Services/Credit/CreateInvitations.php | 1 + app/Services/Invoice/GetInvoicePdf.php | 7 ------- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 50511b171834..242dabd24dbc 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -268,14 +268,22 @@ class Credit extends BaseModel throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?'); $file_path = $this->client->credit_filepath().$this->numberFormatter().'.pdf'; + + if(Ninja::isHosted() && $portal && Storage::disk(config('filesystems.default'))->exists($file_path)){ + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + elseif(Ninja::isHosted() && $portal){ + $file_path = CreateEntityPdf::dispatchNow($invitation,config('filesystems.default')); + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } if(Storage::disk('public')->exists($file_path)) return Storage::disk('public')->{$type}($file_path); $file_path = CreateEntityPdf::dispatchNow($invitation); - - return Storage::disk('public')->{$type}($file_path); + return Storage::disk('public')->{$type}($file_path); } + public function markInvitationsSent() { $this->invitations->each(function ($invitation) { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 34ad4c655da8..43f63cefc64c 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -409,13 +409,20 @@ class Invoice extends BaseModel throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?'); $file_path = $this->client->invoice_filepath().$this->numberFormatter().'.pdf'; + + if(Ninja::isHosted() && $portal && Storage::disk(config('filesystems.default'))->exists($file_path)){ + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + elseif(Ninja::isHosted() && $portal){ + $file_path = CreateEntityPdf::dispatchNow($invitation,config('filesystems.default')); + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } if(Storage::disk('public')->exists($file_path)) return Storage::disk('public')->{$type}($file_path); $file_path = CreateEntityPdf::dispatchNow($invitation); - - return Storage::disk('public')->{$type}($file_path); + return Storage::disk('public')->{$type}($file_path); } public function markInvitationsSent() diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 886b2e62b4fc..87f70d4a75c1 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -224,13 +224,20 @@ class Quote extends BaseModel throw new \Exception('Hard fail, could not create an invitation - is there a valid contact?'); $file_path = $this->client->quote_filepath().$this->numberFormatter().'.pdf'; + + if(Ninja::isHosted() && $portal && Storage::disk(config('filesystems.default'))->exists($file_path)){ + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } + elseif(Ninja::isHosted() && $portal){ + $file_path = CreateEntityPdf::dispatchNow($invitation,config('filesystems.default')); + return Storage::disk(config('filesystems.default'))->{$type}($file_path); + } if(Storage::disk('public')->exists($file_path)) return Storage::disk('public')->{$type}($file_path); $file_path = CreateEntityPdf::dispatchNow($invitation); - - return Storage::disk('public')->{$type}($file_path); + return Storage::disk('public')->{$type}($file_path); } /** diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index 2a819feb3f62..9ceaa7c19534 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -16,6 +16,7 @@ use App\Factory\CreditInvitationFactory; use App\Models\Credit; use App\Models\CreditInvitation; use App\Services\AbstractService; +use Illuminate\Support\Str; class CreateInvitations extends AbstractService { diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index e142f024e414..8d42aabfb6d0 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -41,19 +41,12 @@ class GetInvoicePdf extends AbstractService $disk = 'public'; - // $disk = config('filesystems.default'); - $file = Storage::disk($disk)->exists($file_path); if (! $file) { $file_path = CreateEntityPdf::dispatchNow($invitation); } - // /* Copy from remote disk to local when using cloud file storage. */ - // if(config('filesystems.default') == 's3') - // return TempFile::path(Storage::disk($disk)->url($file_path)); - - // return Storage::disk($disk)->url($file_path); return Storage::disk($disk)->path($file_path); } }