diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 9ecc45ddc161..59e43a47009a 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 b9d9b0ebdc70..71424e31c6b4 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