From 41b19c20c181f80b1334c1c4f730214f429b3dbd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 May 2020 14:54:47 +1000 Subject: [PATCH] Place checks on quote 'isConvertable()' --- app/Http/Controllers/QuoteController.php | 2 +- app/Services/Quote/QuoteService.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 9ecc45ddc..59e43a470 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -534,7 +534,7 @@ class QuoteController extends BaseController $this->entity_transformer = InvoiceTransformer::class; $invoices = $quotes->map(function ($quote, $key) use ($action) { - if (auth()->user()->can('edit', $quote)) { + if (auth()->user()->can('edit', $quote) && $quote->service()->isConvertable()) { $invoice = $quote->service()->convertToInvoice(); return $invoice->id; } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index b9d9b0ebd..71424e31c 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -55,6 +55,7 @@ class QuoteService return $this; $convert_quote = new ConvertQuote($this->quote->client); + $this->invoice = $convert_quote->run($this->quote); $this->quote->fresh(); @@ -125,7 +126,7 @@ class QuoteService return $this; } - public function convertToInvoice() :Invoice + public function convertToInvoice() { //to prevent circular references we need to explicit call this here. @@ -137,6 +138,17 @@ class QuoteService return $this->invoice; } + public function isConvertable() :bool + { + if($this->quote->invoice_id) + return false; + + if($this->quote->status_id == Quote::STATUS_EXPIRED) + return false; + + return true; + } + /** * Saves the quote * @return Quote|null