diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 728eccc15c0d..840899a917e4 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -701,12 +701,9 @@ class InvoiceController extends BaseController break; case 'download': - $file = $invoice->service()->getInvoicePdf(); - $filename = $invoice->getFileName(); - - return response()->streamDownload(function () use ($file) { - echo $file; - }, $filename, ['Content-Type' => 'application/pdf']); + return response()->streamDownload(function () use ($invoice) { + echo $invoice->service()->getInvoicePdf(); + }, $invoice->getFileName(), ['Content-Type' => 'application/pdf']); case 'restore': $this->invoice_repo->restore($invoice); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 94f3218d73f8..0a85ec8e9463 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -720,11 +720,9 @@ class QuoteController extends BaseController break; case 'download': - $file = $quote->service()->getQuotePdf(); - - return response()->streamDownload(function () use ($file) { - echo $file; - }, $quote->numberFormatter().".pdf", ['Content-Type' => 'application/pdf']); + return response()->streamDownload(function () use ($quote) { + echo $quote->service()->getQuotePdf(); + }, $quote->getFileName(), ['Content-Type' => 'application/pdf']); case 'restore': $this->quote_repo->restore($quote); @@ -833,11 +831,9 @@ class QuoteController extends BaseController $headers = array_merge($headers, ['Content-Disposition' => 'inline']); } - $file = $quote->service()->getQuotePdf($contact); - - return response()->streamDownload(function () use ($file) { - echo $file; - }, $quote->numberFormatter().".pdf", $headers); + return response()->streamDownload(function () use ($quote,$contact) { + echo $quote->service()->getQuotePdf($contact); + }, $quote->getFileName(), $headers); } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 083115035696..8de87e02a2a5 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -249,7 +249,6 @@ class BaseModel extends Model return \Illuminate\Support\Str::ascii($formatted_number); - } /** diff --git a/tests/Integration/DownloadHistoricalInvoiceTest.php b/tests/Integration/DownloadHistoricalInvoiceTest.php index ca692976aade..2389b0206ae1 100644 --- a/tests/Integration/DownloadHistoricalInvoiceTest.php +++ b/tests/Integration/DownloadHistoricalInvoiceTest.php @@ -82,6 +82,34 @@ class DownloadHistoricalInvoiceTest extends TestCase } + public function testDownloadQuoteRoute() + { + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->get("/api/v1/quotes/{$this->quote->hashed_id}/download"); + + $response->assertStatus(200); + $response->assertDownload(); + + } + + public function testDownloadQuoteBulkActionRoute() + { + $data = [ + 'action' => 'download', + 'ids' => [$this->quote->hashed_id], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post("/api/v1/quotes/bulk", $data); + + $response->assertStatus(200); + + } private function mockActivity() {