Place checks on quote 'isConvertable()'

This commit is contained in:
David Bomba 2020-05-27 14:54:47 +10:00
parent c72d38ca4f
commit 41b19c20c1
2 changed files with 14 additions and 2 deletions

View File

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

View File

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