From ca591f4451561ed2e334dcae11332294874e926c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 15 Jan 2016 14:05:16 +1100 Subject: [PATCH 1/3] return archived invoice as success --- app/Http/Controllers/InvoiceApiController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 55ea492ddba7..a7131745efc7 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -276,10 +276,15 @@ class InvoiceApiController extends BaseAPIController 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(); From 12d34448081ee10331843c142bd45cd3f981e4de Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Jan 2016 09:22:22 +1100 Subject: [PATCH 2/3] By default include trashed invoices --- app/Http/Controllers/InvoiceApiController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index a7131745efc7..438dbd20b292 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -49,8 +49,8 @@ class InvoiceApiController extends BaseAPIController */ public function index() { - $paginator = Invoice::scope(); - $invoices = Invoice::scope() + $paginator = Invoice::scope()->withTrashed(); + $invoices = Invoice::scope()->withTrashed() ->with(array_merge(['invoice_items'], $this->getIncluded())); if ($clientPublicId = Input::get('client_id')) { From eeb977bab3f8cdb9d9bf6f918452ad2e2614f9f3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 16 Jan 2016 17:07:29 +1100 Subject: [PATCH 3/3] Added delete invoice functionality --- app/Http/Controllers/InvoiceApiController.php | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 438dbd20b292..52b1811ca21f 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -1,6 +1,7 @@ action == ACTION_ARCHIVE) { @@ -297,4 +318,41 @@ class InvoiceApiController extends BaseAPIController return $this->response($data); } + + /** + * @SWG\Delete( + * path="/invoices", + * tags={"invoice"}, + * summary="Delete an invoice", + * @SWG\Parameter( + * in="body", + * name="body", + * @SWG\Schema(ref="#/definitions/Invoice") + * ), + * @SWG\Response( + * response=200, + * description="Delete invoice", + * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice")) + * ), + * @SWG\Response( + * response="default", + * description="an ""unexpected"" error" + * ) + * ) + */ + + public function destroy($publicId) + { + $data['public_id'] = $publicId; + $invoice = Invoice::scope($publicId)->firstOrFail(); + + $this->invoiceRepo->delete($invoice); + + $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); + $data = $this->createItem($invoice, $transformer, 'invoice'); + + return $this->response($data); + + } + }