diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index d9e2d13d08e8..4f4a6212d1e1 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -51,8 +51,8 @@ class ClientApiController extends BaseAPIController public function index() { $clients = Client::scope() - ->with($this->getIncluded()) - ->orderBy('created_at', 'desc')->withTrashed(); + ->with($this->getIncluded()) + ->orderBy('created_at', 'desc')->withTrashed(); // Filter by email if (Input::has('email')) { @@ -100,8 +100,8 @@ class ClientApiController extends BaseAPIController $client = $this->clientRepo->save($request->input()); $client = Client::scope($client->public_id) - ->with('country', 'contacts', 'industry', 'size', 'currency') - ->first(); + ->with('country', 'contacts', 'industry', 'size', 'currency') + ->first(); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); @@ -156,4 +156,7 @@ class ClientApiController extends BaseAPIController return $this->response($data); } + + + } diff --git a/app/Http/Controllers/PaymentApiController.php b/app/Http/Controllers/PaymentApiController.php index e52cc2807109..d6f623aab881 100644 --- a/app/Http/Controllers/PaymentApiController.php +++ b/app/Http/Controllers/PaymentApiController.php @@ -2,7 +2,7 @@ use App\Ninja\Mailers\ContactMailer; use Auth; -use Illuminate\Support\Facades\Log; +use Illuminate\Http\Request; use Input; use Utils; use Response; @@ -87,18 +87,31 @@ class PaymentApiController extends BaseAPIController * ) * ) */ - public function update($publicId) + + public function update(Request $request, $publicId) { $data = Input::all(); $data['public_id'] = $publicId; - $invoice = Invoice::scope($data['invoice_id'])->with('client')->first(); - $error = false; - $payment = $this->paymentRepo->save($data); + + if ($request->action == ACTION_ARCHIVE) { + $payment = Payment::scope($publicId)->firstOrFail(); + $this->paymentRepo->archive($payment); + + $invoice = Invoice::scope($data['invoice_id'])->with('client')->first(); + $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); + $data = $this->createItem($invoice, $transformer, 'invoice'); + + return $this->response($data); + } + + $this->paymentRepo->save($data); + if ($error) { return $error; } - $invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first(); + + $invoice = Invoice::scope($data['invoice_id'])->with('client', 'invoice_items', 'invitations','payments')->first(); $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); $data = $this->createItem($invoice, $transformer, 'invoice'); return $this->response($data); @@ -165,11 +178,44 @@ class PaymentApiController extends BaseAPIController */ $invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first(); - - $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); $data = $this->createItem($invoice, $transformer, 'invoice'); return $this->response($data); } + + /** + * @SWG\Delete( + * path="/payments/{payment_id}", + * summary="Delete a payment", + * tags={"payment"}, + * @SWG\Parameter( + * in="body", + * name="body", + * @SWG\Schema(ref="#/definitions/Payment") + * ), + * @SWG\Response( + * response=200, + * description="Delete payment", + * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment")) + * ), + * @SWG\Response( + * response="default", + * description="an ""unexpected"" error" + * ) + * ) + */ + + public function destroy($publicId) + { + $payment = Payment::scope($publicId)->withTrashed()->first(); + $invoice = Invoice::scope($payment->invoice->public_id)->first(); + + $this->paymentRepo->delete($payment); + + $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer')); + $data = $this->createItem($invoice, $transformer, 'invoice'); + + return $this->response($data); + } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e93c8d3b07f5..349b650e0f01 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -179,7 +179,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function payments() { - return $this->hasMany('App\Models\Payment', 'invoice_id', 'id'); + return $this->hasMany('App\Models\Payment', 'invoice_id', 'id')->withTrashed(); } public function recurring_invoice()