Inheritance: extends App\Http\Requests\InvoiceRequest
 /**
  * Update the specified resource in storage.
  *
  * @param  int      $id
  * @return Response
  */
 public function update(UpdateInvoiceRequest $request)
 {
     $data = $request->input();
     $data['documents'] = $request->file('documents');
     $action = Input::get('action');
     $entityType = Input::get('entityType');
     $invoice = $this->invoiceService->save($data, $request->entity());
     $entityType = $invoice->getEntityType();
     $message = trans("texts.updated_{$entityType}");
     Session::flash('message', $message);
     if ($action == 'clone') {
         return url(sprintf('%ss/%s/clone', $entityType, $invoice->public_id));
     } elseif ($action == 'convert') {
         return $this->convertQuote($request, $invoice->public_id);
     } elseif ($action == 'email') {
         $this->emailInvoice($invoice, Input::get('pdfupload'));
     }
     return url($invoice->getRoute());
 }
 /**
  * @SWG\Put(
  *   path="/invoices",
  *   tags={"invoice"},
  *   summary="Update an invoice",
  *   @SWG\Parameter(
  *     in="body",
  *     name="body",
  *     @SWG\Schema(ref="#/definitions/Invoice")
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="Update invoice",
  *      @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice"))
  *   ),
  *   @SWG\Response(
  *     response="default",
  *     description="an ""unexpected"" error"
  *   )
  * )
  */
 public function update(UpdateInvoiceRequest $request, $publicId)
 {
     if ($request->action == ACTION_ARCHIVE) {
         $invoice = Invoice::scope($publicId)->firstOrFail();
         $this->invoiceRepo->archive($invoice);
         /*
         $response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT);
         $headers = Utils::getApiHeaders();
         return Response::make($response, 200, $headers);
         */
         $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
         $data = $this->createItem($invoice, $transformer, 'invoice');
         return $this->response($data);
     }
     $data = $request->input();
     $data['public_id'] = $publicId;
     $this->invoiceRepo->save($data);
     $invoice = Invoice::scope($publicId)->with('client', 'invoice_items', 'invitations')->firstOrFail();
     $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
     $data = $this->createItem($invoice, $transformer, 'invoice');
     return $this->response($data);
 }
 /**
  * @SWG\Put(
  *   path="/invoices",
  *   tags={"invoice"},
  *   summary="Update an invoice",
  *   @SWG\Parameter(
  *     in="body",
  *     name="body",
  *     @SWG\Schema(ref="#/definitions/Invoice")
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="Update invoice",
  *      @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice"))
  *   ),
  *   @SWG\Response(
  *     response="default",
  *     description="an ""unexpected"" error"
  *   )
  * )
  */
 public function update(UpdateInvoiceRequest $request, $publicId)
 {
     if ($request->action == ACTION_ARCHIVE) {
         $invoice = Invoice::scope($publicId)->firstOrFail();
         $this->invoiceRepo->archive($invoice);
         $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
         $data = $this->createItem($invoice, $transformer, 'invoice');
         return $this->response($data);
     } else {
         if ($request->action == ACTION_CONVERT) {
             $quote = Invoice::scope($publicId)->firstOrFail();
             $invoice = $this->invoiceRepo->cloneInvoice($quote, $quote->id);
             $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
             $data = $this->createItem($invoice, $transformer, 'invoice');
             return $this->response($data);
         } else {
             if ($request->action == ACTION_RESTORE) {
                 $invoice = Invoice::scope($publicId)->withTrashed()->firstOrFail();
                 $this->invoiceRepo->restore($invoice);
                 $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
                 $data = $this->createItem($invoice, $transformer, 'invoice');
                 return $this->response($data);
             }
         }
     }
     $data = $request->input();
     $data['public_id'] = $publicId;
     $this->invoiceRepo->save($data);
     $invoice = Invoice::scope($publicId)->with('client', 'invoice_items', 'invitations')->firstOrFail();
     $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
     $data = $this->createItem($invoice, $transformer, 'invoice');
     return $this->response($data);
 }