diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index be17ba767b6a..9ecc45ddc161 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -528,6 +528,21 @@ class QuoteController extends BaseController return response()->json(['message' => 'Email Sent!'], 200); } + if($action == 'convert') { + + $this->entity_type = Invoice::class; + $this->entity_transformer = InvoiceTransformer::class; + + $invoices = $quotes->map(function ($quote, $key) use ($action) { + if (auth()->user()->can('edit', $quote)) { + $invoice = $quote->service()->convertToInvoice(); + return $invoice->id; + } + }); + + return $this->listResponse(Invoice::withTrashed()->whereIn('id', $invoices)->company()); + } + /* * Send the other actions to the switch */ @@ -642,14 +657,6 @@ class QuoteController extends BaseController } return $this->itemResponse($quote->service()->approve()->save()); - break; - case 'convert': - - $this->entity_type = Invoice::class; - $this->entity_transformer = InvoiceTransformer::class; - - return $this->itemResponse($quote->service()->convertToInvoice()); - break; case 'history': # code... diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 58b87dd265bc..9356721a8f87 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -134,12 +134,11 @@ class QuoteService $invoice->number = null; $invoice->save(); - $invoice->service() + return $invoice->service() ->markSent() ->createInvitations() ->save(); - return $invoice; } /**