diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index cf93c68c9915..d9e2d13d08e8 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -52,7 +52,7 @@ class ClientApiController extends BaseAPIController { $clients = Client::scope() ->with($this->getIncluded()) - ->orderBy('created_at', 'desc'); + ->orderBy('created_at', 'desc')->withTrashed(); // Filter by email if (Input::has('email')) { @@ -131,11 +131,23 @@ class ClientApiController extends BaseAPIController * ) */ - public function update(UpdateClientRequest $request) + public function update(UpdateClientRequest $request, $publicId) { - $client = $this->clientService->save($request->input()); + if ($request->action == ACTION_ARCHIVE) { + $client = Client::scope($publicId)->firstOrFail(); + $this->clientRepo->archive($client); - $client = Client::scope($client->public_id) + $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); + $data = $this->createItem($client, $transformer, ENTITY_CLIENT); + + return $this->response($data); + } + + $data = $request->input(); + $data['public_id'] = $publicId; + $this->clientRepo->save($data); + + $client = Client::scope($publicId) ->with('country', 'contacts', 'industry', 'size', 'currency') ->first(); diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 52b1811ca21f..b9b97835e68b 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -185,6 +185,10 @@ class InvoiceApiController extends BaseAPIController 'partial' => 0 ]; + if (!isset($data['invoice_status_id']) || $data['invoice_status_id'] == 0) { + $data['invoice_status_id'] = INVOICE_STATUS_DRAFT; + } + if (!isset($data['invoice_date'])) { $fields['invoice_date_sql'] = date_create()->format('Y-m-d'); } @@ -297,11 +301,16 @@ 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); + } + 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'); diff --git a/app/Http/routes.php b/app/Http/routes.php index f8f3c7526698..e4fbfc7a933f 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -333,6 +333,7 @@ if (!defined('CONTACT_EMAIL')) { define('ACTION_RESTORE', 'restore'); define('ACTION_ARCHIVE', 'archive'); + define('ACTION_CONVERT', 'convert'); define('ACTION_DELETE', 'delete'); define('ACTIVITY_TYPE_CREATE_CLIENT', 1); diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 9c1a6dcc0356..ffd27f1a9f14 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -244,6 +244,13 @@ class InvoiceRepository extends BaseRepository $invoice->invoice_date = Utils::toSqlDate($data['invoice_date']); } + if(isset($data['invoice_status_id'])) { + if($data['invoice_status_id'] == 0) { + $data['invoice_status_id'] = INVOICE_STATUS_DRAFT; + } + $invoice->invoice_status_id = $data['invoice_status_id']; + } + if ($invoice->is_recurring) { if ($invoice->start_date && $invoice->start_date != Utils::toSqlDate($data['start_date'])) { $invoice->last_sent_date = null;